From ef1462f0d4acac8e598741c67e6169387785af7f Mon Sep 17 00:00:00 2001 From: Hao Chan Date: Wed, 9 Aug 2017 17:59:01 +0800 Subject: [PATCH] HBASE-18483 Fix bug for translateException() in RpcRetryingCaller. --- .../hadoop/hbase/client/RpcRetryingCaller.java | 4 +- .../hadoop/hbase/client/TestRpcRetryingCaller.java | 60 ++++++++++++++++++++++ 2 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestRpcRetryingCaller.java diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/RpcRetryingCaller.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/RpcRetryingCaller.java index 6f587d132d..71579889d6 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/RpcRetryingCaller.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/RpcRetryingCaller.java @@ -252,8 +252,8 @@ public class RpcRetryingCaller { } // Don't let ServiceException out; its rpc specific. t = cause; - // t could be a RemoteException so go aaround again. - translateException(t); + // t could be a RemoteException so go aaround again. + t = translateException(t); } else if (t instanceof DoNotRetryIOException) { throw (DoNotRetryIOException)t; } else if (t instanceof NeedUnmanagedConnectionException) { diff --git a/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestRpcRetryingCaller.java b/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestRpcRetryingCaller.java new file mode 100644 index 0000000000..fdf47cf64b --- /dev/null +++ b/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestRpcRetryingCaller.java @@ -0,0 +1,60 @@ +/** + * 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.hbase.client; + +import com.google.protobuf.ServiceException; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import org.apache.hadoop.hbase.testclassification.SmallTests; +import org.apache.hadoop.ipc.RemoteException; +import org.junit.Before; +import org.junit.Test; +import org.junit.Assert; +import org.junit.experimental.categories.Category; + +/** + * Test the RpcRetryingCaller. + */ +@Category(SmallTests.class) +public class TestRpcRetryingCaller { + + RpcRetryingCaller rpcRetryingCaller; + + @Before + public void setup() throws IOException { + rpcRetryingCaller = new RpcRetryingCaller(100L, 31, 9); + } + + @Test + public void testTranslateException() throws NoSuchMethodException, InvocationTargetException, IllegalArgumentException, IllegalAccessException { + + Method method = rpcRetryingCaller.getClass().getDeclaredMethod("translateException", Throwable.class); + method.setAccessible(true); + + FileNotFoundException fileNotFoundException = new FileNotFoundException("This is the message of a FileNotFoundException"); + + Throwable t = new ServiceException(new RemoteException(fileNotFoundException.getClass().getName(), "This is the message of a RemoteException")); + t = (Throwable) method.invoke(rpcRetryingCaller, t); + Assert.assertEquals(FileNotFoundException.class, t.getClass()); + + } + +} -- 2.11.0 (Apple Git-81)