Search in sources :

Example 6 with ApolloNotificationMessages

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

the class NotificationControllerV2IntegrationTest method testPollNotificationWithDefaultNamespaceAsFile.

@Test(timeout = 5000L)
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testPollNotificationWithDefaultNamespaceAsFile() throws Exception {
    AtomicBoolean stop = new AtomicBoolean();
    String key = assembleKey(someAppId, someCluster, defaultNamespace);
    periodicSendMessage(executorService, key, stop);
    ResponseEntity<List<ApolloConfigNotification>> result = restTemplate.exchange("http://{baseurl}/notifications/v2?appId={appId}&cluster={clusterName}&notifications={notifications}", HttpMethod.GET, null, typeReference, getHostUrl(), someAppId, someCluster, transformApolloConfigNotificationsToString(defaultNamespace + ".properties", ConfigConsts.NOTIFICATION_ID_PLACEHOLDER));
    stop.set(true);
    List<ApolloConfigNotification> notifications = result.getBody();
    assertEquals(HttpStatus.OK, result.getStatusCode());
    assertEquals(1, notifications.size());
    assertEquals(defaultNamespace, 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 7 with ApolloNotificationMessages

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

the class NotificationControllerV2IntegrationTest method testPollNotificationWithMultipleNamespaces.

@Test
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testPollNotificationWithMultipleNamespaces() throws Exception {
    AtomicBoolean stop = new AtomicBoolean();
    String key = assembleKey(someAppId, someCluster, somePublicNamespace);
    periodicSendMessage(executorService, key, stop);
    ResponseEntity<List<ApolloConfigNotification>> result = restTemplate.exchange("http://{baseurl}/notifications/v2?appId={appId}&cluster={clusterName}&notifications={notifications}", HttpMethod.GET, null, typeReference, getHostUrl(), someAppId, someCluster, transformApolloConfigNotificationsToString(defaultNamespace + ".properties", ConfigConsts.NOTIFICATION_ID_PLACEHOLDER, defaultNamespace, ConfigConsts.NOTIFICATION_ID_PLACEHOLDER, somePublicNamespace, ConfigConsts.NOTIFICATION_ID_PLACEHOLDER));
    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 8 with ApolloNotificationMessages

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

the class NotificationControllerV2IntegrationTest method testPollNotificationWthPublicNamespaceAndNoDataCenter.

@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 testPollNotificationWthPublicNamespaceAndNoDataCenter() throws Exception {
    String publicAppId = "somePublicAppId";
    AtomicBoolean stop = new AtomicBoolean();
    String key = assembleKey(publicAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, somePublicNamespace);
    periodicSendMessage(executorService, key, stop);
    ResponseEntity<List<ApolloConfigNotification>> result = restTemplate.exchange("http://{baseurl}/notifications/v2?appId={appId}&cluster={clusterName}&notifications={notifications}", HttpMethod.GET, null, typeReference, getHostUrl(), someAppId, someCluster, transformApolloConfigNotificationsToString(somePublicNamespace, ConfigConsts.NOTIFICATION_ID_PLACEHOLDER));
    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 9 with ApolloNotificationMessages

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

the class NotificationControllerV2IntegrationTest method testPollNotificationWithMultiplePublicNamespaceWithIncorrectCase3WithNotificationIdOutDated.

@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 testPollNotificationWithMultiplePublicNamespaceWithIncorrectCase3WithNotificationIdOutDated() 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, newNotificationId, somePublicNamespace, someOutDatedNotificationId));
    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());
}
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)

Example 10 with ApolloNotificationMessages

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

the class NotificationControllerV2IntegrationTest method testPollNotificationWithDefaultNamespace.

@Test(timeout = 5000L)
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testPollNotificationWithDefaultNamespace() throws Exception {
    AtomicBoolean stop = new AtomicBoolean();
    String key = assembleKey(someAppId, someCluster, defaultNamespace);
    periodicSendMessage(executorService, key, stop);
    ResponseEntity<List<ApolloConfigNotification>> result = restTemplate.exchange("http://{baseurl}/notifications/v2?appId={appId}&cluster={clusterName}&notifications={notifications}", HttpMethod.GET, null, typeReference, getHostUrl(), someAppId, someCluster, transformApolloConfigNotificationsToString(defaultNamespace, ConfigConsts.NOTIFICATION_ID_PLACEHOLDER));
    stop.set(true);
    List<ApolloConfigNotification> notifications = result.getBody();
    assertEquals(HttpStatus.OK, result.getStatusCode());
    assertEquals(1, notifications.size());
    assertEquals(defaultNamespace, 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)

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