Search in sources :

Example 1 with EventBus

use of io.syndesis.common.util.EventBus in project syndesis by syndesisio.

the class SimpleEventBusTest method testSend.

@Test
public void testSend() throws InterruptedException {
    CountDownLatch done = new CountDownLatch(1);
    String[] sub1 = new String[2];
    EventBus eventBus = createEventBus();
    // Add a subscriber named "a"
    eventBus.subscribe("a", (event, data) -> {
        sub1[0] = event;
        sub1[1] = data;
        done.countDown();
    });
    // Now send an event to that subscriber.
    eventBus.send("a", "text", "data");
    // the send could be done async, so we wait for it to complete.
    done.await(5, TimeUnit.SECONDS);
    assertEquals("text", sub1[0]);
    assertEquals("data", sub1[1]);
}
Also used : EventBus(io.syndesis.common.util.EventBus) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 2 with EventBus

use of io.syndesis.common.util.EventBus in project syndesis by syndesisio.

the class SimpleEventBusTest method testBroadcast.

@Test
public void testBroadcast() throws InterruptedException {
    CountDownLatch done = new CountDownLatch(2);
    String[] sub1 = new String[2];
    String[] sub2 = new String[2];
    EventBus eventBus = createEventBus();
    // Add a subscriber named "a"
    eventBus.subscribe("a", (event, data) -> {
        sub1[0] = event;
        sub1[1] = data;
        done.countDown();
    });
    eventBus.subscribe("b", (event, data) -> {
        sub2[0] = event;
        sub2[1] = data;
        done.countDown();
    });
    // Now send an event to that subscriber.
    eventBus.broadcast("text", "data");
    // the send could be done async, so we wait for it to complete.
    done.await(5, TimeUnit.SECONDS);
    assertEquals("text", sub1[0]);
    assertEquals("data", sub1[1]);
    assertEquals("text", sub2[0]);
    assertEquals("data", sub2[1]);
}
Also used : EventBus(io.syndesis.common.util.EventBus) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

EventBus (io.syndesis.common.util.EventBus)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Test (org.junit.Test)2