You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by ni...@apache.org on 2018/01/19 14:09:03 UTC

[incubator-servicecomb-java-chassis] 01/02: SCB-29 integration tests for dynamic configuration

This is an automated email from the ASF dual-hosted git repository.

ningjiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git

commit dd343defdd63427e0c60eb6b68776aa6a4d4f712
Author: lijasonvip <li...@huawei.com>
AuthorDate: Wed Jan 17 22:32:47 2018 +0800

    SCB-29 integration tests for dynamic configuration
    
    Signed-off-by: lijasonvip <li...@huawei.com>
---
 integration-tests/dynamic-config-tests/pom.xml     | 130 +++++++++++++++++++
 .../dynamicconfig/test/DynamicConfigurationIT.java | 144 +++++++++++++++++++++
 .../src/test/resources/log4j.properties            |  17 +++
 .../src/test/resources/microservice.yaml           |  36 ++++++
 integration-tests/pom.xml                          |   1 +
 5 files changed, 328 insertions(+)

diff --git a/integration-tests/dynamic-config-tests/pom.xml b/integration-tests/dynamic-config-tests/pom.xml
new file mode 100644
index 0000000..7c2b828
--- /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-quick-start</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 0000000..a8f0eff
--- /dev/null
+++ b/integration-tests/dynamic-config-tests/src/test/java/org/apache/dynamicconfig/test/DynamicConfigurationIT.java
@@ -0,0 +1,144 @@
+/*
+ * 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 {
+
+
+  public static String url;
+  public static String token;
+
+  @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();
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    //delete
+    clearConfiguration();
+  }
+
+  //delete configuration items set by test code
+  public void clearConfiguration() {
+    String delete = url + "/openapi/v1/envs/DEV/apps/SampleApp/clusters/default/namespaces/application/items/loadbalance?operator=apollo";
+    String release = url + "/openapi/v1/envs/DEV/apps/SampleApp/clusters/default/namespaces/application/releases";
+    RestTemplate rest = new RestTemplate();
+    HttpHeaders headers = new HttpHeaders();
+    headers.add("Content-Type", "application/json;charset=UTF-8");
+    headers.add("Authorization", token);
+    HttpEntity<?> entity = new HttpEntity<Object>(headers);
+
+    ResponseEntity<String> exchange = rest.exchange(delete, HttpMethod.DELETE, entity, String.class);
+    Map<String,String> body = new HashMap<>();
+    body.put("releaseTitle", "release-configuration");
+    body.put("releasedBy", "apollo");
+    entity = new HttpEntity<Object>(body, headers);
+    exchange = rest.exchange(release, HttpMethod.POST, entity, String.class);
+
+  }
+
+  @Test
+  public void testDynamicConfiguration() {
+    //before
+    Assert.assertEquals(DynamicPropertyFactory.getInstance().getStringProperty("loadbalcance", "default").getValue(), "default");
+
+    //set and return 200. release 200,update return 200
+
+    String setLoadBalance = url + "/openapi/v1/envs/DEV/apps/SampleApp/clusters/default/namespaces/application/items";
+
+    String release = url + "/openapi/v1/envs/DEV/apps/SampleApp/clusters/default/namespaces/application/releases";
+    RestTemplate rest = new RestTemplate();
+    HttpHeaders headers = new HttpHeaders();
+    headers.add("Content-Type", "application/json;charset=UTF-8");
+    headers.add("Authorization", token);
+
+    //set new configuration item
+    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());
+
+    //relese loadbalance item
+    body.clear();
+    body.put("releaseTitle", "release-configuration");
+    body.put("releasedBy", "apollo");
+    entity = new HttpEntity<Object>(body, headers);
+    exchange = rest.exchange(release, HttpMethod.POST, entity, String.class);
+    Assert.assertEquals(exchange.getStatusCodeValue(), HttpStatus.OK.value());
+
+    //waiting for a refresh cycle
+    await().atMost(5, SECONDS).until(
+        () -> DynamicPropertyFactory.getInstance().getStringProperty("loadbalance", "default").getValue()
+            .equals("roundrobbin"));
+
+    //update loadbalance value
+    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());
+
+    //release again
+    body.clear();
+    body.put("releaseTitle", "test-release");
+    body.put("releasedBy", "apollo");
+    entity = new HttpEntity<Object>(body, headers);
+    exchange = rest.exchange(release, HttpMethod.POST, entity, String.class);
+    Assert.assertEquals(exchange.getStatusCodeValue(), HttpStatus.OK.value());
+    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 0000000..ba21655
--- /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 0000000..f538cff
--- /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: pojotest
+service_description:
+  name: apollo-test
+  version: 1.0.1
+
+apollo:
+  config:
+    serverUri: http://apollo-quick-start:8070
+    serviceName: SampleApp
+    env: DEV
+    clusters: default
+    namespace: application
+    token: testtoken
+    refreshInterval: 2
+cse:
+  config:
+    client:
+      serverUri: http://127.0.0.1:8070
\ No newline at end of file
diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml
index c5cd398..3412202 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>

-- 
To stop receiving notification emails like this one, please contact
"commits@servicecomb.apache.org" <co...@servicecomb.apache.org>.