WillemJiang closed pull request #514: SCB-29 integration tests for dynamic configuration URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/514
This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/integration-tests/dynamic-config-tests/pom.xml b/integration-tests/dynamic-config-tests/pom.xml new file mode 100644 index 000000000..719853dcd --- /dev/null +++ b/integration-tests/dynamic-config-tests/pom.xml @@ -0,0 +1,130 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one or more + ~ contributor license agreements. See the NOTICE file distributed with + ~ this work for additional information regarding copyright ownership. + ~ The ASF licenses this file to You under the Apache License, Version 2.0 + ~ (the "License"); you may not use this file except in compliance with + ~ the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <parent> + <artifactId>integration-tests</artifactId> + <groupId>org.apache.servicecomb.tests</groupId> + <version>0.6.0-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + + <artifactId>dynamic-config-tests</artifactId> + + <dependencies> + <dependency> + <groupId>org.apache.servicecomb</groupId> + <artifactId>foundation-common</artifactId> + </dependency> + <dependency> + <groupId>com.netflix.archaius</groupId> + <artifactId>archaius-core</artifactId> + </dependency> + <dependency> + <groupId>org.apache.servicecomb</groupId> + <artifactId>config-apollo</artifactId> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + </dependency> + </dependencies> + + + <profiles> + <profile> + <id>docker</id> + <build> + <plugins> + <plugin> + <groupId>io.fabric8</groupId> + <artifactId>docker-maven-plugin</artifactId> + <configuration> + <images> + <image> + <name>lijasonvip/apollodb:1.2</name> + <alias>apollo-db</alias> + <run> + <env> + <TOKEN>testtoken</TOKEN> + </env> + <wait> + <log>mysqld: ready for connections</log> + <tcp> + <ports> + <port>3306</port> + </ports> + </tcp> + <time>60000</time> + </wait> + <ports> + <port>apollodb.port:3306</port> + </ports> + </run> + </image> + <image> + <name>nobodyiam/apollo-quick-start</name> + <alias>apollo.servicecomb.apache.org</alias> + <run> + <links> + <link>apollo-db</link> + </links> + <wait> + <log>Portal started</log> + <tcp> + <ports> + <port>8080</port> + <port>8070</port> + </ports> + </tcp> + <time>120000</time> + </wait> + <ports> + <port>apollo.config:8080</port> + <port>apollo.portal:8070</port> + </ports> + <dependsOn>mysql</dependsOn> + </run> + </image> + </images> + + </configuration> + <executions> + <execution> + <id>start</id> + <phase>pre-integration-test</phase> + <goals> + <goal>start</goal> + </goals> + </execution> + <execution> + <id>stop</id> + <phase>post-integration-test</phase> + <goals> + <goal>stop</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> + </profiles> + +</project> \ No newline at end of file diff --git a/integration-tests/dynamic-config-tests/src/test/java/org/apache/dynamicconfig/test/DynamicConfigurationIT.java b/integration-tests/dynamic-config-tests/src/test/java/org/apache/dynamicconfig/test/DynamicConfigurationIT.java new file mode 100644 index 000000000..5031c1495 --- /dev/null +++ b/integration-tests/dynamic-config-tests/src/test/java/org/apache/dynamicconfig/test/DynamicConfigurationIT.java @@ -0,0 +1,119 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dynamicconfig.test; + +import static java.util.concurrent.TimeUnit.SECONDS; +import static org.awaitility.Awaitility.await; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.servicecomb.foundation.common.utils.BeanUtils; +import org.apache.servicecomb.foundation.common.utils.Log4jUtils; +import org.junit.After; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.web.client.RestTemplate; + +import com.netflix.config.DynamicIntProperty; +import com.netflix.config.DynamicPropertyFactory; +import com.netflix.config.DynamicStringProperty; + +public class DynamicConfigurationIT { + private static String url; + private static String token; + private static final HttpHeaders headers = new HttpHeaders(); + private static final RestTemplate rest = new RestTemplate(); + + @BeforeClass + public static void setUp() throws Exception { + Log4jUtils.init(); + BeanUtils.init(); + url = DynamicPropertyFactory.getInstance().getStringProperty("apollo.config.serverUri", "missing").getValue(); + token = DynamicPropertyFactory.getInstance().getStringProperty("apollo.config.token", "missing").getValue(); + headers.add("Content-Type", "application/json;charset=UTF-8"); + headers.add("Authorization", token); + } + + @After + public void tearDown() { + clearConfiguration(); + } + + public int clearConfiguration() { + String delete = url + "/openapi/v1/envs/DEV/apps/SampleApp/clusters/default/namespaces/application/items/loadbalance?operator=apollo"; + HttpEntity<?> entity = new HttpEntity<Object>(headers); + ResponseEntity<String> exchange = rest.exchange(delete, HttpMethod.DELETE, entity, String.class); + Assert.assertEquals(exchange.getStatusCodeValue(), HttpStatus.OK); + return releaseConfiguration(); + } + + public int releaseConfiguration(){ + String release = url + "/openapi/v1/envs/DEV/apps/SampleApp/clusters/default/namespaces/application/releases"; + RestTemplate rest = new RestTemplate(); + Map<String, String> body = new HashMap<>(); + body.put("releaseTitle", "release-configuration"); + body.put("releasedBy", "apollo"); + HttpEntity<?> entity = new HttpEntity<Object>(body, headers); + ResponseEntity<String> exchange = rest.exchange(release, HttpMethod.POST, entity, String.class); + return exchange.getStatusCodeValue(); + } + + @Test + public void testDynamicConfiguration() { + //before + Assert.assertEquals(DynamicPropertyFactory.getInstance().getStringProperty("loadbalcance", "default").getValue(), "default"); + + String setLoadBalance = url + "/openapi/v1/envs/DEV/apps/SampleApp/clusters/default/namespaces/application/items"; + Map<String, String> body = new HashMap<>(); + body.put("key", "loadbalance"); + body.put("value", "roundrobbin"); + body.put("dataChangeCreatedBy", "apollo"); + HttpEntity<?> entity = new HttpEntity<Object>(body, headers); + ResponseEntity<String> exchange = rest.exchange(setLoadBalance, HttpMethod.POST, entity, String.class); + Assert.assertEquals(exchange.getStatusCodeValue(), HttpStatus.OK.value()); + Assert.assertEquals(releaseConfiguration(), HttpStatus.OK); + + await().atMost(5, SECONDS).until( + () -> DynamicPropertyFactory.getInstance().getStringProperty("loadbalance", "default").getValue() + .equals("roundrobbin")); + + String updateLoadBalance = + url + "/openapi/v1/envs/DEV/apps/SampleApp/clusters/default/namespaces/application/items/" + "loadbalance"; + body.clear(); + body.put("key", "loadbalance"); + body.put("value", "random"); + body.put("dataChangeLastModifiedBy", "apollo"); + entity = new HttpEntity<Object>(body, headers); + exchange = rest.exchange(updateLoadBalance, HttpMethod.PUT, entity, String.class); + Assert.assertEquals(exchange.getStatusCodeValue(), HttpStatus.OK.value()); + Assert.assertEquals(releaseConfiguration(), HttpStatus.OK); + + await().atMost(5, SECONDS).until( + () -> DynamicPropertyFactory.getInstance().getStringProperty("loadbalance", "default").getValue() + .equals("random")); + } +} diff --git a/integration-tests/dynamic-config-tests/src/test/resources/log4j.properties b/integration-tests/dynamic-config-tests/src/test/resources/log4j.properties new file mode 100644 index 000000000..ba2165551 --- /dev/null +++ b/integration-tests/dynamic-config-tests/src/test/resources/log4j.properties @@ -0,0 +1,17 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +log4j.rootLogger=INFO \ No newline at end of file diff --git a/integration-tests/dynamic-config-tests/src/test/resources/microservice.yaml b/integration-tests/dynamic-config-tests/src/test/resources/microservice.yaml new file mode 100644 index 000000000..b83cc7645 --- /dev/null +++ b/integration-tests/dynamic-config-tests/src/test/resources/microservice.yaml @@ -0,0 +1,36 @@ +# +## --------------------------------------------------------------------------- +## Licensed to the Apache Software Foundation (ASF) under one or more +## contributor license agreements. See the NOTICE file distributed with +## this work for additional information regarding copyright ownership. +## The ASF licenses this file to You under the Apache License, Version 2.0 +## (the "License"); you may not use this file except in compliance with +## the License. You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## --------------------------------------------------------------------------- + +APPLICATION_ID: dynamic-config-test +service_description: + name: apollo-test + version: 1.0.1 + +apollo: + config: + serverUri: http://apollo.servicecomb.apache.org:8070 + serviceName: SampleApp + env: DEV + clusters: default + namespace: application + token: testtoken + refreshInterval: 2 +cse: + config: + client: + serverUri: http://apollo.servicecomb.apache.org:8070 \ No newline at end of file diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index c5cd3984b..341220235 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -40,6 +40,7 @@ <module>spring-springmvc-tests</module> <module>spring-zuul-tracing-tests</module> <module>spring-pojo-tests</module> + <module>dynamic-config-tests</module> </modules> <dependencyManagement> ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
