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/11/22 01:31:47 UTC

[servicecomb-java-chassis] branch master updated: [#2534]test case for 3rd registry invoke issue (#2638)

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 2c537f6  [#2534]test case for 3rd registry invoke issue (#2638)
2c537f6 is described below

commit 2c537f67eb259cf3b0493561f63878b073249393
Author: liubao68 <bi...@qq.com>
AuthorDate: Mon Nov 22 09:31:39 2021 +0800

    [#2534]test case for 3rd registry invoke issue (#2638)
    
    * [#2534]test case for 3rd registry invoke issue
    
    * [#2534]avoid conflicts to spring mvc
---
 .../springmvc/client/SpringmvcClient.java          |  2 +-
 .../springmvc/server/SpringmvcServer.java          |  3 +-
 demo/demo-springmvc/springmvc-client/pom.xml       |  2 +-
 .../springmvc/{client => }/SpringmvcClient.java    |  3 +-
 .../servicecomb/demo/springmvc/SpringMvcIT.java    |  1 -
 demo/demo-springmvc/springmvc-server/pom.xml       |  6 ++-
 .../springmvc/{server => }/SpringmvcServer.java    |  2 +-
 .../springmvc/server/ProducerTestsAfterBootup.java |  4 +-
 .../demo/springmvc/third/EarlyConsumer.java        | 62 ++++++++++++++++++++++
 .../HealthSchema.java}                             | 17 +++---
 .../HeartBeatService.java}                         | 14 ++---
 .../demo/springmvc/third/NormalConsumer.java       | 56 +++++++++++++++++++
 .../SpringmvcServer.java => third/Register.java}   | 23 +++++---
 13 files changed, 162 insertions(+), 33 deletions(-)

diff --git a/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-client/src/main/java/org/apache/servicecomb/springboot/springmvc/client/SpringmvcClient.java b/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-client/src/main/java/org/apache/servicecomb/springboot/springmvc/client/SpringmvcClient.java
index 5e092d8..a92df0f 100644
--- a/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-client/src/main/java/org/apache/servicecomb/springboot/springmvc/client/SpringmvcClient.java
+++ b/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-client/src/main/java/org/apache/servicecomb/springboot/springmvc/client/SpringmvcClient.java
@@ -36,7 +36,7 @@ public class SpringmvcClient {
 
     new SpringApplicationBuilder().sources(SpringmvcClient.class).web(WebApplicationType.SERVLET).build().run(args);
 
-    org.apache.servicecomb.demo.springmvc.client.SpringmvcClient.run();
+    org.apache.servicecomb.demo.springmvc.SpringmvcClient.run();
 
     TestMgr.summary();
   }
diff --git a/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-server/src/main/java/org/apache/servicecomb/springboot/springmvc/server/SpringmvcServer.java b/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-server/src/main/java/org/apache/servicecomb/springboot/springmvc/server/SpringmvcServer.java
index 311bd53..1e52dab 100644
--- a/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-server/src/main/java/org/apache/servicecomb/springboot/springmvc/server/SpringmvcServer.java
+++ b/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-server/src/main/java/org/apache/servicecomb/springboot/springmvc/server/SpringmvcServer.java
@@ -23,11 +23,12 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.boot.WebApplicationType;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
 import org.springframework.boot.builder.SpringApplicationBuilder;
 
 import com.netflix.config.DynamicPropertyFactory;
 
-@SpringBootApplication
+@SpringBootApplication(exclude = {WebMvcAutoConfiguration.class})
 @EnableServiceComb
 public class SpringmvcServer {
   private static final Logger LOGGER = LoggerFactory.getLogger(SpringmvcServer.class);
diff --git a/demo/demo-springmvc/springmvc-client/pom.xml b/demo/demo-springmvc/springmvc-client/pom.xml
index a67ddf0..9abbc43 100644
--- a/demo/demo-springmvc/springmvc-client/pom.xml
+++ b/demo/demo-springmvc/springmvc-client/pom.xml
@@ -61,7 +61,7 @@
   </dependencies>
 
   <properties>
-    <demo.main>org.apache.servicecomb.demo.springmvc.client.SpringmvcClient</demo.main>
+    <demo.main>org.apache.servicecomb.demo.springmvc.SpringmvcClient</demo.main>
   </properties>
   <build>
     <plugins>
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/SpringmvcClient.java
similarity index 99%
rename from demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/SpringmvcClient.java
rename to demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/SpringmvcClient.java
index 7b37deb..2bbd2b6 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/SpringmvcClient.java
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.servicecomb.demo.springmvc.client;
+package org.apache.servicecomb.demo.springmvc;
 
 import java.util.Date;
 import java.util.HashMap;
@@ -27,6 +27,7 @@ import org.apache.servicecomb.demo.DemoConst;
 import org.apache.servicecomb.demo.TestMgr;
 import org.apache.servicecomb.demo.controller.Controller;
 import org.apache.servicecomb.demo.controller.Person;
+import org.apache.servicecomb.demo.springmvc.client.CodeFirstRestTemplateSpringmvc;
 import org.apache.servicecomb.demo.springmvc.client.ThirdSvc.ThirdSvcClient;
 import org.apache.servicecomb.foundation.common.utils.BeanUtils;
 import org.apache.servicecomb.foundation.common.utils.Log4jUtils;
diff --git a/demo/demo-springmvc/springmvc-client/src/test/java/org/apache/servicecomb/demo/springmvc/SpringMvcIT.java b/demo/demo-springmvc/springmvc-client/src/test/java/org/apache/servicecomb/demo/springmvc/SpringMvcIT.java
index 5d610de..e3f0e4e 100644
--- a/demo/demo-springmvc/springmvc-client/src/test/java/org/apache/servicecomb/demo/springmvc/SpringMvcIT.java
+++ b/demo/demo-springmvc/springmvc-client/src/test/java/org/apache/servicecomb/demo/springmvc/SpringMvcIT.java
@@ -21,7 +21,6 @@ import static org.hamcrest.core.Is.is;
 import static org.junit.Assert.assertThat;
 
 import org.apache.servicecomb.demo.TestMgr;
-import org.apache.servicecomb.demo.springmvc.client.SpringmvcClient;
 import org.junit.Before;
 import org.junit.Test;
 
diff --git a/demo/demo-springmvc/springmvc-server/pom.xml b/demo/demo-springmvc/springmvc-server/pom.xml
index 8c4e0e9..9b0f839 100644
--- a/demo/demo-springmvc/springmvc-server/pom.xml
+++ b/demo/demo-springmvc/springmvc-server/pom.xml
@@ -37,6 +37,10 @@
       <groupId>org.apache.servicecomb</groupId>
       <artifactId>provider-springmvc</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.servicecomb</groupId>
+      <artifactId>provider-pojo</artifactId>
+    </dependency>
      <dependency>
       <groupId>org.apache.servicecomb</groupId>
       <artifactId>swagger-invocation-validator</artifactId>
@@ -58,7 +62,7 @@
   </dependencies>
 
   <properties>
-    <demo.main>org.apache.servicecomb.demo.springmvc.server.SpringmvcServer</demo.main>
+    <demo.main>org.apache.servicecomb.demo.springmvc.SpringmvcServer</demo.main>
   </properties>
   <build>
     <plugins>
diff --git a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/SpringmvcServer.java b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/SpringmvcServer.java
similarity index 95%
copy from demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/SpringmvcServer.java
copy to demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/SpringmvcServer.java
index 12af40c..38841a9 100644
--- a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/SpringmvcServer.java
+++ b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/SpringmvcServer.java
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.servicecomb.demo.springmvc.server;
+package org.apache.servicecomb.demo.springmvc;
 
 import org.apache.servicecomb.foundation.common.utils.BeanUtils;
 import org.apache.servicecomb.foundation.common.utils.Log4jUtils;
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 e36dcd7..16ddd92 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
@@ -91,9 +91,9 @@ public class ProducerTestsAfterBootup implements BootListener {
 
   public void testRegisteredBasePath() {
     if (DynamicPropertyFactory.getInstance().getBooleanProperty("servicecomb.test.vert.transport", true).get()) {
-      TestMgr.check(19, RegistrationManager.INSTANCE.getMicroservice().getPaths().size());
-    } else {	
       TestMgr.check(20, RegistrationManager.INSTANCE.getMicroservice().getPaths().size());
+    } else {	
+      TestMgr.check(21, RegistrationManager.INSTANCE.getMicroservice().getPaths().size());
     }	
   }
 
diff --git a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/third/EarlyConsumer.java b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/third/EarlyConsumer.java
new file mode 100644
index 0000000..eb43fe1
--- /dev/null
+++ b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/third/EarlyConsumer.java
@@ -0,0 +1,62 @@
+/*
+ * 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.demo.springmvc.third;
+
+import org.apache.servicecomb.core.BootListener;
+import org.apache.servicecomb.provider.pojo.RpcReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+/**
+ * see: https://github.com/apache/servicecomb-java-chassis/issues/2534
+ */
+@Component
+public class EarlyConsumer implements BootListener {
+  private static final Logger LOGGER = LoggerFactory.getLogger(EarlyConsumer.class);
+
+  @RpcReference(microserviceName = "third", schemaId = "heartbeat")
+  private HealthSchema healthSchema;
+
+  private volatile boolean stopped = false;
+
+  public EarlyConsumer() {
+    new Thread() {
+      public void run() {
+        while (!stopped) {
+          LOGGER.info("calling service");
+          try {
+            healthSchema.heartbeat();
+          } catch (Throwable e) {
+            // ignore error
+          }
+          try {
+            Thread.sleep(100);
+          } catch (Throwable e) {
+            // ignore error
+          }
+        }
+      }
+    }.start();
+  }
+
+  @Override
+  public void onAfterRegistry(BootEvent event) {
+    stopped = true;
+  }
+}
\ No newline at end of file
diff --git a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/SpringmvcServer.java b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/third/HealthSchema.java
similarity index 71%
copy from demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/SpringmvcServer.java
copy to demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/third/HealthSchema.java
index 12af40c..d1f8be2 100644
--- a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/SpringmvcServer.java
+++ b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/third/HealthSchema.java
@@ -15,14 +15,13 @@
  * limitations under the License.
  */
 
-package org.apache.servicecomb.demo.springmvc.server;
+package org.apache.servicecomb.demo.springmvc.third;
 
-import org.apache.servicecomb.foundation.common.utils.BeanUtils;
-import org.apache.servicecomb.foundation.common.utils.Log4jUtils;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
 
-public class SpringmvcServer {
-  public static void main(String[] args) throws Exception {
-    Log4jUtils.init();
-    BeanUtils.init();
-  }
-}
+@RequestMapping("/v1")
+public interface HealthSchema {
+  @GetMapping(value = "/heartbeat")
+  void heartbeat();
+}
\ No newline at end of file
diff --git a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/SpringmvcServer.java b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/third/HeartBeatService.java
similarity index 71%
copy from demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/SpringmvcServer.java
copy to demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/third/HeartBeatService.java
index 12af40c..d01b210 100644
--- a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/SpringmvcServer.java
+++ b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/third/HeartBeatService.java
@@ -15,14 +15,14 @@
  * limitations under the License.
  */
 
-package org.apache.servicecomb.demo.springmvc.server;
+package org.apache.servicecomb.demo.springmvc.third;
 
-import org.apache.servicecomb.foundation.common.utils.BeanUtils;
-import org.apache.servicecomb.foundation.common.utils.Log4jUtils;
+import org.apache.servicecomb.provider.rest.common.RestSchema;
+
+@RestSchema(schemaId = "health", schemaInterface = HealthSchema.class)
+public class HeartBeatService implements HealthSchema {
+  @Override
+  public void heartbeat() {
 
-public class SpringmvcServer {
-  public static void main(String[] args) throws Exception {
-    Log4jUtils.init();
-    BeanUtils.init();
   }
 }
diff --git a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/third/NormalConsumer.java b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/third/NormalConsumer.java
new file mode 100644
index 0000000..72ce2ec
--- /dev/null
+++ b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/third/NormalConsumer.java
@@ -0,0 +1,56 @@
+/*
+ * 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.demo.springmvc.third;
+
+import org.apache.servicecomb.core.BootListener;
+import org.apache.servicecomb.demo.TestMgr;
+import org.apache.servicecomb.provider.pojo.RpcReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+/**
+ * see: https://github.com/apache/servicecomb-java-chassis/issues/2534
+ */
+@Component
+public class NormalConsumer implements BootListener {
+  private static final Logger LOGGER = LoggerFactory.getLogger(NormalConsumer.class);
+
+  @RpcReference(microserviceName = "third", schemaId = "heartbeat")
+  private HealthSchema healthSchema;
+
+  @Override
+  public void onAfterRegistry(BootListener.BootEvent event) {
+    try {
+      LOGGER.info("calling service after register");
+
+      healthSchema.heartbeat();
+      LOGGER.info("heartbeat succ");
+    } catch (Throwable e) {
+      TestMgr.failed("3rd invoke failed", e);
+      throw e;
+    }
+  }
+
+
+  @Override
+  public int getOrder() {
+    // 比ThirdServiceRegister晚
+    return 0;
+  }
+}
\ No newline at end of file
diff --git a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/SpringmvcServer.java b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/third/Register.java
similarity index 60%
rename from demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/SpringmvcServer.java
rename to demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/third/Register.java
index 12af40c..16cb416 100644
--- a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/SpringmvcServer.java
+++ b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/third/Register.java
@@ -15,14 +15,21 @@
  * limitations under the License.
  */
 
-package org.apache.servicecomb.demo.springmvc.server;
+package org.apache.servicecomb.demo.springmvc.third;
 
-import org.apache.servicecomb.foundation.common.utils.BeanUtils;
-import org.apache.servicecomb.foundation.common.utils.Log4jUtils;
+import java.util.Arrays;
 
-public class SpringmvcServer {
-  public static void main(String[] args) throws Exception {
-    Log4jUtils.init();
-    BeanUtils.init();
+import org.apache.servicecomb.provider.pojo.registry.ThirdServiceWithInvokerRegister;
+import org.springframework.stereotype.Component;
+
+/**
+ * see: https://github.com/apache/servicecomb-java-chassis/issues/2534
+ */
+@Component
+public class Register extends ThirdServiceWithInvokerRegister {
+  public Register() {
+    super("third");
+    addSchema("heartbeat", HealthSchema.class);
+    setUrls("", Arrays.asList("rest://localhost:8080?sslEnabled=false"));
   }
-}
+}
\ No newline at end of file