use of io.vertx.core.TimeoutStream in project vert.x by eclipse.
the class TimerTest method testTimerStreamCancellation.
@Test
public void testTimerStreamCancellation() throws Exception {
vertx.runOnContext(v -> {
TimeoutStream timer = vertx.timerStream(200);
AtomicBoolean called = new AtomicBoolean();
timer.handler(l -> {
called.set(true);
});
timer.cancel();
vertx.setTimer(500, id -> {
assertFalse(called.get());
testComplete();
});
});
await();
}
use of io.vertx.core.TimeoutStream in project vert.x by eclipse.
the class TimerTest method testTimeoutStreamEndCallbackAsynchronously.
@Test
public void testTimeoutStreamEndCallbackAsynchronously() {
TimeoutStream stream = vertx.timerStream(200);
ThreadLocal<Object> stack = new ThreadLocal<>();
stack.set(true);
stream.endHandler(v2 -> {
assertTrue(Vertx.currentContext().isEventLoopContext());
assertNull(stack.get());
testComplete();
});
stream.handler(id -> {
});
await();
}
use of io.vertx.core.TimeoutStream in project vert.x by eclipse.
the class TimerTest method testPeriodicStreamHandler.
@Test
public void testPeriodicStreamHandler() throws Exception {
TimeoutStream timer = vertx.periodicStream(10);
AtomicInteger count = new AtomicInteger();
timer.handler(l -> {
int value = count.incrementAndGet();
switch(value) {
case 0:
break;
case 1:
throw new RuntimeException();
case 2:
timer.cancel();
testComplete();
break;
default:
fail();
}
});
timer.endHandler(v -> {
fail();
});
await();
}
Aggregations