Search in sources :

Example 16 with ApolloNotificationMessages

use of com.ctrip.framework.apollo.core.dto.ApolloNotificationMessages in project apollo by ctripcorp.

the class ConfigControllerTest method testTransformMessages.

@Test
public void testTransformMessages() throws Exception {
    String someKey = "someKey";
    long someNotificationId = 1;
    String anotherKey = "anotherKey";
    long anotherNotificationId = 2;
    ApolloNotificationMessages notificationMessages = new ApolloNotificationMessages();
    notificationMessages.put(someKey, someNotificationId);
    notificationMessages.put(anotherKey, anotherNotificationId);
    String someMessagesAsString = gson.toJson(notificationMessages);
    ApolloNotificationMessages result = configController.transformMessages(someMessagesAsString);
    assertEquals(notificationMessages.getDetails(), result.getDetails());
}
Also used : ApolloNotificationMessages(com.ctrip.framework.apollo.core.dto.ApolloNotificationMessages) Test(org.junit.Test)

Example 17 with ApolloNotificationMessages

use of com.ctrip.framework.apollo.core.dto.ApolloNotificationMessages in project apollo by ctripcorp.

the class NotificationControllerV2Test method testPollNotificationWithIncorrectCase.

@Test
public void testPollNotificationWithIncorrectCase() throws Exception {
    String appIdWithIncorrectCase = someAppId.toUpperCase();
    String namespaceWithIncorrectCase = defaultNamespace.toUpperCase();
    String someMessage = Joiner.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR).join(someAppId, someCluster, defaultNamespace);
    String someWatchKey = Joiner.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR).join(appIdWithIncorrectCase, someCluster, defaultNamespace);
    Multimap<String, String> watchKeysMap = assembleMultiMap(defaultNamespace, Lists.newArrayList(someWatchKey));
    String notificationAsString = transformApolloConfigNotificationsToString(defaultNamespace.toUpperCase(), someNotificationId);
    when(namespaceUtil.filterNamespaceName(namespaceWithIncorrectCase)).thenReturn(namespaceWithIncorrectCase);
    when(namespaceUtil.normalizeNamespace(appIdWithIncorrectCase, namespaceWithIncorrectCase)).thenReturn(defaultNamespace);
    when(watchKeysUtil.assembleAllWatchKeys(appIdWithIncorrectCase, someCluster, Sets.newHashSet(defaultNamespace), someDataCenter)).thenReturn(watchKeysMap);
    DeferredResult<ResponseEntity<List<ApolloConfigNotification>>> deferredResult = controller.pollNotification(appIdWithIncorrectCase, someCluster, notificationAsString, someDataCenter, someClientIp);
    long someId = 1;
    ReleaseMessage someReleaseMessage = new ReleaseMessage(someMessage);
    someReleaseMessage.setId(someId);
    controller.handleMessage(someReleaseMessage, Topics.APOLLO_RELEASE_TOPIC);
    assertTrue(deferredResult.hasResult());
    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(namespaceWithIncorrectCase, notification.getNamespaceName());
    assertEquals(someId, notification.getNotificationId());
    ApolloNotificationMessages notificationMessages = notification.getMessages();
    assertEquals(1, notificationMessages.getDetails().size());
    assertEquals(someId, notificationMessages.get(someMessage).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 18 with ApolloNotificationMessages

use of com.ctrip.framework.apollo.core.dto.ApolloNotificationMessages in project apollo by ctripcorp.

the class NotificationControllerV2IntegrationTest method testPollNotificationWthMultipleNamespacesAndMultipleNamespacesChanged.

@Test(timeout = 10000L)
@Sql(scripts = "/integration-test/test-release.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testPollNotificationWthMultipleNamespacesAndMultipleNamespacesChanged() throws Exception {
    String publicAppId = "somePublicAppId";
    String someDC = "someDC";
    AtomicBoolean stop = new AtomicBoolean();
    String key = assembleKey(publicAppId, someDC, somePublicNamespace);
    periodicSendMessage(executorService, key, stop);
    ResponseEntity<List<ApolloConfigNotification>> result = restTemplate.exchange("http://{baseurl}/notifications/v2?appId={appId}&cluster={clusterName}&notifications={notifications}&dataCenter={dataCenter}", HttpMethod.GET, null, typeReference, getHostUrl(), someAppId, someCluster, transformApolloConfigNotificationsToString(defaultNamespace, ConfigConsts.NOTIFICATION_ID_PLACEHOLDER, somePublicNamespace, ConfigConsts.NOTIFICATION_ID_PLACEHOLDER), someDC);
    stop.set(true);
    List<ApolloConfigNotification> notifications = result.getBody();
    assertEquals(HttpStatus.OK, result.getStatusCode());
    assertEquals(1, notifications.size());
    assertEquals(somePublicNamespace, notifications.get(0).getNamespaceName());
    assertNotEquals(0, notifications.get(0).getNotificationId());
    ApolloNotificationMessages messages = result.getBody().get(0).getMessages();
    assertEquals(1, messages.getDetails().size());
    assertTrue(messages.has(key));
    assertNotEquals(ConfigConsts.NOTIFICATION_ID_PLACEHOLDER, messages.get(key).longValue());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ApolloNotificationMessages(com.ctrip.framework.apollo.core.dto.ApolloNotificationMessages) List(java.util.List) ApolloConfigNotification(com.ctrip.framework.apollo.core.dto.ApolloConfigNotification) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Example 19 with ApolloNotificationMessages

use of com.ctrip.framework.apollo.core.dto.ApolloNotificationMessages in project apollo by ctripcorp.

the class NotificationControllerV2IntegrationTest method testPollNotificationWthPublicNamespaceAsFile.

@Test(timeout = 5000L)
@Sql(scripts = "/integration-test/test-release.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testPollNotificationWthPublicNamespaceAsFile() throws Exception {
    String publicAppId = "somePublicAppId";
    String someDC = "someDC";
    AtomicBoolean stop = new AtomicBoolean();
    String key = assembleKey(publicAppId, someDC, somePublicNamespace);
    periodicSendMessage(executorService, key, stop);
    ResponseEntity<List<ApolloConfigNotification>> result = restTemplate.exchange("http://{baseurl}/notifications/v2?appId={appId}&cluster={clusterName}&notifications={notifications}&dataCenter={dataCenter}", HttpMethod.GET, null, typeReference, getHostUrl(), someAppId, someCluster, transformApolloConfigNotificationsToString(somePublicNamespace + ".properties", ConfigConsts.NOTIFICATION_ID_PLACEHOLDER), someDC);
    stop.set(true);
    List<ApolloConfigNotification> notifications = result.getBody();
    assertEquals(HttpStatus.OK, result.getStatusCode());
    assertEquals(1, notifications.size());
    assertEquals(somePublicNamespace, notifications.get(0).getNamespaceName());
    assertNotEquals(0, notifications.get(0).getNotificationId());
    ApolloNotificationMessages messages = result.getBody().get(0).getMessages();
    assertEquals(1, messages.getDetails().size());
    assertTrue(messages.has(key));
    assertNotEquals(ConfigConsts.NOTIFICATION_ID_PLACEHOLDER, messages.get(key).longValue());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ApolloNotificationMessages(com.ctrip.framework.apollo.core.dto.ApolloNotificationMessages) List(java.util.List) ApolloConfigNotification(com.ctrip.framework.apollo.core.dto.ApolloConfigNotification) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Example 20 with ApolloNotificationMessages

use of com.ctrip.framework.apollo.core.dto.ApolloNotificationMessages in project apollo by ctripcorp.

the class NotificationControllerV2IntegrationTest method testPollNotificationWithMultiplePublicNamespaceWithIncorrectCase2WithNotificationIdOutDated.

@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 testPollNotificationWithMultiplePublicNamespaceWithIncorrectCase2WithNotificationIdOutDated() 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}&notifications={notifications}", HttpMethod.GET, null, typeReference, getHostUrl(), someAppId, someCluster, transformApolloConfigNotificationsToString(somePublicNameWithIncorrectCase, someOutDatedNotificationId, somePublicNamespace, newNotificationId));
    List<ApolloConfigNotification> notifications = result.getBody();
    assertEquals(HttpStatus.OK, result.getStatusCode());
    assertEquals(1, notifications.size());
    assertEquals(somePublicNameWithIncorrectCase, 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());
}
Also used : ApolloNotificationMessages(com.ctrip.framework.apollo.core.dto.ApolloNotificationMessages) List(java.util.List) ApolloConfigNotification(com.ctrip.framework.apollo.core.dto.ApolloConfigNotification) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Aggregations

ApolloNotificationMessages (com.ctrip.framework.apollo.core.dto.ApolloNotificationMessages)31 ApolloConfigNotification (com.ctrip.framework.apollo.core.dto.ApolloConfigNotification)27 Test (org.junit.Test)27 List (java.util.List)20 Sql (org.springframework.test.context.jdbc.Sql)17 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)9 HttpRequest (com.ctrip.framework.apollo.util.http.HttpRequest)5 InvocationOnMock (org.mockito.invocation.InvocationOnMock)5 ServiceDTO (com.ctrip.framework.apollo.core.dto.ServiceDTO)4 HttpResponse (com.ctrip.framework.apollo.util.http.HttpResponse)4 ReleaseMessage (com.ctrip.framework.apollo.biz.entity.ReleaseMessage)3 ApolloConfig (com.ctrip.framework.apollo.core.dto.ApolloConfig)3 ResponseEntity (org.springframework.http.ResponseEntity)3 Release (com.ctrip.framework.apollo.biz.entity.Release)1 OrderedProperties (com.ctrip.framework.apollo.util.OrderedProperties)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Gson (com.google.gson.Gson)1 Map (java.util.Map)1 Properties (java.util.Properties)1 Before (org.junit.Before)1