use of com.ctrip.framework.apollo.internals.SimpleConfig in project apollo by ctripcorp.
the class JavaConfigPlaceholderAutoUpdateTest method testAutoUpdateWithDeletedProperties.
@Test
public void testAutoUpdateWithDeletedProperties() throws Exception {
int initialTimeout = 1000;
int initialBatch = 2000;
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 = new Properties();
config.onRepositoryChange(ConfigConsts.NAMESPACE_APPLICATION, newProperties);
TimeUnit.MILLISECONDS.sleep(100);
assertEquals(DEFAULT_TIMEOUT, bean.getTimeout());
assertEquals(DEFAULT_BATCH, bean.getBatch());
}
use of com.ctrip.framework.apollo.internals.SimpleConfig in project apollo by ctripcorp.
the class JavaConfigPlaceholderAutoUpdateTest method testAutoUpdateJsonValueWithNoValueAndDefaultValue.
@Test
public void testAutoUpdateJsonValueWithNoValueAndDefaultValue() throws Exception {
String someValidValue = "{\"a\":\"someString\", \"b\":10}";
Properties properties = assembleProperties("jsonProperty", someValidValue);
SimpleConfig config = prepareConfig(ConfigConsts.NAMESPACE_APPLICATION, properties);
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig11.class);
TestApolloJsonValueWithDefaultValue bean = context.getBean(TestApolloJsonValueWithDefaultValue.class);
JsonBean jsonBean = bean.getJsonBean();
assertEquals("someString", jsonBean.getA());
assertEquals(10, jsonBean.getB());
Properties newProperties = new Properties();
config.onRepositoryChange(ConfigConsts.NAMESPACE_APPLICATION, newProperties);
TimeUnit.MILLISECONDS.sleep(100);
JsonBean newJsonBean = bean.getJsonBean();
assertEquals("defaultString", newJsonBean.getA());
assertEquals(1, newJsonBean.getB());
}
use of com.ctrip.framework.apollo.internals.SimpleConfig in project apollo by ctripcorp.
the class JavaConfigPlaceholderAutoUpdateTest method testAutoUpdateWithValueInjectedAsParameter.
@Test
public void testAutoUpdateWithValueInjectedAsParameter() 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(AppConfig3.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 testAutoUpdateWithMultipleNamespaces.
@Test
public void testAutoUpdateWithMultipleNamespaces() throws Exception {
int initialTimeout = 1000;
int initialBatch = 2000;
int newTimeout = 1001;
int newBatch = 2001;
Properties applicationProperties = assembleProperties(TIMEOUT_PROPERTY, String.valueOf(initialTimeout));
Properties fxApolloProperties = assembleProperties(BATCH_PROPERTY, String.valueOf(initialBatch));
SimpleConfig applicationConfig = prepareConfig(ConfigConsts.NAMESPACE_APPLICATION, applicationProperties);
SimpleConfig fxApolloConfig = prepareConfig(FX_APOLLO_NAMESPACE, fxApolloProperties);
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig2.class);
TestJavaConfigBean bean = context.getBean(TestJavaConfigBean.class);
assertEquals(initialTimeout, bean.getTimeout());
assertEquals(initialBatch, bean.getBatch());
Properties newApplicationProperties = assembleProperties(TIMEOUT_PROPERTY, String.valueOf(newTimeout));
applicationConfig.onRepositoryChange(ConfigConsts.NAMESPACE_APPLICATION, newApplicationProperties);
TimeUnit.MILLISECONDS.sleep(100);
assertEquals(newTimeout, bean.getTimeout());
assertEquals(initialBatch, bean.getBatch());
Properties newFxApolloProperties = assembleProperties(BATCH_PROPERTY, String.valueOf(newBatch));
fxApolloConfig.onRepositoryChange(FX_APOLLO_NAMESPACE, newFxApolloProperties);
TimeUnit.MILLISECONDS.sleep(100);
assertEquals(newTimeout, bean.getTimeout());
assertEquals(newBatch, bean.getBatch());
}
use of com.ctrip.framework.apollo.internals.SimpleConfig in project apollo by ctripcorp.
the class JavaConfigPlaceholderAutoUpdateTest method testAutoUpdateWithMultipleNamespacesWithSamePropertiesDeleted.
@Test
public void testAutoUpdateWithMultipleNamespacesWithSamePropertiesDeleted() throws Exception {
int someTimeout = 1000;
int someBatch = 2000;
int anotherBatch = 3000;
Properties applicationProperties = assembleProperties(BATCH_PROPERTY, String.valueOf(someBatch));
Properties fxApolloProperties = assembleProperties(TIMEOUT_PROPERTY, String.valueOf(someTimeout), BATCH_PROPERTY, String.valueOf(anotherBatch));
SimpleConfig applicationConfig = prepareConfig(ConfigConsts.NAMESPACE_APPLICATION, applicationProperties);
prepareConfig(FX_APOLLO_NAMESPACE, fxApolloProperties);
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig2.class);
TestJavaConfigBean bean = context.getBean(TestJavaConfigBean.class);
assertEquals(someTimeout, bean.getTimeout());
assertEquals(someBatch, bean.getBatch());
Properties newProperties = new Properties();
applicationConfig.onRepositoryChange(ConfigConsts.NAMESPACE_APPLICATION, newProperties);
TimeUnit.MILLISECONDS.sleep(100);
assertEquals(someTimeout, bean.getTimeout());
assertEquals(anotherBatch, bean.getBatch());
}
Aggregations