wujimin closed pull request #826: [SCB-763] simplify dynamic config (apollo) 
integration test
URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/826
 
 
   

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
index f265cff2e..7ce0ca252 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 bf6161296..fbe557b12 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 000000000..fac81834a
--- /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(23334);
+  }
+}
\ 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 ffc5b92bb..b7b9e62fe 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:23334
     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


 

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to