diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionImplementation.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionImplementation.java index 53eb5226fb7..11349230a19 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionImplementation.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionImplementation.java @@ -652,7 +652,7 @@ class ConnectionImplementation implements ClusterConnection, Closeable { final byte [] row, boolean useCache, boolean retry, int replicaId) throws IOException { if (this.closed) { - throw new IOException(toString() + " closed"); + throw new DoNotRetryIOException(toString() + " closed"); } if (tableName== null || tableName.getName().length == 0) { throw new IllegalArgumentException( diff --git a/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestClientNoCluster.java b/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestClientNoCluster.java index 41c9a565c5c..a4be9a2b7fe 100644 --- a/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestClientNoCluster.java +++ b/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestClientNoCluster.java @@ -33,7 +33,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; import org.apache.hadoop.hbase.CellComparator; - +import org.apache.hadoop.hbase.DoNotRetryIOException; import org.apache.commons.lang.NotImplementedException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -263,6 +263,32 @@ public class TestClientNoCluster extends Configured implements Tool { } } + @Test + public void testConnectionClosedOnRegionLocate() throws IOException { + Configuration testConf = new Configuration(this.conf); + testConf.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 2); + // Go against meta else we will try to find first region for the table on construction which + // means we'll have to do a bunch more mocking. Tests that go against meta only should be + // good for a bit of testing. + Connection connection = ConnectionFactory.createConnection(testConf); + Table table = connection.getTable(TableName.META_TABLE_NAME); + connection.close(); + try { + Get get = new Get(Bytes.toBytes("dummyRow")); + table.get(get); + fail("Should have thrown DoNotRetryException but no exception thrown"); + } catch (Exception e) { + if (!(e instanceof DoNotRetryIOException)) { + String errMsg = + "Should have thrown DoNotRetryException but actually " + e.getClass().getSimpleName(); + LOG.error(errMsg, e); + fail(errMsg); + } + } finally { + table.close(); + } + } + /** * Override to shutdown going to zookeeper for cluster id and meta location. */