Search in sources :

Example 31 with SimpleConfig

use of com.ctrip.framework.apollo.internals.SimpleConfig in project apollo by ctripcorp.

the class JavaConfigPlaceholderAutoUpdateTest 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);
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig2.class);
    TestJavaConfigBean bean = context.getBean(TestJavaConfigBean.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) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) Properties(java.util.Properties) Test(org.junit.Test)

Example 32 with SimpleConfig

use of com.ctrip.framework.apollo.internals.SimpleConfig in project apollo by ctripcorp.

the class XmlConfigPlaceholderAutoUpdateTest method testAutoUpdateWithValueAndProperty.

@Test
public void testAutoUpdateWithValueAndProperty() 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);
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/XmlConfigPlaceholderTest9.xml");
    TestXmlBeanWithInjectedValue bean = context.getBean(TestXmlBeanWithInjectedValue.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(newTimeout, bean.getTimeout());
    assertEquals(newBatch, bean.getBatch());
}
Also used : SimpleConfig(com.ctrip.framework.apollo.internals.SimpleConfig) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Properties(java.util.Properties) Test(org.junit.Test)

Example 33 with SimpleConfig

use of com.ctrip.framework.apollo.internals.SimpleConfig in project apollo by ctripcorp.

the class XmlConfigPlaceholderAutoUpdateTest method testAutoUpdateWithOneNamespace.

@Test
public void testAutoUpdateWithOneNamespace() 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);
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/XmlConfigPlaceholderTest1.xml");
    TestXmlBean bean = context.getBean(TestXmlBean.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(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 34 with SimpleConfig

use of com.ctrip.framework.apollo.internals.SimpleConfig in project apollo by ctripcorp.

the class XmlConfigPlaceholderAutoUpdateTest method testAutoUpdateWithTypeMismatch.

@Test
public void testAutoUpdateWithTypeMismatch() throws Exception {
    int initialTimeout = 1000;
    int initialBatch = 2000;
    int newTimeout = 1001;
    String newBatch = "newBatch";
    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 = assembleProperties(TIMEOUT_PROPERTY, String.valueOf(newTimeout), BATCH_PROPERTY, newBatch);
    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)

Example 35 with SimpleConfig

use of com.ctrip.framework.apollo.internals.SimpleConfig in project apollo by ctripcorp.

the class XmlConfigPlaceholderAutoUpdateTest 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);
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/XmlConfigPlaceholderTest3.xml");
    TestXmlBean bean = context.getBean(TestXmlBean.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());
}
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

SimpleConfig (com.ctrip.framework.apollo.internals.SimpleConfig)38 Properties (java.util.Properties)37 Test (org.junit.Test)37 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)23 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)13 TestXmlBean (com.ctrip.framework.apollo.spring.XmlConfigPlaceholderTest.TestXmlBean)11 JsonBean (com.ctrip.framework.apollo.spring.JavaConfigPlaceholderTest.JsonBean)3 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 Config (com.ctrip.framework.apollo.Config)1 ConfigChangeListener (com.ctrip.framework.apollo.ConfigChangeListener)1 ConfigRepository (com.ctrip.framework.apollo.internals.ConfigRepository)1 ConfigChangeEvent (com.ctrip.framework.apollo.model.ConfigChangeEvent)1 ApolloConfig (com.ctrip.framework.apollo.spring.annotation.ApolloConfig)1 ApolloConfigChangeListener (com.ctrip.framework.apollo.spring.annotation.ApolloConfigChangeListener)1 EnableApolloConfig (com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig)1 Set (java.util.Set)1 Matchers.anyString (org.mockito.Matchers.anyString)1