use of io.vertx.core.DeploymentOptions in project vert.x by eclipse.
the class ContextTest method testWorkerExecuteFromIo.
@Test
public void testWorkerExecuteFromIo() throws Exception {
AtomicReference<ContextInternal> workerContext = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(1);
vertx.deployVerticle(new AbstractVerticle() {
@Override
public void start() throws Exception {
workerContext.set((ContextInternal) context);
latch.countDown();
}
}, new DeploymentOptions().setWorker(true));
awaitLatch(latch);
workerContext.get().nettyEventLoop().execute(() -> {
assertNull(Vertx.currentContext());
workerContext.get().executeFromIO(() -> {
assertSame(workerContext.get(), Vertx.currentContext());
assertTrue(Context.isOnWorkerThread());
testComplete();
});
});
await();
}
use of io.vertx.core.DeploymentOptions in project vert.x by eclipse.
the class ComplexHATest method deployRandomVerticles.
protected void deployRandomVerticles(Runnable runner) {
int toDeploy = 0;
AtomicInteger deployCount = new AtomicInteger();
List<Integer> numbersToDeploy = new ArrayList<>();
for (int i = 0; i < aliveNodes.size(); i++) {
int numToDeploy = random.nextInt(maxVerticlesPerNode + 1);
numbersToDeploy.add(numToDeploy);
toDeploy += numToDeploy;
}
int index = 0;
for (int pos : aliveNodes) {
Vertx v = vertices[pos];
int numToDeploy = numbersToDeploy.get(index);
index++;
for (int j = 0; j < numToDeploy; j++) {
JsonObject config = new JsonObject();
config.put("foo", TestUtils.randomAlphaString(100));
DeploymentOptions options = new DeploymentOptions().setHa(true).setConfig(config);
String verticleName = "java:io.vertx.test.core.HAVerticle" + (random.nextInt(3) + 1);
v.deployVerticle(verticleName, options, ar -> {
assertTrue(ar.succeeded());
deployCount.incrementAndGet();
});
}
}
int ttoDeploy = toDeploy;
eventLoopWaitUntil(() -> ttoDeploy == deployCount.get(), () -> {
totDeployed += ttoDeploy;
runner.run();
});
}
use of io.vertx.core.DeploymentOptions in project vert.x by eclipse.
the class ClasspathHandlerTest method testCPInBareCommand.
@Test
public void testCPInBareCommand() {
bare = new BareCommand();
bare.setExecutionContext(new ExecutionContext(bare, null, null));
bare.setClasspath("." + File.pathSeparator + "target/externals");
bare.setQuorum(1);
bare.run();
waitUntil(() -> bare.vertx != null);
// Do reproduce the verticle fail-over, set the TCCL
final ClassLoader originalClassloader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(bare.createClassloader());
bare.vertx.deployVerticle(VERTICLE, new DeploymentOptions().setHa(true));
} finally {
Thread.currentThread().setContextClassLoader(originalClassloader);
}
waitUntil(() -> {
try {
return getHttpCode() == 200;
} catch (IOException e) {
return false;
}
});
}
use of io.vertx.core.DeploymentOptions in project vert.x by eclipse.
the class HATest method testQuorumWithHaGroups.
@Test
public void testQuorumWithHaGroups() throws Exception {
vertx1 = startVertx("group1", 2);
vertx2 = startVertx("group2", 2);
vertx1.deployVerticle("java:" + HAVerticle1.class.getName(), new DeploymentOptions().setHa(true), ar -> {
assertTrue(ar.succeeded());
assertTrue(vertx1.deploymentIDs().contains(ar.result()));
});
// Wait a little while
Thread.sleep(500);
//Should not be deployed yet
assertTrue(vertx1.deploymentIDs().isEmpty());
vertx3 = startVertx("group1", 2);
// Now should deploy
waitUntil(() -> vertx1.deploymentIDs().size() == 1);
vertx2.deployVerticle("java:" + HAVerticle1.class.getName(), new DeploymentOptions().setHa(true), ar -> {
assertTrue(ar.succeeded());
assertTrue(vertx2.deploymentIDs().contains(ar.result()));
});
// Wait a little while
Thread.sleep(500);
//Should not be deployed yet
assertTrue(vertx2.deploymentIDs().isEmpty());
vertx4 = startVertx("group2", 2);
// Now should deploy
waitUntil(() -> vertx2.deploymentIDs().size() == 1);
// Noow stop vertx4
CountDownLatch latch = new CountDownLatch(1);
vertx4.close(ar -> {
latch.countDown();
});
awaitLatch(latch);
waitUntil(() -> vertx2.deploymentIDs().isEmpty());
assertTrue(vertx1.deploymentIDs().size() == 1);
CountDownLatch latch2 = new CountDownLatch(1);
vertx3.close(ar -> {
latch2.countDown();
});
awaitLatch(latch2);
waitUntil(() -> vertx1.deploymentIDs().isEmpty());
}
use of io.vertx.core.DeploymentOptions in project vert.x by eclipse.
the class WebsocketTest method testRaceConditionWithWebsocketClientWorker.
@Test
public void testRaceConditionWithWebsocketClientWorker() throws Exception {
CompletableFuture<Context> fut = new CompletableFuture<>();
vertx.deployVerticle(new AbstractVerticle() {
@Override
public void start() throws Exception {
fut.complete(context);
}
}, new DeploymentOptions().setWorker(true), ar -> {
if (ar.failed()) {
fut.completeExceptionally(ar.cause());
}
});
testRaceConditionWithWebsocketClient(fut.get());
}
Aggregations