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

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

commit c121ba897388f0625087ba6453c0d5c48f9dabc0
Author: zhengyangyong <yangyong.zh...@huawei.com>
AuthorDate: Fri Jul 20 14:52:15 2018 +0800

    SCB-763 use vertx sim apollo server in order to simplify dynamic config 
(apollo) integration test
    
    Signed-off-by: zhengyangyong <yangyong.zh...@huawei.com>
---
 integration-tests/dynamic-config-tests/pom.xml     | 83 ------------------
 .../dynamicconfig/test/DynamicConfigurationIT.java | 97 +++-------------------
 .../apache/dynamicconfig/test/SimApolloServer.java | 45 ++++++++++
 .../src/test/resources/microservice.yaml           |  6 +-
 4 files changed, 57 insertions(+), 174 deletions(-)

diff --git a/integration-tests/dynamic-config-tests/pom.xml 
b/integration-tests/dynamic-config-tests/pom.xml
index f265cff..7ce0ca2 100644
--- a/integration-tests/dynamic-config-tests/pom.xml
+++ b/integration-tests/dynamic-config-tests/pom.xml
@@ -46,87 +46,4 @@
     </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>
-                      <container>mysql</container>
-                    </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
index bf61612..fbe557b 100644
--- 
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
@@ -17,112 +17,37 @@
 
 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.AfterClass;
 import org.junit.Assert;
 import org.junit.BeforeClass;
 import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-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.web.client.RestTemplate;
 
 import com.netflix.config.DynamicPropertyFactory;
 
-public class DynamicConfigurationIT {
-  private static final Logger LOGGER = 
LoggerFactory.getLogger(DynamicConfigurationIT.class);
-
-  private static String url;
+import io.vertx.core.Vertx;
 
-  private static String token;
-
-  private static final HttpHeaders headers = new HttpHeaders();
-
-  private static final RestTemplate rest = new RestTemplate();
+public class DynamicConfigurationIT {
+  private static Vertx vertx = null;
 
   @BeforeClass
   public static void setUp() throws Exception {
-    LOGGER.info("testDynamicConfiguration set up");
+    vertx = Vertx.vertx();
+    vertx.deployVerticle(new SimApolloServer());
+
     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();
+  @AfterClass
+  public static void tearDown() {
+    vertx.close();
   }
 
-  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() {
-    LOGGER.info("testDynamicConfiguration starting");
-    //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"));
-
-    LOGGER.info("testDynamicConfiguration end");
+    Assert.assertEquals(6666, 
DynamicPropertyFactory.getInstance().getIntProperty("timeout", 0).get());
   }
 }
diff --git 
a/integration-tests/dynamic-config-tests/src/test/java/org/apache/dynamicconfig/test/SimApolloServer.java
 
b/integration-tests/dynamic-config-tests/src/test/java/org/apache/dynamicconfig/test/SimApolloServer.java
new file mode 100644
index 0000000..60315ac
--- /dev/null
+++ 
b/integration-tests/dynamic-config-tests/src/test/java/org/apache/dynamicconfig/test/SimApolloServer.java
@@ -0,0 +1,45 @@
+/*
+ * 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 io.vertx.core.AbstractVerticle;
+
+public class SimApolloServer extends AbstractVerticle {
+  public void start() {
+    String response = "{\n"
+        + "  \"appId\": \"test\",\n"
+        + "  \"clusterName\": \"default\",\n"
+        + "  \"namespaceName\": \"application\",\n"
+        + "  \"name\": \"20180703151728-release\",\n"
+        + "  \"configurations\": {\n"
+        + "    \"timeout\": \"6666\"\n"
+        + "  },\n"
+        + "  \"comment\": \"\",\n"
+        + "  \"dataChangeCreatedBy\": \"apollo\",\n"
+        + "  \"dataChangeLastModifiedBy\": \"apollo\",\n"
+        + "  \"dataChangeCreatedTime\": \"2018-07-03T15:17:32.000+0800\",\n"
+        + "  \"dataChangeLastModifiedTime\": 
\"2018-07-03T15:17:32.000+0800\"\n"
+        + "}";
+
+    vertx.createHttpServer().requestHandler(req -> {
+      req.response()
+          .putHeader("content-type", "application/json")
+          .end(response);
+    }).listen(8080);
+  }
+}
\ 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
index ffc5b92..12d0cf8 100644
--- 
a/integration-tests/dynamic-config-tests/src/test/resources/microservice.yaml
+++ 
b/integration-tests/dynamic-config-tests/src/test/resources/microservice.yaml
@@ -23,7 +23,7 @@ service_description:
 
 apollo:
   config:
-    serverUri: http://apollo.servicecomb.apache.org:8070
+    serverUri: http://localhost:8080
     serviceName: SampleApp
     env: DEV
     clusters: default
@@ -31,7 +31,3 @@ apollo:
     token: testtoken
     refreshInterval: 2
 
-servicecomb:
-  config:
-    client:
-      serverUri: http://apollo.servicecomb.apache.org:8070
\ No newline at end of file

Reply via email to