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 ji...@apache.org on 2013/09/06 19:17:31 UTC
svn commit: r1520637 - in
/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry:
LossyRetryInvocationHandler.java RetryInvocationHandler.java
Author: jing9
Date: Fri Sep 6 17:17:30 2013
New Revision: 1520637
URL: http://svn.apache.org/r1520637
Log:
HDS-5118. Provide testing support for DFSClient to drop RPC responses. Contributed by Jing Zhao.
Added:
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/LossyRetryInvocationHandler.java
Modified:
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryInvocationHandler.java
Added: hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/LossyRetryInvocationHandler.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/LossyRetryInvocationHandler.java?rev=1520637&view=auto
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/LossyRetryInvocationHandler.java (added)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/LossyRetryInvocationHandler.java Fri Sep 6 17:17:30 2013
@@ -0,0 +1,62 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.io.retry;
+
+import java.lang.reflect.Method;
+import java.net.UnknownHostException;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+
+/**
+ * A dummy invocation handler extending RetryInvocationHandler. It drops the
+ * first N number of responses. This invocation handler is only used for testing.
+ */
+@InterfaceAudience.Private
+public class LossyRetryInvocationHandler<T> extends RetryInvocationHandler<T> {
+ private final int numToDrop;
+ private static final ThreadLocal<Integer> RetryCount =
+ new ThreadLocal<Integer>();
+
+ public LossyRetryInvocationHandler(int numToDrop,
+ FailoverProxyProvider<T> proxyProvider, RetryPolicy retryPolicy) {
+ super(proxyProvider, retryPolicy);
+ this.numToDrop = numToDrop;
+ }
+
+ @Override
+ public Object invoke(Object proxy, Method method, Object[] args)
+ throws Throwable {
+ RetryCount.set(0);
+ return super.invoke(proxy, method, args);
+ }
+
+ @Override
+ protected Object invokeMethod(Method method, Object[] args) throws Throwable {
+ Object result = super.invokeMethod(method, args);
+ int retryCount = RetryCount.get();
+ if (retryCount < this.numToDrop) {
+ RetryCount.set(++retryCount);
+ LOG.info("Drop the response. Current retryCount == " + retryCount);
+ throw new UnknownHostException("Fake Exception");
+ } else {
+ LOG.info("retryCount == " + retryCount
+ + ". It's time to normally process the response");
+ return result;
+ }
+ }
+}
Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryInvocationHandler.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryInvocationHandler.java?rev=1520637&r1=1520636&r2=1520637&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryInvocationHandler.java (original)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryInvocationHandler.java Fri Sep 6 17:17:30 2013
@@ -63,7 +63,7 @@ public class RetryInvocationHandler<T> i
this(proxyProvider, retryPolicy, Collections.<String, RetryPolicy>emptyMap());
}
- RetryInvocationHandler(FailoverProxyProvider<T> proxyProvider,
+ protected RetryInvocationHandler(FailoverProxyProvider<T> proxyProvider,
RetryPolicy defaultPolicy,
Map<String, RetryPolicy> methodNameToPolicyMap) {
this.proxyProvider = proxyProvider;