Search in sources :

Example 1 with TestXmlBean

use of com.ctrip.framework.apollo.spring.XmlConfigPlaceholderTest.TestXmlBean in project apollo by ctripcorp.

the class XmlConfigPlaceholderAutoUpdateTest method testAutoUpdateWithNewProperties.

@Test
public void testAutoUpdateWithNewProperties() throws Exception {
    int initialTimeout = 1000;
    int newTimeout = 1001;
    int newBatch = 2001;
    Properties applicationProperties = assembleProperties(TIMEOUT_PROPERTY, String.valueOf(initialTimeout));
    SimpleConfig applicationConfig = prepareConfig(ConfigConsts.NAMESPACE_APPLICATION, applicationProperties);
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/XmlConfigPlaceholderTest1.xml");
    TestXmlBean bean = context.getBean(TestXmlBean.class);
    assertEquals(initialTimeout, bean.getTimeout());
    assertEquals(DEFAULT_BATCH, bean.getBatch());
    Properties newApplicationProperties = assembleProperties(TIMEOUT_PROPERTY, String.valueOf(newTimeout), BATCH_PROPERTY, String.valueOf(newBatch));
    applicationConfig.onRepositoryChange(ConfigConsts.NAMESPACE_APPLICATION, newApplicationProperties);
    TimeUnit.MILLISECONDS.sleep(100);
    assertEquals(newTimeout, bean.getTimeout());
    assertEquals(newBatch, bean.getBatch());
}
Also used : SimpleConfig(com.ctrip.framework.apollo.internals.SimpleConfig) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) TestXmlBean(com.ctrip.framework.apollo.spring.XmlConfigPlaceholderTest.TestXmlBean) Properties(java.util.Properties) Test(org.junit.Test)

Example 2 with TestXmlBean

use of com.ctrip.framework.apollo.spring.XmlConfigPlaceholderTest.TestXmlBean in project apollo by ctripcorp.

the class XmlConfigPlaceholderAutoUpdateTest method testAutoUpdateWithIrrelevantProperties.

@Test
public void testAutoUpdateWithIrrelevantProperties() throws Exception {
    int initialTimeout = 1000;
    String someIrrelevantKey = "someIrrelevantKey";
    String someIrrelevantValue = "someIrrelevantValue";
    String anotherIrrelevantKey = "anotherIrrelevantKey";
    String anotherIrrelevantValue = "anotherIrrelevantValue";
    Properties applicationProperties = assembleProperties(TIMEOUT_PROPERTY, String.valueOf(initialTimeout), someIrrelevantKey, someIrrelevantValue);
    SimpleConfig applicationConfig = prepareConfig(ConfigConsts.NAMESPACE_APPLICATION, applicationProperties);
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/XmlConfigPlaceholderTest1.xml");
    TestXmlBean bean = context.getBean(TestXmlBean.class);
    assertEquals(initialTimeout, bean.getTimeout());
    assertEquals(DEFAULT_BATCH, bean.getBatch());
    Properties newApplicationProperties = assembleProperties(TIMEOUT_PROPERTY, String.valueOf(initialTimeout), anotherIrrelevantKey, anotherIrrelevantValue);
    applicationConfig.onRepositoryChange(ConfigConsts.NAMESPACE_APPLICATION, newApplicationProperties);
    TimeUnit.MILLISECONDS.sleep(100);
    assertEquals(initialTimeout, bean.getTimeout());
    assertEquals(DEFAULT_BATCH, bean.getBatch());
}
Also used : SimpleConfig(com.ctrip.framework.apollo.internals.SimpleConfig) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) TestXmlBean(com.ctrip.framework.apollo.spring.XmlConfigPlaceholderTest.TestXmlBean) Properties(java.util.Properties) Test(org.junit.Test)

Example 3 with TestXmlBean

use of com.ctrip.framework.apollo.spring.XmlConfigPlaceholderTest.TestXmlBean in project apollo by ctripcorp.

the class XmlConfigPlaceholderAutoUpdateTest 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);
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/XmlConfigPlaceholderTest1.xml");
    TestXmlBean bean = context.getBean(TestXmlBean.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());
}
Also used : SimpleConfig(com.ctrip.framework.apollo.internals.SimpleConfig) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) TestXmlBean(com.ctrip.framework.apollo.spring.XmlConfigPlaceholderTest.TestXmlBean) Properties(java.util.Properties) Test(org.junit.Test)

Example 4 with TestXmlBean

use of com.ctrip.framework.apollo.spring.XmlConfigPlaceholderTest.TestXmlBean in project apollo by ctripcorp.

the class XmlConfigPlaceholderAutoUpdateTest method testAutoUpdateWithMultipleNamespacesWithSameProperties.

@Test
public void testAutoUpdateWithMultipleNamespacesWithSameProperties() throws Exception {
    int someTimeout = 1000;
    int someBatch = 2000;
    int anotherBatch = 3000;
    int someNewTimeout = 1001;
    int someNewBatch = 2001;
    Properties applicationProperties = assembleProperties(BATCH_PROPERTY, String.valueOf(someBatch));
    Properties fxApolloProperties = assembleProperties(TIMEOUT_PROPERTY, String.valueOf(someTimeout), BATCH_PROPERTY, String.valueOf(anotherBatch));
    prepareConfig(ConfigConsts.NAMESPACE_APPLICATION, applicationProperties);
    SimpleConfig fxApolloConfig = prepareConfig(FX_APOLLO_NAMESPACE, fxApolloProperties);
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/XmlConfigPlaceholderTest3.xml");
    TestXmlBean bean = context.getBean(TestXmlBean.class);
    assertEquals(someTimeout, bean.getTimeout());
    assertEquals(someBatch, bean.getBatch());
    Properties newFxApolloProperties = assembleProperties(TIMEOUT_PROPERTY, String.valueOf(someNewTimeout), BATCH_PROPERTY, String.valueOf(someNewBatch));
    fxApolloConfig.onRepositoryChange(FX_APOLLO_NAMESPACE, newFxApolloProperties);
    TimeUnit.MILLISECONDS.sleep(100);
    assertEquals(someNewTimeout, bean.getTimeout());
    assertEquals(someBatch, bean.getBatch());
}
Also used : SimpleConfig(com.ctrip.framework.apollo.internals.SimpleConfig) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) TestXmlBean(com.ctrip.framework.apollo.spring.XmlConfigPlaceholderTest.TestXmlBean) Properties(java.util.Properties) Test(org.junit.Test)

Example 5 with TestXmlBean

use of com.ctrip.framework.apollo.spring.XmlConfigPlaceholderTest.TestXmlBean in project apollo by ctripcorp.

the class XmlConfigPlaceholderAutoUpdateTest method testAutoUpdateWithDeletedPropertiesWithNoDefaultValue.

@Test
public void testAutoUpdateWithDeletedPropertiesWithNoDefaultValue() throws Exception {
    int initialTimeout = 1000;
    int initialBatch = 2000;
    int newTimeout = 1001;
    Properties properties = assembleProperties(TIMEOUT_PROPERTY, String.valueOf(initialTimeout), BATCH_PROPERTY, String.valueOf(initialBatch));
    SimpleConfig config = prepareConfig(ConfigConsts.NAMESPACE_APPLICATION, properties);
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/XmlConfigPlaceholderTest7.xml");
    TestXmlBean bean = context.getBean(TestXmlBean.class);
    assertEquals(initialTimeout, bean.getTimeout());
    assertEquals(initialBatch, bean.getBatch());
    Properties newProperties = assembleProperties(TIMEOUT_PROPERTY, String.valueOf(newTimeout));
    config.onRepositoryChange(ConfigConsts.NAMESPACE_APPLICATION, newProperties);
    TimeUnit.MILLISECONDS.sleep(300);
    assertEquals(newTimeout, bean.getTimeout());
    assertEquals(initialBatch, bean.getBatch());
}
Also used : SimpleConfig(com.ctrip.framework.apollo.internals.SimpleConfig) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) TestXmlBean(com.ctrip.framework.apollo.spring.XmlConfigPlaceholderTest.TestXmlBean) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

TestXmlBean (com.ctrip.framework.apollo.spring.XmlConfigPlaceholderTest.TestXmlBean)12 Test (org.junit.Test)12 SimpleConfig (com.ctrip.framework.apollo.internals.SimpleConfig)11 Properties (java.util.Properties)11 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)10 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)2 YamlConfigFile (com.ctrip.framework.apollo.internals.YamlConfigFile)1