Skip to content

Commit

Permalink
test corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
arnett, stu committed Aug 22, 2017
1 parent fb74d94 commit eb4cd8e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
8 changes: 5 additions & 3 deletions src/main/java/com/emc/rest/smart/Host.java
Original file line number Diff line number Diff line change
Expand Up @@ -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:
* <p>
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/com/emc/rest/smart/HostTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/emc/rest/smart/SmartClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,15 @@ 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);

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");
}
});
Expand Down

0 comments on commit eb4cd8e

Please sign in to comment.