use of com.ctrip.framework.apollo.core.dto.ApolloNotificationMessages in project apollo by ctripcorp.
the class NotificationControllerV2Test method testPollNotificationWithMultipleNamespaceWithNotificationIdOutDated.
@Test
public void testPollNotificationWithMultipleNamespaceWithNotificationIdOutDated() throws Exception {
String someWatchKey = "someKey";
String anotherWatchKey = Joiner.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR).join(someAppId, someCluster, somePublicNamespace);
String yetAnotherWatchKey = Joiner.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR).join(someAppId, defaultCluster, somePublicNamespace);
long notificationId = someNotificationId + 1;
long yetAnotherNotificationId = someNotificationId;
Multimap<String, String> watchKeysMap = assembleMultiMap(defaultNamespace, Lists.newArrayList(someWatchKey));
watchKeysMap.putAll(assembleMultiMap(somePublicNamespace, Lists.newArrayList(anotherWatchKey, yetAnotherWatchKey)));
when(watchKeysUtil.assembleAllWatchKeys(someAppId, someCluster, Sets.newHashSet(defaultNamespace, somePublicNamespace), someDataCenter)).thenReturn(watchKeysMap);
ReleaseMessage someReleaseMessage = mock(ReleaseMessage.class);
when(someReleaseMessage.getId()).thenReturn(notificationId);
when(someReleaseMessage.getMessage()).thenReturn(anotherWatchKey);
ReleaseMessage yetAnotherReleaseMessage = mock(ReleaseMessage.class);
when(yetAnotherReleaseMessage.getId()).thenReturn(yetAnotherNotificationId);
when(yetAnotherReleaseMessage.getMessage()).thenReturn(yetAnotherWatchKey);
when(releaseMessageService.findLatestReleaseMessagesGroupByMessages(Sets.newHashSet(watchKeysMap.values()))).thenReturn(Lists.newArrayList(someReleaseMessage, yetAnotherReleaseMessage));
String notificationAsString = transformApolloConfigNotificationsToString(defaultNamespace, someNotificationId, somePublicNamespace, someNotificationId);
DeferredResult<ResponseEntity<List<ApolloConfigNotification>>> deferredResult = controller.pollNotification(someAppId, someCluster, notificationAsString, someDataCenter, someClientIp);
ResponseEntity<List<ApolloConfigNotification>> result = (ResponseEntity<List<ApolloConfigNotification>>) deferredResult.getResult();
assertEquals(HttpStatus.OK, result.getStatusCode());
assertEquals(1, result.getBody().size());
assertEquals(somePublicNamespace, result.getBody().get(0).getNamespaceName());
assertEquals(notificationId, result.getBody().get(0).getNotificationId());
ApolloNotificationMessages notificationMessages = result.getBody().get(0).getMessages();
assertEquals(2, notificationMessages.getDetails().size());
assertEquals(notificationId, notificationMessages.get(anotherWatchKey).longValue());
assertEquals(yetAnotherNotificationId, notificationMessages.get(yetAnotherWatchKey).longValue());
}
use of com.ctrip.framework.apollo.core.dto.ApolloNotificationMessages in project apollo by ctripcorp.
the class NotificationControllerV2Test method testPollNotificationWithMultipleNamespacesAndHandleMessage.
@Test
public void testPollNotificationWithMultipleNamespacesAndHandleMessage() throws Exception {
String someWatchKey = "someKey";
String anotherWatchKey = Joiner.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR).join(someAppId, someCluster, somePublicNamespace);
Multimap<String, String> watchKeysMap = assembleMultiMap(defaultNamespace, Lists.newArrayList(someWatchKey));
watchKeysMap.putAll(assembleMultiMap(somePublicNamespace, Lists.newArrayList(anotherWatchKey)));
when(watchKeysUtil.assembleAllWatchKeys(someAppId, someCluster, Sets.newHashSet(defaultNamespace, somePublicNamespace), someDataCenter)).thenReturn(watchKeysMap);
String notificationAsString = transformApolloConfigNotificationsToString(defaultNamespace, someNotificationId, somePublicNamespace, someNotificationId);
DeferredResult<ResponseEntity<List<ApolloConfigNotification>>> deferredResult = controller.pollNotification(someAppId, someCluster, notificationAsString, someDataCenter, someClientIp);
assertEquals(watchKeysMap.size(), deferredResults.size());
long someId = 1;
ReleaseMessage someReleaseMessage = new ReleaseMessage(anotherWatchKey);
someReleaseMessage.setId(someId);
controller.handleMessage(someReleaseMessage, Topics.APOLLO_RELEASE_TOPIC);
ResponseEntity<List<ApolloConfigNotification>> response = (ResponseEntity<List<ApolloConfigNotification>>) deferredResult.getResult();
assertEquals(1, response.getBody().size());
ApolloConfigNotification notification = response.getBody().get(0);
assertEquals(HttpStatus.OK, response.getStatusCode());
assertEquals(somePublicNamespace, notification.getNamespaceName());
assertEquals(someId, notification.getNotificationId());
ApolloNotificationMessages notificationMessages = response.getBody().get(0).getMessages();
assertEquals(1, notificationMessages.getDetails().size());
assertEquals(someId, notificationMessages.get(anotherWatchKey).longValue());
}
use of com.ctrip.framework.apollo.core.dto.ApolloNotificationMessages in project apollo by ctripcorp.
the class RemoteConfigLongPollServiceTest method testSubmitLongPollNamespaceWithMessagesUpdated.
@Test
public void testSubmitLongPollNamespaceWithMessagesUpdated() throws Exception {
RemoteConfigRepository someRepository = mock(RemoteConfigRepository.class);
final String someNamespace = "someNamespace";
ApolloNotificationMessages notificationMessages = new ApolloNotificationMessages();
String someKey = "someKey";
long someNotificationId = 1;
notificationMessages.put(someKey, someNotificationId);
ApolloConfigNotification someNotification = mock(ApolloConfigNotification.class);
when(someNotification.getNamespaceName()).thenReturn(someNamespace);
when(someNotification.getMessages()).thenReturn(notificationMessages);
when(pollResponse.getStatusCode()).thenReturn(HttpServletResponse.SC_OK);
when(pollResponse.getBody()).thenReturn(Lists.newArrayList(someNotification));
doAnswer(new Answer<HttpResponse<List<ApolloConfigNotification>>>() {
@Override
public HttpResponse<List<ApolloConfigNotification>> answer(InvocationOnMock invocation) throws Throwable {
try {
TimeUnit.MILLISECONDS.sleep(50);
} catch (InterruptedException e) {
}
return pollResponse;
}
}).when(httpClient).doGet(any(HttpRequest.class), eq(responseType));
final SettableFuture<Boolean> onNotified = SettableFuture.create();
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
onNotified.set(true);
return null;
}
}).when(someRepository).onLongPollNotified(any(ServiceDTO.class), any(ApolloNotificationMessages.class));
remoteConfigLongPollService.submit(someNamespace, someRepository);
onNotified.get(5000, TimeUnit.MILLISECONDS);
// reset to 304
when(pollResponse.getStatusCode()).thenReturn(HttpServletResponse.SC_NOT_MODIFIED);
final ArgumentCaptor<ApolloNotificationMessages> captor = ArgumentCaptor.forClass(ApolloNotificationMessages.class);
verify(someRepository, times(1)).onLongPollNotified(any(ServiceDTO.class), captor.capture());
ApolloNotificationMessages captured = captor.getValue();
assertEquals(1, captured.getDetails().size());
assertEquals(someNotificationId, captured.get(someKey).longValue());
final SettableFuture<Boolean> anotherOnNotified = SettableFuture.create();
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
anotherOnNotified.set(true);
return null;
}
}).when(someRepository).onLongPollNotified(any(ServiceDTO.class), any(ApolloNotificationMessages.class));
String anotherKey = "anotherKey";
long anotherNotificationId = 2;
notificationMessages.put(anotherKey, anotherNotificationId);
// send notifications
when(pollResponse.getStatusCode()).thenReturn(HttpServletResponse.SC_OK);
anotherOnNotified.get(5000, TimeUnit.MILLISECONDS);
remoteConfigLongPollService.stopLongPollingRefresh();
verify(someRepository, times(2)).onLongPollNotified(any(ServiceDTO.class), captor.capture());
captured = captor.getValue();
assertEquals(2, captured.getDetails().size());
assertEquals(someNotificationId, captured.get(someKey).longValue());
assertEquals(anotherNotificationId, captured.get(anotherKey).longValue());
}
use of com.ctrip.framework.apollo.core.dto.ApolloNotificationMessages in project apollo by ctripcorp.
the class RemoteConfigRepositoryTest method testAssembleQueryConfigUrl.
@Test
public void testAssembleQueryConfigUrl() throws Exception {
Gson gson = new Gson();
String someUri = "http://someServer";
String someAppId = "someAppId";
String someCluster = "someCluster+ &.-_someSign";
String someReleaseKey = "20160705193346-583078ef5716c055+20160705193308-31c471ddf9087c3f";
ApolloNotificationMessages notificationMessages = new ApolloNotificationMessages();
String someKey = "someKey";
long someNotificationId = 1;
String anotherKey = "anotherKey";
long anotherNotificationId = 2;
notificationMessages.put(someKey, someNotificationId);
notificationMessages.put(anotherKey, anotherNotificationId);
RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someNamespace);
ApolloConfig someApolloConfig = mock(ApolloConfig.class);
when(someApolloConfig.getReleaseKey()).thenReturn(someReleaseKey);
String queryConfigUrl = remoteConfigRepository.assembleQueryConfigUrl(someUri, someAppId, someCluster, someNamespace, null, notificationMessages, someApolloConfig);
remoteConfigLongPollService.stopLongPollingRefresh();
assertTrue(queryConfigUrl.contains("http://someServer/configs/someAppId/someCluster+%20&.-_someSign/" + someNamespace));
assertTrue(queryConfigUrl.contains("releaseKey=20160705193346-583078ef5716c055%2B20160705193308-31c471ddf9087c3f"));
assertTrue(queryConfigUrl.contains("messages=" + UrlEscapers.urlFormParameterEscaper().escape(gson.toJson(notificationMessages))));
}
use of com.ctrip.framework.apollo.core.dto.ApolloNotificationMessages in project apollo by ctripcorp.
the class NotificationControllerV2IntegrationTest method testPollNotificationWithMultiplePublicNamespaceWithIncorrectCase4WithNotificationIdOutDated.
@Test(timeout = 5000L)
@Sql(scripts = "/integration-test/test-release.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/integration-test/test-release-message.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testPollNotificationWithMultiplePublicNamespaceWithIncorrectCase4WithNotificationIdOutDated() throws Exception {
String publicAppId = "somePublicAppId";
long someOutDatedNotificationId = 1;
long newNotificationId = 20;
String somePublicNameWithIncorrectCase = somePublicNamespace.toUpperCase();
// the same namespace with difference character case, and difference notification id
ResponseEntity<List<ApolloConfigNotification>> result = restTemplate.exchange("http://{baseurl}/notifications/v2?appId={appId}&cluster={clusterName}¬ifications={notifications}", HttpMethod.GET, null, typeReference, getHostUrl(), someAppId, someCluster, transformApolloConfigNotificationsToString(somePublicNamespace, someOutDatedNotificationId, somePublicNameWithIncorrectCase, newNotificationId));
List<ApolloConfigNotification> notifications = result.getBody();
assertEquals(HttpStatus.OK, result.getStatusCode());
assertEquals(1, notifications.size());
assertEquals(somePublicNamespace, notifications.get(0).getNamespaceName());
assertEquals(newNotificationId, notifications.get(0).getNotificationId());
String key = assembleKey(publicAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, somePublicNamespace);
ApolloNotificationMessages messages = result.getBody().get(0).getMessages();
assertEquals(1, messages.getDetails().size());
assertTrue(messages.has(key));
assertEquals(newNotificationId, messages.get(key).longValue());
}
Aggregations