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 5cc68f13d8..b9db0621af 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 @@ 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.concurrent.ConcurrentHashMapEx; import org.apache.servicecomb.foundation.vertx.client.ClientPoolManager; import org.apache.servicecomb.foundation.vertx.client.ClientVerticle; @@ -85,16 +85,16 @@ public static DeploymentOptions createClientDeployOptions( } // deploy Verticle and wait for its success. do not call this method in event-loop thread - public static boolean blockDeploy(Vertx vertx, + public static Map blockDeploy(Vertx vertx, Class cls, DeploymentOptions options) throws InterruptedException { - Holder result = new Holder<>(); + Map 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()); } @@ -103,7 +103,7 @@ public static boolean blockDeploy(Vertx vertx, 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 3e0f98bf54..4afe98a1f2 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,7 @@ package org.apache.servicecomb.transport.highway; +import java.util.Map; import java.util.concurrent.TimeoutException; import javax.ws.rs.core.Response.Status; @@ -63,7 +64,10 @@ public void init(Vertx vertx) throws Exception { DeploymentOptions deployOptions = VertxUtils.createClientDeployOptions(clientMgr, HighwayConfig.getClientThreadCount()); - VertxUtils.blockDeploy(vertx, ClientVerticle.class, deployOptions); + Map 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 b283b568c1..f40ff86b18 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.Const; import org.apache.servicecomb.core.Invocation; @@ -47,7 +48,12 @@ public boolean init() throws Exception { json.put(ENDPOINT_KEY, getEndpoint()); deployOptions.setConfig(json); deployOptions.setWorkerPoolName("pool-worker-transport-highway"); - return VertxUtils.blockDeploy(transportVertx, HighwayServerVerticle.class, deployOptions); + Map result = VertxUtils.blockDeploy(transportVertx, HighwayServerVerticle.class, deployOptions); + if ((boolean) result.get("code")) { + return true; + } else { + throw new IllegalStateException((String) result.get("message")); + } } @Override 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 ee3c63148c..43db614335 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 javax.ws.rs.core.Response.Status; import org.apache.servicecomb.codec.protobuf.definition.OperationProtobuf; @@ -97,10 +100,12 @@ public void testLoginTimeout(@Mocked Vertx vertx) { public void testHighwayClientSSL(@Mocked Vertx vertx) throws Exception { new MockUp() { @Mock - boolean blockDeploy(Vertx vertx, + Map blockDeploy(Vertx vertx, Class cls, DeploymentOptions options) { - return true; + Map result = new HashMap<>(); + result.put("code", true); + return result; } }; @@ -114,10 +119,12 @@ private Object doTestSend(Vertx vertx, HighwayClientConnectionPool pool, Highway Object decodedResponse) throws Exception { new MockUp() { @Mock - boolean blockDeploy(Vertx vertx, + Map blockDeploy(Vertx vertx, Class cls, DeploymentOptions options) { - return true; + Map 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 3267bf28a5..267fd708f7 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 @@ import java.util.Collections; import java.util.List; +import java.util.Map; import org.apache.servicecomb.core.Const; import org.apache.servicecomb.core.Invocation; @@ -105,7 +106,13 @@ public boolean init() throws Exception { options.setWorkerPoolSize(VertxOptions.DEFAULT_WORKER_POOL_SIZE); prepareBlockResource(); - return VertxUtils.blockDeploy(transportVertx, TransportConfig.getRestServerVerticle(), options); + Map 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 dbe6cae4e2..9a5f43f6fe 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 @@ -19,6 +19,8 @@ import java.io.IOException; import java.net.ServerSocket; +import java.util.HashMap; +import java.util.Map; import org.apache.servicecomb.core.Endpoint; import org.apache.servicecomb.core.Invocation; @@ -62,9 +64,11 @@ public Vertx init(VertxOptions vertxOptions) { } @Mock - public boolean blockDeploy(Vertx vertx, Class cls, + public Map blockDeploy(Vertx vertx, Class cls, DeploymentOptions options) throws InterruptedException { - return true; + Map result = new HashMap<>(); + result.put("code", true); + return result; } }; instance.init();