Search in sources :

Example 6 with ReleaseMessage

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);
}
Also used : ReleaseMessage(com.ctrip.framework.apollo.biz.entity.ReleaseMessage) Release(com.ctrip.framework.apollo.biz.entity.Release) Test(org.junit.Test)

Example 7 with ReleaseMessage

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);
}
Also used : ReleaseMessage(com.ctrip.framework.apollo.biz.entity.ReleaseMessage) Release(com.ctrip.framework.apollo.biz.entity.Release) Test(org.junit.Test)

Example 8 with ReleaseMessage

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());
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ReleaseMessage(com.ctrip.framework.apollo.biz.entity.ReleaseMessage) ApolloNotificationMessages(com.ctrip.framework.apollo.core.dto.ApolloNotificationMessages) ApolloConfigNotification(com.ctrip.framework.apollo.core.dto.ApolloConfigNotification) List(java.util.List) Test(org.junit.Test)

Example 9 with ReleaseMessage

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());
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ReleaseMessage(com.ctrip.framework.apollo.biz.entity.ReleaseMessage) ApolloNotificationMessages(com.ctrip.framework.apollo.core.dto.ApolloNotificationMessages) ApolloConfigNotification(com.ctrip.framework.apollo.core.dto.ApolloConfigNotification) List(java.util.List) Test(org.junit.Test)

Example 10 with ReleaseMessage

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);
}
Also used : ReleaseMessage(com.ctrip.framework.apollo.biz.entity.ReleaseMessage)

Aggregations

ReleaseMessage (com.ctrip.framework.apollo.biz.entity.ReleaseMessage)30 Test (org.junit.Test)16 ApolloConfigNotification (com.ctrip.framework.apollo.core.dto.ApolloConfigNotification)9 ResponseEntity (org.springframework.http.ResponseEntity)7 AbstractUnitTest (com.ctrip.framework.apollo.biz.AbstractUnitTest)3 Release (com.ctrip.framework.apollo.biz.entity.Release)3 ApolloNotificationMessages (com.ctrip.framework.apollo.core.dto.ApolloNotificationMessages)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 BizConfig (com.ctrip.framework.apollo.biz.config.BizConfig)2 ReleaseMessageRepository (com.ctrip.framework.apollo.biz.repository.ReleaseMessageRepository)2 Transaction (com.ctrip.framework.apollo.tracer.spi.Transaction)2 Lists (com.google.common.collect.Lists)2 Sets (com.google.common.collect.Sets)2 SettableFuture (com.google.common.util.concurrent.SettableFuture)2 TimeUnit (java.util.concurrent.TimeUnit)2 Awaitility (org.awaitility.Awaitility)2 Awaitility.await (org.awaitility.Awaitility.await)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.assertSame (org.junit.Assert.assertSame)2