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 176dc2f9a [#4074] optimize cors model init failed unclear prompt 
problem. (#4101)
176dc2f9a is described below

commit 176dc2f9aaadbedd32501aaac03731070c9f87f9
Author: Cheng YouLing <[email protected]>
AuthorDate: Thu Dec 7 10:15:42 2023 +0800

    [#4074] optimize cors model init failed unclear prompt problem. (#4101)
---
 .../org/apache/servicecomb/foundation/vertx/VertxUtils.java   | 11 ++++++-----
 .../apache/servicecomb/transport/highway/HighwayClient.java   |  7 ++++++-
 .../servicecomb/transport/highway/HighwayTransport.java       |  8 +++++++-
 .../servicecomb/transport/highway/TestHighwayClient.java      |  9 +++++++--
 .../servicecomb/transport/rest/vertx/VertxRestTransport.java  |  9 ++++++++-
 .../transport/rest/vertx/TestVertxRestTransport.java          |  8 ++++++--
 6 files changed, 40 insertions(+), 12 deletions(-)

diff --git 
a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/VertxUtils.java
 
b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/VertxUtils.java
index bc398616f..331c502ff 100644
--- 
a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/VertxUtils.java
+++ 
b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/VertxUtils.java
@@ -20,13 +20,13 @@ package org.apache.servicecomb.foundation.vertx;
 import java.io.IOException;
 import java.io.InputStream;
 import java.lang.management.ManagementFactory;
+import java.util.HashMap;
 import java.util.Map;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.commons.io.IOUtils;
-import org.apache.servicecomb.foundation.common.Holder;
 import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
 import org.apache.servicecomb.foundation.common.concurrent.ConcurrentHashMapEx;
 import org.apache.servicecomb.foundation.vertx.client.ClientPoolManager;
@@ -84,16 +84,17 @@ public final class VertxUtils {
   }
 
   // deploy Verticle and wait for its success. do not call this method in 
event-loop thread
-  public static <VERTICLE extends Verticle> boolean blockDeploy(Vertx vertx,
+  public static <VERTICLE extends Verticle> Map<String, Object> 
blockDeploy(Vertx vertx,
       Class<VERTICLE> cls,
       DeploymentOptions options) throws InterruptedException {
-    Holder<Boolean> result = new Holder<>();
+    Map<String, Object> result = new HashMap<>();
 
     CountDownLatch latch = new CountDownLatch(1);
     vertx.deployVerticle(cls.getName(), options, ar -> {
-      result.value = ar.succeeded();
+      result.put("code", ar.succeeded());
 
       if (ar.failed()) {
+        result.put("message", ar.cause().getMessage());
         LOGGER.error("deploy vertx failed, cause ", ar.cause());
       }
 
@@ -102,7 +103,7 @@ public final class VertxUtils {
 
     latch.await();
 
-    return result.value;
+    return result;
   }
 
   public static Vertx getOrCreateVertxByName(String name, VertxOptions 
vertxOptions) {
diff --git 
a/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayClient.java
 
b/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayClient.java
index 218f62e62..1a007e370 100644
--- 
a/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayClient.java
+++ 
b/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayClient.java
@@ -17,6 +17,8 @@
 
 package org.apache.servicecomb.transport.highway;
 
+import java.util.Map;
+
 import org.apache.servicecomb.codec.protobuf.definition.OperationProtobuf;
 import org.apache.servicecomb.core.Invocation;
 import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
@@ -50,7 +52,10 @@ public class HighwayClient {
 
     DeploymentOptions deployOptions = 
VertxUtils.createClientDeployOptions(clientMgr,
         HighwayConfig.getClientThreadCount());
-    VertxUtils.blockDeploy(vertx, ClientVerticle.class, deployOptions);
+    Map<String, Object> result = VertxUtils.blockDeploy(vertx, 
ClientVerticle.class, deployOptions);
+    if (!(boolean) result.get("code")) {
+      throw new IllegalStateException((String) result.get("message"));
+    }
   }
 
   @VisibleForTesting
diff --git 
a/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayTransport.java
 
b/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayTransport.java
index f449e9c47..2d5d4fa56 100644
--- 
a/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayTransport.java
+++ 
b/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayTransport.java
@@ -18,6 +18,7 @@
 package org.apache.servicecomb.transport.highway;
 
 import java.util.Collections;
+import java.util.Map;
 
 import org.apache.servicecomb.core.CoreConst;
 import org.apache.servicecomb.core.transport.AbstractTransport;
@@ -45,7 +46,12 @@ public class HighwayTransport extends AbstractTransport {
     json.put(ENDPOINT_KEY, getEndpoint());
     deployOptions.setConfig(json);
     deployOptions.setWorkerPoolName("pool-worker-transport-highway");
-    return VertxUtils.blockDeploy(transportVertx, HighwayServerVerticle.class, 
deployOptions);
+    Map<String, Object> result = VertxUtils.blockDeploy(transportVertx, 
HighwayServerVerticle.class, deployOptions);
+    if ((boolean) result.get("code")) {
+      return true;
+    } else {
+      throw new IllegalStateException((String) result.get("message"));
+    }
   }
 
   public HighwayClient getHighwayClient() {
diff --git 
a/transports/transport-highway/src/test/java/org/apache/servicecomb/transport/highway/TestHighwayClient.java
 
b/transports/transport-highway/src/test/java/org/apache/servicecomb/transport/highway/TestHighwayClient.java
index 014aaa48a..d7a29f0f8 100644
--- 
a/transports/transport-highway/src/test/java/org/apache/servicecomb/transport/highway/TestHighwayClient.java
+++ 
b/transports/transport-highway/src/test/java/org/apache/servicecomb/transport/highway/TestHighwayClient.java
@@ -17,6 +17,9 @@
 
 package org.apache.servicecomb.transport.highway;
 
+import java.util.HashMap;
+import java.util.Map;
+
 import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
 import org.apache.servicecomb.foundation.vertx.VertxUtils;
 import org.apache.servicecomb.foundation.vertx.client.ClientPoolManager;
@@ -86,10 +89,12 @@ public class TestHighwayClient {
   public void testHighwayClientSSL(@Mocked Vertx vertx) throws Exception {
     new MockUp<VertxUtils>() {
       @Mock
-      <VERTICLE extends AbstractVerticle> boolean blockDeploy(Vertx vertx,
+      <VERTICLE extends AbstractVerticle> Map<String, Object> 
blockDeploy(Vertx vertx,
           Class<VERTICLE> cls,
           DeploymentOptions options) {
-        return true;
+        Map<String, Object> result = new HashMap<>();
+        result.put("code", true);
+        return result;
       }
     };
 
diff --git 
a/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/VertxRestTransport.java
 
b/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/VertxRestTransport.java
index 32b0c1fc1..8566a3c3b 100644
--- 
a/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/VertxRestTransport.java
+++ 
b/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/VertxRestTransport.java
@@ -19,6 +19,7 @@ package org.apache.servicecomb.transport.rest.vertx;
 
 import java.util.Collections;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.servicecomb.core.CoreConst;
 import org.apache.servicecomb.core.transport.AbstractTransport;
@@ -93,7 +94,13 @@ public class VertxRestTransport extends AbstractTransport {
     options.setWorkerPoolSize(VertxOptions.DEFAULT_WORKER_POOL_SIZE);
 
     prepareBlockResource();
-    return VertxUtils.blockDeploy(transportVertx, 
TransportConfig.getRestServerVerticle(), options);
+    Map<String, Object> result = VertxUtils.blockDeploy(transportVertx, 
TransportConfig.getRestServerVerticle(),
+        options);
+    if ((boolean) result.get("code")) {
+      return true;
+    } else {
+      throw new IllegalStateException((String) result.get("message"));
+    }
   }
 
   private void prepareBlockResource() {
diff --git 
a/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestVertxRestTransport.java
 
b/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestVertxRestTransport.java
index e8ca51c75..c0e2af45d 100644
--- 
a/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestVertxRestTransport.java
+++ 
b/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestVertxRestTransport.java
@@ -21,6 +21,8 @@ import static 
org.apache.servicecomb.core.transport.AbstractTransport.PUBLISH_AD
 
 import java.io.IOException;
 import java.net.ServerSocket;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
 import org.apache.servicecomb.foundation.vertx.VertxUtils;
@@ -95,9 +97,11 @@ public class TestVertxRestTransport {
         }
 
         @Mock
-        public <VERTICLE extends AbstractVerticle> boolean blockDeploy(Vertx 
vertx, Class<VERTICLE> cls,
+        public <VERTICLE extends AbstractVerticle> Map<String, Object> 
blockDeploy(Vertx vertx, Class<VERTICLE> cls,
             DeploymentOptions options) throws InterruptedException {
-          return true;
+          Map<String, Object> result = new HashMap<>();
+          result.put("code", true);
+          return result;
         }
       };
       instance.init();

Reply via email to