From eb4cd8e37c1fbe429f2ec920debebae457d5055a Mon Sep 17 00:00:00 2001 From: "arnett, stu" Date: Tue, 22 Aug 2017 14:09:34 -0500 Subject: [PATCH] test corrections --- src/main/java/com/emc/rest/smart/Host.java | 8 +++++--- src/test/java/com/emc/rest/smart/HostTest.java | 6 +++--- src/test/java/com/emc/rest/smart/SmartClientTest.java | 4 ++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/emc/rest/smart/Host.java b/src/main/java/com/emc/rest/smart/Host.java index 2b1fc14..4314929 100644 --- a/src/main/java/com/emc/rest/smart/Host.java +++ b/src/main/java/com/emc/rest/smart/Host.java @@ -26,11 +26,11 @@ */ package com.emc.rest.smart; -import java.util.Date; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.Date; + /** * Some basic statements about response index calculation: *

@@ -105,7 +105,9 @@ public boolean isHealthy() { if (!healthy) return false; else if (consecutiveErrors == 0) return true; else { - long coolDownExp = consecutiveErrors > MAX_COOL_DOWN_EXP ? MAX_COOL_DOWN_EXP : consecutiveErrors - 1; + // errorWaitTime * 2 ^ (min(errors-1, 4)) + // i.e. back-off is doubled for each consecutive error up to 4 + long coolDownExp = Math.min(consecutiveErrors - 1, MAX_COOL_DOWN_EXP); long msSinceLastUse = System.currentTimeMillis() - lastConnectionTime; long errorCoolDown = (long) Math.pow(2, coolDownExp) * errorWaitTime; return msSinceLastUse > errorCoolDown; diff --git a/src/test/java/com/emc/rest/smart/HostTest.java b/src/test/java/com/emc/rest/smart/HostTest.java index fc30426..151469e 100644 --- a/src/test/java/com/emc/rest/smart/HostTest.java +++ b/src/test/java/com/emc/rest/smart/HostTest.java @@ -71,7 +71,7 @@ public void testHost() throws Exception { Thread.sleep(errorWaitTime - 500); // wait until just before the error is cooled down Assert.assertFalse(host.isHealthy()); // host should still be in cool down period - Thread.sleep(500); // wait until cool down period is over + Thread.sleep(600); // wait until cool down period is over Assert.assertTrue(host.isHealthy()); // test another error @@ -89,7 +89,7 @@ public void testHost() throws Exception { Thread.sleep(2 * errorWaitTime - 500); // wait until just before cool down is over Assert.assertFalse(host.isHealthy()); - Thread.sleep(500); // wait until cool down period is over + Thread.sleep(600); // wait until cool down period is over Assert.assertTrue(host.isHealthy()); // test one more error @@ -107,7 +107,7 @@ public void testHost() throws Exception { Thread.sleep(2 * 2 * errorWaitTime - 500); // wait until just before cool down is over Assert.assertFalse(host.isHealthy()); - Thread.sleep(500); // wait until cool down period is over + Thread.sleep(600); // wait until cool down period is over Assert.assertTrue(host.isHealthy()); // test no more errors diff --git a/src/test/java/com/emc/rest/smart/SmartClientTest.java b/src/test/java/com/emc/rest/smart/SmartClientTest.java index c15cee8..7306e3a 100644 --- a/src/test/java/com/emc/rest/smart/SmartClientTest.java +++ b/src/test/java/com/emc/rest/smart/SmartClientTest.java @@ -115,7 +115,7 @@ public void testConnTimeout() throws Exception { HttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams, CONNECTION_TIMEOUT_MILLIS); - SmartConfig smartConfig = new SmartConfig("10.4.4.180"); + SmartConfig smartConfig = new SmartConfig("8.8.4.4:9020"); smartConfig.setProperty(ApacheHttpClient4Config.PROPERTY_HTTP_PARAMS, httpParams); final Client client = SmartClientFactory.createStandardClient(smartConfig); @@ -123,7 +123,7 @@ public void testConnTimeout() throws Exception { Future future = Executors.newSingleThreadExecutor().submit(new Runnable() { @Override public void run() { - client.resource("http://10.4.4.180:9020/?ping").get(String.class); + client.resource("http://8.8.4.4:9020/?ping").get(String.class); Assert.fail("response was not expected; choose an IP that is not in use"); } });