Search in sources :

Example 11 with Config

use of com.ctrip.framework.apollo.Config in project apollo by ctripcorp.

the class ApolloMockServerApiTest method testDeleteProperties.

@Test
public void testDeleteProperties() throws Exception {
    Config otherConfig = ConfigService.getConfig(anotherNamespace);
    final SettableFuture<ConfigChangeEvent> future = SettableFuture.create();
    otherConfig.addChangeListener(new ConfigChangeListener() {

        @Override
        public void onChange(ConfigChangeEvent changeEvent) {
            future.set(changeEvent);
        }
    });
    assertEquals("otherValue4", otherConfig.getProperty("key4", null));
    assertEquals("otherValue5", otherConfig.getProperty("key5", null));
    embeddedApollo.deleteProperty(anotherNamespace, "key4");
    ConfigChangeEvent changeEvent = future.get(5, TimeUnit.SECONDS);
    assertNull(otherConfig.getProperty("key4", null));
    assertEquals("otherValue5", otherConfig.getProperty("key5", null));
    assertTrue(changeEvent.isChanged("key4"));
}
Also used : ConfigChangeListener(com.ctrip.framework.apollo.ConfigChangeListener) Config(com.ctrip.framework.apollo.Config) ConfigChangeEvent(com.ctrip.framework.apollo.model.ConfigChangeEvent) Test(org.junit.Test)

Example 12 with Config

use of com.ctrip.framework.apollo.Config in project apollo by ctripcorp.

the class ApolloMockServerApiTest method testUpdateSamePropertyTwice.

@Test
public void testUpdateSamePropertyTwice() throws Exception {
    String someNewValue = "someNewValue";
    Config otherConfig = ConfigService.getConfig(anotherNamespace);
    final Semaphore changes = new Semaphore(0);
    otherConfig.addChangeListener(new ConfigChangeListener() {

        @Override
        public void onChange(ConfigChangeEvent changeEvent) {
            changes.release();
        }
    });
    assertEquals("otherValue3", otherConfig.getProperty("key3", null));
    embeddedApollo.addOrModifyProperty(anotherNamespace, "key3", someNewValue);
    embeddedApollo.addOrModifyProperty(anotherNamespace, "key3", someNewValue);
    assertTrue(changes.tryAcquire(5, TimeUnit.SECONDS));
    assertEquals(someNewValue, otherConfig.getProperty("key3", null));
    assertEquals(0, changes.availablePermits());
}
Also used : ConfigChangeListener(com.ctrip.framework.apollo.ConfigChangeListener) Config(com.ctrip.framework.apollo.Config) ConfigChangeEvent(com.ctrip.framework.apollo.model.ConfigChangeEvent) Semaphore(java.util.concurrent.Semaphore) Test(org.junit.Test)

Example 13 with Config

use of com.ctrip.framework.apollo.Config in project apollo by ctripcorp.

the class ConfigIntegrationTest method testGetConfigWithLocalFileAndRemoteConfigError.

@Test
public void testGetConfigWithLocalFileAndRemoteConfigError() throws Exception {
    String someKey = "someKey";
    String someValue = "someValue";
    Properties properties = new Properties();
    properties.put(someKey, someValue);
    createLocalCachePropertyFile(properties);
    ContextHandler handler = mockConfigServerHandler(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, null);
    startServerWithHandlers(handler);
    Config config = ConfigService.getAppConfig();
    assertEquals(someValue, config.getProperty(someKey, null));
}
Also used : ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) ApolloConfig(com.ctrip.framework.apollo.core.dto.ApolloConfig) Config(com.ctrip.framework.apollo.Config) OrderedProperties(com.ctrip.framework.apollo.util.OrderedProperties) BaseIntegrationTest(com.ctrip.framework.apollo.BaseIntegrationTest) Test(org.junit.Test)

Example 14 with Config

use of com.ctrip.framework.apollo.Config in project apollo by ctripcorp.

the class ConfigIntegrationTest method testLongPollRefresh.

@Test
public void testLongPollRefresh() throws Exception {
    final String someKey = "someKey";
    final String someValue = "someValue";
    final String anotherValue = "anotherValue";
    long someNotificationId = 1;
    long pollTimeoutInMS = 50;
    Map<String, String> configurations = Maps.newHashMap();
    configurations.put(someKey, someValue);
    ApolloConfig apolloConfig = assembleApolloConfig(configurations);
    ContextHandler configHandler = mockConfigServerHandler(HttpServletResponse.SC_OK, apolloConfig);
    ContextHandler pollHandler = mockPollNotificationHandler(pollTimeoutInMS, HttpServletResponse.SC_OK, Lists.newArrayList(new ApolloConfigNotification(apolloConfig.getNamespaceName(), someNotificationId)), false);
    startServerWithHandlers(configHandler, pollHandler);
    Config config = ConfigService.getAppConfig();
    assertEquals(someValue, config.getProperty(someKey, null));
    final SettableFuture<Boolean> longPollFinished = SettableFuture.create();
    config.addChangeListener(new ConfigChangeListener() {

        @Override
        public void onChange(ConfigChangeEvent changeEvent) {
            longPollFinished.set(true);
        }
    });
    apolloConfig.getConfigurations().put(someKey, anotherValue);
    longPollFinished.get(pollTimeoutInMS * 20, TimeUnit.MILLISECONDS);
    assertEquals(anotherValue, config.getProperty(someKey, null));
}
Also used : ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) ConfigChangeListener(com.ctrip.framework.apollo.ConfigChangeListener) ApolloConfig(com.ctrip.framework.apollo.core.dto.ApolloConfig) ApolloConfig(com.ctrip.framework.apollo.core.dto.ApolloConfig) Config(com.ctrip.framework.apollo.Config) ConfigChangeEvent(com.ctrip.framework.apollo.model.ConfigChangeEvent) ApolloConfigNotification(com.ctrip.framework.apollo.core.dto.ApolloConfigNotification) BaseIntegrationTest(com.ctrip.framework.apollo.BaseIntegrationTest) Test(org.junit.Test)

Example 15 with Config

use of com.ctrip.framework.apollo.Config in project apollo by ctripcorp.

the class ConfigIntegrationTest method testGetConfigWithNoLocalFileAndRemoteConfigServiceRetry.

@Test
public void testGetConfigWithNoLocalFileAndRemoteConfigServiceRetry() throws Exception {
    String someKey = "someKey";
    String someValue = "someValue";
    ApolloConfig apolloConfig = assembleApolloConfig(ImmutableMap.of(someKey, someValue));
    boolean failedAtFirstTime = true;
    ContextHandler handler = mockConfigServerHandler(HttpServletResponse.SC_OK, apolloConfig, failedAtFirstTime);
    startServerWithHandlers(handler);
    Config config = ConfigService.getAppConfig();
    assertEquals(someValue, config.getProperty(someKey, null));
}
Also used : ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) ApolloConfig(com.ctrip.framework.apollo.core.dto.ApolloConfig) ApolloConfig(com.ctrip.framework.apollo.core.dto.ApolloConfig) Config(com.ctrip.framework.apollo.Config) BaseIntegrationTest(com.ctrip.framework.apollo.BaseIntegrationTest) Test(org.junit.Test)

Aggregations

Config (com.ctrip.framework.apollo.Config)94 Test (org.junit.Test)79 EnableApolloConfig (com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig)39 Matchers.anyString (org.mockito.Matchers.anyString)31 ApolloConfig (com.ctrip.framework.apollo.spring.annotation.ApolloConfig)26 ConfigChangeListener (com.ctrip.framework.apollo.ConfigChangeListener)22 SimpleConfig (com.ctrip.framework.apollo.internals.SimpleConfig)20 ConfigChangeEvent (com.ctrip.framework.apollo.model.ConfigChangeEvent)16 BaseIntegrationTest (com.ctrip.framework.apollo.BaseIntegrationTest)13 ApolloConfig (com.ctrip.framework.apollo.core.dto.ApolloConfig)13 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)13 ApolloConfigChangeListener (com.ctrip.framework.apollo.spring.annotation.ApolloConfigChangeListener)10 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)10 Properties (java.util.Properties)6 ConfigFactory (com.ctrip.framework.apollo.spi.ConfigFactory)5 PureApolloConfigFactory (com.ctrip.framework.apollo.config.data.internals.PureApolloConfigFactory)4 DefaultConfigFactory (com.ctrip.framework.apollo.spi.DefaultConfigFactory)4 OrderedProperties (com.ctrip.framework.apollo.util.OrderedProperties)4 Set (java.util.Set)4 ApolloConfigNotification (com.ctrip.framework.apollo.core.dto.ApolloConfigNotification)3