use of io.vertx.core.WorkerExecutor in project vert.x by eclipse.
the class NamedWorkerPoolTest method testDestroyWorkerPoolWhenVerticleUndeploys.
@Test
public void testDestroyWorkerPoolWhenVerticleUndeploys() throws Exception {
String poolName = "vert.x-" + TestUtils.randomAlphaString(10);
AtomicReference<Thread> thread = new AtomicReference<>();
CompletableFuture<String> deploymentIdRef = new CompletableFuture<>();
vertx.deployVerticle(new AbstractVerticle() {
@Override
public void start() throws Exception {
WorkerExecutor pool = vertx.createSharedWorkerExecutor(poolName);
pool.executeBlocking(fut -> {
thread.set(Thread.currentThread());
}, ar -> {
});
}
}, onSuccess(deploymentIdRef::complete));
waitUntil(() -> thread.get() != null);
String deploymentId = deploymentIdRef.get(20, TimeUnit.SECONDS);
vertx.undeploy(deploymentId, onSuccess(v -> {
}));
waitUntil(() -> thread.get().getState() == Thread.State.TERMINATED);
}
use of io.vertx.core.WorkerExecutor in project vert.x by eclipse.
the class NamedWorkerPoolTest method testPoolSize.
@Test
public void testPoolSize() throws Exception {
String poolName = "vert.x-" + TestUtils.randomAlphaString(10);
int poolSize = 5;
waitFor(poolSize);
WorkerExecutor worker = vertx.createSharedWorkerExecutor(poolName, poolSize);
CountDownLatch latch1 = new CountDownLatch(poolSize * 100);
Set<String> names = Collections.synchronizedSet(new HashSet<>());
for (int i = 0; i < poolSize * 100; i++) {
worker.executeBlocking(fut -> {
names.add(Thread.currentThread().getName());
latch1.countDown();
}, false, ar -> {
});
}
awaitLatch(latch1);
assertEquals(5, names.size());
}
use of io.vertx.core.WorkerExecutor in project vertx-camel-bridge by vert-x3.
the class OutboundEndpointTest method testWithBlockingWithWorker.
@Test
public void testWithBlockingWithWorker() throws Exception {
AtomicBoolean calledSpy = new AtomicBoolean();
AtomicBoolean startedSpy = new AtomicBoolean();
vertx.createHttpServer().requestHandler(request -> {
calledSpy.set(true);
request.response().end("Alright");
}).listen(8081, ar -> {
startedSpy.set(ar.succeeded());
});
await().atMost(DEFAULT_TIMEOUT).untilAtomic(startedSpy, is(true));
camel.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:my-route").process(exchange -> Thread.sleep(3000)).to("http://localhost:8081");
}
});
WorkerExecutor pool = vertx.createSharedWorkerExecutor("some-fancy-name");
bridge = CamelBridge.create(vertx, new CamelBridgeOptions(camel).addOutboundMapping(fromVertx("camel-route").toCamel("direct:my-route").setBlocking(true).setWorkerExecutor(pool)));
camel.start();
BridgeHelper.startBlocking(bridge);
vertx.eventBus().send("camel-route", "hello");
await().atMost(DEFAULT_TIMEOUT).untilAtomic(calledSpy, is(true));
}
Aggregations