org.apache.hadoop.io.retry.UnreliableInterface.FatalException#org.apache.hadoop.io.retry.UnreliableInterface.UnreliableException源码实例Demo

下面列出了org.apache.hadoop.io.retry.UnreliableInterface.FatalException#org.apache.hadoop.io.retry.UnreliableInterface.UnreliableException 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: hadoop   文件: TestRetryProxy.java
@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
  }
}
 
源代码2 项目: hadoop   文件: TestFailoverProxy.java
@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
  }
}
 
源代码3 项目: hadoop   文件: TestFailoverProxy.java
@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());
  }
}
 
源代码4 项目: hadoop   文件: TestFailoverProxy.java
@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());
}
 
源代码5 项目: big-c   文件: TestRetryProxy.java
@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
  }
}
 
源代码6 项目: big-c   文件: TestFailoverProxy.java
@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
  }
}
 
源代码7 项目: big-c   文件: TestFailoverProxy.java
@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());
  }
}
 
源代码8 项目: big-c   文件: TestFailoverProxy.java
@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());
}
 
源代码9 项目: hadoop   文件: TestRetryProxy.java
@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
  }
}
 
源代码10 项目: hadoop   文件: TestRetryProxy.java
@Test
public void testRetryForever() throws UnreliableException {
  UnreliableInterface unreliable = (UnreliableInterface)
    RetryProxy.create(UnreliableInterface.class, unreliableImpl, RETRY_FOREVER);
  unreliable.alwaysSucceeds();
  unreliable.failsOnceThenSucceeds();
  unreliable.failsTenTimesThenSucceeds();
}
 
源代码11 项目: hadoop   文件: TestRetryProxy.java
@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
  }
}
 
源代码12 项目: hadoop   文件: TestRetryProxy.java
@Test
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
  }
}
 
源代码13 项目: hadoop   文件: TestRetryProxy.java
@Test
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
  }
}
 
源代码14 项目: hadoop   文件: TestRetryProxy.java
@Test
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
  }
}
 
源代码15 项目: hadoop   文件: TestFailoverProxy.java
@Test
public void testSucceedsTenTimesThenFailOver() throws UnreliableException,
    IOException, StandbyException {
  UnreliableInterface unreliable = (UnreliableInterface)RetryProxy.create(
      UnreliableInterface.class,
      newFlipFlopProxyProvider(),
      new FailOverOnceOnAnyExceptionPolicy());
  
  for (int i = 0; i < 10; i++) {
    assertEquals("impl1", unreliable.succeedsTenTimesThenFailsReturningString());
  }
  assertEquals("impl2", unreliable.succeedsTenTimesThenFailsReturningString());
}
 
源代码16 项目: hadoop   文件: TestFailoverProxy.java
@Test
public void testFailoverOnStandbyException()
    throws UnreliableException, IOException, StandbyException {
  UnreliableInterface unreliable = (UnreliableInterface)RetryProxy.create(
      UnreliableInterface.class,
      newFlipFlopProxyProvider(),
      RetryPolicies.failoverOnNetworkException(1));
  
  assertEquals("impl1", unreliable.succeedsOnceThenFailsReturningString());
  try {
    unreliable.succeedsOnceThenFailsReturningString();
    fail("should not have succeeded twice");
  } catch (UnreliableException e) {
    // Make sure there was no failover on normal exception.
    assertEquals("impl1", e.getMessage());
  }
  
  unreliable = (UnreliableInterface)RetryProxy
  .create(UnreliableInterface.class,
      newFlipFlopProxyProvider(
          TypeOfExceptionToFailWith.STANDBY_EXCEPTION,
          TypeOfExceptionToFailWith.UNRELIABLE_EXCEPTION),
      RetryPolicies.failoverOnNetworkException(1));
  
  assertEquals("impl1", unreliable.succeedsOnceThenFailsReturningString());
  // Make sure we fail over since the first implementation threw a StandbyException
  assertEquals("impl2", unreliable.succeedsOnceThenFailsReturningString());
}
 
源代码17 项目: hadoop   文件: TestFailoverProxy.java
@Override
public String failsIfIdentifierDoesntMatch(String identifier)
    throws UnreliableException, StandbyException, IOException {
  // Wait until all threads are trying to invoke this method
  methodLatch.countDown();
  try {
    methodLatch.await();
  } catch (InterruptedException e) {
    throw new RuntimeException(e);
  }
  return super.failsIfIdentifierDoesntMatch(identifier);
}
 
源代码18 项目: hadoop   文件: TestFailoverProxy.java
/**
 * Ensure that when all configured services are throwing StandbyException
 * that we fail over back and forth between them until one is no longer
 * throwing StandbyException.
 */
@Test
public void testFailoverBetweenMultipleStandbys()
    throws UnreliableException, StandbyException, IOException {
  
  final long millisToSleep = 10000;
  
  final UnreliableImplementation impl1 = new UnreliableImplementation("impl1",
      TypeOfExceptionToFailWith.STANDBY_EXCEPTION);
  FlipFlopProxyProvider<UnreliableInterface> proxyProvider
      = new FlipFlopProxyProvider<UnreliableInterface>(
      UnreliableInterface.class,
      impl1,
      new UnreliableImplementation("impl2",
          TypeOfExceptionToFailWith.STANDBY_EXCEPTION));
  
  final UnreliableInterface unreliable = (UnreliableInterface)RetryProxy
    .create(UnreliableInterface.class, proxyProvider,
        RetryPolicies.failoverOnNetworkException(
            RetryPolicies.TRY_ONCE_THEN_FAIL, 10, 1000, 10000));
  
  new Thread() {
    @Override
    public void run() {
      ThreadUtil.sleepAtLeastIgnoreInterrupts(millisToSleep);
      impl1.setIdentifier("renamed-impl1");
    }
  }.start();
  
  String result = unreliable.failsIfIdentifierDoesntMatch("renamed-impl1");
  assertEquals("renamed-impl1", result);
}
 
源代码19 项目: big-c   文件: TestRetryProxy.java
@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
  }
}
 
源代码20 项目: big-c   文件: TestRetryProxy.java
@Test
public void testRetryForever() throws UnreliableException {
  UnreliableInterface unreliable = (UnreliableInterface)
    RetryProxy.create(UnreliableInterface.class, unreliableImpl, RETRY_FOREVER);
  unreliable.alwaysSucceeds();
  unreliable.failsOnceThenSucceeds();
  unreliable.failsTenTimesThenSucceeds();
}
 
源代码21 项目: big-c   文件: TestRetryProxy.java
@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
  }
}
 
源代码22 项目: big-c   文件: TestRetryProxy.java
@Test
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
  }
}
 
源代码23 项目: big-c   文件: TestRetryProxy.java
@Test
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
  }
}
 
源代码24 项目: big-c   文件: TestRetryProxy.java
@Test
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
  }
}
 
源代码25 项目: big-c   文件: TestFailoverProxy.java
@Test
public void testSucceedsTenTimesThenFailOver() throws UnreliableException,
    IOException, StandbyException {
  UnreliableInterface unreliable = (UnreliableInterface)RetryProxy.create(
      UnreliableInterface.class,
      newFlipFlopProxyProvider(),
      new FailOverOnceOnAnyExceptionPolicy());
  
  for (int i = 0; i < 10; i++) {
    assertEquals("impl1", unreliable.succeedsTenTimesThenFailsReturningString());
  }
  assertEquals("impl2", unreliable.succeedsTenTimesThenFailsReturningString());
}
 
源代码26 项目: big-c   文件: TestFailoverProxy.java
@Test
public void testFailoverOnStandbyException()
    throws UnreliableException, IOException, StandbyException {
  UnreliableInterface unreliable = (UnreliableInterface)RetryProxy.create(
      UnreliableInterface.class,
      newFlipFlopProxyProvider(),
      RetryPolicies.failoverOnNetworkException(1));
  
  assertEquals("impl1", unreliable.succeedsOnceThenFailsReturningString());
  try {
    unreliable.succeedsOnceThenFailsReturningString();
    fail("should not have succeeded twice");
  } catch (UnreliableException e) {
    // Make sure there was no failover on normal exception.
    assertEquals("impl1", e.getMessage());
  }
  
  unreliable = (UnreliableInterface)RetryProxy
  .create(UnreliableInterface.class,
      newFlipFlopProxyProvider(
          TypeOfExceptionToFailWith.STANDBY_EXCEPTION,
          TypeOfExceptionToFailWith.UNRELIABLE_EXCEPTION),
      RetryPolicies.failoverOnNetworkException(1));
  
  assertEquals("impl1", unreliable.succeedsOnceThenFailsReturningString());
  // Make sure we fail over since the first implementation threw a StandbyException
  assertEquals("impl2", unreliable.succeedsOnceThenFailsReturningString());
}
 
源代码27 项目: big-c   文件: TestFailoverProxy.java
@Override
public String failsIfIdentifierDoesntMatch(String identifier)
    throws UnreliableException, StandbyException, IOException {
  // Wait until all threads are trying to invoke this method
  methodLatch.countDown();
  try {
    methodLatch.await();
  } catch (InterruptedException e) {
    throw new RuntimeException(e);
  }
  return super.failsIfIdentifierDoesntMatch(identifier);
}
 
源代码28 项目: big-c   文件: TestFailoverProxy.java
/**
 * Ensure that when all configured services are throwing StandbyException
 * that we fail over back and forth between them until one is no longer
 * throwing StandbyException.
 */
@Test
public void testFailoverBetweenMultipleStandbys()
    throws UnreliableException, StandbyException, IOException {
  
  final long millisToSleep = 10000;
  
  final UnreliableImplementation impl1 = new UnreliableImplementation("impl1",
      TypeOfExceptionToFailWith.STANDBY_EXCEPTION);
  FlipFlopProxyProvider<UnreliableInterface> proxyProvider
      = new FlipFlopProxyProvider<UnreliableInterface>(
      UnreliableInterface.class,
      impl1,
      new UnreliableImplementation("impl2",
          TypeOfExceptionToFailWith.STANDBY_EXCEPTION));
  
  final UnreliableInterface unreliable = (UnreliableInterface)RetryProxy
    .create(UnreliableInterface.class, proxyProvider,
        RetryPolicies.failoverOnNetworkException(
            RetryPolicies.TRY_ONCE_THEN_FAIL, 10, 1000, 10000));
  
  new Thread() {
    @Override
    public void run() {
      ThreadUtil.sleepAtLeastIgnoreInterrupts(millisToSleep);
      impl1.setIdentifier("renamed-impl1");
    }
  }.start();
  
  String result = unreliable.failsIfIdentifierDoesntMatch("renamed-impl1");
  assertEquals("renamed-impl1", result);
}
 
源代码29 项目: RDFS   文件: TestRetryProxy.java
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
  }
}
 
源代码30 项目: RDFS   文件: TestRetryProxy.java
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
  }
}