Search in sources :

Example 1 with EventCollector

use of org.apache.karaf.event.service.EventCollector in project karaf by apache.

the class EventTailCommandTest method testTail.

@Test
public void testTail() throws Exception {
    EventTailCommand tail = new EventTailCommand();
    tail.session = mock(Session.class);
    tail.collector = new EventCollector();
    PrintStream out = System.out;
    expect(tail.session.getConsole()).andReturn(out);
    exception = null;
    replay(tail.session);
    ExecutorService executor = Executors.newSingleThreadExecutor();
    executor.execute(() -> {
        try {
            tail.execute();
        } catch (Exception e) {
            exception = e;
        }
    });
    tail.collector.handleEvent(event());
    Thread.sleep(200);
    // Will interrupt the tail
    executor.shutdownNow();
    executor.awaitTermination(10, TimeUnit.SECONDS);
    if (exception != null) {
        throw exception;
    }
    verify(tail.session);
}
Also used : PrintStream(java.io.PrintStream) EventCollector(org.apache.karaf.event.service.EventCollector) ExecutorService(java.util.concurrent.ExecutorService) EventTailCommand(org.apache.karaf.event.command.EventTailCommand) Session(org.apache.karaf.shell.api.console.Session) Test(org.junit.Test)

Example 2 with EventCollector

use of org.apache.karaf.event.service.EventCollector in project karaf by apache.

the class EventDisplayCommandTest method testExecute.

@Test
public void testExecute() throws Exception {
    IMocksControl c = createControl();
    EventDisplayCommand display = new EventDisplayCommand();
    display.session = c.createMock(Session.class);
    expect(display.session.getConsole()).andReturn(System.out);
    display.collector = new EventCollector();
    display.collector.handleEvent(new Event("myTopic", new HashMap<>()));
    c.replay();
    display.execute();
    c.verify();
}
Also used : IMocksControl(org.easymock.IMocksControl) EventDisplayCommand(org.apache.karaf.event.command.EventDisplayCommand) HashMap(java.util.HashMap) EventCollector(org.apache.karaf.event.service.EventCollector) Event(org.osgi.service.event.Event) Session(org.apache.karaf.shell.api.console.Session) Test(org.junit.Test)

Aggregations

EventCollector (org.apache.karaf.event.service.EventCollector)2 Session (org.apache.karaf.shell.api.console.Session)2 Test (org.junit.Test)2 PrintStream (java.io.PrintStream)1 HashMap (java.util.HashMap)1 ExecutorService (java.util.concurrent.ExecutorService)1 EventDisplayCommand (org.apache.karaf.event.command.EventDisplayCommand)1 EventTailCommand (org.apache.karaf.event.command.EventTailCommand)1 IMocksControl (org.easymock.IMocksControl)1 Event (org.osgi.service.event.Event)1