@Test public void shouldReportExceptionThrownByAgent() throws Exception { final CountDownLatch latch = new CountDownLatch(1); final RuntimeException expectedException = new RuntimeException(); when(mockAgent.doWork()).thenThrow(expectedException); doAnswer( (invocation) -> { latch.countDown(); return null; }) .when(mockErrorHandler).onError(expectedException); new Thread(runner).start(); if (!latch.await(3, TimeUnit.SECONDS)) { fail("Should have called error handler"); } verify(mockAgent, times(1)).onStart(); verify(mockAgent, atLeastOnce()).doWork(); verify(mockErrorHandler, atLeastOnce()).onError(expectedException); verify(mockAtomicCounter, atLeastOnce()).increment(); runner.close(); }
public final void close() { close(RETRY_CLOSE_TIMEOUT_MS, null); }
AgentRunner implements Runnable, AutoCloseable { public final void close() { close(RETRY_CLOSE_TIMEOUT_MS, null); } }
AgentRunner implements Runnable, AutoCloseable { public final void close() { close(RETRY_CLOSE_TIMEOUT_MS, null); } AgentRunner(
        final IdleStrategy idleStrategy,
        final ErrorHandler errorHandler,
        final AtomicCounter errorCounter,
        final Agent agent); }
AgentRunner implements Runnable, AutoCloseable { public final void close() { close(RETRY_CLOSE_TIMEOUT_MS, null); } AgentRunner(
        final IdleStrategy idleStrategy,
        final ErrorHandler errorHandler,
        final AtomicCounter errorCounter,
        final Agent agent); static Thread startOnThread(final AgentRunner runner); static Thread startOnThread(final AgentRunner runner, final ThreadFactory threadFactory); Agent agent(); boolean isClosed(); Thread thread(); void run(); final void close(); final void close(final int retryCloseTimeoutMs, final Consumer<Thread> closeFailAction); }
AgentRunner implements Runnable, AutoCloseable { public final void close() { close(RETRY_CLOSE_TIMEOUT_MS, null); } AgentRunner(
        final IdleStrategy idleStrategy,
        final ErrorHandler errorHandler,
        final AtomicCounter errorCounter,
        final Agent agent); static Thread startOnThread(final AgentRunner runner); static Thread startOnThread(final AgentRunner runner, final ThreadFactory threadFactory); Agent agent(); boolean isClosed(); Thread thread(); void run(); final void close(); final void close(final int retryCloseTimeoutMs, final Consumer<Thread> closeFailAction); static final Thread TOMBSTONE; static final int RETRY_CLOSE_TIMEOUT_MS; }