forked from Netflix/astyanax
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue Netflix#421 - Fixed sleep timeout going negative
- Loading branch information
Showing
4 changed files
with
49 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
astyanax-core/src/test/java/com/netflix/astyanax/retry/BoundedExponentialBackoffTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.netflix.astyanax.retry; | ||
|
||
import static com.netflix.astyanax.retry.ExponentialBackoffTest.setAttemptCount; | ||
import static org.junit.Assert.assertTrue; | ||
import org.junit.Test; | ||
|
||
public final class BoundedExponentialBackoffTest { | ||
|
||
@Test | ||
public void testSleepTimeNeverNegative() throws NoSuchFieldException, IllegalAccessException { | ||
BoundedExponentialBackoff backoff = new BoundedExponentialBackoff(500, 5000, -1); | ||
|
||
for(int i = 0; i < 1000; i++) { | ||
setAttemptCount(backoff, i); | ||
assertTrue("Backoff at retry " + i + " was not positive", backoff.getSleepTimeMs() >= 0); | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
astyanax-core/src/test/java/com/netflix/astyanax/retry/ExponentialBackoffTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.netflix.astyanax.retry; | ||
|
||
import java.lang.reflect.Field; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
import org.junit.Test; | ||
|
||
public final class ExponentialBackoffTest { | ||
|
||
|
||
@Test | ||
public void testSleepTimeNeverNegative() throws NoSuchFieldException, IllegalAccessException { | ||
ExponentialBackoff backoff = new ExponentialBackoff(500, -1); | ||
|
||
for(int i = 22; i < 1000; i++) { | ||
setAttemptCount(backoff, i); | ||
assertTrue("Backoff at retry " + i + " was not positive", backoff.getSleepTimeMs() >= 0); | ||
} | ||
} | ||
|
||
public static void setAttemptCount(SleepingRetryPolicy backoff, int attempt) | ||
throws NoSuchFieldException, IllegalAccessException { | ||
Field attempts = SleepingRetryPolicy.class.getDeclaredField("attempts"); | ||
attempts.setAccessible(true); | ||
attempts.setInt(backoff, attempt); | ||
} | ||
} |