Watchdog implements Runnable { public void run() { try { runUnsafe(); } catch (Throwable t) { LOG.error("Caught throwable in periodic Watchdog run. Continuing.", t); } } Watchdog(Clock clock, long waitTimeoutMs);  Watchdog(Clock clock, long waitTimeoutMs, long idleTimeoutMs); ClientCall<ReqT, RespT> watch(ClientCall<ReqT, RespT> innerCall); void run(); void start(ScheduledExecutorService executor); void stop();  }
@Test public void testWaitTimeout() throws Exception { watchedCall.request(1); clock.setTime(waitTimeMs - 1); watchdog.run(); Assert.assertNull(call.cancelMessage); clock.setTime(waitTimeMs); watchdog.run(); Assert.assertNotNull(call.cancelMessage); call.listener.onClose( Status.ABORTED.withDescription("Some upstream exception representing cancellation"), new Metadata()); Assert.assertEquals( listener.closeStatus.getDescription(), "Some upstream exception representing cancellation"); }
@Test public void testNotStarted() { clock.setTime(idleTimeMs - 1); watchdog.run(); Assert.assertNull(call.cancelMessage); clock.setTime(idleTimeMs); watchdog.run(); Assert.assertNotNull(call.cancelMessage); call.listener.onClose( Status.CANCELLED.withDescription("Some upstream exception representing cancellation"), new Metadata()); Assert.assertEquals( listener.closeStatus.getDescription(), "Some upstream exception representing cancellation"); }
@Test public void testIdleTimeout() { call.request(1); call.listener.onMessage(""); clock.setTime(idleTimeMs - 1); watchdog.run(); Assert.assertNull(call.cancelMessage); clock.setTime(idleTimeMs); watchdog.run(); Assert.assertNotNull(call.cancelMessage); call.listener.onClose( Status.CANCELLED.withDescription("Some upstream exception representing cancellation"), new Metadata()); Assert.assertEquals( listener.closeStatus.getDescription(), "Some upstream exception representing cancellation"); }