Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
apollo
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
apollo
Commits
3f428211
Commit
3f428211
authored
Sep 09, 2018
by
nobodyiam
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add removeChangeListener api
parent
ee4cfccc
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
71 additions
and
0 deletions
+71
-0
apollo-client/src/main/java/com/ctrip/framework/apollo/Config.java
...ient/src/main/java/com/ctrip/framework/apollo/Config.java
+8
-0
apollo-client/src/main/java/com/ctrip/framework/apollo/internals/AbstractConfig.java
.../com/ctrip/framework/apollo/internals/AbstractConfig.java
+6
-0
apollo-client/src/test/java/com/ctrip/framework/apollo/internals/DefaultConfigTest.java
...m/ctrip/framework/apollo/internals/DefaultConfigTest.java
+57
-0
No files found.
apollo-client/src/main/java/com/ctrip/framework/apollo/Config.java
View file @
3f428211
...
@@ -178,6 +178,14 @@ public interface Config {
...
@@ -178,6 +178,14 @@ public interface Config {
*/
*/
public
void
addChangeListener
(
ConfigChangeListener
listener
,
Set
<
String
>
interestedKeys
);
public
void
addChangeListener
(
ConfigChangeListener
listener
,
Set
<
String
>
interestedKeys
);
/**
* Remove the change listener
*
* @param listener the specific config change listener to remove
* @return true if the specific config change listener is found and removed
*/
public
boolean
removeChangeListener
(
ConfigChangeListener
listener
);
/**
/**
* Return a set of the property names
* Return a set of the property names
*
*
...
...
apollo-client/src/main/java/com/ctrip/framework/apollo/internals/AbstractConfig.java
View file @
3f428211
...
@@ -85,6 +85,12 @@ public abstract class AbstractConfig implements Config {
...
@@ -85,6 +85,12 @@ public abstract class AbstractConfig implements Config {
}
}
}
}
@Override
public
boolean
removeChangeListener
(
ConfigChangeListener
listener
)
{
m_interestedKeys
.
remove
(
listener
);
return
m_listeners
.
remove
(
listener
);
}
@Override
@Override
public
Integer
getIntProperty
(
String
key
,
Integer
defaultValue
)
{
public
Integer
getIntProperty
(
String
key
,
Integer
defaultValue
)
{
try
{
try
{
...
...
apollo-client/src/test/java/com/ctrip/framework/apollo/internals/DefaultConfigTest.java
View file @
3f428211
...
@@ -3,6 +3,7 @@ package com.ctrip.framework.apollo.internals;
...
@@ -3,6 +3,7 @@ package com.ctrip.framework.apollo.internals;
import
static
org
.
junit
.
Assert
.
assertArrayEquals
;
import
static
org
.
junit
.
Assert
.
assertArrayEquals
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
times
;
import
static
org
.
mockito
.
Mockito
.
times
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
verify
;
...
@@ -705,6 +706,62 @@ public class DefaultConfigTest {
...
@@ -705,6 +706,62 @@ public class DefaultConfigTest {
assertFalse
(
interestedInSomeKeyNotChangedFuture
.
isDone
());
assertFalse
(
interestedInSomeKeyNotChangedFuture
.
isDone
());
}
}
@Test
public
void
testRemoveChangeListener
()
throws
Exception
{
String
someNamespace
=
"someNamespace"
;
final
ConfigChangeEvent
someConfigChangEvent
=
mock
(
ConfigChangeEvent
.
class
);
ConfigChangeEvent
anotherConfigChangEvent
=
mock
(
ConfigChangeEvent
.
class
);
final
SettableFuture
<
ConfigChangeEvent
>
someListenerFuture1
=
SettableFuture
.
create
();
final
SettableFuture
<
ConfigChangeEvent
>
someListenerFuture2
=
SettableFuture
.
create
();
ConfigChangeListener
someListener
=
new
ConfigChangeListener
()
{
@Override
public
void
onChange
(
ConfigChangeEvent
changeEvent
)
{
if
(
someConfigChangEvent
==
changeEvent
)
{
someListenerFuture1
.
set
(
changeEvent
);
}
else
{
someListenerFuture2
.
set
(
changeEvent
);
}
}
};
final
SettableFuture
<
ConfigChangeEvent
>
anotherListenerFuture1
=
SettableFuture
.
create
();
final
SettableFuture
<
ConfigChangeEvent
>
anotherListenerFuture2
=
SettableFuture
.
create
();
ConfigChangeListener
anotherListener
=
new
ConfigChangeListener
()
{
@Override
public
void
onChange
(
ConfigChangeEvent
changeEvent
)
{
if
(
someConfigChangEvent
==
changeEvent
)
{
anotherListenerFuture1
.
set
(
changeEvent
);
}
else
{
anotherListenerFuture2
.
set
(
changeEvent
);
}
}
};
ConfigChangeListener
yetAnotherListener
=
mock
(
ConfigChangeListener
.
class
);
DefaultConfig
config
=
new
DefaultConfig
(
someNamespace
,
mock
(
ConfigRepository
.
class
));
config
.
addChangeListener
(
someListener
);
config
.
addChangeListener
(
anotherListener
);
config
.
fireConfigChange
(
someConfigChangEvent
);
assertEquals
(
someConfigChangEvent
,
someListenerFuture1
.
get
(
500
,
TimeUnit
.
MILLISECONDS
));
assertEquals
(
someConfigChangEvent
,
anotherListenerFuture1
.
get
(
500
,
TimeUnit
.
MILLISECONDS
));
assertFalse
(
config
.
removeChangeListener
(
yetAnotherListener
));
assertTrue
(
config
.
removeChangeListener
(
someListener
));
config
.
fireConfigChange
(
anotherConfigChangEvent
);
assertEquals
(
anotherConfigChangEvent
,
anotherListenerFuture2
.
get
(
500
,
TimeUnit
.
MILLISECONDS
));
TimeUnit
.
MILLISECONDS
.
sleep
(
100
);
assertFalse
(
someListenerFuture2
.
isDone
());
}
@Test
@Test
public
void
testGetPropertyNames
()
{
public
void
testGetPropertyNames
()
{
String
someKeyPrefix
=
"someKey"
;
String
someKeyPrefix
=
"someKey"
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment