You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2021/02/25 07:08:47 UTC

[servicecomb-java-chassis] branch master updated: [#1946] add examples/test case for this issue (#2251)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 3a7cbca  [#1946] add examples/test case for this issue (#2251)
3a7cbca is described below

commit 3a7cbcab01a8a189e23357f12709ab790f7eb25c
Author: bao liu <bi...@qq.com>
AuthorDate: Thu Feb 25 15:08:39 2021 +0800

    [#1946] add examples/test case for this issue (#2251)
---
 .../springmvc/client/PlaceHolderSchemaTest.java    | 34 ++++++++++++++++++++++
 .../src/main/resources/application.yml             |  2 ++
 .../springmvc/server/PlaceHolderSchema.java        | 32 ++++++++++++++++++++
 .../src/main/resources/application.yml             | 12 +++++++-
 .../demo/springmvc/client/SpringmvcClient.java     | 21 ++++++++-----
 .../demo/springmvc/client/TestWeakSpringmvc.java   | 10 +++++--
 .../springmvc/server/ProducerTestsAfterBootup.java |  7 ++++-
 7 files changed, 106 insertions(+), 12 deletions(-)

diff --git a/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-client/src/main/java/org/apache/servicecomb/springboot/springmvc/client/PlaceHolderSchemaTest.java b/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-client/src/main/java/org/apache/servicecomb/springboot/springmvc/client/PlaceHolderSchemaTest.java
new file mode 100644
index 0000000..dc616c6
--- /dev/null
+++ b/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-client/src/main/java/org/apache/servicecomb/springboot/springmvc/client/PlaceHolderSchemaTest.java
@@ -0,0 +1,34 @@
+/*
+ * 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.servicecomb.springboot.springmvc.client;
+
+import org.apache.servicecomb.demo.CategorizedTestCase;
+import org.apache.servicecomb.demo.TestMgr;
+import org.apache.servicecomb.provider.springmvc.reference.RestTemplateBuilder;
+import org.springframework.stereotype.Component;
+import org.springframework.web.client.RestTemplate;
+
+@Component
+public class PlaceHolderSchemaTest implements CategorizedTestCase {
+  @Override
+  public void testAllTransport() throws Exception {
+    RestTemplate template = RestTemplateBuilder.create();
+    String result = template.getForObject("servicecomb://springmvc/placeholder/schema?name=test", String.class);
+    TestMgr.check("test", result);
+  }
+}
diff --git a/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-client/src/main/resources/application.yml b/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-client/src/main/resources/application.yml
index ffd57a8..a036aac 100644
--- a/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-client/src/main/resources/application.yml
+++ b/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-client/src/main/resources/application.yml
@@ -15,6 +15,8 @@
 ## limitations under the License.
 ## ---------------------------------------------------------------------------
 
+APPLICATION_ID: springmvcboottest
+
 server:
   port: 8999
 servicecomb:
diff --git a/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-server/src/main/java/org/apache/servicecomb/springboot/springmvc/server/PlaceHolderSchema.java b/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-server/src/main/java/org/apache/servicecomb/springboot/springmvc/server/PlaceHolderSchema.java
new file mode 100644
index 0000000..bb75e8e
--- /dev/null
+++ b/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-server/src/main/java/org/apache/servicecomb/springboot/springmvc/server/PlaceHolderSchema.java
@@ -0,0 +1,32 @@
+/*
+ * 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.servicecomb.springboot.springmvc.server;
+
+import org.apache.servicecomb.provider.rest.common.RestSchema;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+
+@RestSchema(schemaId = "PlaceHolderSchema")
+@RequestMapping(path = "${test.placeholder.schema}")
+public class PlaceHolderSchema {
+  @GetMapping(path = "/")
+  public String root(@RequestParam("name") String name) {
+    return name;
+  }
+}
diff --git a/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-server/src/main/resources/application.yml b/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-server/src/main/resources/application.yml
index 869e1f5..4165078 100644
--- a/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-server/src/main/resources/application.yml
+++ b/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-server/src/main/resources/application.yml
@@ -15,7 +15,17 @@
 ## limitations under the License.
 ## ---------------------------------------------------------------------------
 
+APPLICATION_ID: springmvcboottest
+
 server:
   port: 8080
 
-test.unresolved.placeholder: jdbc:postgresql://${ip}:${port}/pt
\ No newline at end of file
+test.unresolved.placeholder: jdbc:postgresql://${ip}:${port}/pt
+test:
+  placeholder:
+    schema: placeholder/schema
+
+servicecomb:
+  test:
+    vert:
+      transport: false
\ No newline at end of file
diff --git a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/SpringmvcClient.java b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/SpringmvcClient.java
index b3a1a79..c44c3e1 100644
--- a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/SpringmvcClient.java
+++ b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/SpringmvcClient.java
@@ -159,20 +159,27 @@ public class SpringmvcClient {
       String content = restTemplate
           .getForObject("cse://springmvc/codeFirstSpringmvc/prometheusForTest", String.class);
 
+      String application = DynamicPropertyFactory.getInstance().getStringProperty("APPLICATION_ID", "").get();
+
       TestMgr.check(true,
-          content.contains("servicecomb_invocation{appId=\"springmvctest\",operation=\"springmvc.codeFirst.addDate"));
+          content.contains(
+              "servicecomb_invocation{appId=\"" + application + "\",operation=\"springmvc.codeFirst.addDate"));
       TestMgr.check(true,
-          content.contains("servicecomb_invocation{appId=\"springmvctest\",operation=\"springmvc.codeFirst.sayHello"));
+          content.contains(
+              "servicecomb_invocation{appId=\"" + application + "\",operation=\"springmvc.codeFirst.sayHello"));
       TestMgr.check(true, content.contains(
-          "servicecomb_invocation{appId=\"springmvctest\",operation=\"springmvc.codeFirst.fallbackFromCache"));
+          "servicecomb_invocation{appId=\"" + application + "\",operation=\"springmvc.codeFirst.fallbackFromCache"));
       TestMgr.check(true,
-          content.contains("servicecomb_invocation{appId=\"springmvctest\",operation=\"springmvc.codeFirst.isTrue"));
+          content
+              .contains("servicecomb_invocation{appId=\"" + application + "\",operation=\"springmvc.codeFirst.isTrue"));
       TestMgr.check(true,
-          content.contains("servicecomb_invocation{appId=\"springmvctest\",operation=\"springmvc.codeFirst.add"));
+          content.contains("servicecomb_invocation{appId=\"" + application + "\",operation=\"springmvc.codeFirst.add"));
       TestMgr.check(true,
-          content.contains("servicecomb_invocation{appId=\"springmvctest\",operation=\"springmvc.codeFirst.sayHi2"));
+          content
+              .contains("servicecomb_invocation{appId=\"" + application + "\",operation=\"springmvc.codeFirst.sayHi2"));
       TestMgr.check(true, content
-          .contains("servicecomb_invocation{appId=\"springmvctest\",operation=\"springmvc.codeFirst.saySomething"));
+          .contains(
+              "servicecomb_invocation{appId=\"" + application + "\",operation=\"springmvc.codeFirst.saySomething"));
 
       String[] metricLines = content.split("\n");
       if (metricLines.length > 0) {
diff --git a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestWeakSpringmvc.java b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestWeakSpringmvc.java
index 3802ca1..3c465cf 100644
--- a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestWeakSpringmvc.java
+++ b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestWeakSpringmvc.java
@@ -30,6 +30,7 @@ import org.apache.servicecomb.demo.server.GenericsModel;
 import org.apache.servicecomb.foundation.common.utils.JsonUtils;
 import org.apache.servicecomb.provider.pojo.RpcReference;
 import org.apache.servicecomb.provider.springmvc.reference.RestTemplateBuilder;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
 import org.springframework.web.client.RestTemplate;
 
@@ -96,6 +97,9 @@ interface SpecialNameModelInf {
 
 @Component
 public class TestWeakSpringmvc implements CategorizedTestCase {
+  @Value("${APPLICATION_ID}")
+  private String applicationName;
+
   @RpcReference(microserviceName = "springmvc", schemaId = "weakSpringmvc")
   private DiffNames diffNames;
 
@@ -111,7 +115,7 @@ public class TestWeakSpringmvc implements CategorizedTestCase {
   @RpcReference(microserviceName = "springmvc", schemaId = "weakSpringmvc")
   private SpecialNameModelInf specialNameModelInf;
 
-  @RpcReference(microserviceName = "springmvctest:springmvc", schemaId = "weakSpringmvc")
+  @RpcReference(microserviceName = "${APPLICATION_ID}:springmvc", schemaId = "weakSpringmvc")
   private SpecialNameModelInf specialNameModelInfWithAppId;
 
   private RestTemplate restTemplate = RestTemplateBuilder.create();
@@ -182,14 +186,14 @@ public class TestWeakSpringmvc implements CategorizedTestCase {
     TestMgr.check(8, diffNames2.differentName(2, 3));
     TestMgr.check(7, restTemplate.getForObject("cse://springmvc/weakSpringmvc/diffNames?x=2&y=3", Integer.class));
     TestMgr.check(7, restTemplate
-        .getForObject("cse://springmvctest:springmvc/weakSpringmvc/diffNames?x=2&y=3",
+        .getForObject("cse://" + applicationName + ":springmvc/weakSpringmvc/diffNames?x=2&y=3",
             Integer.class));
     Map<String, Object> args = new HashMap<>();
     args.put("x", 2);
     args.put("y", 3);
     TestMgr.check(7, InvokerUtils.syncInvoke("springmvc",
         "weakSpringmvc", "differentName", args));
-    TestMgr.check(7, InvokerUtils.syncInvoke("springmvctest:springmvc",
+    TestMgr.check(7, InvokerUtils.syncInvoke(applicationName + ":springmvc",
         "weakSpringmvc", "differentName", args));
   }
 }
diff --git a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/ProducerTestsAfterBootup.java b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/ProducerTestsAfterBootup.java
index acde805..60ef51a 100644
--- a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/ProducerTestsAfterBootup.java
+++ b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/ProducerTestsAfterBootup.java
@@ -28,6 +28,7 @@ import org.springframework.stereotype.Component;
 
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectWriter;
+import com.netflix.config.DynamicPropertyFactory;
 
 import io.swagger.models.Swagger;
 import io.swagger.util.Yaml;
@@ -89,7 +90,11 @@ public class ProducerTestsAfterBootup implements BootListener {
   }
 
   public void testRegisteredBasePath() {
-    TestMgr.check(17, RegistrationManager.INSTANCE.getMicroservice().getPaths().size());
+    if (DynamicPropertyFactory.getInstance().getBooleanProperty("servicecomb.test.vert.transport", true).get()) {
+      TestMgr.check(17, RegistrationManager.INSTANCE.getMicroservice().getPaths().size());
+    } else {
+      TestMgr.check(18, RegistrationManager.INSTANCE.getMicroservice().getPaths().size());
+    }
   }
 
   private String getSwaggerContent(Swagger swagger) {