use of io.vertx.core.Context in project vert.x by eclipse.
the class Http2Test method testServerStreamPausedWhenConnectionIsPaused.
@Test
public void testServerStreamPausedWhenConnectionIsPaused() throws Exception {
CountDownLatch fullLatch = new CountDownLatch(1);
CompletableFuture<Void> resumeLatch = new CompletableFuture<>();
server.requestHandler(req -> {
HttpServerResponse resp = req.response();
switch(req.path()) {
case "/0":
{
vertx.setPeriodic(1, timerID -> {
if (resp.writeQueueFull()) {
vertx.cancelTimer(timerID);
fullLatch.countDown();
} else {
resp.write(Buffer.buffer(TestUtils.randomAlphaString(512)));
}
});
break;
}
case "/1":
{
assertTrue(resp.writeQueueFull());
resp.drainHandler(v -> {
resp.end();
});
resumeLatch.complete(null);
break;
}
}
});
startServer();
client.getNow(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/0", resp -> {
resp.pause();
Context ctx = vertx.getOrCreateContext();
resumeLatch.thenAccept(v1 -> {
ctx.runOnContext(v2 -> {
resp.endHandler(v -> {
testComplete();
});
resp.resume();
});
});
});
awaitLatch(fullLatch);
client.getNow(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/1", resp -> {
resp.endHandler(v -> {
complete();
});
});
// Make sure it completes
resumeLatch.get(20, TimeUnit.SECONDS);
await();
}
use of io.vertx.core.Context in project vert.x by eclipse.
the class Http2TestBase method assertOnIOContext.
protected void assertOnIOContext(Context context) {
Context current = Vertx.currentContext();
assertNotNull(current);
assertEquals(context, current);
for (StackTraceElement elt : Thread.currentThread().getStackTrace()) {
if (elt.getMethodName().equals("executeFromIO")) {
return;
}
}
fail("Not from IO");
}
use of io.vertx.core.Context 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());
}
use of io.vertx.core.Context in project vert.x by eclipse.
the class VertxTestBase method createWorker.
/**
* Create a worker verticle for the current Vert.x and return its context.
*
* @return the context
* @throws Exception anything preventing the creation of the worker
*/
protected Context createWorker() 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());
}
});
return fut.get();
}
use of io.vertx.core.Context in project vert.x by eclipse.
the class FakeClusterManager method getCounter.
@Override
public void getCounter(String name, Handler<AsyncResult<Counter>> resultHandler) {
AtomicLong counter = new AtomicLong();
AtomicLong prev = counters.putIfAbsent(name, counter);
if (prev != null) {
counter = prev;
}
AtomicLong theCounter = counter;
Context context = vertx.getOrCreateContext();
context.runOnContext(v -> resultHandler.handle(Future.succeededFuture(new AsynchronousCounter(vertx, theCounter))));
}
Aggregations