Search in sources :

Example 16 with ApolloConfigNotification

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

the class NotificationControllerIntegrationTest method testPollNotificationWithDefaultNamespaceWithNotificationIdOutDated.

@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 testPollNotificationWithDefaultNamespaceWithNotificationIdOutDated() throws Exception {
    long someOutDatedNotificationId = 1;
    ResponseEntity<ApolloConfigNotification> result = restTemplate.getForEntity("http://{baseurl}/notifications?appId={appId}&cluster={clusterName}&namespace={namespace}&notificationId={notificationId}", ApolloConfigNotification.class, getHostUrl(), someAppId, someCluster, defaultNamespace, someOutDatedNotificationId);
    ApolloConfigNotification notification = result.getBody();
    assertEquals(HttpStatus.OK, result.getStatusCode());
    assertEquals(defaultNamespace, notification.getNamespaceName());
    assertEquals(10, notification.getNotificationId());
}
Also used : ApolloConfigNotification(com.ctrip.framework.apollo.core.dto.ApolloConfigNotification) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Example 17 with ApolloConfigNotification

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

the class NotificationControllerIntegrationTest method testPollNotificationWithDefaultNamespaceWithNotificationIdNull.

@Test(timeout = 5000L)
@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 testPollNotificationWithDefaultNamespaceWithNotificationIdNull() throws Exception {
    ResponseEntity<ApolloConfigNotification> result = restTemplate.getForEntity("http://{baseurl}/notifications?appId={appId}&cluster={clusterName}&namespace={namespace}", ApolloConfigNotification.class, getHostUrl(), someAppId, someCluster, defaultNamespace);
    ApolloConfigNotification notification = result.getBody();
    assertEquals(HttpStatus.OK, result.getStatusCode());
    assertEquals(defaultNamespace, notification.getNamespaceName());
    assertEquals(10, notification.getNotificationId());
}
Also used : ApolloConfigNotification(com.ctrip.framework.apollo.core.dto.ApolloConfigNotification) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Example 18 with ApolloConfigNotification

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

the class NotificationControllerIntegrationTest 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();
    periodicSendMessage(executorService, assembleKey(publicAppId, someDC, somePublicNamespace), stop);
    ResponseEntity<ApolloConfigNotification> result = restTemplate.getForEntity("http://{baseurl}/notifications?appId={appId}&cluster={clusterName}&namespace={namespace}&dataCenter={dataCenter}", ApolloConfigNotification.class, getHostUrl(), someAppId, someCluster, somePublicNamespace + ".properties", someDC);
    stop.set(true);
    ApolloConfigNotification notification = result.getBody();
    assertEquals(HttpStatus.OK, result.getStatusCode());
    assertEquals(somePublicNamespace, notification.getNamespaceName());
    assertNotEquals(0, notification.getNotificationId());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ApolloConfigNotification(com.ctrip.framework.apollo.core.dto.ApolloConfigNotification) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Example 19 with ApolloConfigNotification

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

the class RemoteConfigLongPollService method updateNotifications.

private void updateNotifications(List<ApolloConfigNotification> deltaNotifications) {
    for (ApolloConfigNotification notification : deltaNotifications) {
        if (Strings.isNullOrEmpty(notification.getNamespaceName())) {
            continue;
        }
        String namespaceName = notification.getNamespaceName();
        if (m_notifications.containsKey(namespaceName)) {
            m_notifications.put(namespaceName, notification.getNotificationId());
        }
        // since .properties are filtered out by default, so we need to check if there is notification with .properties suffix
        String namespaceNameWithPropertiesSuffix = String.format("%s.%s", namespaceName, ConfigFileFormat.Properties.getValue());
        if (m_notifications.containsKey(namespaceNameWithPropertiesSuffix)) {
            m_notifications.put(namespaceNameWithPropertiesSuffix, notification.getNotificationId());
        }
    }
}
Also used : ApolloConfigNotification(com.ctrip.framework.apollo.core.dto.ApolloConfigNotification)

Example 20 with ApolloConfigNotification

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

the class RemoteConfigLongPollService method assembleNotifications.

String assembleNotifications(Map<String, Long> notificationsMap) {
    List<ApolloConfigNotification> notifications = Lists.newArrayList();
    for (Map.Entry<String, Long> entry : notificationsMap.entrySet()) {
        ApolloConfigNotification notification = new ApolloConfigNotification(entry.getKey(), entry.getValue());
        notifications.add(notification);
    }
    return GSON.toJson(notifications);
}
Also used : ApolloConfigNotification(com.ctrip.framework.apollo.core.dto.ApolloConfigNotification) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map)

Aggregations

ApolloConfigNotification (com.ctrip.framework.apollo.core.dto.ApolloConfigNotification)53 Test (org.junit.Test)41 ApolloNotificationMessages (com.ctrip.framework.apollo.core.dto.ApolloNotificationMessages)28 Sql (org.springframework.test.context.jdbc.Sql)26 List (java.util.List)20 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)15 ReleaseMessage (com.ctrip.framework.apollo.biz.entity.ReleaseMessage)9 ResponseEntity (org.springframework.http.ResponseEntity)8 HttpRequest (com.ctrip.framework.apollo.util.http.HttpRequest)6 InvocationOnMock (org.mockito.invocation.InvocationOnMock)6 ServiceDTO (com.ctrip.framework.apollo.core.dto.ServiceDTO)5 HttpResponse (com.ctrip.framework.apollo.util.http.HttpResponse)5 ApolloConfig (com.ctrip.framework.apollo.core.dto.ApolloConfig)4 BaseIntegrationTest (com.ctrip.framework.apollo.BaseIntegrationTest)3 Config (com.ctrip.framework.apollo.Config)3 ConfigChangeListener (com.ctrip.framework.apollo.ConfigChangeListener)3 ConfigChangeEvent (com.ctrip.framework.apollo.model.ConfigChangeEvent)3 Map (java.util.Map)3 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)3 DeferredResultWrapper (com.ctrip.framework.apollo.configservice.wrapper.DeferredResultWrapper)2