org.apache.hadoop.io.retry.UnreliableInterface.UnreliableException Java Examples

The following examples show how to use org.apache.hadoop.io.retry.UnreliableInterface.UnreliableException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestFailoverProxy.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test
public void testFailoverOnNetworkExceptionIdempotentOperation()
    throws UnreliableException, IOException, StandbyException {
  UnreliableInterface unreliable = (UnreliableInterface)RetryProxy.create(
      UnreliableInterface.class,
      newFlipFlopProxyProvider(
          TypeOfExceptionToFailWith.IO_EXCEPTION,
          TypeOfExceptionToFailWith.UNRELIABLE_EXCEPTION),
      RetryPolicies.failoverOnNetworkException(1));
  
  assertEquals("impl1", unreliable.succeedsOnceThenFailsReturningString());
  try {
    unreliable.succeedsOnceThenFailsReturningString();
    fail("should not have succeeded twice");
  } catch (IOException e) {
    // Make sure we *don't* fail over since the first implementation threw an
    // IOException and this method is not idempotent
    assertEquals("impl1", e.getMessage());
  }
  
  assertEquals("impl1", unreliable.succeedsOnceThenFailsReturningStringIdempotent());
  // Make sure we fail over since the first implementation threw an
  // IOException and this method is idempotent.
  assertEquals("impl2", unreliable.succeedsOnceThenFailsReturningStringIdempotent());
}
 
Example #2
Source File: TestFailoverProxy.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test
public void testNeverFailOver() throws UnreliableException,
    IOException, StandbyException {
  UnreliableInterface unreliable = (UnreliableInterface)RetryProxy.create(
      UnreliableInterface.class,
      newFlipFlopProxyProvider(),
      RetryPolicies.TRY_ONCE_THEN_FAIL);

  unreliable.succeedsOnceThenFailsReturningString();
  try {
    unreliable.succeedsOnceThenFailsReturningString();
    fail("should not have succeeded twice");
  } catch (UnreliableException e) {
    assertEquals("impl1", e.getMessage());
  }
}
 
Example #3
Source File: TestRetryProxy.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test
public void testRetryByException() throws UnreliableException {
  Map<Class<? extends Exception>, RetryPolicy> exceptionToPolicyMap =
    Collections.<Class<? extends Exception>, RetryPolicy>singletonMap(FatalException.class, TRY_ONCE_THEN_FAIL);
  
  UnreliableInterface unreliable = (UnreliableInterface)
    RetryProxy.create(UnreliableInterface.class, unreliableImpl,
                      retryByException(RETRY_FOREVER, exceptionToPolicyMap));
  unreliable.failsOnceThenSucceeds();
  try {
    unreliable.alwaysFailsWithFatalException();
    fail("Should fail");
  } catch (FatalException e) {
    // expected
  }
}
 
Example #4
Source File: TestFailoverProxy.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test
public void testSuccedsOnceThenFailOver() throws UnreliableException,
    IOException, StandbyException {
  UnreliableInterface unreliable = (UnreliableInterface)RetryProxy.create(
      UnreliableInterface.class, newFlipFlopProxyProvider(),
      new FailOverOnceOnAnyExceptionPolicy());
  
  assertEquals("impl1", unreliable.succeedsOnceThenFailsReturningString());
  assertEquals("impl2", unreliable.succeedsOnceThenFailsReturningString());
  try {
    unreliable.succeedsOnceThenFailsReturningString();
    fail("should not have succeeded more than twice");
  } catch (UnreliableException e) {
    // expected
  }
}
 
Example #5
Source File: TestFailoverProxy.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test
public void testSuccedsOnceThenFailOver() throws UnreliableException,
    IOException, StandbyException {
  UnreliableInterface unreliable = (UnreliableInterface)RetryProxy.create(
      UnreliableInterface.class, newFlipFlopProxyProvider(),
      new FailOverOnceOnAnyExceptionPolicy());
  
  assertEquals("impl1", unreliable.succeedsOnceThenFailsReturningString());
  assertEquals("impl2", unreliable.succeedsOnceThenFailsReturningString());
  try {
    unreliable.succeedsOnceThenFailsReturningString();
    fail("should not have succeeded more than twice");
  } catch (UnreliableException e) {
    // expected
  }
}
 
Example #6
Source File: TestFailoverProxy.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test
public void testNeverFailOver() throws UnreliableException,
    IOException, StandbyException {
  UnreliableInterface unreliable = (UnreliableInterface)RetryProxy.create(
      UnreliableInterface.class,
      newFlipFlopProxyProvider(),
      RetryPolicies.TRY_ONCE_THEN_FAIL);

  unreliable.succeedsOnceThenFailsReturningString();
  try {
    unreliable.succeedsOnceThenFailsReturningString();
    fail("should not have succeeded twice");
  } catch (UnreliableException e) {
    assertEquals("impl1", e.getMessage());
  }
}
 
Example #7
Source File: TestRetryProxy.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test
public void testRetryByException() throws UnreliableException {
  Map<Class<? extends Exception>, RetryPolicy> exceptionToPolicyMap =
    Collections.<Class<? extends Exception>, RetryPolicy>singletonMap(FatalException.class, TRY_ONCE_THEN_FAIL);
  
  UnreliableInterface unreliable = (UnreliableInterface)
    RetryProxy.create(UnreliableInterface.class, unreliableImpl,
                      retryByException(RETRY_FOREVER, exceptionToPolicyMap));
  unreliable.failsOnceThenSucceeds();
  try {
    unreliable.alwaysFailsWithFatalException();
    fail("Should fail");
  } catch (FatalException e) {
    // expected
  }
}
 
Example #8
Source File: TestFailoverProxy.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test
public void testFailoverOnNetworkExceptionIdempotentOperation()
    throws UnreliableException, IOException, StandbyException {
  UnreliableInterface unreliable = (UnreliableInterface)RetryProxy.create(
      UnreliableInterface.class,
      newFlipFlopProxyProvider(
          TypeOfExceptionToFailWith.IO_EXCEPTION,
          TypeOfExceptionToFailWith.UNRELIABLE_EXCEPTION),
      RetryPolicies.failoverOnNetworkException(1));
  
  assertEquals("impl1", unreliable.succeedsOnceThenFailsReturningString());
  try {
    unreliable.succeedsOnceThenFailsReturningString();
    fail("should not have succeeded twice");
  } catch (IOException e) {
    // Make sure we *don't* fail over since the first implementation threw an
    // IOException and this method is not idempotent
    assertEquals("impl1", e.getMessage());
  }
  
  assertEquals("impl1", unreliable.succeedsOnceThenFailsReturningStringIdempotent());
  // Make sure we fail over since the first implementation threw an
  // IOException and this method is idempotent.
  assertEquals("impl2", unreliable.succeedsOnceThenFailsReturningStringIdempotent());
}
 
Example #9
Source File: TestRetryProxy.java    From hadoop-gpu with Apache License 2.0 5 votes vote down vote up
public void testTryOnceThenFail() throws UnreliableException {
  UnreliableInterface unreliable = (UnreliableInterface)
    RetryProxy.create(UnreliableInterface.class, unreliableImpl, TRY_ONCE_THEN_FAIL);
  unreliable.alwaysSucceeds();
  try {
    unreliable.failsOnceThenSucceeds();
    fail("Should fail");
  } catch (UnreliableException e) {
    // expected
  }
}
 
Example #10
Source File: TestRetryProxy.java    From RDFS with Apache License 2.0 5 votes vote down vote up
public void testTryOnceThenFail() throws UnreliableException {
  UnreliableInterface unreliable = (UnreliableInterface)
    RetryProxy.create(UnreliableInterface.class, unreliableImpl, TRY_ONCE_THEN_FAIL);
  unreliable.alwaysSucceeds();
  try {
    unreliable.failsOnceThenSucceeds();
    fail("Should fail");
  } catch (UnreliableException e) {
    // expected
  }
}
 
Example #11
Source File: TestRetryProxy.java    From RDFS with Apache License 2.0 5 votes vote down vote up
public void testTryOnceDontFail() throws UnreliableException {
  UnreliableInterface unreliable = (UnreliableInterface)
    RetryProxy.create(UnreliableInterface.class, unreliableImpl, TRY_ONCE_DONT_FAIL);
  unreliable.alwaysSucceeds();
  unreliable.failsOnceThenSucceeds();
  try {
    unreliable.failsOnceThenSucceedsWithReturnValue();
    fail("Should fail");
  } catch (UnreliableException e) {
    // expected
  }
}
 
Example #12
Source File: TestRetryProxy.java    From RDFS with Apache License 2.0 5 votes vote down vote up
public void testRetryForever() throws UnreliableException {
  UnreliableInterface unreliable = (UnreliableInterface)
    RetryProxy.create(UnreliableInterface.class, unreliableImpl, RETRY_FOREVER);
  unreliable.alwaysSucceeds();
  unreliable.failsOnceThenSucceeds();
  unreliable.failsTenTimesThenSucceeds();
}
 
Example #13
Source File: TestRetryProxy.java    From RDFS with Apache License 2.0 5 votes vote down vote up
public void testRetryUpToMaximumCountWithFixedSleep() throws UnreliableException {
  UnreliableInterface unreliable = (UnreliableInterface)
    RetryProxy.create(UnreliableInterface.class, unreliableImpl,
                      retryUpToMaximumCountWithFixedSleep(8, 1, TimeUnit.NANOSECONDS));
  unreliable.alwaysSucceeds();
  unreliable.failsOnceThenSucceeds();
  try {
    unreliable.failsTenTimesThenSucceeds();
    fail("Should fail");
  } catch (UnreliableException e) {
    // expected
  }
}
 
Example #14
Source File: TestRetryProxy.java    From RDFS with Apache License 2.0 5 votes vote down vote up
public void testRetryUpToMaximumTimeWithFixedSleep() throws UnreliableException {
  UnreliableInterface unreliable = (UnreliableInterface)
    RetryProxy.create(UnreliableInterface.class, unreliableImpl,
                      retryUpToMaximumTimeWithFixedSleep(80, 10, TimeUnit.NANOSECONDS));
  unreliable.alwaysSucceeds();
  unreliable.failsOnceThenSucceeds();
  try {
    unreliable.failsTenTimesThenSucceeds();
    fail("Should fail");
  } catch (UnreliableException e) {
    // expected
  }
}
 
Example #15
Source File: TestRetryProxy.java    From RDFS with Apache License 2.0 5 votes vote down vote up
public void testRetryUpToMaximumCountWithProportionalSleep() throws UnreliableException {
  UnreliableInterface unreliable = (UnreliableInterface)
    RetryProxy.create(UnreliableInterface.class, unreliableImpl,
                      retryUpToMaximumCountWithProportionalSleep(8, 1, TimeUnit.NANOSECONDS));
  unreliable.alwaysSucceeds();
  unreliable.failsOnceThenSucceeds();
  try {
    unreliable.failsTenTimesThenSucceeds();
    fail("Should fail");
  } catch (UnreliableException e) {
    // expected
  }
}
 
Example #16
Source File: TestRetryProxy.java    From RDFS with Apache License 2.0 5 votes vote down vote up
public void testExponentialRetry() throws UnreliableException {
  UnreliableInterface unreliable = (UnreliableInterface)
    RetryProxy.create(UnreliableInterface.class, unreliableImpl,
                      exponentialBackoffRetry(5, 1L, TimeUnit.NANOSECONDS));
  unreliable.alwaysSucceeds();
  unreliable.failsOnceThenSucceeds();
  try {
    unreliable.failsTenTimesThenSucceeds();
    fail("Should fail");
  } catch (UnreliableException e) {
    // expected
  }
}
 
Example #17
Source File: TestRetryProxy.java    From RDFS with Apache License 2.0 5 votes vote down vote up
public void testRetryByException() throws UnreliableException {
  Map<Class<? extends Exception>, RetryPolicy> exceptionToPolicyMap =
    Collections.<Class<? extends Exception>, RetryPolicy>singletonMap(FatalException.class, TRY_ONCE_THEN_FAIL);
  
  UnreliableInterface unreliable = (UnreliableInterface)
    RetryProxy.create(UnreliableInterface.class, unreliableImpl,
                      retryByException(RETRY_FOREVER, exceptionToPolicyMap));
  unreliable.failsOnceThenSucceeds();
  try {
    unreliable.alwaysFailsWithFatalException();
    fail("Should fail");
  } catch (FatalException e) {
    // expected
  }
}
 
Example #18
Source File: TestRetryProxy.java    From RDFS with Apache License 2.0 5 votes vote down vote up
public void testRetryByRemoteException() throws UnreliableException {
  Map<Class<? extends Exception>, RetryPolicy> exceptionToPolicyMap =
    Collections.<Class<? extends Exception>, RetryPolicy>singletonMap(FatalException.class, TRY_ONCE_THEN_FAIL);
  
  UnreliableInterface unreliable = (UnreliableInterface)
    RetryProxy.create(UnreliableInterface.class, unreliableImpl,
                      retryByRemoteException(RETRY_FOREVER, exceptionToPolicyMap));
  try {
    unreliable.alwaysFailsWithRemoteFatalException();
    fail("Should fail");
  } catch (RemoteException e) {
    // expected
  }
}
 
Example #19
Source File: TestRetryProxy.java    From hadoop-gpu with Apache License 2.0 5 votes vote down vote up
public void testRetryByRemoteException() throws UnreliableException {
  Map<Class<? extends Exception>, RetryPolicy> exceptionToPolicyMap =
    Collections.<Class<? extends Exception>, RetryPolicy>singletonMap(FatalException.class, TRY_ONCE_THEN_FAIL);
  
  UnreliableInterface unreliable = (UnreliableInterface)
    RetryProxy.create(UnreliableInterface.class, unreliableImpl,
                      retryByRemoteException(RETRY_FOREVER, exceptionToPolicyMap));
  try {
    unreliable.alwaysFailsWithRemoteFatalException();
    fail("Should fail");
  } catch (RemoteException e) {
    // expected
  }
}
 
Example #20
Source File: TestRetryProxy.java    From hadoop-gpu with Apache License 2.0 5 votes vote down vote up
public void testTryOnceDontFail() throws UnreliableException {
  UnreliableInterface unreliable = (UnreliableInterface)
    RetryProxy.create(UnreliableInterface.class, unreliableImpl, TRY_ONCE_DONT_FAIL);
  unreliable.alwaysSucceeds();
  unreliable.failsOnceThenSucceeds();
  try {
    unreliable.failsOnceThenSucceedsWithReturnValue();
    fail("Should fail");
  } catch (UnreliableException e) {
    // expected
  }
}
 
Example #21
Source File: TestRetryProxy.java    From hadoop-gpu with Apache License 2.0 5 votes vote down vote up
public void testRetryForever() throws UnreliableException {
  UnreliableInterface unreliable = (UnreliableInterface)
    RetryProxy.create(UnreliableInterface.class, unreliableImpl, RETRY_FOREVER);
  unreliable.alwaysSucceeds();
  unreliable.failsOnceThenSucceeds();
  unreliable.failsTenTimesThenSucceeds();
}
 
Example #22
Source File: TestRetryProxy.java    From hadoop-gpu with Apache License 2.0 5 votes vote down vote up
public void testRetryUpToMaximumCountWithFixedSleep() throws UnreliableException {
  UnreliableInterface unreliable = (UnreliableInterface)
    RetryProxy.create(UnreliableInterface.class, unreliableImpl,
                      retryUpToMaximumCountWithFixedSleep(8, 1, TimeUnit.NANOSECONDS));
  unreliable.alwaysSucceeds();
  unreliable.failsOnceThenSucceeds();
  try {
    unreliable.failsTenTimesThenSucceeds();
    fail("Should fail");
  } catch (UnreliableException e) {
    // expected
  }
}
 
Example #23
Source File: TestRetryProxy.java    From hadoop-gpu with Apache License 2.0 5 votes vote down vote up
public void testRetryUpToMaximumTimeWithFixedSleep() throws UnreliableException {
  UnreliableInterface unreliable = (UnreliableInterface)
    RetryProxy.create(UnreliableInterface.class, unreliableImpl,
                      retryUpToMaximumTimeWithFixedSleep(80, 10, TimeUnit.NANOSECONDS));
  unreliable.alwaysSucceeds();
  unreliable.failsOnceThenSucceeds();
  try {
    unreliable.failsTenTimesThenSucceeds();
    fail("Should fail");
  } catch (UnreliableException e) {
    // expected
  }
}
 
Example #24
Source File: TestRetryProxy.java    From hadoop-gpu with Apache License 2.0 5 votes vote down vote up
public void testRetryUpToMaximumCountWithProportionalSleep() throws UnreliableException {
  UnreliableInterface unreliable = (UnreliableInterface)
    RetryProxy.create(UnreliableInterface.class, unreliableImpl,
                      retryUpToMaximumCountWithProportionalSleep(8, 1, TimeUnit.NANOSECONDS));
  unreliable.alwaysSucceeds();
  unreliable.failsOnceThenSucceeds();
  try {
    unreliable.failsTenTimesThenSucceeds();
    fail("Should fail");
  } catch (UnreliableException e) {
    // expected
  }
}
 
Example #25
Source File: TestRetryProxy.java    From hadoop-gpu with Apache License 2.0 5 votes vote down vote up
public void testExponentialRetry() throws UnreliableException {
  UnreliableInterface unreliable = (UnreliableInterface)
    RetryProxy.create(UnreliableInterface.class, unreliableImpl,
                      exponentialBackoffRetry(5, 1L, TimeUnit.NANOSECONDS));
  unreliable.alwaysSucceeds();
  unreliable.failsOnceThenSucceeds();
  try {
    unreliable.failsTenTimesThenSucceeds();
    fail("Should fail");
  } catch (UnreliableException e) {
    // expected
  }
}
 
Example #26
Source File: TestRetryProxy.java    From hadoop-gpu with Apache License 2.0 5 votes vote down vote up
public void testRetryByException() throws UnreliableException {
  Map<Class<? extends Exception>, RetryPolicy> exceptionToPolicyMap =
    Collections.<Class<? extends Exception>, RetryPolicy>singletonMap(FatalException.class, TRY_ONCE_THEN_FAIL);
  
  UnreliableInterface unreliable = (UnreliableInterface)
    RetryProxy.create(UnreliableInterface.class, unreliableImpl,
                      retryByException(RETRY_FOREVER, exceptionToPolicyMap));
  unreliable.failsOnceThenSucceeds();
  try {
    unreliable.alwaysFailsWithFatalException();
    fail("Should fail");
  } catch (FatalException e) {
    // expected
  }
}
 
Example #27
Source File: TestRetryProxy.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test
public void testTryOnceThenFail() throws UnreliableException {
  UnreliableInterface unreliable = (UnreliableInterface)
    RetryProxy.create(UnreliableInterface.class, unreliableImpl, TRY_ONCE_THEN_FAIL);
  unreliable.alwaysSucceeds();
  try {
    unreliable.failsOnceThenSucceeds();
    fail("Should fail");
  } catch (UnreliableException e) {
    // expected
  }
}
 
Example #28
Source File: TestRetryProxy.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test
public void testTryOnceThenFail() throws UnreliableException {
  UnreliableInterface unreliable = (UnreliableInterface)
    RetryProxy.create(UnreliableInterface.class, unreliableImpl, TRY_ONCE_THEN_FAIL);
  unreliable.alwaysSucceeds();
  try {
    unreliable.failsOnceThenSucceeds();
    fail("Should fail");
  } catch (UnreliableException e) {
    // expected
  }
}
 
Example #29
Source File: TestRetryProxy.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test
public void testRetryForever() throws UnreliableException {
  UnreliableInterface unreliable = (UnreliableInterface)
    RetryProxy.create(UnreliableInterface.class, unreliableImpl, RETRY_FOREVER);
  unreliable.alwaysSucceeds();
  unreliable.failsOnceThenSucceeds();
  unreliable.failsTenTimesThenSucceeds();
}
 
Example #30
Source File: TestRetryProxy.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test
public void testRetryUpToMaximumCountWithFixedSleep() throws UnreliableException {
  UnreliableInterface unreliable = (UnreliableInterface)
    RetryProxy.create(UnreliableInterface.class, unreliableImpl,
                      retryUpToMaximumCountWithFixedSleep(8, 1, TimeUnit.NANOSECONDS));
  unreliable.alwaysSucceeds();
  unreliable.failsOnceThenSucceeds();
  try {
    unreliable.failsTenTimesThenSucceeds();
    fail("Should fail");
  } catch (UnreliableException e) {
    // expected
  }
}