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 b5095c1  [SCB-2252]report error when invoke a service when SCBEngine 
is not ready (#2362)
b5095c1 is described below

commit b5095c12829af98c7833a804391db24a101b08f0
Author: bao liu <[email protected]>
AuthorDate: Wed Apr 28 14:40:38 2021 +0800

    [SCB-2252]report error when invoke a service when SCBEngine is not ready 
(#2362)
---
 .../org/apache/servicecomb/core/SCBEngine.java     |  1 +
 .../ConsumerMicroserviceVersionsMeta.java          | 12 ---
 .../core/provider/consumer/ReferenceConfig.java    |  2 -
 .../client/TestInvokeWhenServerNotReady.java       | 90 ++++++++++++++++++++++
 .../apache/servicecomb/provider/pojo/Invoker.java  |  2 +-
 5 files changed, 92 insertions(+), 15 deletions(-)

diff --git a/core/src/main/java/org/apache/servicecomb/core/SCBEngine.java 
b/core/src/main/java/org/apache/servicecomb/core/SCBEngine.java
index 7e05dfa..fc9d276 100644
--- a/core/src/main/java/org/apache/servicecomb/core/SCBEngine.java
+++ b/core/src/main/java/org/apache/servicecomb/core/SCBEngine.java
@@ -548,6 +548,7 @@ public class SCBEngine {
    * @return
    */
   public MicroserviceReferenceConfig createMicroserviceReferenceConfig(String 
microserviceName, String versionRule) {
+    ensureStatusUp();
     MicroserviceVersions microserviceVersions = DiscoveryManager.INSTANCE
         .getOrCreateMicroserviceVersions(parseAppId(microserviceName), 
microserviceName);
     ConsumerMicroserviceVersionsMeta microserviceVersionsMeta = CoreMetaUtils
diff --git 
a/core/src/main/java/org/apache/servicecomb/core/definition/ConsumerMicroserviceVersionsMeta.java
 
b/core/src/main/java/org/apache/servicecomb/core/definition/ConsumerMicroserviceVersionsMeta.java
index 4db23b2..4510302 100644
--- 
a/core/src/main/java/org/apache/servicecomb/core/definition/ConsumerMicroserviceVersionsMeta.java
+++ 
b/core/src/main/java/org/apache/servicecomb/core/definition/ConsumerMicroserviceVersionsMeta.java
@@ -17,14 +17,11 @@
 package org.apache.servicecomb.core.definition;
 
 import org.apache.servicecomb.core.SCBEngine;
-import 
org.apache.servicecomb.core.provider.consumer.MicroserviceReferenceConfig;
 import org.apache.servicecomb.registry.consumer.MicroserviceVersions;
 
 public class ConsumerMicroserviceVersionsMeta extends MicroserviceVersionsMeta 
{
   private MicroserviceVersions microserviceVersions;
 
-  private MicroserviceReferenceConfig microserviceReferenceConfig;
-
   public ConsumerMicroserviceVersionsMeta(SCBEngine scbEngine, 
MicroserviceVersions microserviceVersions) {
     super(scbEngine, microserviceVersions.getMicroserviceName());
 
@@ -34,13 +31,4 @@ public class ConsumerMicroserviceVersionsMeta extends 
MicroserviceVersionsMeta {
   public MicroserviceVersions getMicroserviceVersions() {
     return microserviceVersions;
   }
-
-  public MicroserviceReferenceConfig getOrCreateMicroserviceReferenceConfig() {
-    if (microserviceReferenceConfig == null ||
-        microserviceReferenceConfig.isExpired()) {
-      microserviceReferenceConfig = new MicroserviceReferenceConfig(this, 
null);
-    }
-
-    return microserviceReferenceConfig;
-  }
 }
diff --git 
a/core/src/main/java/org/apache/servicecomb/core/provider/consumer/ReferenceConfig.java
 
b/core/src/main/java/org/apache/servicecomb/core/provider/consumer/ReferenceConfig.java
index 6a78d63..0932f92 100644
--- 
a/core/src/main/java/org/apache/servicecomb/core/provider/consumer/ReferenceConfig.java
+++ 
b/core/src/main/java/org/apache/servicecomb/core/provider/consumer/ReferenceConfig.java
@@ -19,8 +19,6 @@ package org.apache.servicecomb.core.provider.consumer;
 
 // operation level, to keep compatible, not change name
 public class ReferenceConfig {
-  protected MicroserviceReferenceConfig microserviceReferenceConfig;
-
   protected String transport;
 
   protected String versionRule;
diff --git 
a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestInvokeWhenServerNotReady.java
 
b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestInvokeWhenServerNotReady.java
new file mode 100644
index 0000000..5be0e2f
--- /dev/null
+++ 
b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestInvokeWhenServerNotReady.java
@@ -0,0 +1,90 @@
+/*
+ * 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.client;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.servicecomb.core.provider.consumer.InvokerUtils;
+import org.apache.servicecomb.demo.CommonSchemaInterface;
+import org.apache.servicecomb.provider.pojo.RpcReference;
+import org.apache.servicecomb.provider.springmvc.reference.RestTemplateBuilder;
+import org.apache.servicecomb.swagger.invocation.context.InvocationContext;
+import org.springframework.stereotype.Component;
+import org.springframework.web.client.RestTemplate;
+
+@Component
+public class TestInvokeWhenServerNotReady {
+  @RpcReference(schemaId = "SpringMVCCommonSchemaInterface", microserviceName 
= "springmvc")
+  private CommonSchemaInterface client;
+
+  // only invoke RPC before system is up, these setup is for testing calls 
before system ready
+  public TestInvokeWhenServerNotReady() {
+    startRestTemplateCall();
+    startRpcCall();
+    startInvokerUtilsCall();
+  }
+
+  private void startRestTemplateCall() {
+    new Thread() {
+      public void run() {
+        for (int i = 0; i < 100; i++) {
+          try {
+            RestTemplate template = RestTemplateBuilder.create();
+            
template.getForObject("servicecomb://springmvc/upload/isServerStartUpSuccess", 
Boolean.class);
+          } catch (Throwable e) {
+            // ignore
+          }
+        }
+      }
+    }.start();
+  }
+
+  private void startRpcCall() {
+    new Thread() {
+      public void run() {
+        for (int i = 0; i < 100; i++) {
+          try {
+            InvocationContext context = new InvocationContext();
+            client.testInvocationTimeout(context, 1001, "customized");
+          } catch (Throwable e) {
+            // ignore
+          }
+        }
+      }
+    }.start();
+  }
+
+  private void startInvokerUtilsCall() {
+    new Thread() {
+      public void run() {
+        for (int i = 0; i < 100; i++) {
+          try {
+            Map<String, Object> args = new HashMap<>();
+            args.put("timeout", 1);
+            args.put("name", "customized");
+            InvokerUtils
+                .syncInvoke("springmvc", "SpringMVCCommonSchemaInterface", 
"testInvocationTimeout", args, String.class);
+          } catch (Throwable e) {
+            // ignore
+          }
+        }
+      }
+    }.start();
+  }
+}
diff --git 
a/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/Invoker.java
 
b/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/Invoker.java
index 04e4a1e..1856be2 100644
--- 
a/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/Invoker.java
+++ 
b/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/Invoker.java
@@ -66,7 +66,7 @@ public class Invoker implements InvocationHandler {
       return defaultMethodMeta.getOrCreateMethodHandle(proxy, method)
           .invokeWithArguments(args);
     }
-
+    SCBEngine.getInstance().ensureStatusUp();
     prepareInvocationCaller();
     return invocationCaller.call(method, metaRefresher, invocationCreator, 
args);
   }

Reply via email to