This is an automated email from the ASF dual-hosted git repository.

Apache9 pushed a commit to branch branch-3
in repository https://gitbox.apache.org/repos/asf/hbase.git


The following commit(s) were added to refs/heads/branch-3 by this push:
     new 8d71ad7ca18 HBASE-30140 Rewrite TestScannersFromClientSide (#8195)
8d71ad7ca18 is described below

commit 8d71ad7ca183d2f6b566d7367b50206425039aa3
Author: Duo Zhang <[email protected]>
AuthorDate: Thu May 7 21:48:04 2026 +0800

    HBASE-30140 Rewrite TestScannersFromClientSide (#8195)
    
    Signed-off-by: Xiao Liu <[email protected]>
    (cherry picked from commit 4c65507a7947138b20668d191e198bd55b67960a)
---
 .../hbase/client/TestScannersFromClientSide.java   | 1007 +++++++++-----------
 1 file changed, 463 insertions(+), 544 deletions(-)

diff --git 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestScannersFromClientSide.java
 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestScannersFromClientSide.java
index 9b623d9ada2..520f3a0dc07 100644
--- 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestScannersFromClientSide.java
+++ 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestScannersFromClientSide.java
@@ -22,32 +22,27 @@ import static 
org.apache.hadoop.hbase.client.FromClientSideTest3.generateHugeVal
 import static org.apache.hadoop.hbase.ipc.RpcClient.DEFAULT_CODEC_CLASS;
 import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
 import java.util.List;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hbase.Cell;
 import org.apache.hadoop.hbase.CompareOperator;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
-import org.apache.hadoop.hbase.HBaseTestingUtil;
+import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate;
 import org.apache.hadoop.hbase.HConstants;
 import org.apache.hadoop.hbase.HRegionLocation;
 import org.apache.hadoop.hbase.HTestConst;
 import org.apache.hadoop.hbase.KeyValue;
 import org.apache.hadoop.hbase.SingleProcessHBaseCluster;
-import org.apache.hadoop.hbase.StartTestingClusterOption;
 import org.apache.hadoop.hbase.TableName;
-import org.apache.hadoop.hbase.TableNameTestRule;
 import org.apache.hadoop.hbase.TableNotFoundException;
 import org.apache.hadoop.hbase.client.Scan.ReadType;
 import org.apache.hadoop.hbase.exceptions.DeserializationException;
@@ -61,270 +56,202 @@ import 
org.apache.hadoop.hbase.testclassification.ClientTests;
 import org.apache.hadoop.hbase.testclassification.LargeTests;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
-import org.junit.AfterClass;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.TestTemplate;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import org.apache.hbase.thirdparty.com.google.common.base.Preconditions;
-
 /**
  * A client-side test, mostly testing scanners with various parameters. 
Parameterized on different
  * registry implementations.
  */
-@Category({ ClientTests.class, LargeTests.class })
-@RunWith(Parameterized.class)
-public class TestScannersFromClientSide {
-
-  @ClassRule
-  public static final HBaseClassTestRule CLASS_RULE =
-    HBaseClassTestRule.forClass(TestScannersFromClientSide.class);
-
-  private static final Logger LOG = 
LoggerFactory.getLogger(TestScannersFromClientSide.class);
-
-  private static HBaseTestingUtil TEST_UTIL;
-  private static byte[] ROW = Bytes.toBytes("testRow");
-  private static byte[] FAMILY = Bytes.toBytes("testFamily");
-  private static byte[] QUALIFIER = Bytes.toBytes("testQualifier");
-  private static byte[] VALUE = Bytes.toBytes("testValue");
-
-  @Rule
-  public TableNameTestRule name = new TableNameTestRule();
-
-  @AfterClass
-  public static void tearDownAfterClass() throws Exception {
-    if (TEST_UTIL != null) {
-      TEST_UTIL.shutdownMiniCluster();
-    }
+@Tag(LargeTests.TAG)
+@Tag(ClientTests.TAG)
+@HBaseParameterizedTestTemplate(name = "{index}: registryImpl={0}, 
numHedgedReqs={1}")
+public class TestScannersFromClientSide extends FromClientSideTestBase {
+
+  public TestScannersFromClientSide(Class<? extends ConnectionRegistry> 
registryImpl,
+    int numHedgedReqs) {
+    super(registryImpl, numHedgedReqs);
   }
 
-  @Parameterized.Parameters
-  public static Collection<Object[]> parameters() {
-    return Arrays.asList(new Object[][] { { MasterRegistry.class, 1 }, { 
MasterRegistry.class, 2 },
-      { ZKConnectionRegistry.class, 1 } });
-  }
+  private static final Logger LOG = 
LoggerFactory.getLogger(TestScannersFromClientSide.class);
 
-  /**
-   * JUnit does not provide an easy way to run a hook after each parameterized 
run. Without that
-   * there is no easy way to restart the test cluster after each parameterized 
run. Annotation
-   * BeforeParam does not work either because it runs before parameterization 
and hence does not
-   * have access to the test parameters (which is weird). This *hack* checks 
if the current instance
-   * of test cluster configuration has the passed parameterized configs. In 
such a case, we can just
-   * reuse the cluster for test and do not need to initialize from scratch. 
While this is a hack, it
-   * saves a ton of time for the full test and de-flakes it.
-   */
-  private static boolean isSameParameterizedCluster(Class<?> registryImpl, int 
numHedgedReqs) {
-    // initialize() is called for every unit test, however we only want to 
reset the cluster state
-    // at the end of every parameterized run.
-    if (TEST_UTIL == null) {
-      return false;
-    }
-    Configuration conf = TEST_UTIL.getConfiguration();
-    Class<?> confClass = 
conf.getClass(HConstants.CLIENT_CONNECTION_REGISTRY_IMPL_CONF_KEY,
-      ZKConnectionRegistry.class);
-    int hedgedReqConfig = 
conf.getInt(MasterRegistry.MASTER_REGISTRY_HEDGED_REQS_FANOUT_KEY,
-      AbstractRpcBasedConnectionRegistry.HEDGED_REQS_FANOUT_DEFAULT);
-    return confClass.getName().equals(registryImpl.getName()) && numHedgedReqs 
== hedgedReqConfig;
-  }
-
-  public TestScannersFromClientSide(Class<?> registryImpl, int numHedgedReqs) 
throws Exception {
-    if (isSameParameterizedCluster(registryImpl, numHedgedReqs)) {
-      return;
-    }
-    if (TEST_UTIL != null) {
-      // We reached the end of a parameterized run, clean up the cluster.
-      TEST_UTIL.shutdownMiniCluster();
-    }
-    TEST_UTIL = new HBaseTestingUtil();
+  @BeforeAll
+  public static void setUpBeforeClass() throws Exception {
     Configuration conf = TEST_UTIL.getConfiguration();
     conf.setLong(HConstants.HBASE_CLIENT_SCANNER_MAX_RESULT_SIZE_KEY, 10 * 
1024 * 1024);
-    conf.setClass(HConstants.CLIENT_CONNECTION_REGISTRY_IMPL_CONF_KEY, 
registryImpl,
-      ConnectionRegistry.class);
-    Preconditions.checkArgument(numHedgedReqs > 0);
-    conf.setInt(MasterRegistry.MASTER_REGISTRY_HEDGED_REQS_FANOUT_KEY, 
numHedgedReqs);
-    StartTestingClusterOption.Builder builder = 
StartTestingClusterOption.builder();
-    // Multiple masters needed only when hedged reads for master registry are 
enabled.
-    builder.numMasters(numHedgedReqs > 1 ? 3 : 1).numRegionServers(3);
-    TEST_UTIL.startMiniCluster(builder.build());
+    SLAVES = 3;
+    initialize();
   }
 
   /**
    * Test from client side for batch of scan
    */
-  @Test
+  @TestTemplate
   public void testScanBatch() throws Exception {
-    final TableName tableName = name.getTableName();
     byte[][] QUALIFIERS = HTestConst.makeNAscii(QUALIFIER, 8);
 
-    Table ht = TEST_UTIL.createTable(tableName, FAMILY);
+    TEST_UTIL.createTable(tableName, FAMILY);
+    try (Connection conn = getConnection(); Table ht = 
conn.getTable(tableName)) {
+      Put put;
+      Scan scan;
+      Delete delete;
+      Result result;
+      ResultScanner scanner;
+      boolean toLog = true;
+      List<Cell> kvListExp;
 
-    Put put;
-    Scan scan;
-    Delete delete;
-    Result result;
-    ResultScanner scanner;
-    boolean toLog = true;
-    List<Cell> kvListExp;
+      // table: row, family, c0:0, c1:1, ... , c7:7
+      put = new Put(ROW);
+      for (int i = 0; i < QUALIFIERS.length; i++) {
+        KeyValue kv = new KeyValue(ROW, FAMILY, QUALIFIERS[i], i, VALUE);
+        put.add(kv);
+      }
+      ht.put(put);
 
-    // table: row, family, c0:0, c1:1, ... , c7:7
-    put = new Put(ROW);
-    for (int i = 0; i < QUALIFIERS.length; i++) {
-      KeyValue kv = new KeyValue(ROW, FAMILY, QUALIFIERS[i], i, VALUE);
+      // table: row, family, c0:0, c1:1, ..., c6:2, c6:6 , c7:7
+      put = new Put(ROW);
+      KeyValue kv = new KeyValue(ROW, FAMILY, QUALIFIERS[6], 2, VALUE);
       put.add(kv);
-    }
-    ht.put(put);
-
-    // table: row, family, c0:0, c1:1, ..., c6:2, c6:6 , c7:7
-    put = new Put(ROW);
-    KeyValue kv = new KeyValue(ROW, FAMILY, QUALIFIERS[6], 2, VALUE);
-    put.add(kv);
-    ht.put(put);
-
-    // delete upto ts: 3
-    delete = new Delete(ROW);
-    delete.addFamily(FAMILY, 3);
-    ht.delete(delete);
-
-    // without batch
-    scan = new Scan().withStartRow(ROW);
-    scan.readAllVersions();
-    scanner = ht.getScanner(scan);
-
-    // c4:4, c5:5, c6:6, c7:7
-    kvListExp = new ArrayList<>();
-    kvListExp.add(new KeyValue(ROW, FAMILY, QUALIFIERS[4], 4, VALUE));
-    kvListExp.add(new KeyValue(ROW, FAMILY, QUALIFIERS[5], 5, VALUE));
-    kvListExp.add(new KeyValue(ROW, FAMILY, QUALIFIERS[6], 6, VALUE));
-    kvListExp.add(new KeyValue(ROW, FAMILY, QUALIFIERS[7], 7, VALUE));
-    result = scanner.next();
-    verifyResult(result, kvListExp, toLog, "Testing first batch of scan");
-
-    // with batch
-    scan = new Scan().withStartRow(ROW);
-    scan.readAllVersions();
-    scan.setBatch(2);
-    scanner = ht.getScanner(scan);
-
-    // First batch: c4:4, c5:5
-    kvListExp = new ArrayList<>();
-    kvListExp.add(new KeyValue(ROW, FAMILY, QUALIFIERS[4], 4, VALUE));
-    kvListExp.add(new KeyValue(ROW, FAMILY, QUALIFIERS[5], 5, VALUE));
-    result = scanner.next();
-    verifyResult(result, kvListExp, toLog, "Testing first batch of scan");
-
-    // Second batch: c6:6, c7:7
-    kvListExp = new ArrayList<>();
-    kvListExp.add(new KeyValue(ROW, FAMILY, QUALIFIERS[6], 6, VALUE));
-    kvListExp.add(new KeyValue(ROW, FAMILY, QUALIFIERS[7], 7, VALUE));
-    result = scanner.next();
-    verifyResult(result, kvListExp, toLog, "Testing second batch of scan");
+      ht.put(put);
 
+      // delete upto ts: 3
+      delete = new Delete(ROW);
+      delete.addFamily(FAMILY, 3);
+      ht.delete(delete);
+
+      // without batch
+      scan = new Scan().withStartRow(ROW);
+      scan.readAllVersions();
+      scanner = ht.getScanner(scan);
+
+      // c4:4, c5:5, c6:6, c7:7
+      kvListExp = new ArrayList<>();
+      kvListExp.add(new KeyValue(ROW, FAMILY, QUALIFIERS[4], 4, VALUE));
+      kvListExp.add(new KeyValue(ROW, FAMILY, QUALIFIERS[5], 5, VALUE));
+      kvListExp.add(new KeyValue(ROW, FAMILY, QUALIFIERS[6], 6, VALUE));
+      kvListExp.add(new KeyValue(ROW, FAMILY, QUALIFIERS[7], 7, VALUE));
+      result = scanner.next();
+      verifyResult(result, kvListExp, toLog, "Testing first batch of scan");
+
+      // with batch
+      scan = new Scan().withStartRow(ROW);
+      scan.readAllVersions();
+      scan.setBatch(2);
+      scanner = ht.getScanner(scan);
+
+      // First batch: c4:4, c5:5
+      kvListExp = new ArrayList<>();
+      kvListExp.add(new KeyValue(ROW, FAMILY, QUALIFIERS[4], 4, VALUE));
+      kvListExp.add(new KeyValue(ROW, FAMILY, QUALIFIERS[5], 5, VALUE));
+      result = scanner.next();
+      verifyResult(result, kvListExp, toLog, "Testing first batch of scan");
+
+      // Second batch: c6:6, c7:7
+      kvListExp = new ArrayList<>();
+      kvListExp.add(new KeyValue(ROW, FAMILY, QUALIFIERS[6], 6, VALUE));
+      kvListExp.add(new KeyValue(ROW, FAMILY, QUALIFIERS[7], 7, VALUE));
+      result = scanner.next();
+      verifyResult(result, kvListExp, toLog, "Testing second batch of scan");
+    }
   }
 
-  @Test
+  @TestTemplate
   public void testMaxResultSizeIsSetToDefault() throws Exception {
-    final TableName tableName = name.getTableName();
-    Table ht = TEST_UTIL.createTable(tableName, FAMILY);
+    TEST_UTIL.createTable(tableName, FAMILY);
+    try (Connection conn = getConnection(); Table ht = 
conn.getTable(tableName)) {
+      // The max result size we expect the scan to use by default.
+      long expectedMaxResultSize =
+        
TEST_UTIL.getConfiguration().getLong(HConstants.HBASE_CLIENT_SCANNER_MAX_RESULT_SIZE_KEY,
+          HConstants.DEFAULT_HBASE_CLIENT_SCANNER_MAX_RESULT_SIZE);
 
-    // The max result size we expect the scan to use by default.
-    long expectedMaxResultSize =
-      
TEST_UTIL.getConfiguration().getLong(HConstants.HBASE_CLIENT_SCANNER_MAX_RESULT_SIZE_KEY,
-        HConstants.DEFAULT_HBASE_CLIENT_SCANNER_MAX_RESULT_SIZE);
+      int numRows = 5;
+      byte[][] ROWS = HTestConst.makeNAscii(ROW, numRows);
 
-    int numRows = 5;
-    byte[][] ROWS = HTestConst.makeNAscii(ROW, numRows);
+      int numQualifiers = 10;
+      byte[][] QUALIFIERS = HTestConst.makeNAscii(QUALIFIER, numQualifiers);
 
-    int numQualifiers = 10;
-    byte[][] QUALIFIERS = HTestConst.makeNAscii(QUALIFIER, numQualifiers);
+      // Specify the cell size such that a single row will be larger than the 
default
+      // value of maxResultSize. This means that Scan RPCs should return at 
most a single
+      // result back to the client.
+      int cellSize = (int) (expectedMaxResultSize / (numQualifiers - 1));
+      byte[] cellValue = Bytes.createMaxByteArray(cellSize);
 
-    // Specify the cell size such that a single row will be larger than the 
default
-    // value of maxResultSize. This means that Scan RPCs should return at most 
a single
-    // result back to the client.
-    int cellSize = (int) (expectedMaxResultSize / (numQualifiers - 1));
-    byte[] cellValue = Bytes.createMaxByteArray(cellSize);
-
-    Put put;
-    List<Put> puts = new ArrayList<>();
-    for (int row = 0; row < ROWS.length; row++) {
-      put = new Put(ROWS[row]);
-      for (int qual = 0; qual < QUALIFIERS.length; qual++) {
-        KeyValue kv = new KeyValue(ROWS[row], FAMILY, QUALIFIERS[qual], 
cellValue);
-        put.add(kv);
+      Put put;
+      List<Put> puts = new ArrayList<>();
+      for (int row = 0; row < ROWS.length; row++) {
+        put = new Put(ROWS[row]);
+        for (int qual = 0; qual < QUALIFIERS.length; qual++) {
+          KeyValue kv = new KeyValue(ROWS[row], FAMILY, QUALIFIERS[qual], 
cellValue);
+          put.add(kv);
+        }
+        puts.add(put);
+      }
+      ht.put(puts);
+
+      // Create a scan with the default configuration.
+      Scan scan = new Scan();
+
+      try (ResultScanner scanner = ht.getScanner(scan)) {
+        assertThat(scanner, instanceOf(AsyncTableResultScanner.class));
+        scanner.next();
+        AsyncTableResultScanner s = (AsyncTableResultScanner) scanner;
+        // The scanner should have, at most, a single result in its cache. If 
there more results
+        // exists in the cache it means that more than the expected max result 
size was fetched.
+        assertTrue(s.getCacheSize() <= 1, "The cache contains: " + 
s.getCacheSize() + " results");
       }
-      puts.add(put);
-    }
-    ht.put(puts);
-
-    // Create a scan with the default configuration.
-    Scan scan = new Scan();
-
-    try (ResultScanner scanner = ht.getScanner(scan)) {
-      assertThat(scanner, instanceOf(AsyncTableResultScanner.class));
-      scanner.next();
-      AsyncTableResultScanner s = (AsyncTableResultScanner) scanner;
-      // The scanner should have, at most, a single result in its cache. If 
there more results
-      // exists
-      // in the cache it means that more than the expected max result size was 
fetched.
-      assertTrue("The cache contains: " + s.getCacheSize() + " results", 
s.getCacheSize() <= 1);
     }
   }
 
   /**
    * Scan on not existing table should throw the exception with correct message
    */
-  @Test
-  public void testScannerForNotExistingTable() {
+  @TestTemplate
+  public void testScannerForNotExistingTable() throws Exception {
     String[] tableNames = { "A", "Z", "A:A", "Z:Z" };
     for (String tableName : tableNames) {
-      try {
-        Table table = 
TEST_UTIL.getConnection().getTable(TableName.valueOf(tableName));
-        testSmallScan(table, true, 1, 5);
-        fail("TableNotFoundException was not thrown");
-      } catch (TableNotFoundException e) {
+      try (Connection conn = getConnection();
+        Table table = conn.getTable(TableName.valueOf(tableName))) {
+        TableNotFoundException e = assertThrows(TableNotFoundException.class,
+          () -> testSmallScan(table, true, 1, 5), "TableNotFoundException was 
not thrown");
         // We expect that the message for TableNotFoundException would have 
only the table name only
         // Otherwise that would mean that localeRegionInMeta doesn't work 
properly
         assertEquals(e.getMessage(), tableName);
-      } catch (Exception e) {
-        fail("Unexpected exception " + e.getMessage());
       }
     }
   }
 
-  @Test
+  @TestTemplate
   public void testSmallScan() throws Exception {
-    final TableName tableName = name.getTableName();
-
     int numRows = 10;
     byte[][] ROWS = HTestConst.makeNAscii(ROW, numRows);
 
     int numQualifiers = 10;
     byte[][] QUALIFIERS = HTestConst.makeNAscii(QUALIFIER, numQualifiers);
 
-    Table ht = TEST_UTIL.createTable(tableName, FAMILY);
-
-    Put put;
-    List<Put> puts = new ArrayList<>();
-    for (int row = 0; row < ROWS.length; row++) {
-      put = new Put(ROWS[row]);
-      for (int qual = 0; qual < QUALIFIERS.length; qual++) {
-        KeyValue kv = new KeyValue(ROWS[row], FAMILY, QUALIFIERS[qual], VALUE);
-        put.add(kv);
+    TEST_UTIL.createTable(tableName, FAMILY);
+    try (Connection conn = getConnection(); Table ht = 
conn.getTable(tableName)) {
+      Put put;
+      List<Put> puts = new ArrayList<>();
+      for (int row = 0; row < ROWS.length; row++) {
+        put = new Put(ROWS[row]);
+        for (int qual = 0; qual < QUALIFIERS.length; qual++) {
+          KeyValue kv = new KeyValue(ROWS[row], FAMILY, QUALIFIERS[qual], 
VALUE);
+          put.add(kv);
+        }
+        puts.add(put);
       }
-      puts.add(put);
-    }
-    ht.put(puts);
+      ht.put(puts);
 
-    int expectedRows = numRows;
-    int expectedCols = numRows * numQualifiers;
+      int expectedRows = numRows;
+      int expectedCols = numRows * numQualifiers;
 
-    // Test normal and reversed
-    testSmallScan(ht, true, expectedRows, expectedCols);
-    testSmallScan(ht, false, expectedRows, expectedCols);
+      // Test normal and reversed
+      testSmallScan(ht, true, expectedRows, expectedCols);
+      testSmallScan(ht, false, expectedRows, expectedCols);
+    }
   }
 
   /**
@@ -351,284 +278,283 @@ public class TestScannersFromClientSide {
 
   private void verifyExpectedCounts(Table table, Scan scan, int 
expectedRowCount,
     int expectedCellCount) throws Exception {
-    ResultScanner scanner = table.getScanner(scan);
-
-    int rowCount = 0;
-    int cellCount = 0;
-    Result r = null;
-    while ((r = scanner.next()) != null) {
-      rowCount++;
-      cellCount += r.rawCells().length;
-    }
+    try (ResultScanner scanner = table.getScanner(scan)) {
+
+      int rowCount = 0;
+      int cellCount = 0;
+      Result r = null;
+      while ((r = scanner.next()) != null) {
+        rowCount++;
+        cellCount += r.rawCells().length;
+      }
 
-    assertTrue("Expected row count: " + expectedRowCount + " Actual row count: 
" + rowCount,
-      expectedRowCount == rowCount);
-    assertTrue("Expected cell count: " + expectedCellCount + " Actual cell 
count: " + cellCount,
-      expectedCellCount == cellCount);
-    scanner.close();
+      assertEquals(expectedRowCount, rowCount,
+        "Expected row count: " + expectedRowCount + " Actual row count: " + 
rowCount);
+      assertEquals(expectedCellCount, cellCount,
+        "Expected cell count: " + expectedCellCount + " Actual cell count: " + 
cellCount);
+    }
   }
 
   /**
    * Test from client side for get with maxResultPerCF set
    */
-  @Test
+  @TestTemplate
   public void testGetMaxResults() throws Exception {
-    final TableName tableName = name.getTableName();
     byte[][] FAMILIES = HTestConst.makeNAscii(FAMILY, 3);
     byte[][] QUALIFIERS = HTestConst.makeNAscii(QUALIFIER, 20);
 
-    Table ht = TEST_UTIL.createTable(tableName, FAMILIES);
+    TEST_UTIL.createTable(tableName, FAMILIES);
+    try (Connection conn = getConnection(); Table ht = 
conn.getTable(tableName)) {
+      Get get;
+      Put put;
+      Result result;
+      boolean toLog = true;
+      List<Cell> kvListExp;
 
-    Get get;
-    Put put;
-    Result result;
-    boolean toLog = true;
-    List<Cell> kvListExp;
+      kvListExp = new ArrayList<>();
+      // Insert one CF for row[0]
+      put = new Put(ROW);
+      for (int i = 0; i < 10; i++) {
+        KeyValue kv = new KeyValue(ROW, FAMILIES[0], QUALIFIERS[i], 1, VALUE);
+        put.add(kv);
+        kvListExp.add(kv);
+      }
+      ht.put(put);
 
-    kvListExp = new ArrayList<>();
-    // Insert one CF for row[0]
-    put = new Put(ROW);
-    for (int i = 0; i < 10; i++) {
-      KeyValue kv = new KeyValue(ROW, FAMILIES[0], QUALIFIERS[i], 1, VALUE);
-      put.add(kv);
-      kvListExp.add(kv);
-    }
-    ht.put(put);
-
-    get = new Get(ROW);
-    result = ht.get(get);
-    verifyResult(result, kvListExp, toLog, "Testing without setting 
maxResults");
-
-    get = new Get(ROW);
-    get.setMaxResultsPerColumnFamily(2);
-    result = ht.get(get);
-    kvListExp = new ArrayList<>();
-    kvListExp.add(new KeyValue(ROW, FAMILIES[0], QUALIFIERS[0], 1, VALUE));
-    kvListExp.add(new KeyValue(ROW, FAMILIES[0], QUALIFIERS[1], 1, VALUE));
-    verifyResult(result, kvListExp, toLog, "Testing basic setMaxResults");
-
-    // Filters: ColumnRangeFilter
-    get = new Get(ROW);
-    get.setMaxResultsPerColumnFamily(5);
-    get.setFilter(new ColumnRangeFilter(QUALIFIERS[2], true, QUALIFIERS[5], 
true));
-    result = ht.get(get);
-    kvListExp = new ArrayList<>();
-    kvListExp.add(new KeyValue(ROW, FAMILIES[0], QUALIFIERS[2], 1, VALUE));
-    kvListExp.add(new KeyValue(ROW, FAMILIES[0], QUALIFIERS[3], 1, VALUE));
-    kvListExp.add(new KeyValue(ROW, FAMILIES[0], QUALIFIERS[4], 1, VALUE));
-    kvListExp.add(new KeyValue(ROW, FAMILIES[0], QUALIFIERS[5], 1, VALUE));
-    verifyResult(result, kvListExp, toLog, "Testing single CF with CRF");
-
-    // Insert two more CF for row[0]
-    // 20 columns for CF2, 10 columns for CF1
-    put = new Put(ROW);
-    for (int i = 0; i < QUALIFIERS.length; i++) {
-      KeyValue kv = new KeyValue(ROW, FAMILIES[2], QUALIFIERS[i], 1, VALUE);
-      put.add(kv);
-    }
-    ht.put(put);
+      get = new Get(ROW);
+      result = ht.get(get);
+      verifyResult(result, kvListExp, toLog, "Testing without setting 
maxResults");
+
+      get = new Get(ROW);
+      get.setMaxResultsPerColumnFamily(2);
+      result = ht.get(get);
+      kvListExp = new ArrayList<>();
+      kvListExp.add(new KeyValue(ROW, FAMILIES[0], QUALIFIERS[0], 1, VALUE));
+      kvListExp.add(new KeyValue(ROW, FAMILIES[0], QUALIFIERS[1], 1, VALUE));
+      verifyResult(result, kvListExp, toLog, "Testing basic setMaxResults");
+
+      // Filters: ColumnRangeFilter
+      get = new Get(ROW);
+      get.setMaxResultsPerColumnFamily(5);
+      get.setFilter(new ColumnRangeFilter(QUALIFIERS[2], true, QUALIFIERS[5], 
true));
+      result = ht.get(get);
+      kvListExp = new ArrayList<>();
+      kvListExp.add(new KeyValue(ROW, FAMILIES[0], QUALIFIERS[2], 1, VALUE));
+      kvListExp.add(new KeyValue(ROW, FAMILIES[0], QUALIFIERS[3], 1, VALUE));
+      kvListExp.add(new KeyValue(ROW, FAMILIES[0], QUALIFIERS[4], 1, VALUE));
+      kvListExp.add(new KeyValue(ROW, FAMILIES[0], QUALIFIERS[5], 1, VALUE));
+      verifyResult(result, kvListExp, toLog, "Testing single CF with CRF");
+
+      // Insert two more CF for row[0]
+      // 20 columns for CF2, 10 columns for CF1
+      put = new Put(ROW);
+      for (int i = 0; i < QUALIFIERS.length; i++) {
+        KeyValue kv = new KeyValue(ROW, FAMILIES[2], QUALIFIERS[i], 1, VALUE);
+        put.add(kv);
+      }
+      ht.put(put);
 
-    put = new Put(ROW);
-    for (int i = 0; i < 10; i++) {
-      KeyValue kv = new KeyValue(ROW, FAMILIES[1], QUALIFIERS[i], 1, VALUE);
-      put.add(kv);
-    }
-    ht.put(put);
-
-    get = new Get(ROW);
-    get.setMaxResultsPerColumnFamily(12);
-    get.addFamily(FAMILIES[1]);
-    get.addFamily(FAMILIES[2]);
-    result = ht.get(get);
-    kvListExp = new ArrayList<>();
-    // Exp: CF1:q0, ..., q9, CF2: q0, q1, q10, q11, ..., q19
-    for (int i = 0; i < 10; i++) {
-      kvListExp.add(new KeyValue(ROW, FAMILIES[1], QUALIFIERS[i], 1, VALUE));
-    }
-    for (int i = 0; i < 2; i++) {
-      kvListExp.add(new KeyValue(ROW, FAMILIES[2], QUALIFIERS[i], 1, VALUE));
-    }
-    for (int i = 10; i < 20; i++) {
-      kvListExp.add(new KeyValue(ROW, FAMILIES[2], QUALIFIERS[i], 1, VALUE));
-    }
-    verifyResult(result, kvListExp, toLog, "Testing multiple CFs");
-
-    // Filters: ColumnRangeFilter and ColumnPrefixFilter
-    get = new Get(ROW);
-    get.setMaxResultsPerColumnFamily(3);
-    get.setFilter(new ColumnRangeFilter(QUALIFIERS[2], true, null, true));
-    result = ht.get(get);
-    kvListExp = new ArrayList<>();
-    for (int i = 2; i < 5; i++) {
-      kvListExp.add(new KeyValue(ROW, FAMILIES[0], QUALIFIERS[i], 1, VALUE));
-    }
-    for (int i = 2; i < 5; i++) {
-      kvListExp.add(new KeyValue(ROW, FAMILIES[1], QUALIFIERS[i], 1, VALUE));
-    }
-    for (int i = 2; i < 5; i++) {
-      kvListExp.add(new KeyValue(ROW, FAMILIES[2], QUALIFIERS[i], 1, VALUE));
-    }
-    verifyResult(result, kvListExp, toLog, "Testing multiple CFs + CRF");
-
-    get = new Get(ROW);
-    get.setMaxResultsPerColumnFamily(7);
-    get.setFilter(new ColumnPrefixFilter(QUALIFIERS[1]));
-    result = ht.get(get);
-    kvListExp = new ArrayList<>();
-    kvListExp.add(new KeyValue(ROW, FAMILIES[0], QUALIFIERS[1], 1, VALUE));
-    kvListExp.add(new KeyValue(ROW, FAMILIES[1], QUALIFIERS[1], 1, VALUE));
-    kvListExp.add(new KeyValue(ROW, FAMILIES[2], QUALIFIERS[1], 1, VALUE));
-    for (int i = 10; i < 16; i++) {
-      kvListExp.add(new KeyValue(ROW, FAMILIES[2], QUALIFIERS[i], 1, VALUE));
+      put = new Put(ROW);
+      for (int i = 0; i < 10; i++) {
+        KeyValue kv = new KeyValue(ROW, FAMILIES[1], QUALIFIERS[i], 1, VALUE);
+        put.add(kv);
+      }
+      ht.put(put);
+
+      get = new Get(ROW);
+      get.setMaxResultsPerColumnFamily(12);
+      get.addFamily(FAMILIES[1]);
+      get.addFamily(FAMILIES[2]);
+      result = ht.get(get);
+      kvListExp = new ArrayList<>();
+      // Exp: CF1:q0, ..., q9, CF2: q0, q1, q10, q11, ..., q19
+      for (int i = 0; i < 10; i++) {
+        kvListExp.add(new KeyValue(ROW, FAMILIES[1], QUALIFIERS[i], 1, VALUE));
+      }
+      for (int i = 0; i < 2; i++) {
+        kvListExp.add(new KeyValue(ROW, FAMILIES[2], QUALIFIERS[i], 1, VALUE));
+      }
+      for (int i = 10; i < 20; i++) {
+        kvListExp.add(new KeyValue(ROW, FAMILIES[2], QUALIFIERS[i], 1, VALUE));
+      }
+      verifyResult(result, kvListExp, toLog, "Testing multiple CFs");
+
+      // Filters: ColumnRangeFilter and ColumnPrefixFilter
+      get = new Get(ROW);
+      get.setMaxResultsPerColumnFamily(3);
+      get.setFilter(new ColumnRangeFilter(QUALIFIERS[2], true, null, true));
+      result = ht.get(get);
+      kvListExp = new ArrayList<>();
+      for (int i = 2; i < 5; i++) {
+        kvListExp.add(new KeyValue(ROW, FAMILIES[0], QUALIFIERS[i], 1, VALUE));
+      }
+      for (int i = 2; i < 5; i++) {
+        kvListExp.add(new KeyValue(ROW, FAMILIES[1], QUALIFIERS[i], 1, VALUE));
+      }
+      for (int i = 2; i < 5; i++) {
+        kvListExp.add(new KeyValue(ROW, FAMILIES[2], QUALIFIERS[i], 1, VALUE));
+      }
+      verifyResult(result, kvListExp, toLog, "Testing multiple CFs + CRF");
+
+      get = new Get(ROW);
+      get.setMaxResultsPerColumnFamily(7);
+      get.setFilter(new ColumnPrefixFilter(QUALIFIERS[1]));
+      result = ht.get(get);
+      kvListExp = new ArrayList<>();
+      kvListExp.add(new KeyValue(ROW, FAMILIES[0], QUALIFIERS[1], 1, VALUE));
+      kvListExp.add(new KeyValue(ROW, FAMILIES[1], QUALIFIERS[1], 1, VALUE));
+      kvListExp.add(new KeyValue(ROW, FAMILIES[2], QUALIFIERS[1], 1, VALUE));
+      for (int i = 10; i < 16; i++) {
+        kvListExp.add(new KeyValue(ROW, FAMILIES[2], QUALIFIERS[i], 1, VALUE));
+      }
+      verifyResult(result, kvListExp, toLog, "Testing multiple CFs + PFF");
     }
-    verifyResult(result, kvListExp, toLog, "Testing multiple CFs + PFF");
 
   }
 
   /**
    * Test from client side for scan with maxResultPerCF set
    */
-  @Test
+  @TestTemplate
   public void testScanMaxResults() throws Exception {
-    final TableName tableName = name.getTableName();
     byte[][] ROWS = HTestConst.makeNAscii(ROW, 2);
     byte[][] FAMILIES = HTestConst.makeNAscii(FAMILY, 3);
     byte[][] QUALIFIERS = HTestConst.makeNAscii(QUALIFIER, 10);
 
-    Table ht = TEST_UTIL.createTable(tableName, FAMILIES);
-
-    Put put;
-    Scan scan;
-    Result result;
-    boolean toLog = true;
-    List<Cell> kvListExp, kvListScan;
-
-    kvListExp = new ArrayList<>();
-
-    for (int r = 0; r < ROWS.length; r++) {
-      put = new Put(ROWS[r]);
-      for (int c = 0; c < FAMILIES.length; c++) {
-        for (int q = 0; q < QUALIFIERS.length; q++) {
-          KeyValue kv = new KeyValue(ROWS[r], FAMILIES[c], QUALIFIERS[q], 1, 
VALUE);
-          put.add(kv);
-          if (q < 4) {
-            kvListExp.add(kv);
+    TEST_UTIL.createTable(tableName, FAMILIES);
+    try (Connection conn = getConnection(); Table ht = 
conn.getTable(tableName)) {
+      Put put;
+      Scan scan;
+      Result result;
+      boolean toLog = true;
+      List<Cell> kvListExp, kvListScan;
+
+      kvListExp = new ArrayList<>();
+
+      for (int r = 0; r < ROWS.length; r++) {
+        put = new Put(ROWS[r]);
+        for (int c = 0; c < FAMILIES.length; c++) {
+          for (int q = 0; q < QUALIFIERS.length; q++) {
+            KeyValue kv = new KeyValue(ROWS[r], FAMILIES[c], QUALIFIERS[q], 1, 
VALUE);
+            put.add(kv);
+            if (q < 4) {
+              kvListExp.add(kv);
+            }
           }
         }
+        ht.put(put);
       }
-      ht.put(put);
-    }
 
-    scan = new Scan();
-    scan.setMaxResultsPerColumnFamily(4);
-    ResultScanner scanner = ht.getScanner(scan);
-    kvListScan = new ArrayList<>();
-    while ((result = scanner.next()) != null) {
-      for (Cell kv : result.listCells()) {
-        kvListScan.add(kv);
+      scan = new Scan();
+      scan.setMaxResultsPerColumnFamily(4);
+      ResultScanner scanner = ht.getScanner(scan);
+      kvListScan = new ArrayList<>();
+      while ((result = scanner.next()) != null) {
+        for (Cell kv : result.listCells()) {
+          kvListScan.add(kv);
+        }
       }
+      result = Result.create(kvListScan);
+      verifyResult(result, kvListExp, toLog, "Testing scan with maxResults");
     }
-    result = Result.create(kvListScan);
-    verifyResult(result, kvListExp, toLog, "Testing scan with maxResults");
-
   }
 
   /**
    * Test from client side for get with rowOffset
    */
-  @Test
+  @TestTemplate
   public void testGetRowOffset() throws Exception {
-    final TableName tableName = name.getTableName();
     byte[][] FAMILIES = HTestConst.makeNAscii(FAMILY, 3);
     byte[][] QUALIFIERS = HTestConst.makeNAscii(QUALIFIER, 20);
 
-    Table ht = TEST_UTIL.createTable(tableName, FAMILIES);
-
-    Get get;
-    Put put;
-    Result result;
-    boolean toLog = true;
-    List<Cell> kvListExp;
+    TEST_UTIL.createTable(tableName, FAMILIES);
+    try (Connection conn = getConnection(); Table ht = 
conn.getTable(tableName)) {
+      Get get;
+      Put put;
+      Result result;
+      boolean toLog = true;
+      List<Cell> kvListExp;
 
-    // Insert one CF for row
-    kvListExp = new ArrayList<>();
-    put = new Put(ROW);
-    for (int i = 0; i < 10; i++) {
-      KeyValue kv = new KeyValue(ROW, FAMILIES[0], QUALIFIERS[i], 1, VALUE);
-      put.add(kv);
-      // skipping first two kvs
-      if (i < 2) {
-        continue;
-      }
-      kvListExp.add(kv);
-    }
-    ht.put(put);
-
-    // setting offset to 2
-    get = new Get(ROW);
-    get.setRowOffsetPerColumnFamily(2);
-    result = ht.get(get);
-    verifyResult(result, kvListExp, toLog, "Testing basic setRowOffset");
-
-    // setting offset to 20
-    get = new Get(ROW);
-    get.setRowOffsetPerColumnFamily(20);
-    result = ht.get(get);
-    kvListExp = new ArrayList<>();
-    verifyResult(result, kvListExp, toLog, "Testing offset > #kvs");
-
-    // offset + maxResultPerCF
-    get = new Get(ROW);
-    get.setRowOffsetPerColumnFamily(4);
-    get.setMaxResultsPerColumnFamily(5);
-    result = ht.get(get);
-    kvListExp = new ArrayList<>();
-    for (int i = 4; i < 9; i++) {
-      kvListExp.add(new KeyValue(ROW, FAMILIES[0], QUALIFIERS[i], 1, VALUE));
-    }
-    verifyResult(result, kvListExp, toLog, "Testing offset + 
setMaxResultsPerCF");
-
-    // Filters: ColumnRangeFilter
-    get = new Get(ROW);
-    get.setRowOffsetPerColumnFamily(1);
-    get.setFilter(new ColumnRangeFilter(QUALIFIERS[2], true, QUALIFIERS[5], 
true));
-    result = ht.get(get);
-    kvListExp = new ArrayList<>();
-    kvListExp.add(new KeyValue(ROW, FAMILIES[0], QUALIFIERS[3], 1, VALUE));
-    kvListExp.add(new KeyValue(ROW, FAMILIES[0], QUALIFIERS[4], 1, VALUE));
-    kvListExp.add(new KeyValue(ROW, FAMILIES[0], QUALIFIERS[5], 1, VALUE));
-    verifyResult(result, kvListExp, toLog, "Testing offset with CRF");
-
-    // Insert into two more CFs for row
-    // 10 columns for CF2, 10 columns for CF1
-    for (int j = 2; j > 0; j--) {
+      // Insert one CF for row
+      kvListExp = new ArrayList<>();
       put = new Put(ROW);
       for (int i = 0; i < 10; i++) {
-        KeyValue kv = new KeyValue(ROW, FAMILIES[j], QUALIFIERS[i], 1, VALUE);
+        KeyValue kv = new KeyValue(ROW, FAMILIES[0], QUALIFIERS[i], 1, VALUE);
         put.add(kv);
+        // skipping first two kvs
+        if (i < 2) {
+          continue;
+        }
+        kvListExp.add(kv);
       }
       ht.put(put);
-    }
 
-    get = new Get(ROW);
-    get.setRowOffsetPerColumnFamily(4);
-    get.setMaxResultsPerColumnFamily(2);
-    get.addFamily(FAMILIES[1]);
-    get.addFamily(FAMILIES[2]);
-    result = ht.get(get);
-    kvListExp = new ArrayList<>();
-    // Exp: CF1:q4, q5, CF2: q4, q5
-    kvListExp.add(new KeyValue(ROW, FAMILIES[1], QUALIFIERS[4], 1, VALUE));
-    kvListExp.add(new KeyValue(ROW, FAMILIES[1], QUALIFIERS[5], 1, VALUE));
-    kvListExp.add(new KeyValue(ROW, FAMILIES[2], QUALIFIERS[4], 1, VALUE));
-    kvListExp.add(new KeyValue(ROW, FAMILIES[2], QUALIFIERS[5], 1, VALUE));
-    verifyResult(result, kvListExp, toLog, "Testing offset + multiple CFs + 
maxResults");
+      // setting offset to 2
+      get = new Get(ROW);
+      get.setRowOffsetPerColumnFamily(2);
+      result = ht.get(get);
+      verifyResult(result, kvListExp, toLog, "Testing basic setRowOffset");
+
+      // setting offset to 20
+      get = new Get(ROW);
+      get.setRowOffsetPerColumnFamily(20);
+      result = ht.get(get);
+      kvListExp = new ArrayList<>();
+      verifyResult(result, kvListExp, toLog, "Testing offset > #kvs");
+
+      // offset + maxResultPerCF
+      get = new Get(ROW);
+      get.setRowOffsetPerColumnFamily(4);
+      get.setMaxResultsPerColumnFamily(5);
+      result = ht.get(get);
+      kvListExp = new ArrayList<>();
+      for (int i = 4; i < 9; i++) {
+        kvListExp.add(new KeyValue(ROW, FAMILIES[0], QUALIFIERS[i], 1, VALUE));
+      }
+      verifyResult(result, kvListExp, toLog, "Testing offset + 
setMaxResultsPerCF");
+
+      // Filters: ColumnRangeFilter
+      get = new Get(ROW);
+      get.setRowOffsetPerColumnFamily(1);
+      get.setFilter(new ColumnRangeFilter(QUALIFIERS[2], true, QUALIFIERS[5], 
true));
+      result = ht.get(get);
+      kvListExp = new ArrayList<>();
+      kvListExp.add(new KeyValue(ROW, FAMILIES[0], QUALIFIERS[3], 1, VALUE));
+      kvListExp.add(new KeyValue(ROW, FAMILIES[0], QUALIFIERS[4], 1, VALUE));
+      kvListExp.add(new KeyValue(ROW, FAMILIES[0], QUALIFIERS[5], 1, VALUE));
+      verifyResult(result, kvListExp, toLog, "Testing offset with CRF");
+
+      // Insert into two more CFs for row
+      // 10 columns for CF2, 10 columns for CF1
+      for (int j = 2; j > 0; j--) {
+        put = new Put(ROW);
+        for (int i = 0; i < 10; i++) {
+          KeyValue kv = new KeyValue(ROW, FAMILIES[j], QUALIFIERS[i], 1, 
VALUE);
+          put.add(kv);
+        }
+        ht.put(put);
+      }
+
+      get = new Get(ROW);
+      get.setRowOffsetPerColumnFamily(4);
+      get.setMaxResultsPerColumnFamily(2);
+      get.addFamily(FAMILIES[1]);
+      get.addFamily(FAMILIES[2]);
+      result = ht.get(get);
+      kvListExp = new ArrayList<>();
+      // Exp: CF1:q4, q5, CF2: q4, q5
+      kvListExp.add(new KeyValue(ROW, FAMILIES[1], QUALIFIERS[4], 1, VALUE));
+      kvListExp.add(new KeyValue(ROW, FAMILIES[1], QUALIFIERS[5], 1, VALUE));
+      kvListExp.add(new KeyValue(ROW, FAMILIES[2], QUALIFIERS[4], 1, VALUE));
+      kvListExp.add(new KeyValue(ROW, FAMILIES[2], QUALIFIERS[5], 1, VALUE));
+      verifyResult(result, kvListExp, toLog, "Testing offset + multiple CFs + 
maxResults");
+    }
   }
 
-  @Test
+  @TestTemplate
   public void testRawScanExpiredCell() throws Exception {
-    final TableName tableName = name.getTableName();
-    try (final Table table = TEST_UTIL.createTable(tableName, FAMILY)) {
+    TEST_UTIL.createTable(tableName, FAMILY);
+    try (Connection conn = getConnection(); Table table = 
conn.getTable(tableName)) {
       final Put put = new Put(ROW);
       put.addColumn(FAMILY, QUALIFIER, VALUE);
       put.setTTL(0);
@@ -639,16 +565,13 @@ public class TestScannersFromClientSide {
         assertArrayEquals(VALUE, result.getValue(FAMILY, QUALIFIER));
         assertNull(scanner.next());
       }
-    } finally {
-      TEST_UTIL.deleteTable(tableName);
     }
   }
 
-  @Test
+  @TestTemplate
   public void testScanRawDeleteFamilyVersion() throws Exception {
-    TableName tableName = name.getTableName();
     TEST_UTIL.createTable(tableName, FAMILY);
-    Configuration conf = new Configuration(TEST_UTIL.getConfiguration());
+    Configuration conf = getClientConf();
     conf.set(RPC_CODEC_CONF_KEY, "");
     conf.set(DEFAULT_CODEC_CLASS, "");
     try (Connection connection = ConnectionFactory.createConnection(conf);
@@ -663,87 +586,84 @@ public class TestScannersFromClientSide {
         count++;
       }
       assertEquals(1, count);
-    } finally {
-      TEST_UTIL.deleteTable(tableName);
     }
   }
 
   /**
    * Test from client side for scan while the region is reopened on the same 
region server.
    */
-  @Test
+  @TestTemplate
   public void testScanOnReopenedRegion() throws Exception {
-    final TableName tableName = name.getTableName();
     byte[][] QUALIFIERS = HTestConst.makeNAscii(QUALIFIER, 2);
 
-    Table ht = TEST_UTIL.createTable(tableName, FAMILY);
+    TEST_UTIL.createTable(tableName, FAMILY);
+    try (Connection conn = getConnection(); Table ht = 
conn.getTable(tableName)) {
+      Put put;
+      Scan scan;
+      Result result;
+      ResultScanner scanner;
+      boolean toLog = false;
+      List<Cell> kvListExp;
 
-    Put put;
-    Scan scan;
-    Result result;
-    ResultScanner scanner;
-    boolean toLog = false;
-    List<Cell> kvListExp;
+      // table: row, family, c0:0, c1:1
+      put = new Put(ROW);
+      for (int i = 0; i < QUALIFIERS.length; i++) {
+        KeyValue kv = new KeyValue(ROW, FAMILY, QUALIFIERS[i], i, VALUE);
+        put.add(kv);
+      }
+      ht.put(put);
 
-    // table: row, family, c0:0, c1:1
-    put = new Put(ROW);
-    for (int i = 0; i < QUALIFIERS.length; i++) {
-      KeyValue kv = new KeyValue(ROW, FAMILY, QUALIFIERS[i], i, VALUE);
-      put.add(kv);
-    }
-    ht.put(put);
+      scan = new Scan().withStartRow(ROW);
+      scanner = ht.getScanner(scan);
 
-    scan = new Scan().withStartRow(ROW);
-    scanner = ht.getScanner(scan);
+      HRegionLocation loc;
 
-    HRegionLocation loc;
+      try (RegionLocator locator = 
TEST_UTIL.getConnection().getRegionLocator(tableName)) {
+        loc = locator.getRegionLocation(ROW);
+      }
+      RegionInfo hri = loc.getRegion();
+      SingleProcessHBaseCluster cluster = TEST_UTIL.getMiniHBaseCluster();
+      byte[] regionName = hri.getRegionName();
+      int i = cluster.getServerWith(regionName);
+      HRegionServer rs = cluster.getRegionServer(i);
+      LOG.info("Unassigning " + hri);
+      TEST_UTIL.getAdmin().unassign(hri.getRegionName(), true);
+      long startTime = EnvironmentEdgeManager.currentTime();
+      long timeOut = 10000;
+      boolean offline = false;
+      while (true) {
+        if (rs.getOnlineRegion(regionName) == null) {
+          offline = true;
+          break;
+        }
+        assertTrue(EnvironmentEdgeManager.currentTime() < startTime + timeOut,
+          "Timed out in closing the testing region");
+      }
+      assertTrue(offline);
+      LOG.info("Assigning " + hri);
+      TEST_UTIL.getAdmin().assign(hri.getRegionName());
+      startTime = EnvironmentEdgeManager.currentTime();
+      while (true) {
+        rs = cluster.getRegionServer(cluster.getServerWith(regionName));
+        if (rs != null && rs.getOnlineRegion(regionName) != null) {
+          offline = false;
+          break;
+        }
+        assertTrue(EnvironmentEdgeManager.currentTime() < startTime + timeOut,
+          "Timed out in open the testing region");
+      }
+      assertFalse(offline);
 
-    try (RegionLocator locator = 
TEST_UTIL.getConnection().getRegionLocator(tableName)) {
-      loc = locator.getRegionLocation(ROW);
-    }
-    RegionInfo hri = loc.getRegion();
-    SingleProcessHBaseCluster cluster = TEST_UTIL.getMiniHBaseCluster();
-    byte[] regionName = hri.getRegionName();
-    int i = cluster.getServerWith(regionName);
-    HRegionServer rs = cluster.getRegionServer(i);
-    LOG.info("Unassigning " + hri);
-    TEST_UTIL.getAdmin().unassign(hri.getRegionName(), true);
-    long startTime = EnvironmentEdgeManager.currentTime();
-    long timeOut = 10000;
-    boolean offline = false;
-    while (true) {
-      if (rs.getOnlineRegion(regionName) == null) {
-        offline = true;
-        break;
-      }
-      assertTrue("Timed out in closing the testing region",
-        EnvironmentEdgeManager.currentTime() < startTime + timeOut);
+      // c0:0, c1:1
+      kvListExp = new ArrayList<>();
+      kvListExp.add(new KeyValue(ROW, FAMILY, QUALIFIERS[0], 0, VALUE));
+      kvListExp.add(new KeyValue(ROW, FAMILY, QUALIFIERS[1], 1, VALUE));
+      result = scanner.next();
+      verifyResult(result, kvListExp, toLog, "Testing scan on re-opened 
region");
     }
-    assertTrue(offline);
-    LOG.info("Assigning " + hri);
-    TEST_UTIL.getAdmin().assign(hri.getRegionName());
-    startTime = EnvironmentEdgeManager.currentTime();
-    while (true) {
-      rs = cluster.getRegionServer(cluster.getServerWith(regionName));
-      if (rs != null && rs.getOnlineRegion(regionName) != null) {
-        offline = false;
-        break;
-      }
-      assertTrue("Timed out in open the testing region",
-        EnvironmentEdgeManager.currentTime() < startTime + timeOut);
-    }
-    assertFalse(offline);
-
-    // c0:0, c1:1
-    kvListExp = new ArrayList<>();
-    kvListExp.add(new KeyValue(ROW, FAMILY, QUALIFIERS[0], 0, VALUE));
-    kvListExp.add(new KeyValue(ROW, FAMILY, QUALIFIERS[1], 1, VALUE));
-    result = scanner.next();
-    verifyResult(result, kvListExp, toLog, "Testing scan on re-opened region");
   }
 
   static void verifyResult(Result result, List<Cell> expKvList, boolean toLog, 
String msg) {
-
     LOG.info(msg);
     LOG.info("Expected count: " + expKvList.size());
     LOG.info("Actual count: " + result.size());
@@ -762,18 +682,18 @@ public class TestScannersFromClientSide {
         LOG.info("get kv is: " + kv.toString());
         LOG.info("exp kv is: " + kvExp.toString());
       }
-      assertTrue("Not equal", kvExp.equals(kv));
+      assertTrue(kvExp.equals(kv), "Not equal");
     }
 
     assertEquals(expKvList.size(), result.size());
   }
 
-  @Test
+  @TestTemplate
   public void testReadExpiredDataForRawScan() throws IOException {
-    TableName tableName = name.getTableName();
     long ts = EnvironmentEdgeManager.currentTime() - 10000;
     byte[] value = Bytes.toBytes("expired");
-    try (Table table = TEST_UTIL.createTable(tableName, FAMILY)) {
+    TEST_UTIL.createTable(tableName, FAMILY);
+    try (Connection conn = getConnection(); Table table = 
conn.getTable(tableName)) {
       table.put(new Put(ROW).addColumn(FAMILY, QUALIFIER, ts, value));
       assertArrayEquals(value, table.get(new Get(ROW)).getValue(FAMILY, 
QUALIFIER));
       TEST_UTIL.getAdmin().modifyColumnFamily(tableName,
@@ -788,11 +708,11 @@ public class TestScannersFromClientSide {
     }
   }
 
-  @Test
+  @TestTemplate
   public void testScanWithColumnsAndFilterAndVersion() throws IOException {
-    TableName tableName = name.getTableName();
     long now = EnvironmentEdgeManager.currentTime();
-    try (Table table = TEST_UTIL.createTable(tableName, FAMILY, 4)) {
+    TEST_UTIL.createTable(tableName, FAMILY, 4);
+    try (Connection conn = getConnection(); Table table = 
conn.getTable(tableName)) {
       for (int i = 0; i < 4; i++) {
         Put put = new Put(ROW);
         put.addColumn(FAMILY, QUALIFIER, now + i, VALUE);
@@ -811,10 +731,10 @@ public class TestScannersFromClientSide {
     }
   }
 
-  @Test
+  @TestTemplate
   public void testScanWithSameStartRowStopRow() throws IOException {
-    TableName tableName = name.getTableName();
-    try (Table table = TEST_UTIL.createTable(tableName, FAMILY)) {
+    TEST_UTIL.createTable(tableName, FAMILY);
+    try (Connection conn = getConnection(); Table table = 
conn.getTable(tableName)) {
       table.put(new Put(ROW).addColumn(FAMILY, QUALIFIER, VALUE));
 
       Scan scan = new Scan().withStartRow(ROW).withStopRow(ROW);
@@ -848,14 +768,13 @@ public class TestScannersFromClientSide {
     }
   }
 
-  @Test
+  @TestTemplate
   public void testReverseScanWithFlush() throws Exception {
-    TableName tableName = name.getTableName();
     final int BATCH_SIZE = 10;
     final int ROWS_TO_INSERT = 100;
     final byte[] LARGE_VALUE = generateHugeValue(128 * 1024);
-
-    try (Table table = TEST_UTIL.createTable(tableName, FAMILY);
+    TEST_UTIL.createTable(tableName, FAMILY);
+    try (Connection conn = getConnection(); Table table = 
conn.getTable(tableName);
       Admin admin = TEST_UTIL.getAdmin()) {
       List<Put> putList = new ArrayList<>();
       for (long i = 0; i < ROWS_TO_INSERT; i++) {
@@ -881,19 +800,19 @@ public class TestScannersFromClientSide {
       int count = 0;
 
       try (ResultScanner results = table.getScanner(scan)) {
-        for (Result result : results) {
+        while (results.next() != null) {
           count++;
         }
       }
-      assertEquals("Expected " + ROWS_TO_INSERT + " rows in the table but it 
is " + count,
-        ROWS_TO_INSERT, count);
+      assertEquals(ROWS_TO_INSERT, count,
+        "Expected " + ROWS_TO_INSERT + " rows in the table but it is " + 
count);
     }
   }
 
-  @Test
+  @TestTemplate
   public void testScannerWithPartialResults() throws Exception {
-    TableName tableName = TableName.valueOf("testScannerWithPartialResults");
-    try (Table table = TEST_UTIL.createMultiRegionTable(tableName, 
Bytes.toBytes("c"), 4)) {
+    TEST_UTIL.createMultiRegionTable(tableName, Bytes.toBytes("c"), 4);
+    try (Connection conn = getConnection(); Table table = 
conn.getTable(tableName)) {
       List<Put> puts = new ArrayList<>();
       byte[] largeArray = new byte[10000];
       Put put = new Put(Bytes.toBytes("aaaa0"));
@@ -914,15 +833,15 @@ public class TestScannersFromClientSide {
       scan.setMaxResultSize(10001);
       scan.withStopRow(Bytes.toBytes("bbbb"));
       scan.setFilter(new LimitKVsReturnFilter());
-      ResultScanner rs = table.getScanner(scan);
-      Result result;
-      int expectedKvNumber = 6;
-      int returnedKvNumber = 0;
-      while ((result = rs.next()) != null) {
-        returnedKvNumber += result.listCells().size();
+      try (ResultScanner rs = table.getScanner(scan)) {
+        Result result;
+        int expectedKvNumber = 6;
+        int returnedKvNumber = 0;
+        while ((result = rs.next()) != null) {
+          returnedKvNumber += result.listCells().size();
+        }
+        assertEquals(expectedKvNumber, returnedKvNumber);
       }
-      rs.close();
-      assertEquals(expectedKvNumber, returnedKvNumber);
     }
   }
 

Reply via email to