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
d6a85e18
Commit
d6a85e18
authored
Oct 31, 2019
by
Zhuohao Li
Committed by
Jared Tan
Oct 31, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix #2092. (#2696)
* fix #2092. * fix #2092. * change to Integer.compare. * code clean. * code clean.
parent
76ac64b5
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
2 deletions
+42
-2
apollo-configservice/src/main/java/com/ctrip/framework/apollo/configservice/controller/NotificationControllerV2.java
...lo/configservice/controller/NotificationControllerV2.java
+3
-1
apollo-configservice/src/main/java/com/ctrip/framework/apollo/configservice/wrapper/DeferredResultWrapper.java
...k/apollo/configservice/wrapper/DeferredResultWrapper.java
+7
-1
apollo-configservice/src/test/java/com/ctrip/framework/apollo/configservice/controller/NotificationControllerV2Test.java
...onfigservice/controller/NotificationControllerV2Test.java
+32
-0
No files found.
apollo-configservice/src/main/java/com/ctrip/framework/apollo/configservice/controller/NotificationControllerV2.java
View file @
d6a85e18
...
@@ -21,7 +21,9 @@ import com.google.common.collect.Lists;
...
@@ -21,7 +21,9 @@ import com.google.common.collect.Lists;
import
com.google.common.collect.Maps
;
import
com.google.common.collect.Maps
;
import
com.google.common.collect.Multimap
;
import
com.google.common.collect.Multimap
;
import
com.google.common.collect.Multimaps
;
import
com.google.common.collect.Multimaps
;
import
com.google.common.collect.Ordering
;
import
com.google.common.collect.Sets
;
import
com.google.common.collect.Sets
;
import
com.google.common.collect.TreeMultimap
;
import
com.google.gson.Gson
;
import
com.google.gson.Gson
;
import
com.google.gson.reflect.TypeToken
;
import
com.google.gson.reflect.TypeToken
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
...
@@ -54,7 +56,7 @@ import java.util.function.Function;
...
@@ -54,7 +56,7 @@ import java.util.function.Function;
public
class
NotificationControllerV2
implements
ReleaseMessageListener
{
public
class
NotificationControllerV2
implements
ReleaseMessageListener
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
NotificationControllerV2
.
class
);
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
NotificationControllerV2
.
class
);
private
final
Multimap
<
String
,
DeferredResultWrapper
>
deferredResults
=
private
final
Multimap
<
String
,
DeferredResultWrapper
>
deferredResults
=
Multimaps
.
synchronizedSetMultimap
(
HashMultimap
.
create
(
));
Multimaps
.
synchronizedSetMultimap
(
TreeMultimap
.
create
(
String
.
CASE_INSENSITIVE_ORDER
,
Ordering
.
natural
()
));
private
static
final
Splitter
STRING_SPLITTER
=
private
static
final
Splitter
STRING_SPLITTER
=
Splitter
.
on
(
ConfigConsts
.
CLUSTER_NAMESPACE_SEPARATOR
).
omitEmptyStrings
();
Splitter
.
on
(
ConfigConsts
.
CLUSTER_NAMESPACE_SEPARATOR
).
omitEmptyStrings
();
private
static
final
Type
notificationsTypeReference
=
private
static
final
Type
notificationsTypeReference
=
...
...
apollo-configservice/src/main/java/com/ctrip/framework/apollo/configservice/wrapper/DeferredResultWrapper.java
View file @
d6a85e18
...
@@ -7,6 +7,7 @@ import com.ctrip.framework.apollo.core.dto.ApolloConfigNotification;
...
@@ -7,6 +7,7 @@ import com.ctrip.framework.apollo.core.dto.ApolloConfigNotification;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.lang.NonNull
;
import
org.springframework.web.context.request.async.DeferredResult
;
import
org.springframework.web.context.request.async.DeferredResult
;
import
java.util.List
;
import
java.util.List
;
...
@@ -15,7 +16,7 @@ import java.util.Map;
...
@@ -15,7 +16,7 @@ import java.util.Map;
/**
/**
* @author Jason Song(song_s@ctrip.com)
* @author Jason Song(song_s@ctrip.com)
*/
*/
public
class
DeferredResultWrapper
{
public
class
DeferredResultWrapper
implements
Comparable
<
DeferredResultWrapper
>
{
private
static
final
ResponseEntity
<
List
<
ApolloConfigNotification
>>
private
static
final
ResponseEntity
<
List
<
ApolloConfigNotification
>>
NOT_MODIFIED_RESPONSE_LIST
=
new
ResponseEntity
<>(
HttpStatus
.
NOT_MODIFIED
);
NOT_MODIFIED_RESPONSE_LIST
=
new
ResponseEntity
<>(
HttpStatus
.
NOT_MODIFIED
);
...
@@ -64,4 +65,9 @@ public class DeferredResultWrapper {
...
@@ -64,4 +65,9 @@ public class DeferredResultWrapper {
public
DeferredResult
<
ResponseEntity
<
List
<
ApolloConfigNotification
>>>
getResult
()
{
public
DeferredResult
<
ResponseEntity
<
List
<
ApolloConfigNotification
>>>
getResult
()
{
return
result
;
return
result
;
}
}
@Override
public
int
compareTo
(
@NonNull
DeferredResultWrapper
deferredResultWrapper
)
{
return
Integer
.
compare
(
this
.
hashCode
(),
deferredResultWrapper
.
hashCode
());
}
}
}
apollo-configservice/src/test/java/com/ctrip/framework/apollo/configservice/controller/NotificationControllerV2Test.java
View file @
d6a85e18
...
@@ -340,6 +340,38 @@ public class NotificationControllerV2Test {
...
@@ -340,6 +340,38 @@ public class NotificationControllerV2Test {
assertTrue
(
deferredResult
.
hasResult
()
&&
anotherDeferredResult
.
hasResult
());
assertTrue
(
deferredResult
.
hasResult
()
&&
anotherDeferredResult
.
hasResult
());
}
}
@Test
public
void
testPollNotificationWithCaseInsensitiveAppId
()
throws
Exception
{
String
someWatchKey
=
Joiner
.
on
(
ConfigConsts
.
CLUSTER_NAMESPACE_SEPARATOR
)
.
join
(
someAppId
,
someCluster
,
defaultNamespace
);
String
anotherWatchKey
=
Joiner
.
on
(
ConfigConsts
.
CLUSTER_NAMESPACE_SEPARATOR
)
.
join
(
"someAPPID"
,
someCluster
,
defaultNamespace
);
Multimap
<
String
,
String
>
watchKeysMap
=
assembleMultiMap
(
defaultNamespace
,
Lists
.
newArrayList
(
someWatchKey
));
String
notificationAsString
=
transformApolloConfigNotificationsToString
(
defaultNamespace
,
someNotificationId
);
when
(
watchKeysUtil
.
assembleAllWatchKeys
(
someAppId
,
someCluster
,
Sets
.
newHashSet
(
defaultNamespace
),
someDataCenter
)).
thenReturn
(
watchKeysMap
);
DeferredResult
<
ResponseEntity
<
List
<
ApolloConfigNotification
>>>
deferredResult
=
controller
.
pollNotification
(
someAppId
,
someCluster
,
notificationAsString
,
someDataCenter
,
someClientIp
);
long
someId
=
1
;
ReleaseMessage
someReleaseMessage
=
new
ReleaseMessage
(
anotherWatchKey
);
someReleaseMessage
.
setId
(
someId
);
controller
.
handleMessage
(
someReleaseMessage
,
Topics
.
APOLLO_RELEASE_TOPIC
);
//now both of them should have result
assertTrue
(
deferredResult
.
hasResult
());
}
private
String
transformApolloConfigNotificationsToString
(
private
String
transformApolloConfigNotificationsToString
(
String
namespace
,
long
notificationId
)
{
String
namespace
,
long
notificationId
)
{
List
<
ApolloConfigNotification
>
notifications
=
List
<
ApolloConfigNotification
>
notifications
=
...
...
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