@Test public void should_wait_until_correct_time() throws InterruptedException { Logger loggger = mock(Logger.class); Metrics metrics = new Metrics(); Sleeper sleeper = mock(Sleeper.class); Backoff b = new Backoff(sleeper, loggger, metrics); long now = System.currentTimeMillis(); b.waitUntil(TimeUnit.MILLISECONDS.toSeconds(now) + 1); ArgumentCaptor<Long> arg = ArgumentCaptor.forClass(Long.class); verify(sleeper).sleep(arg.capture()); assertTrue(arg.getValue() < 2000 && arg.getValue() > 0); }
@SuppressWarnings("checkstyle:designforextension") public void waitUntil(final long waitUntil) throws InterruptedException { this.currentType = BackoffType.WAIT_UNTIL; long waitFor = TimeUnit.SECONDS.toMillis(waitUntil) - System.currentTimeMillis(); if (waitFor > 0) { waitFor += TimeUnit.SECONDS.toMillis(1); log.info("Waiting for {} ms", waitFor); sleeper.sleep(waitFor); } }
Backoff { @SuppressWarnings("checkstyle:designforextension") public void waitUntil(final long waitUntil) throws InterruptedException { this.currentType = BackoffType.WAIT_UNTIL; long waitFor = TimeUnit.SECONDS.toMillis(waitUntil) - System.currentTimeMillis(); if (waitFor > 0) { waitFor += TimeUnit.SECONDS.toMillis(1); log.info("Waiting for {} ms", waitFor); sleeper.sleep(waitFor); } } }
Backoff { @SuppressWarnings("checkstyle:designforextension") public void waitUntil(final long waitUntil) throws InterruptedException { this.currentType = BackoffType.WAIT_UNTIL; long waitFor = TimeUnit.SECONDS.toMillis(waitUntil) - System.currentTimeMillis(); if (waitFor > 0) { waitFor += TimeUnit.SECONDS.toMillis(1); log.info("Waiting for {} ms", waitFor); sleeper.sleep(waitFor); } } Backoff(
            final Sleeper sleeper,
            final Logger log,
            final Metrics metrics); }
Backoff { @SuppressWarnings("checkstyle:designforextension") public void waitUntil(final long waitUntil) throws InterruptedException { this.currentType = BackoffType.WAIT_UNTIL; long waitFor = TimeUnit.SECONDS.toMillis(waitUntil) - System.currentTimeMillis(); if (waitFor > 0) { waitFor += TimeUnit.SECONDS.toMillis(1); log.info("Waiting for {} ms", waitFor); sleeper.sleep(waitFor); } } Backoff(
            final Sleeper sleeper,
            final Logger log,
            final Metrics metrics); @SuppressWarnings("checkstyle:designforextension") void linearBackoff(); @SuppressWarnings("checkstyle:designforextension") void exponentialBackoff(); @SuppressWarnings("checkstyle:designforextension") void waitUntil(final long waitUntil); @SuppressWarnings("checkstyle:designforextension") void reset(); }
Backoff { @SuppressWarnings("checkstyle:designforextension") public void waitUntil(final long waitUntil) throws InterruptedException { this.currentType = BackoffType.WAIT_UNTIL; long waitFor = TimeUnit.SECONDS.toMillis(waitUntil) - System.currentTimeMillis(); if (waitFor > 0) { waitFor += TimeUnit.SECONDS.toMillis(1); log.info("Waiting for {} ms", waitFor); sleeper.sleep(waitFor); } } Backoff(
            final Sleeper sleeper,
            final Logger log,
            final Metrics metrics); @SuppressWarnings("checkstyle:designforextension") void linearBackoff(); @SuppressWarnings("checkstyle:designforextension") void exponentialBackoff(); @SuppressWarnings("checkstyle:designforextension") void waitUntil(final long waitUntil); @SuppressWarnings("checkstyle:designforextension") void reset();  }