diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/RpcRetryingCallerImpl.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/RpcRetryingCallerImpl.java index fb58bfae9ef..2a7dc5f7e7a 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/RpcRetryingCallerImpl.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/RpcRetryingCallerImpl.java @@ -224,13 +224,12 @@ public class RpcRetryingCallerImpl implements RpcRetryingCaller { if (t instanceof ServiceException) { ServiceException se = (ServiceException)t; Throwable cause = se.getCause(); - if (cause != null && cause instanceof DoNotRetryIOException) { + if (cause instanceof DoNotRetryIOException) { throw (DoNotRetryIOException)cause; } // Don't let ServiceException out; its rpc specific. - t = cause; - // t could be a RemoteException so go around again. - translateException(t); + // It also could be a RemoteException, so go around again. + t = translateException(cause); } else if (t instanceof DoNotRetryIOException) { throw (DoNotRetryIOException)t; } diff --git a/hbase-client/src/test/java/org/apache/hadoop/hbase/client/RpcRetryingCallerImplTest.java b/hbase-client/src/test/java/org/apache/hadoop/hbase/client/RpcRetryingCallerImplTest.java new file mode 100644 index 00000000000..0291bb79122 --- /dev/null +++ b/hbase-client/src/test/java/org/apache/hadoop/hbase/client/RpcRetryingCallerImplTest.java @@ -0,0 +1,50 @@ +/* + 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 org.apache.hadoop.hbase.CallDroppedException; +import org.apache.hadoop.hbase.DoNotRetryIOException; +import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.ipc.RemoteWithExtrasException; +import org.apache.hadoop.hbase.testclassification.ClientTests; +import org.apache.hadoop.hbase.testclassification.SmallTests; +import org.junit.Assert; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.apache.hbase.thirdparty.com.google.protobuf.ServiceException; + +@Category({ ClientTests.class, SmallTests.class}) +public class RpcRetryingCallerImplTest { + + @ClassRule + public static final HBaseClassTestRule CLASS_RULE = + HBaseClassTestRule.forClass(RpcRetryingCallerImplTest.class); + + @Test + public void itTranslatesRemoteExceptionFromServiceException() throws DoNotRetryIOException { + String message = "CDE for test"; + ServiceException exception = new ServiceException( + new RemoteWithExtrasException(CallDroppedException.class.getName(), message, false)); + + Throwable result = RpcRetryingCallerImpl.translateException(exception); + Assert.assertTrue("Expect unwrap CallDroppedException", + result instanceof CallDroppedException); + Assert.assertEquals(message, result.getMessage()); + } +}