|
@@ -7,6 +7,7 @@ import static org.junit.Assert.assertTrue;
|
|
|
import com.ctrip.framework.apollo.build.MockInjector;
|
|
|
import com.ctrip.framework.apollo.core.ConfigConsts;
|
|
|
import com.ctrip.framework.apollo.internals.SimpleConfig;
|
|
|
+import com.ctrip.framework.apollo.internals.YamlConfigFile;
|
|
|
import com.ctrip.framework.apollo.spring.JavaConfigPlaceholderTest.JsonBean;
|
|
|
import com.ctrip.framework.apollo.spring.XmlConfigPlaceholderTest.TestXmlBean;
|
|
|
import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
|
|
@@ -71,6 +72,31 @@ public class JavaConfigPlaceholderAutoUpdateTest extends AbstractSpringIntegrati
|
|
|
assertEquals(newBatch, bean.getBatch());
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void testAutoUpdateWithOneYamlFile() 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(AppConfig12.class);
|
|
|
+
|
|
|
+ TestJavaConfigBean bean = context.getBean(TestJavaConfigBean.class);
|
|
|
+
|
|
|
+ assertEquals(initialTimeout, bean.getTimeout());
|
|
|
+ assertEquals(initialBatch, bean.getBatch());
|
|
|
+
|
|
|
+ configFile.onRepositoryChange("application.yaml", readYamlContentAsConfigFileProperties("case1-new.yaml"));
|
|
|
+
|
|
|
+ TimeUnit.MILLISECONDS.sleep(100);
|
|
|
+
|
|
|
+ assertEquals(newTimeout, bean.getTimeout());
|
|
|
+ assertEquals(newBatch, bean.getBatch());
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
public void testAutoUpdateWithValueAndXmlProperty() throws Exception {
|
|
|
int initialTimeout = 1000;
|
|
@@ -106,6 +132,36 @@ public class JavaConfigPlaceholderAutoUpdateTest extends AbstractSpringIntegrati
|
|
|
assertEquals(newBatch, xmlBean.getBatch());
|
|
|
}
|
|
|
|
|
|
+ @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());
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
public void testAutoUpdateDisabled() throws Exception {
|
|
|
int initialTimeout = 1000;
|
|
@@ -213,6 +269,35 @@ public class JavaConfigPlaceholderAutoUpdateTest extends AbstractSpringIntegrati
|
|
|
assertEquals(someBatch, bean.getBatch());
|
|
|
}
|
|
|
|
|
|
+ @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());
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
public void testAutoUpdateWithNewProperties() throws Exception {
|
|
|
int initialTimeout = 1000;
|
|
@@ -241,6 +326,30 @@ public class JavaConfigPlaceholderAutoUpdateTest extends AbstractSpringIntegrati
|
|
|
assertEquals(newBatch, bean.getBatch());
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void testAutoUpdateWithNewPropertiesWithYamlFile() throws Exception {
|
|
|
+ int initialTimeout = 1000;
|
|
|
+ int newTimeout = 1001;
|
|
|
+ int newBatch = 2001;
|
|
|
+
|
|
|
+ YamlConfigFile configFile = prepareYamlConfigFile("application.yaml",
|
|
|
+ readYamlContentAsConfigFileProperties("case3.yaml"));
|
|
|
+
|
|
|
+ AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig12.class);
|
|
|
+
|
|
|
+ TestJavaConfigBean bean = context.getBean(TestJavaConfigBean.class);
|
|
|
+
|
|
|
+ assertEquals(initialTimeout, bean.getTimeout());
|
|
|
+ assertEquals(DEFAULT_BATCH, bean.getBatch());
|
|
|
+
|
|
|
+ configFile.onRepositoryChange("application.yaml", readYamlContentAsConfigFileProperties("case3-new.yaml"));
|
|
|
+
|
|
|
+ TimeUnit.MILLISECONDS.sleep(100);
|
|
|
+
|
|
|
+ assertEquals(newTimeout, bean.getTimeout());
|
|
|
+ assertEquals(newBatch, bean.getBatch());
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
public void testAutoUpdateWithIrrelevantProperties() throws Exception {
|
|
|
int initialTimeout = 1000;
|
|
@@ -301,6 +410,29 @@ public class JavaConfigPlaceholderAutoUpdateTest extends AbstractSpringIntegrati
|
|
|
assertEquals(DEFAULT_BATCH, bean.getBatch());
|
|
|
}
|
|
|
|
|
|
+ @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());
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
public void testAutoUpdateWithMultipleNamespacesWithSamePropertiesDeleted() throws Exception {
|
|
|
int someTimeout = 1000;
|
|
@@ -389,6 +521,30 @@ public class JavaConfigPlaceholderAutoUpdateTest extends AbstractSpringIntegrati
|
|
|
assertEquals(initialBatch, bean.getBatch());
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void testAutoUpdateWithTypeMismatchWithYamlFile() throws Exception {
|
|
|
+ int initialTimeout = 1000;
|
|
|
+ int initialBatch = 2000;
|
|
|
+ int newTimeout = 1001;
|
|
|
+
|
|
|
+ YamlConfigFile configFile = prepareYamlConfigFile("application.yaml",
|
|
|
+ readYamlContentAsConfigFileProperties("case5.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("case5-new.yaml"));
|
|
|
+
|
|
|
+ TimeUnit.MILLISECONDS.sleep(100);
|
|
|
+
|
|
|
+ assertEquals(newTimeout, bean.getTimeout());
|
|
|
+ assertEquals(initialBatch, bean.getBatch());
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
public void testAutoUpdateWithValueInjectedAsParameter() throws Exception {
|
|
|
int initialTimeout = 1000;
|
|
@@ -949,6 +1105,34 @@ public class JavaConfigPlaceholderAutoUpdateTest extends AbstractSpringIntegrati
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Configuration
|
|
|
+ @EnableApolloConfig("application.yaMl")
|
|
|
+ static class AppConfig12 {
|
|
|
+ @Bean
|
|
|
+ TestJavaConfigBean testJavaConfigBean() {
|
|
|
+ return new TestJavaConfigBean();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Configuration
|
|
|
+ @EnableApolloConfig("application.yaml")
|
|
|
+ @ImportResource("spring/XmlConfigPlaceholderTest11.xml")
|
|
|
+ static class AppConfig13 {
|
|
|
+ @Bean
|
|
|
+ TestJavaConfigBean testJavaConfigBean() {
|
|
|
+ return new TestJavaConfigBean();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Configuration
|
|
|
+ @EnableApolloConfig({"application.yml", "FX.apollo"})
|
|
|
+ static class AppConfig14 {
|
|
|
+ @Bean
|
|
|
+ TestJavaConfigBean testJavaConfigBean() {
|
|
|
+ return new TestJavaConfigBean();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
static class TestJavaConfigBean {
|
|
|
|
|
|
@Value("${timeout:100}")
|