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:04 UTC
[incubator-servicecomb-java-chassis] 02/02: SCB-29 fix pr comment
for integration test of 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 2e812dd80f1b947d9ae3dd839f2e17adc033b86f
Author: lijasonvip <li...@huawei.com>
AuthorDate: Thu Jan 18 16:06:14 2018 +0800
SCB-29 fix pr comment for integration test of dynamic configuration
---
integration-tests/dynamic-config-tests/pom.xml | 2 +-
.../dynamicconfig/test/DynamicConfigurationIT.java | 67 +++++++---------------
.../src/test/resources/microservice.yaml | 6 +-
3 files changed, 25 insertions(+), 50 deletions(-)
diff --git a/integration-tests/dynamic-config-tests/pom.xml b/integration-tests/dynamic-config-tests/pom.xml
index 7c2b828..719853d 100644
--- a/integration-tests/dynamic-config-tests/pom.xml
+++ b/integration-tests/dynamic-config-tests/pom.xml
@@ -80,7 +80,7 @@
</image>
<image>
<name>nobodyiam/apollo-quick-start</name>
- <alias>apollo-quick-start</alias>
+ <alias>apollo.servicecomb.apache.org</alias>
<run>
<links>
<link>apollo-db</link>
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 a8f0eff..5031c14 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
@@ -43,10 +43,10 @@ import com.netflix.config.DynamicPropertyFactory;
import com.netflix.config.DynamicStringProperty;
public class DynamicConfigurationIT {
-
-
- public static String url;
- public static String token;
+ 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 {
@@ -54,31 +54,32 @@ public class DynamicConfigurationIT {
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() throws Exception {
- //delete
+ public void tearDown() {
clearConfiguration();
}
- //delete configuration items set by test code
- public void clearConfiguration() {
+ public int 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<>();
+ 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");
- entity = new HttpEntity<Object>(body, headers);
- exchange = rest.exchange(release, HttpMethod.POST, entity, String.class);
-
+ HttpEntity<?> entity = new HttpEntity<Object>(body, headers);
+ ResponseEntity<String> exchange = rest.exchange(release, HttpMethod.POST, entity, String.class);
+ return exchange.getStatusCodeValue();
}
@Test
@@ -86,40 +87,20 @@ public class DynamicConfigurationIT {
//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());
+ Assert.assertEquals(releaseConfiguration(), HttpStatus.OK);
- //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();
@@ -129,14 +110,8 @@ public class DynamicConfigurationIT {
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);
- //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/microservice.yaml b/integration-tests/dynamic-config-tests/src/test/resources/microservice.yaml
index f538cff..b83cc76 100644
--- a/integration-tests/dynamic-config-tests/src/test/resources/microservice.yaml
+++ b/integration-tests/dynamic-config-tests/src/test/resources/microservice.yaml
@@ -16,14 +16,14 @@
## limitations under the License.
## ---------------------------------------------------------------------------
-APPLICATION_ID: pojotest
+APPLICATION_ID: dynamic-config-test
service_description:
name: apollo-test
version: 1.0.1
apollo:
config:
- serverUri: http://apollo-quick-start:8070
+ serverUri: http://apollo.servicecomb.apache.org:8070
serviceName: SampleApp
env: DEV
clusters: default
@@ -33,4 +33,4 @@ apollo:
cse:
config:
client:
- serverUri: http://127.0.0.1:8070
\ No newline at end of file
+ serverUri: http://apollo.servicecomb.apache.org:8070
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
"commits@servicecomb.apache.org" <co...@servicecomb.apache.org>.