Search in sources :

Example 6 with YamlConfigFile

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());
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) TestXmlBean(com.ctrip.framework.apollo.spring.XmlConfigPlaceholderTest.TestXmlBean) YamlConfigFile(com.ctrip.framework.apollo.internals.YamlConfigFile) Test(org.junit.Test)

Example 7 with YamlConfigFile

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());
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) YamlConfigFile(com.ctrip.framework.apollo.internals.YamlConfigFile) Test(org.junit.Test)

Example 8 with YamlConfigFile

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());
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) Properties(java.util.Properties) YamlConfigFile(com.ctrip.framework.apollo.internals.YamlConfigFile) Test(org.junit.Test)

Example 9 with YamlConfigFile

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));
}
Also used : ConfigChange(com.ctrip.framework.apollo.model.ConfigChange) EnableApolloConfig(com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig) ApolloConfig(com.ctrip.framework.apollo.spring.annotation.ApolloConfig) SimpleConfig(com.ctrip.framework.apollo.internals.SimpleConfig) Config(com.ctrip.framework.apollo.Config) ConfigChangeEvent(com.ctrip.framework.apollo.model.ConfigChangeEvent) Matchers.anyString(org.mockito.Matchers.anyString) YamlConfigFile(com.ctrip.framework.apollo.internals.YamlConfigFile) Test(org.junit.Test)

Example 10 with YamlConfigFile

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;
}
Also used : ConfigRepository(com.ctrip.framework.apollo.internals.ConfigRepository) YamlConfigFile(com.ctrip.framework.apollo.internals.YamlConfigFile)

Aggregations

YamlConfigFile (com.ctrip.framework.apollo.internals.YamlConfigFile)10 Test (org.junit.Test)9 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)6 Config (com.ctrip.framework.apollo.Config)2 SimpleConfig (com.ctrip.framework.apollo.internals.SimpleConfig)2 ApolloConfig (com.ctrip.framework.apollo.spring.annotation.ApolloConfig)2 EnableApolloConfig (com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig)2 Properties (java.util.Properties)2 Matchers.anyString (org.mockito.Matchers.anyString)2 ConfigFile (com.ctrip.framework.apollo.ConfigFile)1 ConfigFileChangeListener (com.ctrip.framework.apollo.ConfigFileChangeListener)1 ConfigRepository (com.ctrip.framework.apollo.internals.ConfigRepository)1 JsonConfigFile (com.ctrip.framework.apollo.internals.JsonConfigFile)1 LocalFileConfigRepository (com.ctrip.framework.apollo.internals.LocalFileConfigRepository)1 PropertiesConfigFile (com.ctrip.framework.apollo.internals.PropertiesConfigFile)1 XmlConfigFile (com.ctrip.framework.apollo.internals.XmlConfigFile)1 YmlConfigFile (com.ctrip.framework.apollo.internals.YmlConfigFile)1 ConfigChange (com.ctrip.framework.apollo.model.ConfigChange)1 ConfigChangeEvent (com.ctrip.framework.apollo.model.ConfigChangeEvent)1 TestXmlBean (com.ctrip.framework.apollo.spring.XmlConfigPlaceholderTest.TestXmlBean)1