diff --git a/core/src/main/java/org/jclouds/http/handlers/BackoffLimitedRetryHandler.java b/core/src/main/java/org/jclouds/http/handlers/BackoffLimitedRetryHandler.java index 083d092623..5be70e39c1 100644 --- a/core/src/main/java/org/jclouds/http/handlers/BackoffLimitedRetryHandler.java +++ b/core/src/main/java/org/jclouds/http/handlers/BackoffLimitedRetryHandler.java @@ -110,7 +110,7 @@ public class BackoffLimitedRetryHandler implements HttpRetryHandler { public void imposeBackoffExponentialDelay(long period, int pow, int failureCount, String commandDescription) { long delayMs = (long) (period * Math.pow(failureCount, pow)); - logger.debug("Retry %1$d/%2$d after server error, delaying for %3$d ms: %4$s", failureCount, + logger.debug("Retry %d/%d after server error, delaying for %d ms: %s", failureCount, retryCountLimit, delayMs, commandDescription); try { Thread.sleep(delayMs); diff --git a/core/src/test/java/org/jclouds/http/handlers/BackoffLimitedRetryHandlerTest.java b/core/src/test/java/org/jclouds/http/handlers/BackoffLimitedRetryHandlerTest.java index 9740905582..15d1facc0b 100644 --- a/core/src/test/java/org/jclouds/http/handlers/BackoffLimitedRetryHandlerTest.java +++ b/core/src/test/java/org/jclouds/http/handlers/BackoffLimitedRetryHandlerTest.java @@ -56,34 +56,34 @@ public class BackoffLimitedRetryHandlerTest { void testExponentialBackoffDelay() throws InterruptedException { long acceptableDelay = 25; // Delay to forgive if tests run long. - long startTime = System.currentTimeMillis(); + long startTime = System.nanoTime(); handler.imposeBackoffExponentialDelay(1, "TEST FAILURE: 1"); - long elapsedTime = System.currentTimeMillis() - startTime; + long elapsedTime = (System.nanoTime() - startTime)/1000000; assertTrue(elapsedTime >= 50); assertTrue(elapsedTime < 50 + acceptableDelay); - startTime = System.currentTimeMillis(); + startTime = System.nanoTime(); handler.imposeBackoffExponentialDelay(2, "TEST FAILURE: 2"); - elapsedTime = System.currentTimeMillis() - startTime; + elapsedTime = (System.nanoTime() - startTime)/1000000; assertTrue(elapsedTime >= 200); assertTrue(elapsedTime < 200 + acceptableDelay); - startTime = System.currentTimeMillis(); + startTime = System.nanoTime(); handler.imposeBackoffExponentialDelay(3, "TEST FAILURE: 3"); - elapsedTime = System.currentTimeMillis() - startTime; + elapsedTime = (System.nanoTime() - startTime)/1000000; assertTrue(elapsedTime >= 450); assertTrue(elapsedTime < 450 + acceptableDelay); - startTime = System.currentTimeMillis(); + startTime = System.nanoTime(); handler.imposeBackoffExponentialDelay(4, "TEST FAILURE: 4"); - elapsedTime = System.currentTimeMillis() - startTime; + elapsedTime = (System.nanoTime() - startTime)/1000000; assertTrue(elapsedTime >= 800); assertTrue(elapsedTime < 800 + acceptableDelay); - startTime = System.currentTimeMillis(); + startTime = System.nanoTime(); handler.imposeBackoffExponentialDelay(5, "TEST FAILURE: 5"); - elapsedTime = System.currentTimeMillis() - startTime; - assertTrue(elapsedTime >= 1250); + elapsedTime = (System.nanoTime() - startTime)/1000000; + assert (elapsedTime >= 1249) : elapsedTime ; assertTrue(elapsedTime < 1250 + acceptableDelay); }