use of com.ctrip.framework.apollo.internals.YamlConfigFile in project apollo by ctripcorp.
the class JavaConfigPlaceholderAutoUpdateTest method testAutoUpdateWithYamlFileWithValueAndXmlProperty.
@Test
public void testAutoUpdateWithYamlFileWithValueAndXmlProperty() throws Exception {
int initialTimeout = 1000;
int initialBatch = 2000;
int newTimeout = 1001;
int newBatch = 2001;
YamlConfigFile configFile = prepareYamlConfigFile("application.yaml", readYamlContentAsConfigFileProperties("case1.yaml"));
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig13.class);
TestJavaConfigBean javaConfigBean = context.getBean(TestJavaConfigBean.class);
TestXmlBean xmlBean = context.getBean(TestXmlBean.class);
assertEquals(initialTimeout, javaConfigBean.getTimeout());
assertEquals(initialBatch, javaConfigBean.getBatch());
assertEquals(initialTimeout, xmlBean.getTimeout());
assertEquals(initialBatch, xmlBean.getBatch());
configFile.onRepositoryChange("application.yaml", readYamlContentAsConfigFileProperties("case1-new.yaml"));
TimeUnit.MILLISECONDS.sleep(100);
assertEquals(newTimeout, javaConfigBean.getTimeout());
assertEquals(newBatch, javaConfigBean.getBatch());
assertEquals(newTimeout, xmlBean.getTimeout());
assertEquals(newBatch, xmlBean.getBatch());
}
use of com.ctrip.framework.apollo.internals.YamlConfigFile in project apollo by ctripcorp.
the class JavaConfigPlaceholderAutoUpdateTest method testAutoUpdateWithDeletedPropertiesWithYamlFile.
@Test
public void testAutoUpdateWithDeletedPropertiesWithYamlFile() throws Exception {
int initialTimeout = 1000;
int initialBatch = 2000;
YamlConfigFile configFile = prepareYamlConfigFile("application.yaml", readYamlContentAsConfigFileProperties("case4.yaml"));
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig12.class);
TestJavaConfigBean bean = context.getBean(TestJavaConfigBean.class);
assertEquals(initialTimeout, bean.getTimeout());
assertEquals(initialBatch, bean.getBatch());
configFile.onRepositoryChange("application.yaml", readYamlContentAsConfigFileProperties("case4-new.yaml"));
TimeUnit.MILLISECONDS.sleep(100);
assertEquals(DEFAULT_TIMEOUT, bean.getTimeout());
assertEquals(DEFAULT_BATCH, bean.getBatch());
}
use of com.ctrip.framework.apollo.internals.YamlConfigFile in project apollo by ctripcorp.
the class JavaConfigPlaceholderAutoUpdateTest method testAutoUpdateWithMultipleNamespacesWithSamePropertiesWithYamlFile.
@Test
public void testAutoUpdateWithMultipleNamespacesWithSamePropertiesWithYamlFile() throws Exception {
int someTimeout = 1000;
int someBatch = 2000;
int anotherBatch = 3000;
int someNewBatch = 2001;
YamlConfigFile configFile = prepareYamlConfigFile("application.yml", readYamlContentAsConfigFileProperties("case2.yml"));
Properties fxApolloProperties = assembleProperties(TIMEOUT_PROPERTY, String.valueOf(someTimeout), BATCH_PROPERTY, String.valueOf(anotherBatch));
prepareConfig(FX_APOLLO_NAMESPACE, fxApolloProperties);
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig14.class);
TestJavaConfigBean bean = context.getBean(TestJavaConfigBean.class);
assertEquals(someTimeout, bean.getTimeout());
assertEquals(someBatch, bean.getBatch());
configFile.onRepositoryChange("application.yml", readYamlContentAsConfigFileProperties("case2-new.yml"));
TimeUnit.MILLISECONDS.sleep(100);
assertEquals(someTimeout, bean.getTimeout());
assertEquals(someNewBatch, bean.getBatch());
}
use of com.ctrip.framework.apollo.internals.YamlConfigFile in project apollo by ctripcorp.
the class JavaConfigAnnotationTest method testApolloConfigChangeListenerWithYamlFile.
@Test
public void testApolloConfigChangeListenerWithYamlFile() throws Exception {
String someKey = "someKey";
String someValue = "someValue";
String anotherValue = "anotherValue";
YamlConfigFile configFile = prepareYamlConfigFile(APPLICATION_YAML_NAMESPACE, readYamlContentAsConfigFileProperties("case9.yml"));
TestApolloConfigChangeListenerWithYamlFile bean = getBean(TestApolloConfigChangeListenerWithYamlFile.class, AppConfig9.class);
Config yamlConfig = bean.getYamlConfig();
SettableFuture<ConfigChangeEvent> future = bean.getConfigChangeEventFuture();
assertEquals(someValue, yamlConfig.getProperty(someKey, null));
assertFalse(future.isDone());
configFile.onRepositoryChange(APPLICATION_YAML_NAMESPACE, readYamlContentAsConfigFileProperties("case9-new.yml"));
ConfigChangeEvent configChangeEvent = future.get(100, TimeUnit.MILLISECONDS);
ConfigChange change = configChangeEvent.getChange(someKey);
assertEquals(someValue, change.getOldValue());
assertEquals(anotherValue, change.getNewValue());
assertEquals(anotherValue, yamlConfig.getProperty(someKey, null));
}
use of com.ctrip.framework.apollo.internals.YamlConfigFile in project apollo by ctripcorp.
the class AbstractSpringIntegrationTest method prepareYamlConfigFile.
protected static YamlConfigFile prepareYamlConfigFile(String namespaceNameWithFormat, Properties properties) {
ConfigRepository configRepository = mock(ConfigRepository.class);
when(configRepository.getConfig()).thenReturn(properties);
// spy it for testing after
YamlConfigFile configFile = spy(new YamlConfigFile(namespaceNameWithFormat, configRepository));
mockConfigFile(namespaceNameWithFormat, configFile);
return configFile;
}
Aggregations