use of com.ctrip.framework.apollo.core.dto.ApolloConfig in project apollo by ctripcorp.
the class ConfigIntegrationTest method assembleApolloConfig.
private ApolloConfig assembleApolloConfig(Map<String, String> configurations) {
ApolloConfig apolloConfig = new ApolloConfig(someAppId, someClusterName, defaultNamespace, someReleaseKey);
apolloConfig.setConfigurations(configurations);
return apolloConfig;
}
use of com.ctrip.framework.apollo.core.dto.ApolloConfig 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));
}
use of com.ctrip.framework.apollo.core.dto.ApolloConfig 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));
}
use of com.ctrip.framework.apollo.core.dto.ApolloConfig in project apollo by ctripcorp.
the class ConfigIntegrationTest method testLongPollRefreshWithMultipleNamespacesAndMultipleNamespaceNotified.
@Test
public void testLongPollRefreshWithMultipleNamespacesAndMultipleNamespaceNotified() 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), new ApolloConfigNotification(someOtherNamespace, someNotificationId)), false);
startServerWithHandlers(configHandler, pollHandler);
Config config = ConfigService.getAppConfig();
Config someOtherConfig = ConfigService.getConfig(someOtherNamespace);
assertEquals(someValue, config.getProperty(someKey, null));
assertEquals(someValue, someOtherConfig.getProperty(someKey, null));
final SettableFuture<Boolean> longPollFinished = SettableFuture.create();
final SettableFuture<Boolean> someOtherNamespacelongPollFinished = SettableFuture.create();
config.addChangeListener(new ConfigChangeListener() {
@Override
public void onChange(ConfigChangeEvent changeEvent) {
longPollFinished.set(true);
}
});
someOtherConfig.addChangeListener(new ConfigChangeListener() {
@Override
public void onChange(ConfigChangeEvent changeEvent) {
someOtherNamespacelongPollFinished.set(true);
}
});
apolloConfig.getConfigurations().put(someKey, anotherValue);
longPollFinished.get(5000, TimeUnit.MILLISECONDS);
someOtherNamespacelongPollFinished.get(5000, TimeUnit.MILLISECONDS);
assertEquals(anotherValue, config.getProperty(someKey, null));
assertEquals(anotherValue, someOtherConfig.getProperty(someKey, null));
}
use of com.ctrip.framework.apollo.core.dto.ApolloConfig in project apollo by ctripcorp.
the class ConfigIntegrationTest method testOrderGetConfigWithNoLocalFileButWithRemoteConfig.
@Test
public void testOrderGetConfigWithNoLocalFileButWithRemoteConfig() throws Exception {
setPropertiesOrderEnabled(true);
String someKey1 = "someKey1";
String someValue1 = "someValue1";
String someKey2 = "someKey2";
String someValue2 = "someValue2";
Map<String, String> configurations = new LinkedHashMap<>();
configurations.put(someKey1, someValue1);
configurations.put(someKey2, someValue2);
ApolloConfig apolloConfig = assembleApolloConfig(ImmutableMap.copyOf(configurations));
ContextHandler handler = mockConfigServerHandler(HttpServletResponse.SC_OK, apolloConfig);
startServerWithHandlers(handler);
Config config = ConfigService.getAppConfig();
Set<String> propertyNames = config.getPropertyNames();
Iterator<String> it = propertyNames.iterator();
assertEquals(someKey1, it.next());
assertEquals(someKey2, it.next());
}
Aggregations