DelayedResponse implements Delayed { public DelayedResponse(JRTServerConfigRequest request) { this(request, System.currentTimeMillis() + request.getTimeout()); } DelayedResponse(JRTServerConfigRequest request);   DelayedResponse(JRTServerConfigRequest request, long returnTime); Long getReturnTime(); JRTServerConfigRequest getRequest(); @Override long getDelay(TimeUnit unit); @Override int compareTo(Delayed delayed); @Override String toString();  }
@Test public void testDelayedResponse() { ConfigTester tester = new ConfigTester(); final long timeout = 20000; JRTServerConfigRequest request1 = tester.createRequest("baz", configId, namespace, timeout); DelayedResponse delayed1 = new DelayedResponse(request1); assertTrue(delayed1.getReturnTime() > System.currentTimeMillis()); assertTrue(delayed1.getDelay(TimeUnit.MILLISECONDS) > 0); assertTrue(delayed1.getDelay(TimeUnit.MILLISECONDS) <= timeout); try { Thread.sleep(1); } catch (InterruptedException e) { e.printStackTrace(); } JRTServerConfigRequest request2 = tester.createRequest("baz", configId, namespace, timeout); DelayedResponse delayed2 = new DelayedResponse(request2); assertTrue("delayed1=" + delayed1.getReturnTime() + ", delayed2=" + delayed2.getReturnTime() + ": delayed2 should be greater than delayed1", delayed2.getReturnTime() > delayed1.getReturnTime()); assertThat(delayed1.compareTo(delayed1), is(0)); assertThat(delayed1.compareTo(delayed2), is(-1)); assertThat(delayed2.compareTo(delayed1), is(1)); }