You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by sz...@apache.org on 2013/08/01 04:23:41 UTC

svn commit: r1509071 - in /hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common: ./ src/ src/main/java/ src/main/java/org/apache/hadoop/io/retry/ src/test/core/ src/test/java/org/apache/hadoop/io/retry/

Author: szetszwo
Date: Thu Aug  1 02:23:41 2013
New Revision: 1509071

URL: http://svn.apache.org/r1509071
Log:
svn merge -c 1509070 from trunk for HADOOP-9803. Add a generic type parameter to RetryInvocationHandler.

Modified:
    hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/   (props changed)
    hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/CHANGES.txt   (contents, props changed)
    hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/   (props changed)
    hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/   (props changed)
    hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryInvocationHandler.java
    hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryProxy.java
    hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/core/   (props changed)
    hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/retry/TestFailoverProxy.java
    hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/retry/UnreliableInterface.java

Propchange: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/
------------------------------------------------------------------------------
  Merged /hadoop/common/trunk/hadoop-common-project/hadoop-common:r1509070

Modified: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/CHANGES.txt?rev=1509071&r1=1509070&r2=1509071&view=diff
==============================================================================
--- hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/CHANGES.txt (original)
+++ hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/CHANGES.txt Thu Aug  1 02:23:41 2013
@@ -47,6 +47,9 @@ Release 2.1.1-beta - UNRELEASED
     HADOOP-9787. ShutdownHelper util to shutdown threads and threadpools.
     (Karthik Kambatla via Sandy Ryza)
 
+    HADOOP-9803. Add a generic type parameter to RetryInvocationHandler.
+    (szetszwo)
+
   OPTIMIZATIONS
 
   BUG FIXES

Propchange: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/CHANGES.txt
------------------------------------------------------------------------------
  Merged /hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt:r1509070

Propchange: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/
------------------------------------------------------------------------------
  Merged /hadoop/common/trunk/hadoop-common-project/hadoop-common/src:r1509070

Propchange: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/
------------------------------------------------------------------------------
  Merged /hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java:r1509070

Modified: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryInvocationHandler.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryInvocationHandler.java?rev=1509071&r1=1509070&r2=1509071&view=diff
==============================================================================
--- hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryInvocationHandler.java (original)
+++ hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryInvocationHandler.java Thu Aug  1 02:23:41 2013
@@ -45,9 +45,9 @@ import com.google.common.annotations.Vis
  * side.
  */
 @InterfaceAudience.Private
-public class RetryInvocationHandler implements RpcInvocationHandler {
+public class RetryInvocationHandler<T> implements RpcInvocationHandler {
   public static final Log LOG = LogFactory.getLog(RetryInvocationHandler.class);
-  private final FailoverProxyProvider proxyProvider;
+  private final FailoverProxyProvider<T> proxyProvider;
 
   /**
    * The number of times the associated proxyProvider has ever been failed over.
@@ -57,14 +57,14 @@ public class RetryInvocationHandler impl
   
   private final RetryPolicy defaultPolicy;
   private final Map<String,RetryPolicy> methodNameToPolicyMap;
-  private Object currentProxy;
+  private T currentProxy;
 
-  protected RetryInvocationHandler(FailoverProxyProvider proxyProvider,
+  protected RetryInvocationHandler(FailoverProxyProvider<T> proxyProvider,
       RetryPolicy retryPolicy) {
     this(proxyProvider, retryPolicy, Collections.<String, RetryPolicy>emptyMap());
   }
 
-  RetryInvocationHandler(FailoverProxyProvider proxyProvider,
+  RetryInvocationHandler(FailoverProxyProvider<T> proxyProvider,
       RetryPolicy defaultPolicy,
       Map<String, RetryPolicy> methodNameToPolicyMap) {
     this.proxyProvider = proxyProvider;

Modified: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryProxy.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryProxy.java?rev=1509071&r1=1509070&r2=1509071&view=diff
==============================================================================
--- hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryProxy.java (original)
+++ hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryProxy.java Thu Aug  1 02:23:41 2013
@@ -58,7 +58,7 @@ public class RetryProxy {
     return Proxy.newProxyInstance(
         proxyProvider.getInterface().getClassLoader(),
         new Class<?>[] { iface },
-        new RetryInvocationHandler(proxyProvider, retryPolicy)
+        new RetryInvocationHandler<T>(proxyProvider, retryPolicy)
         );
   }
   
@@ -99,7 +99,7 @@ public class RetryProxy {
     return Proxy.newProxyInstance(
         proxyProvider.getInterface().getClassLoader(),
         new Class<?>[] { iface },
-        new RetryInvocationHandler(proxyProvider, defaultPolicy,
+        new RetryInvocationHandler<T>(proxyProvider, defaultPolicy,
             methodNameToPolicyMap)
         );
   }

Propchange: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/core/
------------------------------------------------------------------------------
  Merged /hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/core:r1509070

Modified: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/retry/TestFailoverProxy.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/retry/TestFailoverProxy.java?rev=1509071&r1=1509070&r2=1509071&view=diff
==============================================================================
--- hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/retry/TestFailoverProxy.java (original)
+++ hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/retry/TestFailoverProxy.java Thu Aug  1 02:23:41 2013
@@ -28,7 +28,6 @@ import org.apache.hadoop.ipc.StandbyExce
 import org.apache.hadoop.util.ThreadUtil;
 import org.junit.Test;
 
-@SuppressWarnings("unchecked")
 public class TestFailoverProxy {
 
   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
   public void testSuccedsOnceThenFailOver() throws UnreliableException,
       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("impl2", unreliable.succeedsOnceThenFailsReturningString());
@@ -107,12 +120,10 @@ public class TestFailoverProxy {
   @Test
   public void testSucceedsTenTimesThenFailOver() throws UnreliableException,
       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++) {
       assertEquals("impl1", unreliable.succeedsTenTimesThenFailsReturningString());
@@ -123,11 +134,9 @@ public class TestFailoverProxy {
   @Test
   public void testNeverFailOver() 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.TRY_ONCE_THEN_FAIL);
 
     unreliable.succeedsOnceThenFailsReturningString();
@@ -142,11 +151,9 @@ public class TestFailoverProxy {
   @Test
   public void testFailoverOnStandbyException()
       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));
     
     assertEquals("impl1", unreliable.succeedsOnceThenFailsReturningString());
@@ -160,9 +167,9 @@ public class TestFailoverProxy {
     
     unreliable = (UnreliableInterface)RetryProxy
     .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));
     
     assertEquals("impl1", unreliable.succeedsOnceThenFailsReturningString());
@@ -173,11 +180,11 @@ public class TestFailoverProxy {
   @Test
   public void testFailoverOnNetworkExceptionIdempotentOperation()
       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));
     
     assertEquals("impl1", unreliable.succeedsOnceThenFailsReturningString());
@@ -204,9 +211,9 @@ public class TestFailoverProxy {
   public void testExceptionPropagatedForNonIdempotentVoid() throws Exception {
     UnreliableInterface unreliable = (UnreliableInterface)RetryProxy
     .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));
 
     try {
@@ -268,7 +275,8 @@ public class TestFailoverProxy {
    */
   @Test
   public void testConcurrentMethodFailures() throws InterruptedException {
-    FlipFlopProxyProvider proxyProvider = new FlipFlopProxyProvider(
+    FlipFlopProxyProvider<UnreliableInterface> proxyProvider
+        = new FlipFlopProxyProvider<UnreliableInterface>(
         UnreliableInterface.class,
         new SynchronizedUnreliableImplementation("impl1",
             TypeOfExceptionToFailWith.STANDBY_EXCEPTION,
@@ -305,7 +313,8 @@ public class TestFailoverProxy {
     
     final UnreliableImplementation impl1 = new UnreliableImplementation("impl1",
         TypeOfExceptionToFailWith.STANDBY_EXCEPTION);
-    FlipFlopProxyProvider proxyProvider = new FlipFlopProxyProvider(
+    FlipFlopProxyProvider<UnreliableInterface> proxyProvider
+        = new FlipFlopProxyProvider<UnreliableInterface>(
         UnreliableInterface.class,
         impl1,
         new UnreliableImplementation("impl2",
@@ -333,13 +342,13 @@ public class TestFailoverProxy {
    */
   @Test
   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 {
       unreliable.failsIfIdentifierDoesntMatch("no-such-identifier");

Modified: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/retry/UnreliableInterface.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/retry/UnreliableInterface.java?rev=1509071&r1=1509070&r2=1509071&view=diff
==============================================================================
--- hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/retry/UnreliableInterface.java (original)
+++ hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/retry/UnreliableInterface.java Thu Aug  1 02:23:41 2013
@@ -26,6 +26,8 @@ import org.apache.hadoop.ipc.StandbyExce
 public interface UnreliableInterface {
   
   public static class UnreliableException extends Exception {
+    private static final long serialVersionUID = 1L;
+
     private String identifier;
     
     public UnreliableException() {
@@ -43,6 +45,7 @@ public interface UnreliableInterface {
   }
   
   public static class FatalException extends UnreliableException {
+    private static final long serialVersionUID = 1L;
     // no body
   }