|
@@ -28,7 +28,6 @@ import org.apache.hadoop.ipc.StandbyException;
|
|
import org.apache.hadoop.util.ThreadUtil;
|
|
import org.apache.hadoop.util.ThreadUtil;
|
|
import org.junit.Test;
|
|
import org.junit.Test;
|
|
|
|
|
|
-@SuppressWarnings("unchecked")
|
|
|
|
public class TestFailoverProxy {
|
|
public class TestFailoverProxy {
|
|
|
|
|
|
public static class FlipFlopProxyProvider<T> implements FailoverProxyProvider<T> {
|
|
public static class FlipFlopProxyProvider<T> implements FailoverProxyProvider<T> {
|
|
@@ -84,15 +83,29 @@ public class TestFailoverProxy {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private static FlipFlopProxyProvider<UnreliableInterface>
|
|
|
|
+ newFlipFlopProxyProvider() {
|
|
|
|
+ return new FlipFlopProxyProvider<UnreliableInterface>(
|
|
|
|
+ UnreliableInterface.class,
|
|
|
|
+ new UnreliableImplementation("impl1"),
|
|
|
|
+ new UnreliableImplementation("impl2"));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static FlipFlopProxyProvider<UnreliableInterface>
|
|
|
|
+ newFlipFlopProxyProvider(TypeOfExceptionToFailWith t1,
|
|
|
|
+ TypeOfExceptionToFailWith t2) {
|
|
|
|
+ return new FlipFlopProxyProvider<UnreliableInterface>(
|
|
|
|
+ UnreliableInterface.class,
|
|
|
|
+ new UnreliableImplementation("impl1", t1),
|
|
|
|
+ new UnreliableImplementation("impl2", t2));
|
|
|
|
+ }
|
|
|
|
+
|
|
@Test
|
|
@Test
|
|
public void testSuccedsOnceThenFailOver() throws UnreliableException,
|
|
public void testSuccedsOnceThenFailOver() throws UnreliableException,
|
|
IOException, StandbyException {
|
|
IOException, StandbyException {
|
|
- UnreliableInterface unreliable = (UnreliableInterface)RetryProxy
|
|
|
|
- .create(UnreliableInterface.class,
|
|
|
|
- new FlipFlopProxyProvider(UnreliableInterface.class,
|
|
|
|
- new UnreliableImplementation("impl1"),
|
|
|
|
- new UnreliableImplementation("impl2")),
|
|
|
|
- new FailOverOnceOnAnyExceptionPolicy());
|
|
|
|
|
|
+ UnreliableInterface unreliable = (UnreliableInterface)RetryProxy.create(
|
|
|
|
+ UnreliableInterface.class, newFlipFlopProxyProvider(),
|
|
|
|
+ new FailOverOnceOnAnyExceptionPolicy());
|
|
|
|
|
|
assertEquals("impl1", unreliable.succeedsOnceThenFailsReturningString());
|
|
assertEquals("impl1", unreliable.succeedsOnceThenFailsReturningString());
|
|
assertEquals("impl2", unreliable.succeedsOnceThenFailsReturningString());
|
|
assertEquals("impl2", unreliable.succeedsOnceThenFailsReturningString());
|
|
@@ -107,12 +120,10 @@ public class TestFailoverProxy {
|
|
@Test
|
|
@Test
|
|
public void testSucceedsTenTimesThenFailOver() throws UnreliableException,
|
|
public void testSucceedsTenTimesThenFailOver() throws UnreliableException,
|
|
IOException, StandbyException {
|
|
IOException, StandbyException {
|
|
- UnreliableInterface unreliable = (UnreliableInterface)RetryProxy
|
|
|
|
- .create(UnreliableInterface.class,
|
|
|
|
- new FlipFlopProxyProvider(UnreliableInterface.class,
|
|
|
|
- new UnreliableImplementation("impl1"),
|
|
|
|
- new UnreliableImplementation("impl2")),
|
|
|
|
- new FailOverOnceOnAnyExceptionPolicy());
|
|
|
|
|
|
+ UnreliableInterface unreliable = (UnreliableInterface)RetryProxy.create(
|
|
|
|
+ UnreliableInterface.class,
|
|
|
|
+ newFlipFlopProxyProvider(),
|
|
|
|
+ new FailOverOnceOnAnyExceptionPolicy());
|
|
|
|
|
|
for (int i = 0; i < 10; i++) {
|
|
for (int i = 0; i < 10; i++) {
|
|
assertEquals("impl1", unreliable.succeedsTenTimesThenFailsReturningString());
|
|
assertEquals("impl1", unreliable.succeedsTenTimesThenFailsReturningString());
|
|
@@ -123,11 +134,9 @@ public class TestFailoverProxy {
|
|
@Test
|
|
@Test
|
|
public void testNeverFailOver() throws UnreliableException,
|
|
public void testNeverFailOver() throws UnreliableException,
|
|
IOException, StandbyException {
|
|
IOException, StandbyException {
|
|
- UnreliableInterface unreliable = (UnreliableInterface)RetryProxy
|
|
|
|
- .create(UnreliableInterface.class,
|
|
|
|
- new FlipFlopProxyProvider(UnreliableInterface.class,
|
|
|
|
- new UnreliableImplementation("impl1"),
|
|
|
|
- new UnreliableImplementation("impl2")),
|
|
|
|
|
|
+ UnreliableInterface unreliable = (UnreliableInterface)RetryProxy.create(
|
|
|
|
+ UnreliableInterface.class,
|
|
|
|
+ newFlipFlopProxyProvider(),
|
|
RetryPolicies.TRY_ONCE_THEN_FAIL);
|
|
RetryPolicies.TRY_ONCE_THEN_FAIL);
|
|
|
|
|
|
unreliable.succeedsOnceThenFailsReturningString();
|
|
unreliable.succeedsOnceThenFailsReturningString();
|
|
@@ -142,11 +151,9 @@ public class TestFailoverProxy {
|
|
@Test
|
|
@Test
|
|
public void testFailoverOnStandbyException()
|
|
public void testFailoverOnStandbyException()
|
|
throws UnreliableException, IOException, StandbyException {
|
|
throws UnreliableException, IOException, StandbyException {
|
|
- UnreliableInterface unreliable = (UnreliableInterface)RetryProxy
|
|
|
|
- .create(UnreliableInterface.class,
|
|
|
|
- new FlipFlopProxyProvider(UnreliableInterface.class,
|
|
|
|
- new UnreliableImplementation("impl1"),
|
|
|
|
- new UnreliableImplementation("impl2")),
|
|
|
|
|
|
+ UnreliableInterface unreliable = (UnreliableInterface)RetryProxy.create(
|
|
|
|
+ UnreliableInterface.class,
|
|
|
|
+ newFlipFlopProxyProvider(),
|
|
RetryPolicies.failoverOnNetworkException(1));
|
|
RetryPolicies.failoverOnNetworkException(1));
|
|
|
|
|
|
assertEquals("impl1", unreliable.succeedsOnceThenFailsReturningString());
|
|
assertEquals("impl1", unreliable.succeedsOnceThenFailsReturningString());
|
|
@@ -160,9 +167,9 @@ public class TestFailoverProxy {
|
|
|
|
|
|
unreliable = (UnreliableInterface)RetryProxy
|
|
unreliable = (UnreliableInterface)RetryProxy
|
|
.create(UnreliableInterface.class,
|
|
.create(UnreliableInterface.class,
|
|
- new FlipFlopProxyProvider(UnreliableInterface.class,
|
|
|
|
- new UnreliableImplementation("impl1", TypeOfExceptionToFailWith.STANDBY_EXCEPTION),
|
|
|
|
- new UnreliableImplementation("impl2", TypeOfExceptionToFailWith.UNRELIABLE_EXCEPTION)),
|
|
|
|
|
|
+ newFlipFlopProxyProvider(
|
|
|
|
+ TypeOfExceptionToFailWith.STANDBY_EXCEPTION,
|
|
|
|
+ TypeOfExceptionToFailWith.UNRELIABLE_EXCEPTION),
|
|
RetryPolicies.failoverOnNetworkException(1));
|
|
RetryPolicies.failoverOnNetworkException(1));
|
|
|
|
|
|
assertEquals("impl1", unreliable.succeedsOnceThenFailsReturningString());
|
|
assertEquals("impl1", unreliable.succeedsOnceThenFailsReturningString());
|
|
@@ -173,11 +180,11 @@ public class TestFailoverProxy {
|
|
@Test
|
|
@Test
|
|
public void testFailoverOnNetworkExceptionIdempotentOperation()
|
|
public void testFailoverOnNetworkExceptionIdempotentOperation()
|
|
throws UnreliableException, IOException, StandbyException {
|
|
throws UnreliableException, IOException, StandbyException {
|
|
- UnreliableInterface unreliable = (UnreliableInterface)RetryProxy
|
|
|
|
- .create(UnreliableInterface.class,
|
|
|
|
- new FlipFlopProxyProvider(UnreliableInterface.class,
|
|
|
|
- new UnreliableImplementation("impl1", TypeOfExceptionToFailWith.IO_EXCEPTION),
|
|
|
|
- new UnreliableImplementation("impl2", TypeOfExceptionToFailWith.UNRELIABLE_EXCEPTION)),
|
|
|
|
|
|
+ UnreliableInterface unreliable = (UnreliableInterface)RetryProxy.create(
|
|
|
|
+ UnreliableInterface.class,
|
|
|
|
+ newFlipFlopProxyProvider(
|
|
|
|
+ TypeOfExceptionToFailWith.IO_EXCEPTION,
|
|
|
|
+ TypeOfExceptionToFailWith.UNRELIABLE_EXCEPTION),
|
|
RetryPolicies.failoverOnNetworkException(1));
|
|
RetryPolicies.failoverOnNetworkException(1));
|
|
|
|
|
|
assertEquals("impl1", unreliable.succeedsOnceThenFailsReturningString());
|
|
assertEquals("impl1", unreliable.succeedsOnceThenFailsReturningString());
|
|
@@ -204,9 +211,9 @@ public class TestFailoverProxy {
|
|
public void testExceptionPropagatedForNonIdempotentVoid() throws Exception {
|
|
public void testExceptionPropagatedForNonIdempotentVoid() throws Exception {
|
|
UnreliableInterface unreliable = (UnreliableInterface)RetryProxy
|
|
UnreliableInterface unreliable = (UnreliableInterface)RetryProxy
|
|
.create(UnreliableInterface.class,
|
|
.create(UnreliableInterface.class,
|
|
- new FlipFlopProxyProvider(UnreliableInterface.class,
|
|
|
|
- new UnreliableImplementation("impl1", TypeOfExceptionToFailWith.IO_EXCEPTION),
|
|
|
|
- new UnreliableImplementation("impl2", TypeOfExceptionToFailWith.UNRELIABLE_EXCEPTION)),
|
|
|
|
|
|
+ newFlipFlopProxyProvider(
|
|
|
|
+ TypeOfExceptionToFailWith.IO_EXCEPTION,
|
|
|
|
+ TypeOfExceptionToFailWith.UNRELIABLE_EXCEPTION),
|
|
RetryPolicies.failoverOnNetworkException(1));
|
|
RetryPolicies.failoverOnNetworkException(1));
|
|
|
|
|
|
try {
|
|
try {
|
|
@@ -268,7 +275,8 @@ public class TestFailoverProxy {
|
|
*/
|
|
*/
|
|
@Test
|
|
@Test
|
|
public void testConcurrentMethodFailures() throws InterruptedException {
|
|
public void testConcurrentMethodFailures() throws InterruptedException {
|
|
- FlipFlopProxyProvider proxyProvider = new FlipFlopProxyProvider(
|
|
|
|
|
|
+ FlipFlopProxyProvider<UnreliableInterface> proxyProvider
|
|
|
|
+ = new FlipFlopProxyProvider<UnreliableInterface>(
|
|
UnreliableInterface.class,
|
|
UnreliableInterface.class,
|
|
new SynchronizedUnreliableImplementation("impl1",
|
|
new SynchronizedUnreliableImplementation("impl1",
|
|
TypeOfExceptionToFailWith.STANDBY_EXCEPTION,
|
|
TypeOfExceptionToFailWith.STANDBY_EXCEPTION,
|
|
@@ -305,7 +313,8 @@ public class TestFailoverProxy {
|
|
|
|
|
|
final UnreliableImplementation impl1 = new UnreliableImplementation("impl1",
|
|
final UnreliableImplementation impl1 = new UnreliableImplementation("impl1",
|
|
TypeOfExceptionToFailWith.STANDBY_EXCEPTION);
|
|
TypeOfExceptionToFailWith.STANDBY_EXCEPTION);
|
|
- FlipFlopProxyProvider proxyProvider = new FlipFlopProxyProvider(
|
|
|
|
|
|
+ FlipFlopProxyProvider<UnreliableInterface> proxyProvider
|
|
|
|
+ = new FlipFlopProxyProvider<UnreliableInterface>(
|
|
UnreliableInterface.class,
|
|
UnreliableInterface.class,
|
|
impl1,
|
|
impl1,
|
|
new UnreliableImplementation("impl2",
|
|
new UnreliableImplementation("impl2",
|
|
@@ -333,13 +342,13 @@ public class TestFailoverProxy {
|
|
*/
|
|
*/
|
|
@Test
|
|
@Test
|
|
public void testExpectedIOException() {
|
|
public void testExpectedIOException() {
|
|
- UnreliableInterface unreliable = (UnreliableInterface)RetryProxy
|
|
|
|
- .create(UnreliableInterface.class,
|
|
|
|
- new FlipFlopProxyProvider(UnreliableInterface.class,
|
|
|
|
- new UnreliableImplementation("impl1", TypeOfExceptionToFailWith.REMOTE_EXCEPTION),
|
|
|
|
- new UnreliableImplementation("impl2", TypeOfExceptionToFailWith.UNRELIABLE_EXCEPTION)),
|
|
|
|
- RetryPolicies.failoverOnNetworkException(
|
|
|
|
- RetryPolicies.TRY_ONCE_THEN_FAIL, 10, 1000, 10000));
|
|
|
|
|
|
+ UnreliableInterface unreliable = (UnreliableInterface)RetryProxy.create(
|
|
|
|
+ UnreliableInterface.class,
|
|
|
|
+ newFlipFlopProxyProvider(
|
|
|
|
+ TypeOfExceptionToFailWith.REMOTE_EXCEPTION,
|
|
|
|
+ TypeOfExceptionToFailWith.UNRELIABLE_EXCEPTION),
|
|
|
|
+ RetryPolicies.failoverOnNetworkException(
|
|
|
|
+ RetryPolicies.TRY_ONCE_THEN_FAIL, 10, 1000, 10000));
|
|
|
|
|
|
try {
|
|
try {
|
|
unreliable.failsIfIdentifierDoesntMatch("no-such-identifier");
|
|
unreliable.failsIfIdentifierDoesntMatch("no-such-identifier");
|