use of com.ctrip.framework.apollo.biz.entity.ReleaseMessage in project apollo by ctripcorp.
the class ConfigServiceWithCacheTest method testFindLatestActiveReleaseWithReleaseMessageNotification.
@Test
public void testFindLatestActiveReleaseWithReleaseMessageNotification() throws Exception {
long someNewNotificationId = someNotificationId + 1;
ReleaseMessage anotherReleaseMessage = mock(ReleaseMessage.class);
Release anotherRelease = mock(Release.class);
when(releaseMessageService.findLatestReleaseMessageForMessages(Lists.newArrayList(someKey))).thenReturn(someReleaseMessage);
when(releaseService.findLatestActiveRelease(someAppId, someClusterName, someNamespaceName)).thenReturn(someRelease);
when(someReleaseMessage.getId()).thenReturn(someNotificationId);
Release release = configServiceWithCache.findLatestActiveRelease(someAppId, someClusterName, someNamespaceName, someNotificationMessages);
when(releaseMessageService.findLatestReleaseMessageForMessages(Lists.newArrayList(someKey))).thenReturn(anotherReleaseMessage);
when(releaseService.findLatestActiveRelease(someAppId, someClusterName, someNamespaceName)).thenReturn(anotherRelease);
when(anotherReleaseMessage.getMessage()).thenReturn(someKey);
when(anotherReleaseMessage.getId()).thenReturn(someNewNotificationId);
Release stillOldRelease = configServiceWithCache.findLatestActiveRelease(someAppId, someClusterName, someNamespaceName, someNotificationMessages);
configServiceWithCache.handleMessage(anotherReleaseMessage, Topics.APOLLO_RELEASE_TOPIC);
Release shouldBeNewRelease = configServiceWithCache.findLatestActiveRelease(someAppId, someClusterName, someNamespaceName, someNotificationMessages);
assertEquals(someRelease, release);
assertEquals(someRelease, stillOldRelease);
assertEquals(anotherRelease, shouldBeNewRelease);
verify(releaseMessageService, times(2)).findLatestReleaseMessageForMessages(Lists.newArrayList(someKey));
verify(releaseService, times(2)).findLatestActiveRelease(someAppId, someClusterName, someNamespaceName);
}
use of com.ctrip.framework.apollo.biz.entity.ReleaseMessage in project apollo by ctripcorp.
the class ConfigServiceWithCacheTest method testFindLatestActiveReleaseWithDirtyRelease.
@Test
public void testFindLatestActiveReleaseWithDirtyRelease() throws Exception {
long someNewNotificationId = someNotificationId + 1;
ReleaseMessage anotherReleaseMessage = mock(ReleaseMessage.class);
Release anotherRelease = mock(Release.class);
when(releaseMessageService.findLatestReleaseMessageForMessages(Lists.newArrayList(someKey))).thenReturn(someReleaseMessage);
when(releaseService.findLatestActiveRelease(someAppId, someClusterName, someNamespaceName)).thenReturn(someRelease);
when(someReleaseMessage.getId()).thenReturn(someNotificationId);
Release release = configServiceWithCache.findLatestActiveRelease(someAppId, someClusterName, someNamespaceName, someNotificationMessages);
when(releaseMessageService.findLatestReleaseMessageForMessages(Lists.newArrayList(someKey))).thenReturn(anotherReleaseMessage);
when(releaseService.findLatestActiveRelease(someAppId, someClusterName, someNamespaceName)).thenReturn(anotherRelease);
when(anotherReleaseMessage.getId()).thenReturn(someNewNotificationId);
Release stillOldRelease = configServiceWithCache.findLatestActiveRelease(someAppId, someClusterName, someNamespaceName, someNotificationMessages);
someNotificationMessages.put(someKey, someNewNotificationId);
Release shouldBeNewRelease = configServiceWithCache.findLatestActiveRelease(someAppId, someClusterName, someNamespaceName, someNotificationMessages);
assertEquals(someRelease, release);
assertEquals(someRelease, stillOldRelease);
assertEquals(anotherRelease, shouldBeNewRelease);
verify(releaseMessageService, times(2)).findLatestReleaseMessageForMessages(Lists.newArrayList(someKey));
verify(releaseService, times(2)).findLatestActiveRelease(someAppId, someClusterName, someNamespaceName);
}
use of com.ctrip.framework.apollo.biz.entity.ReleaseMessage 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.biz.entity.ReleaseMessage 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.biz.entity.ReleaseMessage in project apollo by ctripcorp.
the class AbstractBaseIntegrationTest method sendReleaseMessage.
protected void sendReleaseMessage(String message) {
ReleaseMessage releaseMessage = new ReleaseMessage(message);
releaseMessageRepository.save(releaseMessage);
}
Aggregations