本文整理匯總了Java中com.ctrip.framework.apollo.ConfigService.getAppConfig方法的典型用法代碼示例。如果您正苦於以下問題:Java ConfigService.getAppConfig方法的具體用法?Java ConfigService.getAppConfig怎麽用?Java ConfigService.getAppConfig使用的例子?那麽恭喜您, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.ctrip.framework.apollo.ConfigService的用法示例。
在下文中一共展示了ConfigService.getAppConfig方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Java代碼示例。
示例1: testGetConfigWithLocalFileAndWithRemoteConfig
點讚 3
import com.ctrip.framework.apollo.ConfigService; //導入方法依賴的package包/類
@Test
public void testGetConfigWithLocalFileAndWithRemoteConfig() throws Exception {
String someKey = "someKey";
String someValue = "someValue";
String anotherValue = "anotherValue";
Properties properties = new Properties();
properties.put(someKey, someValue);
createLocalCachePropertyFile(properties);
ApolloConfig apolloConfig = assembleApolloConfig(ImmutableMap.of(someKey, anotherValue));
ContextHandler handler = mockConfigServerHandler(HttpServletResponse.SC_OK, apolloConfig);
startServerWithHandlers(handler);
Config config = ConfigService.getAppConfig();
assertEquals(anotherValue, config.getProperty(someKey, null));
}
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:18,
示例2: SimpleApolloConfigDemo
點讚 3
import com.ctrip.framework.apollo.ConfigService; //導入方法依賴的package包/類
public SimpleApolloConfigDemo() {
ConfigChangeListener changeListener = new ConfigChangeListener() {
@Override
public void onChange(ConfigChangeEvent changeEvent) {
logger.info("Changes for namespace {}", changeEvent.getNamespace());
for (String key : changeEvent.changedKeys()) {
ConfigChange change = changeEvent.getChange(key);
logger.info("Change - key: {}, oldValue: {}, newValue: {}, changeType: {}",
change.getPropertyName(), change.getOldValue(), change.getNewValue(),
change.getChangeType());
}
}
};
config = ConfigService.getAppConfig();
config.addChangeListener(changeListener);
}
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:17,
示例3: testGetConfigWithNoLocalFileButWithRemoteConfig
點讚 2
import com.ctrip.framework.apollo.ConfigService; //導入方法依賴的package包/類
@Test
public void testGetConfigWithNoLocalFileButWithRemoteConfig() throws Exception {
String someKey = "someKey";
String someValue = "someValue";
String someNonExistedKey = "someNonExistedKey";
String someDefaultValue = "someDefaultValue";
ApolloConfig apolloConfig = assembleApolloConfig(ImmutableMap.of(someKey, someValue));
ContextHandler handler = mockConfigServerHandler(HttpServletResponse.SC_OK, apolloConfig);
startServerWithHandlers(handler);
Config config = ConfigService.getAppConfig();
assertEquals(someValue, config.getProperty(someKey, null));
assertEquals(someDefaultValue, config.getProperty(someNonExistedKey, someDefaultValue));
}
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:16,
示例4: testGetConfigWithNoLocalFileAndRemoteConfigError
點讚 2
import com.ctrip.framework.apollo.ConfigService; //導入方法依賴的package包/類
@Test
public void testGetConfigWithNoLocalFileAndRemoteConfigError() throws Exception {
ContextHandler handler =
mockConfigServerHandler(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, null);
startServerWithHandlers(handler);
Config config = ConfigService.getAppConfig();
String someKey = "someKey";
String someDefaultValue = "defaultValue" + Math.random();
assertEquals(someDefaultValue, config.getProperty(someKey, someDefaultValue));
}
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:14,
示例5: testGetConfigWithLocalFileAndRemoteConfigError
點讚 2
import com.ctrip.framework.apollo.ConfigService; //導入方法依賴的package包/類
@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));
}
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:16,
示例6: testGetConfigWithNoLocalFileAndRemoteMetaServiceRetry
點讚 2
import com.ctrip.framework.apollo.ConfigService; //導入方法依賴的package包/類
@Test
public void testGetConfigWithNoLocalFileAndRemoteMetaServiceRetry() throws Exception {
String someKey = "someKey";
String someValue = "someValue";
ApolloConfig apolloConfig = assembleApolloConfig(ImmutableMap.of(someKey, someValue));
ContextHandler configHandler = mockConfigServerHandler(HttpServletResponse.SC_OK, apolloConfig);
boolean failAtFirstTime = true;
ContextHandler metaServerHandler = mockMetaServerHandler(failAtFirstTime);
startServerWithHandlers(metaServerHandler, configHandler);
Config config = ConfigService.getAppConfig();
assertEquals(someValue, config.getProperty(someKey, null));
}
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:15,
示例7: testGetConfigWithNoLocalFileAndRemoteConfigServiceRetry
點讚 2
import com.ctrip.framework.apollo.ConfigService; //導入方法依賴的package包/類
@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));
}
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:15,
示例8: testLongPollRefresh
點讚 2
import com.ctrip.framework.apollo.ConfigService; //導入方法依賴的package包/類
@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 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 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));
}
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:39,
示例9: testRefreshConfig
點讚 2
import com.ctrip.framework.apollo.ConfigService; //導入方法依賴的package包/類
@Test
public void testRefreshConfig() throws Exception {
final String someKey = "someKey";
final String someValue = "someValue";
final String anotherValue = "anotherValue";
int someRefreshInterval = 500;
TimeUnit someRefreshTimeUnit = TimeUnit.MILLISECONDS;
setRefreshInterval(someRefreshInterval);
setRefreshTimeUnit(someRefreshTimeUnit);
Map configurations = Maps.newHashMap();
configurations.put(someKey, someValue);
ApolloConfig apolloConfig = assembleApolloConfig(configurations);
ContextHandler handler = mockConfigServerHandler(HttpServletResponse.SC_OK, apolloConfig);
startServerWithHandlers(handler);
Config config = ConfigService.getAppConfig();
final List changeEvents = Lists.newArrayList();
final SettableFuture refreshFinished = SettableFuture.create();
config.addChangeListener(new ConfigChangeListener() {
AtomicInteger counter = new AtomicInteger(0);
@Override
public void onChange(ConfigChangeEvent changeEvent) {
//only need to assert once
if (counter.incrementAndGet() > 1) {
return;
}
assertEquals(1, changeEvent.changedKeys().size());
assertTrue(changeEvent.isChanged(someKey));
assertEquals(someValue, changeEvent.getChange(someKey).getOldValue());
assertEquals(anotherValue, changeEvent.getChange(someKey).getNewValue());
// if there is any assertion failed above, this line won't be executed
changeEvents.add(changeEvent);
refreshFinished.set(true);
}
});
apolloConfig.getConfigurations().put(someKey, anotherValue);
refreshFinished.get(someRefreshInterval * 5, someRefreshTimeUnit);
assertThat(
"Change event's size should equal to one or there must be some assertion failed in change listener",
1, equalTo(changeEvents.size()));
assertEquals(anotherValue, config.getProperty(someKey, null));
}
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:51,
示例10: testLongPollRefreshWithMultipleNamespacesAndOnlyOneNamespaceNotified
點讚 2
import com.ctrip.framework.apollo.ConfigService; //導入方法依賴的package包/類
@Test
public void testLongPollRefreshWithMultipleNamespacesAndOnlyOneNamespaceNotified() throws Exception {
final String someKey = "someKey";
final String someValue = "someValue";
final String anotherValue = "anotherValue";
long someNotificationId = 1;
long pollTimeoutInMS = 50;
Map 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 someOtherConfig = ConfigService.getConfig(someOtherNamespace);
Config config = ConfigService.getAppConfig();
assertEquals(someValue, config.getProperty(someKey, null));
assertEquals(someValue, someOtherConfig.getProperty(someKey, null));
final SettableFuture longPollFinished = SettableFuture.create();
config.addChangeListener(new ConfigChangeListener() {
@Override
public void onChange(ConfigChangeEvent changeEvent) {
longPollFinished.set(true);
}
});
apolloConfig.getConfigurations().put(someKey, anotherValue);
longPollFinished.get(5000, TimeUnit.MILLISECONDS);
assertEquals(anotherValue, config.getProperty(someKey, null));
TimeUnit.MILLISECONDS.sleep(pollTimeoutInMS * 10);
assertEquals(someValue, someOtherConfig.getProperty(someKey, null));
}
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:44,
注:本文中的com.ctrip.framework.apollo.ConfigService.getAppConfig方法示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。