Skip to content

Commit

Permalink
[#4074] optimize cors model init failed unclear prompt problem. (#4095)
Browse files Browse the repository at this point in the history
  • Loading branch information
chengyouling authored Dec 7, 2023
1 parent 549024f commit 07ccddc
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -85,16 +85,16 @@ public static <CLIENT_POOL> DeploymentOptions createClientDeployOptions(
}

// 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());
}

Expand All @@ -103,7 +103,7 @@ public static <VERTICLE extends Verticle> boolean blockDeploy(Vertx vertx,

latch.await();

return result.value;
return result;
}

public static Vertx getOrCreateVertxByName(String name, VertxOptions vertxOptions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, Object> result = VertxUtils.blockDeploy(vertx, ClientVerticle.class, deployOptions);
if (!(boolean) result.get("code")) {
throw new IllegalStateException((String) result.get("message"));
}
}

@VisibleForTesting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, Object> result = VertxUtils.blockDeploy(transportVertx, HighwayServerVerticle.class, deployOptions);
if ((boolean) result.get("code")) {
return true;
} else {
throw new IllegalStateException((String) result.get("message"));
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -97,10 +100,12 @@ public void testLoginTimeout(@Mocked Vertx vertx) {
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;
}
};

Expand All @@ -114,10 +119,12 @@ private Object doTestSend(Vertx vertx, HighwayClientConnectionPool pool, Highway
Object decodedResponse) 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;
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -62,9 +64,11 @@ public Vertx init(VertxOptions vertxOptions) {
}

@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();
Expand Down

0 comments on commit 07ccddc

Please sign in to comment.