Search in sources :

Example 1 with TimeoutStream

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();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TimeoutStream(io.vertx.core.TimeoutStream) Test(org.junit.Test)

Example 2 with TimeoutStream

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();
}
Also used : TimeoutStream(io.vertx.core.TimeoutStream) Test(org.junit.Test)

Example 3 with TimeoutStream

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();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TimeoutStream(io.vertx.core.TimeoutStream) Test(org.junit.Test)

Aggregations

TimeoutStream (io.vertx.core.TimeoutStream)3 Test (org.junit.Test)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1