Search in sources :

Example 1 with EventTailCommand

use of org.apache.karaf.event.command.EventTailCommand 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)

Aggregations

PrintStream (java.io.PrintStream)1 ExecutorService (java.util.concurrent.ExecutorService)1 EventTailCommand (org.apache.karaf.event.command.EventTailCommand)1 EventCollector (org.apache.karaf.event.service.EventCollector)1 Session (org.apache.karaf.shell.api.console.Session)1 Test (org.junit.Test)1