use of com.ctrip.framework.apollo.internals.SimpleConfig in project apollo by ctripcorp.
the class JavaConfigAnnotationTest method testApolloConfigChangeListenerWithInterestedKeyPrefixes_fire.
@Test
public void testApolloConfigChangeListenerWithInterestedKeyPrefixes_fire() throws InterruptedException {
// default mock, useless here
// just for speed up test without waiting
mockConfig(ConfigConsts.NAMESPACE_APPLICATION, mock(Config.class));
SimpleConfig simpleConfig = spy(this.prepareConfig(TestApolloConfigChangeListenerWithInterestedKeyPrefixesBean1.SPECIAL_NAMESPACE, new Properties()));
mockConfig(TestApolloConfigChangeListenerWithInterestedKeyPrefixesBean1.SPECIAL_NAMESPACE, simpleConfig);
TestApolloConfigChangeListenerWithInterestedKeyPrefixesBean1 bean = getBean(TestApolloConfigChangeListenerWithInterestedKeyPrefixesBean1.class, AppConfig11.class);
verify(simpleConfig, atLeastOnce()).addChangeListener(any(ConfigChangeListener.class), Mockito.nullable(Set.class), anySetOf(String.class));
Properties properties = new Properties();
properties.put("logging.level.com", "debug");
properties.put("logging.level.root", "warn");
properties.put("number.value", "333");
// publish config change
simpleConfig.onRepositoryChange(TestApolloConfigChangeListenerWithInterestedKeyPrefixesBean1.SPECIAL_NAMESPACE, properties);
// get event from bean
ConfigChangeEvent configChangeEvent = bean.getConfigChangeEvent();
Set<String> interestedChangedKeys = configChangeEvent.interestedChangedKeys();
assertEquals(Sets.newHashSet("logging.level.com", "logging.level.root", "number.value"), interestedChangedKeys);
}
use of com.ctrip.framework.apollo.internals.SimpleConfig in project apollo by ctripcorp.
the class JavaConfigPlaceholderAutoUpdateTest method testAutoUpdateWithNotSupportedNestedProperty.
@Test
public void testAutoUpdateWithNotSupportedNestedProperty() throws Exception {
String someKeyValue = "someKeyValue";
String anotherKeyValue = "anotherKeyValue";
int someValue = 1234;
int someNewValue = 2345;
Properties properties = assembleProperties(SOME_KEY_PROPERTY, someKeyValue, ANOTHER_KEY_PROPERTY, anotherKeyValue, String.format("%s.%s", someKeyValue, anotherKeyValue), String.valueOf(someValue));
SimpleConfig config = prepareConfig(ConfigConsts.NAMESPACE_APPLICATION, properties);
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(NestedPropertyConfig1.class);
TestNestedPropertyBean bean = context.getBean(TestNestedPropertyBean.class);
assertEquals(someValue, bean.getNestedProperty());
Properties newProperties = assembleProperties(SOME_KEY_PROPERTY, someKeyValue, ANOTHER_KEY_PROPERTY, anotherKeyValue, String.format("%s.%s", someKeyValue, anotherKeyValue), String.valueOf(someNewValue));
config.onRepositoryChange(ConfigConsts.NAMESPACE_APPLICATION, newProperties);
TimeUnit.MILLISECONDS.sleep(100);
// Does not support this scenario
assertEquals(someValue, bean.getNestedProperty());
}
use of com.ctrip.framework.apollo.internals.SimpleConfig in project apollo by ctripcorp.
the class JavaConfigPlaceholderAutoUpdateTest method testAutoUpdateWithNestedPropertyWithDefaultValue.
@Test
public void testAutoUpdateWithNestedPropertyWithDefaultValue() throws Exception {
String someKeyValue = "someKeyValue";
String someNewKeyValue = "someNewKeyValue";
int someValue = 1234;
int someNewValue = 2345;
Properties properties = assembleProperties(SOME_KEY_PROPERTY, someKeyValue, ANOTHER_KEY_PROPERTY, String.valueOf(someValue));
SimpleConfig config = prepareConfig(ConfigConsts.NAMESPACE_APPLICATION, properties);
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(NestedPropertyConfig2.class);
TestNestedPropertyBeanWithDefaultValue bean = context.getBean(TestNestedPropertyBeanWithDefaultValue.class);
assertEquals(someValue, bean.getNestedProperty());
Properties newProperties = assembleProperties(SOME_KEY_PROPERTY, someNewKeyValue, ANOTHER_KEY_PROPERTY, String.valueOf(someValue), someNewKeyValue, String.valueOf(someNewValue));
config.onRepositoryChange(ConfigConsts.NAMESPACE_APPLICATION, newProperties);
TimeUnit.MILLISECONDS.sleep(100);
assertEquals(someNewValue, bean.getNestedProperty());
}
use of com.ctrip.framework.apollo.internals.SimpleConfig in project apollo by ctripcorp.
the class JavaConfigPlaceholderAutoUpdateTest method testApplicationPropertySourceWithValueInjectedInConfiguration.
@Test
public void testApplicationPropertySourceWithValueInjectedInConfiguration() throws Exception {
int initialTimeout = 1000;
int initialBatch = 2000;
int newTimeout = 1001;
int newBatch = 2001;
Properties properties = assembleProperties(TIMEOUT_PROPERTY, String.valueOf(initialTimeout), BATCH_PROPERTY, String.valueOf(initialBatch));
SimpleConfig config = prepareConfig(ConfigConsts.NAMESPACE_APPLICATION, properties);
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig7.class);
TestJavaConfigBean2 bean = context.getBean(TestJavaConfigBean2.class);
assertEquals(initialTimeout, bean.getTimeout());
assertEquals(initialBatch, bean.getBatch());
Properties newProperties = assembleProperties(TIMEOUT_PROPERTY, String.valueOf(newTimeout), BATCH_PROPERTY, String.valueOf(newBatch));
config.onRepositoryChange(ConfigConsts.NAMESPACE_APPLICATION, newProperties);
TimeUnit.MILLISECONDS.sleep(100);
// Does not support this scenario
assertEquals(initialTimeout, bean.getTimeout());
assertEquals(initialBatch, bean.getBatch());
}
use of com.ctrip.framework.apollo.internals.SimpleConfig in project apollo by ctripcorp.
the class JavaConfigPlaceholderAutoUpdateTest method testAutoUpdateDisabled.
@Test
public void testAutoUpdateDisabled() throws Exception {
int initialTimeout = 1000;
int initialBatch = 2000;
int newTimeout = 1001;
int newBatch = 2001;
MockConfigUtil mockConfigUtil = new MockConfigUtil();
mockConfigUtil.setAutoUpdateInjectedSpringProperties(false);
MockInjector.setInstance(ConfigUtil.class, mockConfigUtil);
Properties properties = assembleProperties(TIMEOUT_PROPERTY, String.valueOf(initialTimeout), BATCH_PROPERTY, String.valueOf(initialBatch));
SimpleConfig config = prepareConfig(ConfigConsts.NAMESPACE_APPLICATION, properties);
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig1.class);
TestJavaConfigBean bean = context.getBean(TestJavaConfigBean.class);
assertEquals(initialTimeout, bean.getTimeout());
assertEquals(initialBatch, bean.getBatch());
Properties newProperties = assembleProperties(TIMEOUT_PROPERTY, String.valueOf(newTimeout), BATCH_PROPERTY, String.valueOf(newBatch));
config.onRepositoryChange(ConfigConsts.NAMESPACE_APPLICATION, newProperties);
TimeUnit.MILLISECONDS.sleep(100);
assertEquals(initialTimeout, bean.getTimeout());
assertEquals(initialBatch, bean.getBatch());
}
Aggregations