You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by te...@apache.org on 2018/09/06 10:59:51 UTC

[1/2] hbase git commit: HBASE-21138 Close HRegion instance at the end of every test in TestHRegion

Repository: hbase
Updated Branches:
  refs/heads/master 855f4bbb2 -> a37c40faa


http://git-wip-us.apache.org/repos/asf/hbase/blob/a37c40fa/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java
index fd4add2..342e820 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java
@@ -246,7 +246,9 @@ public class TestHRegion {
   }
 
   @After
-  public void tearDown() throws Exception {
+  public void tearDown() throws IOException {
+    // Region may have been closed, but it is still no harm if we close it again here using HTU.
+    HBaseTestingUtility.closeRegionAndWAL(region);
     EnvironmentEdgeManagerTestHelper.reset();
     LOG.info("Cleaning test directory: " + TEST_UTIL.getDataTestDir());
     TEST_UTIL.cleanupTestDir();
@@ -258,7 +260,7 @@ public class TestHRegion {
    */
   @Test
   public void testSequenceId() throws IOException {
-    HRegion region = initHRegion(tableName, method, CONF, COLUMN_FAMILY_BYTES);
+    region = initHRegion(tableName, method, CONF, COLUMN_FAMILY_BYTES);
     assertEquals(HConstants.NO_SEQNUM, region.getMaxFlushedSeqId());
     // Weird. This returns 0 if no store files or no edits. Afraid to change it.
     assertEquals(0, (long)region.getMaxStoreSeqId().get(COLUMN_FAMILY_BYTES));
@@ -293,7 +295,7 @@ public class TestHRegion {
    */
   @Test
   public void testCloseCarryingSnapshot() throws IOException {
-    HRegion region = initHRegion(tableName, method, CONF, COLUMN_FAMILY_BYTES);
+    region = initHRegion(tableName, method, CONF, COLUMN_FAMILY_BYTES);
     HStore store = region.getStore(COLUMN_FAMILY_BYTES);
     // Get some random bytes.
     byte [] value = Bytes.toBytes(method);
@@ -341,7 +343,7 @@ public class TestHRegion {
     Path rootDir = new Path(dir + "testMemstoreSnapshotSize");
     MyFaultyFSLog faultyLog = new MyFaultyFSLog(fs, rootDir, "testMemstoreSnapshotSize", CONF);
     faultyLog.init();
-    HRegion region = initHRegion(tableName, null, null, false, Durability.SYNC_WAL, faultyLog,
+    region = initHRegion(tableName, null, null, false, Durability.SYNC_WAL, faultyLog,
         COLUMN_FAMILY_BYTES);
 
     HStore store = region.getStore(COLUMN_FAMILY_BYTES);
@@ -363,7 +365,6 @@ public class TestHRegion {
     MemStoreSize mss = store.getFlushableSize();
     assertTrue("flushable size should be zero, but it is " + mss,
         mss.getDataSize() == 0);
-    HBaseTestingUtility.closeRegionAndWAL(region);
   }
 
   /**
@@ -389,7 +390,7 @@ public class TestHRegion {
     Path rootDir = new Path(dir + testName);
     FSHLog hLog = new FSHLog(fs, rootDir, testName, CONF);
     hLog.init();
-    HRegion region = initHRegion(tableName, null, null, false, Durability.SYNC_WAL, hLog,
+    region = initHRegion(tableName, null, null, false, Durability.SYNC_WAL, hLog,
         COLUMN_FAMILY_BYTES);
     HStore store = region.getStore(COLUMN_FAMILY_BYTES);
     assertEquals(0, region.getMemStoreDataSize());
@@ -421,7 +422,6 @@ public class TestHRegion {
         expectedSize, store.getFlushableSize().getDataSize());
 
     region.setCoprocessorHost(null);
-    HBaseTestingUtility.closeRegionAndWAL(region);
   }
 
   /**
@@ -778,32 +778,27 @@ public class TestHRegion {
   public void testSkipRecoveredEditsReplayAllIgnored() throws Exception {
     byte[] family = Bytes.toBytes("family");
     this.region = initHRegion(tableName, method, CONF, family);
-    try {
-      Path regiondir = region.getRegionFileSystem().getRegionDir();
-      FileSystem fs = region.getRegionFileSystem().getFileSystem();
+    Path regiondir = region.getRegionFileSystem().getRegionDir();
+    FileSystem fs = region.getRegionFileSystem().getFileSystem();
 
-      Path recoveredEditsDir = WALSplitter.getRegionDirRecoveredEditsDir(regiondir);
-      for (int i = 1000; i < 1050; i += 10) {
-        Path recoveredEdits = new Path(recoveredEditsDir, String.format("%019d", i));
-        FSDataOutputStream dos = fs.create(recoveredEdits);
-        dos.writeInt(i);
-        dos.close();
-      }
-      long minSeqId = 2000;
-      Path recoveredEdits = new Path(recoveredEditsDir, String.format("%019d", minSeqId - 1));
+    Path recoveredEditsDir = WALSplitter.getRegionDirRecoveredEditsDir(regiondir);
+    for (int i = 1000; i < 1050; i += 10) {
+      Path recoveredEdits = new Path(recoveredEditsDir, String.format("%019d", i));
       FSDataOutputStream dos = fs.create(recoveredEdits);
+      dos.writeInt(i);
       dos.close();
+    }
+    long minSeqId = 2000;
+    Path recoveredEdits = new Path(recoveredEditsDir, String.format("%019d", minSeqId - 1));
+    FSDataOutputStream dos = fs.create(recoveredEdits);
+    dos.close();
 
-      Map<byte[], Long> maxSeqIdInStores = new TreeMap<>(Bytes.BYTES_COMPARATOR);
-      for (HStore store : region.getStores()) {
-        maxSeqIdInStores.put(Bytes.toBytes(store.getColumnFamilyName()), minSeqId);
-      }
-      long seqId = region.replayRecoveredEditsIfAny(regiondir, maxSeqIdInStores, null, null);
-      assertEquals(minSeqId, seqId);
-    } finally {
-      HBaseTestingUtility.closeRegionAndWAL(this.region);
-      this.region = null;
+    Map<byte[], Long> maxSeqIdInStores = new TreeMap<>(Bytes.BYTES_COMPARATOR);
+    for (HStore store : region.getStores()) {
+      maxSeqIdInStores.put(Bytes.toBytes(store.getColumnFamilyName()), minSeqId);
     }
+    long seqId = region.replayRecoveredEditsIfAny(regiondir, maxSeqIdInStores, null, null);
+    assertEquals(minSeqId, seqId);
   }
 
   @Test
@@ -1197,58 +1192,52 @@ public class TestHRegion {
     wal.init();
     this.region = initHRegion(tableName, HConstants.EMPTY_START_ROW,
       HConstants.EMPTY_END_ROW, false, Durability.USE_DEFAULT, wal, family);
-    try {
-      int i = 0;
-      Put put = new Put(Bytes.toBytes(i));
-      put.setDurability(Durability.SKIP_WAL); // have to skip mocked wal
-      put.addColumn(family, Bytes.toBytes(i), Bytes.toBytes(i));
-      region.put(put);
+    int i = 0;
+    Put put = new Put(Bytes.toBytes(i));
+    put.setDurability(Durability.SKIP_WAL); // have to skip mocked wal
+    put.addColumn(family, Bytes.toBytes(i), Bytes.toBytes(i));
+    region.put(put);
 
-      // 1. Test case where START_FLUSH throws exception
-      wal.flushActions = new FlushAction [] {FlushAction.START_FLUSH};
+    // 1. Test case where START_FLUSH throws exception
+    wal.flushActions = new FlushAction [] {FlushAction.START_FLUSH};
 
-      // start cache flush will throw exception
-      try {
-        region.flush(true);
-        fail("This should have thrown exception");
-      } catch (DroppedSnapshotException unexpected) {
-        // this should not be a dropped snapshot exception. Meaning that RS will not abort
-        throw unexpected;
-      } catch (IOException expected) {
-        // expected
-      }
-      // The WAL is hosed now. It has two edits appended. We cannot roll the log without it
-      // throwing a DroppedSnapshotException to force an abort. Just clean up the mess.
-      region.close(true);
-      wal.close();
-
-      // 2. Test case where START_FLUSH succeeds but COMMIT_FLUSH will throw exception
-      wal.flushActions = new FlushAction [] {FlushAction.COMMIT_FLUSH};
-      wal = new FailAppendFlushMarkerWAL(FileSystem.get(walConf), FSUtils.getRootDir(walConf),
-            method, walConf);
-      wal.init();
-      this.region = initHRegion(tableName, HConstants.EMPTY_START_ROW,
-        HConstants.EMPTY_END_ROW, false, Durability.USE_DEFAULT, wal, family);
-      region.put(put);
+    // start cache flush will throw exception
+    try {
+      region.flush(true);
+      fail("This should have thrown exception");
+    } catch (DroppedSnapshotException unexpected) {
+      // this should not be a dropped snapshot exception. Meaning that RS will not abort
+      throw unexpected;
+    } catch (IOException expected) {
+      // expected
+    }
+    // The WAL is hosed now. It has two edits appended. We cannot roll the log without it
+    // throwing a DroppedSnapshotException to force an abort. Just clean up the mess.
+    region.close(true);
+    wal.close();
 
-      // 3. Test case where ABORT_FLUSH will throw exception.
-      // Even if ABORT_FLUSH throws exception, we should not fail with IOE, but continue with
-      // DroppedSnapshotException. Below COMMMIT_FLUSH will cause flush to abort
-      wal.flushActions = new FlushAction [] {FlushAction.COMMIT_FLUSH, FlushAction.ABORT_FLUSH};
+    // 2. Test case where START_FLUSH succeeds but COMMIT_FLUSH will throw exception
+    wal.flushActions = new FlushAction [] {FlushAction.COMMIT_FLUSH};
+    wal = new FailAppendFlushMarkerWAL(FileSystem.get(walConf), FSUtils.getRootDir(walConf),
+          method, walConf);
+    wal.init();
+    this.region = initHRegion(tableName, HConstants.EMPTY_START_ROW,
+      HConstants.EMPTY_END_ROW, false, Durability.USE_DEFAULT, wal, family);
+    region.put(put);
 
-      try {
-        region.flush(true);
-        fail("This should have thrown exception");
-      } catch (DroppedSnapshotException expected) {
-        // we expect this exception, since we were able to write the snapshot, but failed to
-        // write the flush marker to WAL
-      } catch (IOException unexpected) {
-        throw unexpected;
-      }
+    // 3. Test case where ABORT_FLUSH will throw exception.
+    // Even if ABORT_FLUSH throws exception, we should not fail with IOE, but continue with
+    // DroppedSnapshotException. Below COMMMIT_FLUSH will cause flush to abort
+    wal.flushActions = new FlushAction [] {FlushAction.COMMIT_FLUSH, FlushAction.ABORT_FLUSH};
 
-    } finally {
-      HBaseTestingUtility.closeRegionAndWAL(this.region);
-      this.region = null;
+    try {
+      region.flush(true);
+      fail("This should have thrown exception");
+    } catch (DroppedSnapshotException expected) {
+      // we expect this exception, since we were able to write the snapshot, but failed to
+      // write the flush marker to WAL
+    } catch (IOException unexpected) {
+      throw unexpected;
     }
   }
 
@@ -1260,50 +1249,45 @@ public class TestHRegion {
 
     // Setting up region
     this.region = initHRegion(tableName, method, hc, families);
+    // Put data in region
+    final int startRow = 100;
+    putData(startRow, numRows, qual1, families);
+    putData(startRow, numRows, qual2, families);
+    putData(startRow, numRows, qual3, families);
+    final AtomicBoolean done = new AtomicBoolean(false);
+    final AtomicInteger gets = new AtomicInteger(0);
+    GetTillDoneOrException[] threads = new GetTillDoneOrException[10];
     try {
-      // Put data in region
-      final int startRow = 100;
-      putData(startRow, numRows, qual1, families);
-      putData(startRow, numRows, qual2, families);
-      putData(startRow, numRows, qual3, families);
-      final AtomicBoolean done = new AtomicBoolean(false);
-      final AtomicInteger gets = new AtomicInteger(0);
-      GetTillDoneOrException[] threads = new GetTillDoneOrException[10];
-      try {
-        // Set ten threads running concurrently getting from the region.
-        for (int i = 0; i < threads.length / 2; i++) {
-          threads[i] = new GetTillDoneOrException(i, Bytes.toBytes("" + startRow), done, gets);
-          threads[i].setDaemon(true);
-          threads[i].start();
-        }
-        // Artificially make the condition by setting closing flag explicitly.
-        // I can't make the issue happen with a call to region.close().
-        this.region.closing.set(true);
-        for (int i = threads.length / 2; i < threads.length; i++) {
-          threads[i] = new GetTillDoneOrException(i, Bytes.toBytes("" + startRow), done, gets);
-          threads[i].setDaemon(true);
-          threads[i].start();
-        }
-      } finally {
-        if (this.region != null) {
-          HBaseTestingUtility.closeRegionAndWAL(this.region);
-        }
+      // Set ten threads running concurrently getting from the region.
+      for (int i = 0; i < threads.length / 2; i++) {
+        threads[i] = new GetTillDoneOrException(i, Bytes.toBytes("" + startRow), done, gets);
+        threads[i].setDaemon(true);
+        threads[i].start();
       }
-      done.set(true);
-      for (GetTillDoneOrException t : threads) {
-        try {
-          t.join();
-        } catch (InterruptedException e) {
-          e.printStackTrace();
-        }
-        if (t.e != null) {
-          LOG.info("Exception=" + t.e);
-          assertFalse("Found a NPE in " + t.getName(), t.e instanceof NullPointerException);
-        }
+      // Artificially make the condition by setting closing flag explicitly.
+      // I can't make the issue happen with a call to region.close().
+      this.region.closing.set(true);
+      for (int i = threads.length / 2; i < threads.length; i++) {
+        threads[i] = new GetTillDoneOrException(i, Bytes.toBytes("" + startRow), done, gets);
+        threads[i].setDaemon(true);
+        threads[i].start();
       }
     } finally {
-      HBaseTestingUtility.closeRegionAndWAL(this.region);
-      this.region = null;
+      if (this.region != null) {
+        HBaseTestingUtility.closeRegionAndWAL(this.region);
+      }
+    }
+    done.set(true);
+    for (GetTillDoneOrException t : threads) {
+      try {
+        t.join();
+      } catch (InterruptedException e) {
+        e.printStackTrace();
+      }
+      if (t.e != null) {
+        LOG.info("Exception=" + t.e);
+        assertFalse("Found a NPE in " + t.getName(), t.e instanceof NullPointerException);
+      }
     }
   }
 
@@ -1348,41 +1332,36 @@ public class TestHRegion {
     byte[][] FAMILIES = new byte[][] { Bytes.toBytes("trans-blob"), Bytes.toBytes("trans-type"),
         Bytes.toBytes("trans-date"), Bytes.toBytes("trans-tags"), Bytes.toBytes("trans-group") };
     this.region = initHRegion(tableName, method, CONF, FAMILIES);
-    try {
-      String value = "this is the value";
-      String value2 = "this is some other value";
-      String keyPrefix1 = "prefix1";
-      String keyPrefix2 = "prefix2";
-      String keyPrefix3 = "prefix3";
-      putRows(this.region, 3, value, keyPrefix1);
-      putRows(this.region, 3, value, keyPrefix2);
-      putRows(this.region, 3, value, keyPrefix3);
-      putRows(this.region, 3, value2, keyPrefix1);
-      putRows(this.region, 3, value2, keyPrefix2);
-      putRows(this.region, 3, value2, keyPrefix3);
-      System.out.println("Checking values for key: " + keyPrefix1);
-      assertEquals("Got back incorrect number of rows from scan", 3,
-          getNumberOfRows(keyPrefix1, value2, this.region));
-      System.out.println("Checking values for key: " + keyPrefix2);
-      assertEquals("Got back incorrect number of rows from scan", 3,
-          getNumberOfRows(keyPrefix2, value2, this.region));
-      System.out.println("Checking values for key: " + keyPrefix3);
-      assertEquals("Got back incorrect number of rows from scan", 3,
-          getNumberOfRows(keyPrefix3, value2, this.region));
-      deleteColumns(this.region, value2, keyPrefix1);
-      deleteColumns(this.region, value2, keyPrefix2);
-      deleteColumns(this.region, value2, keyPrefix3);
-      System.out.println("Starting important checks.....");
-      assertEquals("Got back incorrect number of rows from scan: " + keyPrefix1, 0,
-          getNumberOfRows(keyPrefix1, value2, this.region));
-      assertEquals("Got back incorrect number of rows from scan: " + keyPrefix2, 0,
-          getNumberOfRows(keyPrefix2, value2, this.region));
-      assertEquals("Got back incorrect number of rows from scan: " + keyPrefix3, 0,
-          getNumberOfRows(keyPrefix3, value2, this.region));
-    } finally {
-      HBaseTestingUtility.closeRegionAndWAL(this.region);
-      this.region = null;
-    }
+    String value = "this is the value";
+    String value2 = "this is some other value";
+    String keyPrefix1 = "prefix1";
+    String keyPrefix2 = "prefix2";
+    String keyPrefix3 = "prefix3";
+    putRows(this.region, 3, value, keyPrefix1);
+    putRows(this.region, 3, value, keyPrefix2);
+    putRows(this.region, 3, value, keyPrefix3);
+    putRows(this.region, 3, value2, keyPrefix1);
+    putRows(this.region, 3, value2, keyPrefix2);
+    putRows(this.region, 3, value2, keyPrefix3);
+    System.out.println("Checking values for key: " + keyPrefix1);
+    assertEquals("Got back incorrect number of rows from scan", 3,
+        getNumberOfRows(keyPrefix1, value2, this.region));
+    System.out.println("Checking values for key: " + keyPrefix2);
+    assertEquals("Got back incorrect number of rows from scan", 3,
+        getNumberOfRows(keyPrefix2, value2, this.region));
+    System.out.println("Checking values for key: " + keyPrefix3);
+    assertEquals("Got back incorrect number of rows from scan", 3,
+        getNumberOfRows(keyPrefix3, value2, this.region));
+    deleteColumns(this.region, value2, keyPrefix1);
+    deleteColumns(this.region, value2, keyPrefix2);
+    deleteColumns(this.region, value2, keyPrefix3);
+    System.out.println("Starting important checks.....");
+    assertEquals("Got back incorrect number of rows from scan: " + keyPrefix1, 0,
+        getNumberOfRows(keyPrefix1, value2, this.region));
+    assertEquals("Got back incorrect number of rows from scan: " + keyPrefix2, 0,
+        getNumberOfRows(keyPrefix2, value2, this.region));
+    assertEquals("Got back incorrect number of rows from scan: " + keyPrefix3, 0,
+        getNumberOfRows(keyPrefix3, value2, this.region));
   }
 
   @Test
@@ -1398,9 +1377,6 @@ public class TestHRegion {
       region.append(append);
     } catch (IOException e) {
       exceptionCaught = true;
-    } finally {
-      HBaseTestingUtility.closeRegionAndWAL(this.region);
-      this.region = null;
     }
     assertTrue(exceptionCaught == true);
   }
@@ -1417,9 +1393,6 @@ public class TestHRegion {
       region.increment(inc);
     } catch (IOException e) {
       exceptionCaught = true;
-    } finally {
-      HBaseTestingUtility.closeRegionAndWAL(this.region);
-      this.region = null;
     }
     assertTrue(exceptionCaught == true);
   }
@@ -1501,130 +1474,115 @@ public class TestHRegion {
   public void testFamilyWithAndWithoutColon() throws Exception {
     byte[] cf = Bytes.toBytes(COLUMN_FAMILY);
     this.region = initHRegion(tableName, method, CONF, cf);
+    Put p = new Put(tableName.toBytes());
+    byte[] cfwithcolon = Bytes.toBytes(COLUMN_FAMILY + ":");
+    p.addColumn(cfwithcolon, cfwithcolon, cfwithcolon);
+    boolean exception = false;
     try {
-      Put p = new Put(tableName.toBytes());
-      byte[] cfwithcolon = Bytes.toBytes(COLUMN_FAMILY + ":");
-      p.addColumn(cfwithcolon, cfwithcolon, cfwithcolon);
-      boolean exception = false;
-      try {
-        this.region.put(p);
-      } catch (NoSuchColumnFamilyException e) {
-        exception = true;
-      }
-      assertTrue(exception);
-    } finally {
-      HBaseTestingUtility.closeRegionAndWAL(this.region);
-      this.region = null;
+      this.region.put(p);
+    } catch (NoSuchColumnFamilyException e) {
+      exception = true;
     }
+    assertTrue(exception);
   }
 
   @Test
   public void testBatchPut_whileNoRowLocksHeld() throws IOException {
     final Put[] puts = new Put[10];
     MetricsWALSource source = CompatibilitySingletonFactory.getInstance(MetricsWALSource.class);
-    try {
-      long syncs = prepareRegionForBachPut(puts, source, false);
+    long syncs = prepareRegionForBachPut(puts, source, false);
 
-      OperationStatus[] codes = this.region.batchMutate(puts);
-      assertEquals(10, codes.length);
-      for (int i = 0; i < 10; i++) {
-        assertEquals(OperationStatusCode.SUCCESS, codes[i].getOperationStatusCode());
-      }
-      metricsAssertHelper.assertCounter("syncTimeNumOps", syncs + 1, source);
-
-      LOG.info("Next a batch put with one invalid family");
-      puts[5].addColumn(Bytes.toBytes("BAD_CF"), qual, value);
-      codes = this.region.batchMutate(puts);
-      assertEquals(10, codes.length);
-      for (int i = 0; i < 10; i++) {
-        assertEquals((i == 5) ? OperationStatusCode.BAD_FAMILY : OperationStatusCode.SUCCESS,
-            codes[i].getOperationStatusCode());
-      }
+    OperationStatus[] codes = this.region.batchMutate(puts);
+    assertEquals(10, codes.length);
+    for (int i = 0; i < 10; i++) {
+      assertEquals(OperationStatusCode.SUCCESS, codes[i].getOperationStatusCode());
+    }
+    metricsAssertHelper.assertCounter("syncTimeNumOps", syncs + 1, source);
 
-      metricsAssertHelper.assertCounter("syncTimeNumOps", syncs + 2, source);
-    } finally {
-      HBaseTestingUtility.closeRegionAndWAL(this.region);
-      this.region = null;
+    LOG.info("Next a batch put with one invalid family");
+    puts[5].addColumn(Bytes.toBytes("BAD_CF"), qual, value);
+    codes = this.region.batchMutate(puts);
+    assertEquals(10, codes.length);
+    for (int i = 0; i < 10; i++) {
+      assertEquals((i == 5) ? OperationStatusCode.BAD_FAMILY : OperationStatusCode.SUCCESS,
+          codes[i].getOperationStatusCode());
     }
+
+    metricsAssertHelper.assertCounter("syncTimeNumOps", syncs + 2, source);
   }
 
   @Test
   public void testBatchPut_whileMultipleRowLocksHeld() throws Exception {
     final Put[] puts = new Put[10];
     MetricsWALSource source = CompatibilitySingletonFactory.getInstance(MetricsWALSource.class);
-    try {
-      long syncs = prepareRegionForBachPut(puts, source, false);
+    long syncs = prepareRegionForBachPut(puts, source, false);
 
-      puts[5].addColumn(Bytes.toBytes("BAD_CF"), qual, value);
+    puts[5].addColumn(Bytes.toBytes("BAD_CF"), qual, value);
 
-      LOG.info("batchPut will have to break into four batches to avoid row locks");
-      RowLock rowLock1 = region.getRowLock(Bytes.toBytes("row_2"));
-      RowLock rowLock2 = region.getRowLock(Bytes.toBytes("row_1"));
-      RowLock rowLock3 = region.getRowLock(Bytes.toBytes("row_3"));
-      RowLock rowLock4 = region.getRowLock(Bytes.toBytes("row_3"), true);
+    LOG.info("batchPut will have to break into four batches to avoid row locks");
+    RowLock rowLock1 = region.getRowLock(Bytes.toBytes("row_2"));
+    RowLock rowLock2 = region.getRowLock(Bytes.toBytes("row_1"));
+    RowLock rowLock3 = region.getRowLock(Bytes.toBytes("row_3"));
+    RowLock rowLock4 = region.getRowLock(Bytes.toBytes("row_3"), true);
 
-      MultithreadedTestUtil.TestContext ctx = new MultithreadedTestUtil.TestContext(CONF);
-      final AtomicReference<OperationStatus[]> retFromThread = new AtomicReference<>();
-      final CountDownLatch startingPuts = new CountDownLatch(1);
-      final CountDownLatch startingClose = new CountDownLatch(1);
-      TestThread putter = new TestThread(ctx) {
-        @Override
-        public void doWork() throws IOException {
-          startingPuts.countDown();
-          retFromThread.set(region.batchMutate(puts));
-        }
-      };
-      LOG.info("...starting put thread while holding locks");
-      ctx.addThread(putter);
-      ctx.startThreads();
-
-      // Now attempt to close the region from another thread.  Prior to HBASE-12565
-      // this would cause the in-progress batchMutate operation to to fail with
-      // exception because it use to release and re-acquire the close-guard lock
-      // between batches.  Caller then didn't get status indicating which writes succeeded.
-      // We now expect this thread to block until the batchMutate call finishes.
-      Thread regionCloseThread = new TestThread(ctx) {
-        @Override
-        public void doWork() {
-          try {
-            startingPuts.await();
-            // Give some time for the batch mutate to get in.
-            // We don't want to race with the mutate
-            Thread.sleep(10);
-            startingClose.countDown();
-            HBaseTestingUtility.closeRegionAndWAL(region);
-          } catch (IOException e) {
-            throw new RuntimeException(e);
-          } catch (InterruptedException e) {
-            throw new RuntimeException(e);
-          }
+    MultithreadedTestUtil.TestContext ctx = new MultithreadedTestUtil.TestContext(CONF);
+    final AtomicReference<OperationStatus[]> retFromThread = new AtomicReference<>();
+    final CountDownLatch startingPuts = new CountDownLatch(1);
+    final CountDownLatch startingClose = new CountDownLatch(1);
+    TestThread putter = new TestThread(ctx) {
+      @Override
+      public void doWork() throws IOException {
+        startingPuts.countDown();
+        retFromThread.set(region.batchMutate(puts));
+      }
+    };
+    LOG.info("...starting put thread while holding locks");
+    ctx.addThread(putter);
+    ctx.startThreads();
+
+    // Now attempt to close the region from another thread.  Prior to HBASE-12565
+    // this would cause the in-progress batchMutate operation to to fail with
+    // exception because it use to release and re-acquire the close-guard lock
+    // between batches.  Caller then didn't get status indicating which writes succeeded.
+    // We now expect this thread to block until the batchMutate call finishes.
+    Thread regionCloseThread = new TestThread(ctx) {
+      @Override
+      public void doWork() {
+        try {
+          startingPuts.await();
+          // Give some time for the batch mutate to get in.
+          // We don't want to race with the mutate
+          Thread.sleep(10);
+          startingClose.countDown();
+          HBaseTestingUtility.closeRegionAndWAL(region);
+        } catch (IOException e) {
+          throw new RuntimeException(e);
+        } catch (InterruptedException e) {
+          throw new RuntimeException(e);
         }
-      };
-      regionCloseThread.start();
+      }
+    };
+    regionCloseThread.start();
 
-      startingClose.await();
-      startingPuts.await();
-      Thread.sleep(100);
-      LOG.info("...releasing row lock 1, which should let put thread continue");
-      rowLock1.release();
-      rowLock2.release();
-      rowLock3.release();
-      waitForCounter(source, "syncTimeNumOps", syncs + 1);
+    startingClose.await();
+    startingPuts.await();
+    Thread.sleep(100);
+    LOG.info("...releasing row lock 1, which should let put thread continue");
+    rowLock1.release();
+    rowLock2.release();
+    rowLock3.release();
+    waitForCounter(source, "syncTimeNumOps", syncs + 1);
 
-      LOG.info("...joining on put thread");
-      ctx.stop();
-      regionCloseThread.join();
+    LOG.info("...joining on put thread");
+    ctx.stop();
+    regionCloseThread.join();
 
-      OperationStatus[] codes = retFromThread.get();
-      for (int i = 0; i < codes.length; i++) {
-        assertEquals((i == 5) ? OperationStatusCode.BAD_FAMILY : OperationStatusCode.SUCCESS,
-            codes[i].getOperationStatusCode());
-      }
-      rowLock4.release();
-    } finally {
-      HBaseTestingUtility.closeRegionAndWAL(this.region);
-      this.region = null;
+    OperationStatus[] codes = retFromThread.get();
+    for (int i = 0; i < codes.length; i++) {
+      assertEquals((i == 5) ? OperationStatusCode.BAD_FAMILY : OperationStatusCode.SUCCESS,
+          codes[i].getOperationStatusCode());
     }
+    rowLock4.release();
   }
 
   private void waitForCounter(MetricsWALSource source, String metricName, long expectedCount)
@@ -1644,69 +1602,64 @@ public class TestHRegion {
   public void testAtomicBatchPut() throws IOException {
     final Put[] puts = new Put[10];
     MetricsWALSource source = CompatibilitySingletonFactory.getInstance(MetricsWALSource.class);
-    try {
-      long syncs = prepareRegionForBachPut(puts, source, false);
-
-      // 1. Straight forward case, should succeed
-      MutationBatchOperation batchOp = new MutationBatchOperation(region, puts, true,
-          HConstants.NO_NONCE, HConstants.NO_NONCE);
-      OperationStatus[] codes = this.region.batchMutate(batchOp);
-      assertEquals(10, codes.length);
-      for (int i = 0; i < 10; i++) {
-        assertEquals(OperationStatusCode.SUCCESS, codes[i].getOperationStatusCode());
-      }
-      metricsAssertHelper.assertCounter("syncTimeNumOps", syncs + 1, source);
-
-      // 2. Failed to get lock
-      RowLock lock = region.getRowLock(Bytes.toBytes("row_" + 3));
-      // Method {@link HRegion#getRowLock(byte[])} is reentrant. As 'row_3' is locked in this
-      // thread, need to run {@link HRegion#batchMutate(HRegion.BatchOperation)} in different thread
-      MultithreadedTestUtil.TestContext ctx = new MultithreadedTestUtil.TestContext(CONF);
-      final AtomicReference<IOException> retFromThread = new AtomicReference<>();
-      final CountDownLatch finishedPuts = new CountDownLatch(1);
-      final MutationBatchOperation finalBatchOp = new MutationBatchOperation(region, puts, true,
-          HConstants
-          .NO_NONCE,
-          HConstants.NO_NONCE);
-      TestThread putter = new TestThread(ctx) {
-        @Override
-        public void doWork() throws IOException {
-          try {
-            region.batchMutate(finalBatchOp);
-          } catch (IOException ioe) {
-            LOG.error("test failed!", ioe);
-            retFromThread.set(ioe);
-          }
-          finishedPuts.countDown();
-        }
-      };
-      LOG.info("...starting put thread while holding locks");
-      ctx.addThread(putter);
-      ctx.startThreads();
-      LOG.info("...waiting for batch puts while holding locks");
-      try {
-        finishedPuts.await();
-      } catch (InterruptedException e) {
-        LOG.error("Interrupted!", e);
-      } finally {
-        if (lock != null) {
-          lock.release();
+    long syncs = prepareRegionForBachPut(puts, source, false);
+
+    // 1. Straight forward case, should succeed
+    MutationBatchOperation batchOp = new MutationBatchOperation(region, puts, true,
+        HConstants.NO_NONCE, HConstants.NO_NONCE);
+    OperationStatus[] codes = this.region.batchMutate(batchOp);
+    assertEquals(10, codes.length);
+    for (int i = 0; i < 10; i++) {
+      assertEquals(OperationStatusCode.SUCCESS, codes[i].getOperationStatusCode());
+    }
+    metricsAssertHelper.assertCounter("syncTimeNumOps", syncs + 1, source);
+
+    // 2. Failed to get lock
+    RowLock lock = region.getRowLock(Bytes.toBytes("row_" + 3));
+    // Method {@link HRegion#getRowLock(byte[])} is reentrant. As 'row_3' is locked in this
+    // thread, need to run {@link HRegion#batchMutate(HRegion.BatchOperation)} in different thread
+    MultithreadedTestUtil.TestContext ctx = new MultithreadedTestUtil.TestContext(CONF);
+    final AtomicReference<IOException> retFromThread = new AtomicReference<>();
+    final CountDownLatch finishedPuts = new CountDownLatch(1);
+    final MutationBatchOperation finalBatchOp = new MutationBatchOperation(region, puts, true,
+        HConstants
+        .NO_NONCE,
+        HConstants.NO_NONCE);
+    TestThread putter = new TestThread(ctx) {
+      @Override
+      public void doWork() throws IOException {
+        try {
+          region.batchMutate(finalBatchOp);
+        } catch (IOException ioe) {
+          LOG.error("test failed!", ioe);
+          retFromThread.set(ioe);
         }
+        finishedPuts.countDown();
       }
-      assertNotNull(retFromThread.get());
-      metricsAssertHelper.assertCounter("syncTimeNumOps", syncs + 1, source);
-
-      // 3. Exception thrown in validation
-      LOG.info("Next a batch put with one invalid family");
-      puts[5].addColumn(Bytes.toBytes("BAD_CF"), qual, value);
-      batchOp = new MutationBatchOperation(region, puts, true, HConstants.NO_NONCE,
-          HConstants.NO_NONCE);
-      thrown.expect(NoSuchColumnFamilyException.class);
-      this.region.batchMutate(batchOp);
+    };
+    LOG.info("...starting put thread while holding locks");
+    ctx.addThread(putter);
+    ctx.startThreads();
+    LOG.info("...waiting for batch puts while holding locks");
+    try {
+      finishedPuts.await();
+    } catch (InterruptedException e) {
+      LOG.error("Interrupted!", e);
     } finally {
-      HBaseTestingUtility.closeRegionAndWAL(this.region);
-      this.region = null;
+      if (lock != null) {
+        lock.release();
+      }
     }
+    assertNotNull(retFromThread.get());
+    metricsAssertHelper.assertCounter("syncTimeNumOps", syncs + 1, source);
+
+    // 3. Exception thrown in validation
+    LOG.info("Next a batch put with one invalid family");
+    puts[5].addColumn(Bytes.toBytes("BAD_CF"), qual, value);
+    batchOp = new MutationBatchOperation(region, puts, true, HConstants.NO_NONCE,
+        HConstants.NO_NONCE);
+    thrown.expect(NoSuchColumnFamilyException.class);
+    this.region.batchMutate(batchOp);
   }
 
   @Test
@@ -1716,19 +1669,14 @@ public class TestHRegion {
     final Put[] puts = new Put[10];
     MetricsWALSource source = CompatibilitySingletonFactory.getInstance(MetricsWALSource.class);
 
-    try {
-      long syncs = prepareRegionForBachPut(puts, source, true);
+    long syncs = prepareRegionForBachPut(puts, source, true);
 
-      OperationStatus[] codes = this.region.batchMutate(puts);
-      assertEquals(10, codes.length);
-      for (int i = 0; i < 10; i++) {
-        assertEquals(OperationStatusCode.SANITY_CHECK_FAILURE, codes[i].getOperationStatusCode());
-      }
-      metricsAssertHelper.assertCounter("syncTimeNumOps", syncs, source);
-    } finally {
-      HBaseTestingUtility.closeRegionAndWAL(this.region);
-      this.region = null;
+    OperationStatus[] codes = this.region.batchMutate(puts);
+    assertEquals(10, codes.length);
+    for (int i = 0; i < 10; i++) {
+      assertEquals(OperationStatusCode.SANITY_CHECK_FAILURE, codes[i].getOperationStatusCode());
     }
+    metricsAssertHelper.assertCounter("syncTimeNumOps", syncs, source);
   }
 
   /**
@@ -1764,67 +1712,62 @@ public class TestHRegion {
 
     // Setting up region
     this.region = initHRegion(tableName, method, CONF, fam1);
-    try {
-      // Putting empty data in key
-      Put put = new Put(row1);
-      put.addColumn(fam1, qf1, emptyVal);
-
-      // checkAndPut with empty value
-      boolean res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.EQUAL, new BinaryComparator(
-          emptyVal), put);
-      assertTrue(res);
-
-      // Putting data in key
-      put = new Put(row1);
-      put.addColumn(fam1, qf1, val1);
-
-      // checkAndPut with correct value
-      res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.EQUAL, new BinaryComparator(emptyVal),
-          put);
-      assertTrue(res);
-
-      // not empty anymore
-      res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.EQUAL, new BinaryComparator(emptyVal),
-          put);
-      assertFalse(res);
-
-      Delete delete = new Delete(row1);
-      delete.addColumn(fam1, qf1);
-      res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.EQUAL, new BinaryComparator(emptyVal),
-          delete);
-      assertFalse(res);
-
-      put = new Put(row1);
-      put.addColumn(fam1, qf1, val2);
-      // checkAndPut with correct value
-      res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.EQUAL, new BinaryComparator(val1),
-          put);
-      assertTrue(res);
-
-      // checkAndDelete with correct value
-      delete = new Delete(row1);
-      delete.addColumn(fam1, qf1);
-      delete.addColumn(fam1, qf1);
-      res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.EQUAL, new BinaryComparator(val2),
-          delete);
-      assertTrue(res);
-
-      delete = new Delete(row1);
-      res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.EQUAL, new BinaryComparator(emptyVal),
-          delete);
-      assertTrue(res);
-
-      // checkAndPut looking for a null value
-      put = new Put(row1);
-      put.addColumn(fam1, qf1, val1);
-
-      res = region
-          .checkAndMutate(row1, fam1, qf1, CompareOperator.EQUAL, new NullComparator(), put);
-      assertTrue(res);
-    } finally {
-      HBaseTestingUtility.closeRegionAndWAL(this.region);
-      this.region = null;
-    }
+    // Putting empty data in key
+    Put put = new Put(row1);
+    put.addColumn(fam1, qf1, emptyVal);
+
+    // checkAndPut with empty value
+    boolean res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.EQUAL,
+        new BinaryComparator(emptyVal), put);
+    assertTrue(res);
+
+    // Putting data in key
+    put = new Put(row1);
+    put.addColumn(fam1, qf1, val1);
+
+    // checkAndPut with correct value
+    res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.EQUAL,
+        new BinaryComparator(emptyVal), put);
+    assertTrue(res);
+
+    // not empty anymore
+    res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.EQUAL,
+        new BinaryComparator(emptyVal), put);
+    assertFalse(res);
+
+    Delete delete = new Delete(row1);
+    delete.addColumn(fam1, qf1);
+    res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.EQUAL,
+        new BinaryComparator(emptyVal), delete);
+    assertFalse(res);
+
+    put = new Put(row1);
+    put.addColumn(fam1, qf1, val2);
+    // checkAndPut with correct value
+    res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.EQUAL,
+        new BinaryComparator(val1), put);
+    assertTrue(res);
+
+    // checkAndDelete with correct value
+    delete = new Delete(row1);
+    delete.addColumn(fam1, qf1);
+    delete.addColumn(fam1, qf1);
+    res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.EQUAL,
+        new BinaryComparator(val2), delete);
+    assertTrue(res);
+
+    delete = new Delete(row1);
+    res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.EQUAL,
+        new BinaryComparator(emptyVal), delete);
+    assertTrue(res);
+
+    // checkAndPut looking for a null value
+    put = new Put(row1);
+    put.addColumn(fam1, qf1, val1);
+
+    res = region
+        .checkAndMutate(row1, fam1, qf1, CompareOperator.EQUAL, new NullComparator(), put);
+    assertTrue(res);
   }
 
   @Test
@@ -1839,46 +1782,41 @@ public class TestHRegion {
 
     // Setting up region
     this.region = initHRegion(tableName, method, CONF, fam1);
-    try {
-      // Putting data in key
-      Put put = new Put(row1);
-      put.addColumn(fam1, qf1, val1);
-      region.put(put);
+    // Putting data in key
+    Put put = new Put(row1);
+    put.addColumn(fam1, qf1, val1);
+    region.put(put);
 
-      // checkAndPut with wrong value
-      boolean res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.EQUAL, new BinaryComparator(
-          val2), put);
-      assertEquals(false, res);
-
-      // checkAndDelete with wrong value
-      Delete delete = new Delete(row1);
-      delete.addFamily(fam1);
-      res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.EQUAL, new BinaryComparator(val2),
-          put);
-      assertEquals(false, res);
-
-      // Putting data in key
-      put = new Put(row1);
-      put.addColumn(fam1, qf1, Bytes.toBytes(bd1));
-      region.put(put);
+    // checkAndPut with wrong value
+    boolean res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.EQUAL,
+        new BinaryComparator(val2), put);
+    assertEquals(false, res);
 
-      // checkAndPut with wrong value
-      res =
-          region.checkAndMutate(row1, fam1, qf1, CompareOperator.EQUAL, new BigDecimalComparator(
-              bd2), put);
-      assertEquals(false, res);
-
-      // checkAndDelete with wrong value
-      delete = new Delete(row1);
-      delete.addFamily(fam1);
-      res =
-          region.checkAndMutate(row1, fam1, qf1, CompareOperator.EQUAL, new BigDecimalComparator(
-              bd2), put);
-      assertEquals(false, res);
-    } finally {
-      HBaseTestingUtility.closeRegionAndWAL(this.region);
-      this.region = null;
-    }
+    // checkAndDelete with wrong value
+    Delete delete = new Delete(row1);
+    delete.addFamily(fam1);
+    res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.EQUAL,
+        new BinaryComparator(val2), put);
+    assertEquals(false, res);
+
+    // Putting data in key
+    put = new Put(row1);
+    put.addColumn(fam1, qf1, Bytes.toBytes(bd1));
+    region.put(put);
+
+    // checkAndPut with wrong value
+    res =
+        region.checkAndMutate(row1, fam1, qf1, CompareOperator.EQUAL,
+            new BigDecimalComparator(bd2), put);
+    assertEquals(false, res);
+
+    // checkAndDelete with wrong value
+    delete = new Delete(row1);
+    delete.addFamily(fam1);
+    res =
+        region.checkAndMutate(row1, fam1, qf1, CompareOperator.EQUAL,
+            new BigDecimalComparator(bd2), put);
+    assertEquals(false, res);
   }
 
   @Test
@@ -1891,46 +1829,41 @@ public class TestHRegion {
 
     // Setting up region
     this.region = initHRegion(tableName, method, CONF, fam1);
-    try {
-      // Putting data in key
-      Put put = new Put(row1);
-      put.addColumn(fam1, qf1, val1);
-      region.put(put);
+    // Putting data in key
+    Put put = new Put(row1);
+    put.addColumn(fam1, qf1, val1);
+    region.put(put);
 
-      // checkAndPut with correct value
-      boolean res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.EQUAL, new BinaryComparator(
-          val1), put);
-      assertEquals(true, res);
-
-      // checkAndDelete with correct value
-      Delete delete = new Delete(row1);
-      delete.addColumn(fam1, qf1);
-      res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.EQUAL, new BinaryComparator(val1),
-          delete);
-      assertEquals(true, res);
-
-      // Putting data in key
-      put = new Put(row1);
-      put.addColumn(fam1, qf1, Bytes.toBytes(bd1));
-      region.put(put);
+    // checkAndPut with correct value
+    boolean res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.EQUAL,
+        new BinaryComparator(val1), put);
+    assertEquals(true, res);
+
+    // checkAndDelete with correct value
+    Delete delete = new Delete(row1);
+    delete.addColumn(fam1, qf1);
+    res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.EQUAL, new BinaryComparator(val1),
+        delete);
+    assertEquals(true, res);
+
+    // Putting data in key
+    put = new Put(row1);
+    put.addColumn(fam1, qf1, Bytes.toBytes(bd1));
+    region.put(put);
 
-      // checkAndPut with correct value
-      res =
-          region.checkAndMutate(row1, fam1, qf1, CompareOperator.EQUAL, new BigDecimalComparator(
-              bd1), put);
-      assertEquals(true, res);
-
-      // checkAndDelete with correct value
-      delete = new Delete(row1);
-      delete.addColumn(fam1, qf1);
-      res =
-          region.checkAndMutate(row1, fam1, qf1, CompareOperator.EQUAL, new BigDecimalComparator(
-              bd1), delete);
-      assertEquals(true, res);
-    } finally {
-      HBaseTestingUtility.closeRegionAndWAL(this.region);
-      this.region = null;
-    }
+    // checkAndPut with correct value
+    res =
+        region.checkAndMutate(row1, fam1, qf1, CompareOperator.EQUAL, new BigDecimalComparator(
+            bd1), put);
+    assertEquals(true, res);
+
+    // checkAndDelete with correct value
+    delete = new Delete(row1);
+    delete.addColumn(fam1, qf1);
+    res =
+        region.checkAndMutate(row1, fam1, qf1, CompareOperator.EQUAL, new BigDecimalComparator(
+            bd1), delete);
+    assertEquals(true, res);
   }
 
   @Test
@@ -1945,86 +1878,81 @@ public class TestHRegion {
 
     // Setting up region
     this.region = initHRegion(tableName, method, CONF, fam1);
-    try {
-      // Putting val3 in key
-      Put put = new Put(row1);
-      put.addColumn(fam1, qf1, val3);
-      region.put(put);
+    // Putting val3 in key
+    Put put = new Put(row1);
+    put.addColumn(fam1, qf1, val3);
+    region.put(put);
 
-      // Test CompareOp.LESS: original = val3, compare with val3, fail
-      boolean res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.LESS,
-          new BinaryComparator(val3), put);
-      assertEquals(false, res);
-
-      // Test CompareOp.LESS: original = val3, compare with val4, fail
-      res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.LESS,
-          new BinaryComparator(val4), put);
-      assertEquals(false, res);
-
-      // Test CompareOp.LESS: original = val3, compare with val2,
-      // succeed (now value = val2)
-      put = new Put(row1);
-      put.addColumn(fam1, qf1, val2);
-      res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.LESS,
-          new BinaryComparator(val2), put);
-      assertEquals(true, res);
-
-      // Test CompareOp.LESS_OR_EQUAL: original = val2, compare with val3, fail
-      res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.LESS_OR_EQUAL,
-          new BinaryComparator(val3), put);
-      assertEquals(false, res);
-
-      // Test CompareOp.LESS_OR_EQUAL: original = val2, compare with val2,
-      // succeed (value still = val2)
-      res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.LESS_OR_EQUAL,
-          new BinaryComparator(val2), put);
-      assertEquals(true, res);
-
-      // Test CompareOp.LESS_OR_EQUAL: original = val2, compare with val1,
-      // succeed (now value = val3)
-      put = new Put(row1);
-      put.addColumn(fam1, qf1, val3);
-      res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.LESS_OR_EQUAL,
-          new BinaryComparator(val1), put);
-      assertEquals(true, res);
-
-      // Test CompareOp.GREATER: original = val3, compare with val3, fail
-      res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.GREATER,
-          new BinaryComparator(val3), put);
-      assertEquals(false, res);
-
-      // Test CompareOp.GREATER: original = val3, compare with val2, fail
-      res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.GREATER,
-          new BinaryComparator(val2), put);
-      assertEquals(false, res);
-
-      // Test CompareOp.GREATER: original = val3, compare with val4,
-      // succeed (now value = val2)
-      put = new Put(row1);
-      put.addColumn(fam1, qf1, val2);
-      res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.GREATER,
-          new BinaryComparator(val4), put);
-      assertEquals(true, res);
-
-      // Test CompareOp.GREATER_OR_EQUAL: original = val2, compare with val1, fail
-      res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.GREATER_OR_EQUAL,
-          new BinaryComparator(val1), put);
-      assertEquals(false, res);
-
-      // Test CompareOp.GREATER_OR_EQUAL: original = val2, compare with val2,
-      // succeed (value still = val2)
-      res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.GREATER_OR_EQUAL,
-          new BinaryComparator(val2), put);
-      assertEquals(true, res);
-
-      // Test CompareOp.GREATER_OR_EQUAL: original = val2, compare with val3, succeed
-      res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.GREATER_OR_EQUAL,
-          new BinaryComparator(val3), put);
-      assertEquals(true, res);
-    } finally {
-      HBaseTestingUtility.closeRegionAndWAL(this.region);
-      this.region = null;
-    }
+    // Test CompareOp.LESS: original = val3, compare with val3, fail
+    boolean res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.LESS,
+        new BinaryComparator(val3), put);
+    assertEquals(false, res);
+
+    // Test CompareOp.LESS: original = val3, compare with val4, fail
+    res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.LESS,
+        new BinaryComparator(val4), put);
+    assertEquals(false, res);
+
+    // Test CompareOp.LESS: original = val3, compare with val2,
+    // succeed (now value = val2)
+    put = new Put(row1);
+    put.addColumn(fam1, qf1, val2);
+    res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.LESS,
+        new BinaryComparator(val2), put);
+    assertEquals(true, res);
+
+    // Test CompareOp.LESS_OR_EQUAL: original = val2, compare with val3, fail
+    res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.LESS_OR_EQUAL,
+        new BinaryComparator(val3), put);
+    assertEquals(false, res);
+
+    // Test CompareOp.LESS_OR_EQUAL: original = val2, compare with val2,
+    // succeed (value still = val2)
+    res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.LESS_OR_EQUAL,
+        new BinaryComparator(val2), put);
+    assertEquals(true, res);
+
+    // Test CompareOp.LESS_OR_EQUAL: original = val2, compare with val1,
+    // succeed (now value = val3)
+    put = new Put(row1);
+    put.addColumn(fam1, qf1, val3);
+    res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.LESS_OR_EQUAL,
+        new BinaryComparator(val1), put);
+    assertEquals(true, res);
+
+    // Test CompareOp.GREATER: original = val3, compare with val3, fail
+    res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.GREATER,
+        new BinaryComparator(val3), put);
+    assertEquals(false, res);
+
+    // Test CompareOp.GREATER: original = val3, compare with val2, fail
+    res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.GREATER,
+        new BinaryComparator(val2), put);
+    assertEquals(false, res);
+
+    // Test CompareOp.GREATER: original = val3, compare with val4,
+    // succeed (now value = val2)
+    put = new Put(row1);
+    put.addColumn(fam1, qf1, val2);
+    res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.GREATER,
+        new BinaryComparator(val4), put);
+    assertEquals(true, res);
+
+    // Test CompareOp.GREATER_OR_EQUAL: original = val2, compare with val1, fail
+    res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.GREATER_OR_EQUAL,
+        new BinaryComparator(val1), put);
+    assertEquals(false, res);
+
+    // Test CompareOp.GREATER_OR_EQUAL: original = val2, compare with val2,
+    // succeed (value still = val2)
+    res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.GREATER_OR_EQUAL,
+        new BinaryComparator(val2), put);
+    assertEquals(true, res);
+
+    // Test CompareOp.GREATER_OR_EQUAL: original = val2, compare with val3, succeed
+    res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.GREATER_OR_EQUAL,
+        new BinaryComparator(val3), put);
+    assertEquals(true, res);
   }
 
   @Test
@@ -2040,55 +1968,45 @@ public class TestHRegion {
 
     // Setting up region
     this.region = initHRegion(tableName, method, CONF, families);
-    try {
-      // Putting data in the key to check
-      Put put = new Put(row1);
-      put.addColumn(fam1, qf1, val1);
-      region.put(put);
+    // Putting data in the key to check
+    Put put = new Put(row1);
+    put.addColumn(fam1, qf1, val1);
+    region.put(put);
 
-      // Creating put to add
-      long ts = System.currentTimeMillis();
-      KeyValue kv = new KeyValue(row1, fam2, qf1, ts, KeyValue.Type.Put, val2);
-      put = new Put(row1);
-      put.add(kv);
+    // Creating put to add
+    long ts = System.currentTimeMillis();
+    KeyValue kv = new KeyValue(row1, fam2, qf1, ts, KeyValue.Type.Put, val2);
+    put = new Put(row1);
+    put.add(kv);
 
-      // checkAndPut with wrong value
-      boolean res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.EQUAL, new BinaryComparator(
-          val1), put);
-      assertEquals(true, res);
+    // checkAndPut with wrong value
+    boolean res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.EQUAL,
+        new BinaryComparator(val1), put);
+    assertEquals(true, res);
 
-      Get get = new Get(row1);
-      get.addColumn(fam2, qf1);
-      Cell[] actual = region.get(get).rawCells();
+    Get get = new Get(row1);
+    get.addColumn(fam2, qf1);
+    Cell[] actual = region.get(get).rawCells();
 
-      Cell[] expected = { kv };
+    Cell[] expected = { kv };
 
-      assertEquals(expected.length, actual.length);
-      for (int i = 0; i < actual.length; i++) {
-        assertEquals(expected[i], actual[i]);
-      }
-    } finally {
-      HBaseTestingUtility.closeRegionAndWAL(this.region);
-      this.region = null;
+    assertEquals(expected.length, actual.length);
+    for (int i = 0; i < actual.length; i++) {
+      assertEquals(expected[i], actual[i]);
     }
   }
 
   @Test
   public void testCheckAndPut_wrongRowInPut() throws IOException {
     this.region = initHRegion(tableName, method, CONF, COLUMNS);
+    Put put = new Put(row2);
+    put.addColumn(fam1, qual1, value1);
     try {
-      Put put = new Put(row2);
-      put.addColumn(fam1, qual1, value1);
-      try {
-        region.checkAndMutate(row, fam1, qual1, CompareOperator.EQUAL,
-            new BinaryComparator(value2), put);
-        fail();
-      } catch (org.apache.hadoop.hbase.DoNotRetryIOException expected) {
-        // expected exception.
-      }
-    } finally {
-      HBaseTestingUtility.closeRegionAndWAL(this.region);
-      this.region = null;
+      region.checkAndMutate(row, fam1, qual1, CompareOperator.EQUAL,
+          new BinaryComparator(value2), put);
+      fail();
+    } catch (org.apache.hadoop.hbase.DoNotRetryIOException expected) {
+      // expected exception.
     }
   }
 
@@ -2109,63 +2027,58 @@ public class TestHRegion {
 
     // Setting up region
     this.region = initHRegion(tableName, method, CONF, families);
-    try {
-      // Put content
-      Put put = new Put(row1);
-      put.addColumn(fam1, qf1, val1);
-      region.put(put);
-      Threads.sleep(2);
-
-      put = new Put(row1);
-      put.addColumn(fam1, qf1, val2);
-      put.addColumn(fam2, qf1, val3);
-      put.addColumn(fam2, qf2, val2);
-      put.addColumn(fam2, qf3, val1);
-      put.addColumn(fam1, qf3, val1);
-      region.put(put);
+    // Put content
+    Put put = new Put(row1);
+    put.addColumn(fam1, qf1, val1);
+    region.put(put);
+    Threads.sleep(2);
+
+    put = new Put(row1);
+    put.addColumn(fam1, qf1, val2);
+    put.addColumn(fam2, qf1, val3);
+    put.addColumn(fam2, qf2, val2);
+    put.addColumn(fam2, qf3, val1);
+    put.addColumn(fam1, qf3, val1);
+    region.put(put);
 
-      // Multi-column delete
-      Delete delete = new Delete(row1);
-      delete.addColumn(fam1, qf1);
-      delete.addColumn(fam2, qf1);
-      delete.addColumn(fam1, qf3);
-      boolean res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.EQUAL, new BinaryComparator(
-          val2), delete);
-      assertEquals(true, res);
-
-      Get get = new Get(row1);
-      get.addColumn(fam1, qf1);
-      get.addColumn(fam1, qf3);
-      get.addColumn(fam2, qf2);
-      Result r = region.get(get);
-      assertEquals(2, r.size());
-      assertArrayEquals(val1, r.getValue(fam1, qf1));
-      assertArrayEquals(val2, r.getValue(fam2, qf2));
-
-      // Family delete
-      delete = new Delete(row1);
-      delete.addFamily(fam2);
-      res = region.checkAndMutate(row1, fam2, qf1, CompareOperator.EQUAL, new BinaryComparator(emptyVal),
-          delete);
-      assertEquals(true, res);
-
-      get = new Get(row1);
-      r = region.get(get);
-      assertEquals(1, r.size());
-      assertArrayEquals(val1, r.getValue(fam1, qf1));
-
-      // Row delete
-      delete = new Delete(row1);
-      res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.EQUAL, new BinaryComparator(val1),
-          delete);
-      assertEquals(true, res);
-      get = new Get(row1);
-      r = region.get(get);
-      assertEquals(0, r.size());
-    } finally {
-      HBaseTestingUtility.closeRegionAndWAL(this.region);
-      this.region = null;
-    }
+    // Multi-column delete
+    Delete delete = new Delete(row1);
+    delete.addColumn(fam1, qf1);
+    delete.addColumn(fam2, qf1);
+    delete.addColumn(fam1, qf3);
+    boolean res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.EQUAL,
+        new BinaryComparator(val2), delete);
+    assertEquals(true, res);
+
+    Get get = new Get(row1);
+    get.addColumn(fam1, qf1);
+    get.addColumn(fam1, qf3);
+    get.addColumn(fam2, qf2);
+    Result r = region.get(get);
+    assertEquals(2, r.size());
+    assertArrayEquals(val1, r.getValue(fam1, qf1));
+    assertArrayEquals(val2, r.getValue(fam2, qf2));
+
+    // Family delete
+    delete = new Delete(row1);
+    delete.addFamily(fam2);
+    res = region.checkAndMutate(row1, fam2, qf1, CompareOperator.EQUAL,
+        new BinaryComparator(emptyVal), delete);
+    assertEquals(true, res);
+
+    get = new Get(row1);
+    r = region.get(get);
+    assertEquals(1, r.size());
+    assertArrayEquals(val1, r.getValue(fam1, qf1));
+
+    // Row delete
+    delete = new Delete(row1);
+    res = region.checkAndMutate(row1, fam1, qf1, CompareOperator.EQUAL, new BinaryComparator(val1),
+        delete);
+    assertEquals(true, res);
+    get = new Get(row1);
+    r = region.get(get);
+    assertEquals(0, r.size());
   }
 
   // ////////////////////////////////////////////////////////////////////////////
@@ -2183,23 +2096,18 @@ public class TestHRegion {
     put.addColumn(fam1, qual, 2, value);
 
     this.region = initHRegion(tableName, method, CONF, fam1);
-    try {
-      region.put(put);
+    region.put(put);
 
-      // We do support deleting more than 1 'latest' version
-      Delete delete = new Delete(row1);
-      delete.addColumn(fam1, qual);
-      delete.addColumn(fam1, qual);
-      region.delete(delete);
+    // We do support deleting more than 1 'latest' version
+    Delete delete = new Delete(row1);
+    delete.addColumn(fam1, qual);
+    delete.addColumn(fam1, qual);
+    region.delete(delete);
 
-      Get get = new Get(row1);
-      get.addFamily(fam1);
-      Result r = region.get(get);
-      assertEquals(0, r.size());
-    } finally {
-      HBaseTestingUtility.closeRegionAndWAL(this.region);
-      this.region = null;
-    }
+    Get get = new Get(row1);
+    get.addFamily(fam1);
+    Result r = region.get(get);
+    assertEquals(0, r.size());
   }
 
   @Test
@@ -2212,35 +2120,26 @@ public class TestHRegion {
 
     // Setting up region
     this.region = initHRegion(tableName, method, CONF, fam1, fam2, fam3);
+    List<Cell> kvs = new ArrayList<>();
+    kvs.add(new KeyValue(row1, fam4, null, null));
+
+    // testing existing family
+    byte[] family = fam2;
+    NavigableMap<byte[], List<Cell>> deleteMap = new TreeMap<>(Bytes.BYTES_COMPARATOR);
+    deleteMap.put(family, kvs);
+    region.delete(deleteMap, Durability.SYNC_WAL);
+
+    // testing non existing family
+    boolean ok = false;
+    family = fam4;
     try {
-      List<Cell> kvs = new ArrayList<>();
-      kvs.add(new KeyValue(row1, fam4, null, null));
-
-      // testing existing family
-      byte[] family = fam2;
-      try {
-        NavigableMap<byte[], List<Cell>> deleteMap = new TreeMap<>(Bytes.BYTES_COMPARATOR);
-        deleteMap.put(family, kvs);
-        region.delete(deleteMap, Durability.SYNC_WAL);
-      } catch (Exception e) {
-        fail("Family " + new String(family, StandardCharsets.UTF_8) + " does not exist");
-      }
-
-      // testing non existing family
-      boolean ok = false;
-      family = fam4;
-      try {
-        NavigableMap<byte[], List<Cell>> deleteMap = new TreeMap<>(Bytes.BYTES_COMPARATOR);
-        deleteMap.put(family, kvs);
-        region.delete(deleteMap, Durability.SYNC_WAL);
-      } catch (Exception e) {
-        ok = true;
-      }
-      assertTrue("Family " + new String(family, StandardCharsets.UTF_8) + " does exist", ok);
-    } finally {
-      HBaseTestingUtility.closeRegionAndWAL(this.region);
-      this.region = null;
+      deleteMap = new TreeMap<>(Bytes.BYTES_COMPARATOR);
+      deleteMap.put(family, kvs);
+      region.delete(deleteMap, Durability.SYNC_WAL);
+    } catch (Exception e) {
+      ok = true;
     }
+    assertTrue("Family " + new String(family, StandardCharsets.UTF_8) + " does exist", ok);
   }
 
   @Test
@@ -2248,66 +2147,61 @@ public class TestHRegion {
     byte[] fam = Bytes.toBytes("info");
     byte[][] families = { fam };
     this.region = initHRegion(tableName, method, CONF, families);
-    try {
-      EnvironmentEdgeManagerTestHelper.injectEdge(new IncrementingEnvironmentEdge());
+    EnvironmentEdgeManagerTestHelper.injectEdge(new IncrementingEnvironmentEdge());
 
-      byte[] row = Bytes.toBytes("table_name");
-      // column names
-      byte[] serverinfo = Bytes.toBytes("serverinfo");
-      byte[] splitA = Bytes.toBytes("splitA");
-      byte[] splitB = Bytes.toBytes("splitB");
+    byte[] row = Bytes.toBytes("table_name");
+    // column names
+    byte[] serverinfo = Bytes.toBytes("serverinfo");
+    byte[] splitA = Bytes.toBytes("splitA");
+    byte[] splitB = Bytes.toBytes("splitB");
 
-      // add some data:
-      Put put = new Put(row);
-      put.addColumn(fam, splitA, Bytes.toBytes("reference_A"));
-      region.put(put);
+    // add some data:
+    Put put = new Put(row);
+    put.addColumn(fam, splitA, Bytes.toBytes("reference_A"));
+    region.put(put);
 
-      put = new Put(row);
-      put.addColumn(fam, splitB, Bytes.toBytes("reference_B"));
-      region.put(put);
+    put = new Put(row);
+    put.addColumn(fam, splitB, Bytes.toBytes("reference_B"));
+    region.put(put);
 
-      put = new Put(row);
-      put.addColumn(fam, serverinfo, Bytes.toBytes("ip_address"));
-      region.put(put);
+    put = new Put(row);
+    put.addColumn(fam, serverinfo, Bytes.toBytes("ip_address"));
+    region.put(put);
+
+    // ok now delete a split:
+    Delete delete = new Delete(row);
+    delete.addColumns(fam, splitA);
+    region.delete(delete);
 
-      // ok now delete a split:
-      Delete delete = new Delete(row);
-      delete.addColumns(fam, splitA);
-      region.delete(delete);
+    // assert some things:
+    Get get = new Get(row).addColumn(fam, serverinfo);
+    Result result = region.get(get);
+    assertEquals(1, result.size());
 
-      // assert some things:
-      Get get = new Get(row).addColumn(fam, serverinfo);
-      Result result = region.get(get);
-      assertEquals(1, result.size());
+    get = new Get(row).addColumn(fam, splitA);
+    result = region.get(get);
+    assertEquals(0, result.size());
 
-      get = new Get(row).addColumn(fam, splitA);
-      result = region.get(get);
-      assertEquals(0, result.size());
+    get = new Get(row).addColumn(fam, splitB);
+    result = region.get(get);
+    assertEquals(1, result.size());
 
-      get = new Get(row).addColumn(fam, splitB);
-      result = region.get(get);
-      assertEquals(1, result.size());
+    // Assert that after a delete, I can put.
+    put = new Put(row);
+    put.addColumn(fam, splitA, Bytes.toBytes("reference_A"));
+    region.put(put);
+    get = new Get(row);
+    result = region.get(get);
+    assertEquals(3, result.size());
 
-      // Assert that after a delete, I can put.
-      put = new Put(row);
-      put.addColumn(fam, splitA, Bytes.toBytes("reference_A"));
-      region.put(put);
-      get = new Get(row);
-      result = region.get(get);
-      assertEquals(3, result.size());
-
-      // Now delete all... then test I can add stuff back
-      delete = new Delete(row);
-      region.delete(delete);
-      assertEquals(0, region.get(get).size());
-
-      region.put(new Put(row).addColumn(fam, splitA, Bytes.toBytes("reference_A")));
-      result = region.get(get);
-      assertEquals(1, result.size());
-    } finally {
-      HBaseTestingUtility.closeRegionAndWAL(this.region);
-      this.region = null;
-    }
+    // Now delete all... then test I can add stuff back
+    delete = new Delete(row);
+    region.delete(delete);
+    assertEquals(0, region.get(get).size());
+
+    region.put(new Put(row).addColumn(fam, splitA, Bytes.toBytes("reference_A")));
+    result = region.get(get);
+    assertEquals(1, result.size());
   }
 
   @Test
@@ -2315,37 +2209,32 @@ public class TestHRegion {
     byte[] fam = Bytes.toBytes("info");
     byte[][] families = { fam };
     this.region = initHRegion(tableName, method, CONF, families);
-    try {
-      byte[] row = Bytes.toBytes("table_name");
-      // column names
-      byte[] serverinfo = Bytes.toBytes("serverinfo");
-
-      // add data in the far future
-      Put put = new Put(row);
-      put.addColumn(fam, serverinfo, HConstants.LATEST_TIMESTAMP - 5, Bytes.toBytes("value"));
-      region.put(put);
+    byte[] row = Bytes.toBytes("table_name");
+    // column names
+    byte[] serverinfo = Bytes.toBytes("serverinfo");
 
-      // now delete something in the present
-      Delete delete = new Delete(row);
-      region.delete(delete);
+    // add data in the far future
+    Put put = new Put(row);
+    put.addColumn(fam, serverinfo, HConstants.LATEST_TIMESTAMP - 5, Bytes.toBytes("value"));
+    region.put(put);
 
-      // make sure we still see our data
-      Get get = new Get(row).addColumn(fam, serverinfo);
-      Result result = region.get(get);
-      assertEquals(1, result.size());
+    // now delete something in the present
+    Delete delete = new Delete(row);
+    region.delete(delete);
 
-      // delete the future row
-      delete = new Delete(row, HConstants.LATEST_TIMESTAMP - 3);
-      region.delete(delete);
+    // make sure we still see our data
+    Get get = new Get(row).addColumn(fam, serverinfo);
+    Result result = region.get(get);
+    assertEquals(1, result.size());
 
-      // make sure it is gone
-      get = new Get(row).addColumn(fam, serverinfo);
-      result = region.get(get);
-      assertEquals(0, result.size());
-    } finally {
-      HBaseTestingUtility.closeRegionAndWAL(this.region);
-      this.region = null;
-    }
+    // delete the future row
+    delete = new Delete(row, HConstants.LATEST_TIMESTAMP - 3);
+    region.delete(delete);
+
+    // make sure it is gone
+    get = new Get(row).addColumn(fam, serverinfo);
+    result = region.get(get);
+    assertEquals(0, result.size());
   }
 
   /**
@@ -2357,45 +2246,39 @@ public class TestHRegion {
     byte[] fam = Bytes.toBytes("info");
     byte[][] families = { fam };
     this.region = initHRegion(tableName, method, CONF, families);
-    try {
-      byte[] row = Bytes.toBytes("row1");
-      // column names
-      byte[] qual = Bytes.toBytes("qual");
+    byte[] row = Bytes.toBytes("row1");
+    // column names
+    byte[] qual = Bytes.toBytes("qual");
 
-      // add data with LATEST_TIMESTAMP, put without WAL
-      Put put = new Put(row);
-      put.addColumn(fam, qual, HConstants.LATEST_TIMESTAMP, Bytes.toBytes("value"));
-      region.put(put);
-
-      // Make sure it shows up with an actual timestamp
-      Get get = new Get(row).addColumn(fam, qual);
-      Result result = region.get(get);
-      assertEquals(1, result.size());
-      Cell kv = result.rawCells()[0];
-      LOG.info("Got: " + kv);
-      assertTrue("LATEST_TIMESTAMP was not replaced with real timestamp",
-          kv.getTimestamp() != HConstants.LATEST_TIMESTAMP);
-
-      // Check same with WAL enabled (historically these took different
-      // code paths, so check both)
-      row = Bytes.toBytes("row2");
-      put = new Put(row);
-      put.addColumn(fam, qual, HConstants.LATEST_TIMESTAMP, Bytes.toBytes("value"));
-      region.put(put);
+    // add data with LATEST_TIMESTAMP, put without WAL
+    Put put = new Put(row);
+    put.addColumn(fam, qual, HConstants.LATEST_TIMESTAMP, Bytes.toBytes("value"));
+    region.put(put);
 
-      // Make sure it shows up with an actual timestamp
-      get = new Get(row).addColumn(fam, qual);
-      result = region.get(get);
-      assertEquals(1, result.size());
-      kv = result.rawCells()[0];
-      LOG.info("Got: " + kv);
-      assertTrue("LATEST_TIMESTAMP was not replaced with real timestamp",
-          kv.getTimestamp() != HConstants.LATEST_TIMESTAMP);
-    } finally {
-      HBaseTestingUtility.closeRegionAndWAL(this.region);
-      this.region = null;
-    }
+    // Make sure it shows up with an actual timestamp
+    Get get = new Get(row).addColumn(fam, qual);
+    Result result = region.get(get);
+    assertEquals(1, result.size());
+    Cell kv = result.rawCells()[0];
+    LOG.info("Got: " + kv);
+    assertTrue("LATEST_TIMESTAMP was not replaced with real timestamp",
+        kv.getTimestamp() != HConstants.LATEST_TIMESTAMP);
+
+    // Check same with WAL enabled (historically these took different
+    // code paths, so check both)
+    row = Bytes.toBytes("row2");
+    put = new Put(row);
+    put.addColumn(fam, qual, HConstants.LATEST_TIMESTAMP, Bytes.toBytes("value"));
+    region.put(put);
 
+    // Make sure it shows up with an actual timestamp
+    get = new Get(row).addColumn(fam, qual);
+    result = region.get(get);
+    assertEquals(1, result.size());
+    kv = result.rawCells()[0];
+    LOG.info("Got: " + kv);
+    assertTrue("LATEST_TIMESTAMP was not replaced with real timestamp",
+        kv.getTimestamp() != HConstants.LATEST_TIMESTAMP);
   }
 
   /**
@@ -2413,22 +2296,17 @@ public class TestHRegion {
     this.region = initHRegion(tableName, method, CONF, families);
     boolean caughtExcep = false;
     try {
-      try {
-        // no TS specified == use latest. should not error
-        region.put(new Put(row).addColumn(fam, Bytes.toBytes("qual"), Bytes.toBytes("value")));
-        // TS out of range. should error
-        region.put(new Put(row).addColumn(fam, Bytes.toBytes("qual"),
-            System.currentTimeMillis() + 2000, Bytes.toBytes("value")));
-        fail("Expected IOE for TS out of configured timerange");
-      } catch (FailedSanityCheckException ioe) {
-        LOG.debug("Received expected exception", ioe);
-        caughtExcep = true;
-      }
-      assertTrue("Should catch FailedSanityCheckException", caughtExcep);
-    } finally {
-      HBaseTestingUtility.closeRegionAndWAL(this.region);
-      this.region = null;
+      // no TS specified == use latest. should not error
+      region.put(new Put(row).addColumn(fam, Bytes.toBytes("qual"), Bytes.toBytes("value")));
+      // TS out of range. should error
+      region.put(new Put(row).addColumn(fam, Bytes.toBytes("qual"),
+          System.currentTimeMillis() + 2000, Bytes.toBytes("value")));
+      fail("Expected IOE for TS out of configured timerange");
+    } catch (FailedSanityCheckException ioe) {
+      LOG.debug("Received expected exception", ioe);
+      caughtExcep = true;
     }
+    assertTrue("Should catch FailedSanityCheckException", caughtExcep);
   }
 
   @Test
@@ -2436,41 +2314,36 @@ public class TestHRegion {
     byte[] fam1 = Bytes.toBytes("columnA");
     byte[] fam2 = Bytes.toBytes("columnB");
     this.region = initHRegion(tableName, method, CONF, fam1, fam2);
-    try {
-      byte[] rowA = Bytes.toBytes("rowA");
-      byte[] rowB = Bytes.toBytes("rowB");
+    byte[] rowA = Bytes.toBytes("rowA");
+    byte[] rowB = Bytes.toBytes("rowB");
 
-      byte[] value = Bytes.toBytes("value");
+    byte[] value = Bytes.toBytes("value");
 
-      Delete delete = new Delete(rowA);
-      delete.addFamily(fam1);
+    Delete delete = new Delete(rowA);
+    delete.addFamily(fam1);
 
-      region.delete(delete);
+    region.delete(delete);
 
-      // now create data.
-      Put put = new Put(rowA);
-      put.addColumn(fam2, null, value);
-      region.put(put);
+    // now create data.
+    Put put = new Put(rowA);
+    put.addColumn(fam2, null, value);
+    region.put(put);
 
-      put = new Put(rowB);
-      put.addColumn(fam1, null, value);
-      put.addColumn(fam2, null, value);
-      region.put(put);
+    put = new Put(rowB);
+    put.addColumn(fam1, null, value);
+    put.addColumn(fam2, null, value);
+    region.put(put);
 
-      Scan scan = new Scan();
-      scan.addFamily(fam1).addFamily(fam2);
-      InternalScanner s = region.getScanner(scan);
-      List<Cell> results = new ArrayList<>();
-      s.next(results);
-      assertTrue(CellUtil.matchingRows(results.get(0), rowA));
+    Scan scan = new Scan();
+    scan.addFamily(fam1).addFamily(fam2);
+    InternalScanner s = region.getScanner(scan);
+    List<Cell> results = new ArrayList<>();
+    s.next(results);
+    assertTrue(CellUtil.matchingRows(results.get(0), rowA));
 
-      results.clear();
-      s.next(results);
-      assertTrue(CellUtil.matchingRows(results.get(0), rowB));
-    } finally {
-      HBaseTestingUtility.closeRegionAndWAL(this.region);
-      this.region = null;
-    }
+    results.clear();
+    s.next(results);
+    assertTrue(CellUtil.matchingRows(results.get(0), rowB));
   }
 
   @Test
@@ -2482,7 +2355,7 @@ public class TestHRegion {
     // This chunk creation is done throughout the code base. Do we want to move it into core?
     // It is missing from this test. W/o it we NPE.
     ChunkCreator.initialize(MemStoreLABImpl.CHUNK_SIZE_DEFAULT, false, 0, 0, 0, null);
-    HRegion region = initHRegion(tableName, null, null, false, Durability.SYNC_WAL, hLog,
+    region = initHRegion(tableName, null, null, false, Durability.SYNC_WAL, hLog,
         COLUMN_FAMILY_BYTES);
 
     Cell originalCell = CellUtil.createCell(row, COLUMN_FAMILY_BYTES, qual1,
@@ -2563,46 +2436,41 @@ public class TestHRegion {
 
   public void doTestDelete_AndPostInsert(Delete delete) throws IOException, InterruptedException {
     this.region = initHRegion(tableName, method, CONF, fam1);
-    try {
-      EnvironmentEdgeManagerTestHelper.injectEdge(new IncrementingEnvironmentEdge());
-      Put put = new Put(row);
-      put.addColumn(fam1, qual1, value1);
-      region.put(put);
+    EnvironmentEdgeManagerTestHelper.injectEdge(new IncrementingEnvironmentEdge());
+    Put put = new Put(row);
+    put.addColumn(fam1, qual1, value1);
+    region.put(put);
 
-      // now delete the value:
-      region.delete(delete);
+    // now delete the value:
+    region.delete(delete);
 
-      // ok put data:
-      put = new Put(row);
-      put.addColumn(fam1, qual1, value2);
-      region.put(put);
+    // ok put data:
+    put = new Put(row);
+    put.addColumn(fam1, qual1, value2);
+    region.put(put);
 
-      // ok get:
-      Get get = new Get(row);
-      get.addColumn(fam1, qual1);
-
-      Result r = region.get(get);
-      assertEquals(1, r.size());
-      assertArrayEquals(value2, r.getValue(fam1, qual1));
-
-      // next:
-      Scan scan = new Scan(row);
-      scan.addColumn(fam1, qual1);
-      InternalScanner s = region.getScanner(scan);
-
-      List<Cell> results = new ArrayList<>();
-      assertEquals(false, s.next(results));
-      assertEquals(1, results.size());
-      Cell kv = results.get(0);
-
-      assertArrayEquals(value2, CellUtil.cloneValue(kv));
-      assertArrayEquals(fam1, CellUtil.cloneFamily(kv));
-      assertArrayEquals(qual1, CellUtil.cloneQualifier(kv));
-      assertArrayEquals(row, CellUtil.cloneRow(kv));
-    } finally {
-      HBaseTestingUtility.closeRegionAndWAL(this.region);
-      this.region = null;
-    }
+    // ok get:
+    Get get = new Get(row);
+    get.addColumn(fam1, qual1);
+
+    Result r = region.get(get);
+    assertEquals(1, r.size());
+    assertArrayEquals(value2, r.getValue(fam1, qual1));
+
+    // next:
+    Scan scan = new Scan(row);
+    scan.addColumn(fam1, qual1);
+    InternalScanner s = region.getScanner(scan);
+
+    List<Cell> results = new ArrayList<>();
+    assertEquals(false, s.next(results));
+    assertEquals(1, results.size());
+    Cell kv = results.get(0);
+
+    assertArrayEquals(value2, CellUtil.cloneValue(kv));
+    assertArrayEquals(fam1, CellUtil.cloneFamily(kv));
+    assertArrayEquals(qual1, CellUtil.cloneQualifier(kv));
+    assertArrayEquals(row, CellUtil.cloneRow(kv));
   }
 
   @Test
@@ -2614,31 +2482,26 @@ public class TestHRegion {
 
     // Setting up region
     this.region = initHRegion(tableName, method, CONF, fam1);
-    try {
-      // Building checkerList
-      List<Cell> kvs = new ArrayList<>();
-      kvs.add(new KeyValue(row1, fam1, col1, null));
-      kvs.add(new KeyValue(row1, fam1, col2, null));
-      kvs.add(new KeyValue(row1, fam1, col3, null));
-
-      NavigableMap<byte[], List<Cell>> deleteMap = new TreeMap<>(Bytes.BYTES_COMPARATOR);
-      deleteMap.put(fam1, kvs);
-      region.delete(deleteMap, Durability.SYNC_WAL);
+    // Building checkerList
+    List<Cell> kvs = new ArrayList<>();
+    kvs.add(new KeyValue(row1, fam1, col1, null));
+    kvs.add(new KeyValue(row1, fam1, col2, null));
+    kvs.add(new KeyValue(row1, fam1, col3, null));
 
-      // extract the key values out the memstore:
-      // This is kinda hacky, but better than nothing...
-      long now = System.currentTimeMillis();
-      AbstractMemStore memstore = (AbstractMemStore)region.getStore(fam1).memstore;
-      Cell firstCell = memstore.getActive().first();
-      assertTrue(firstCell.getTimestamp() <= now);
-      now = firstCell.getTimestamp();
-      for (Cell cell : memstore.getActive().getCellSet()) {
-        assertTrue(cell.getTimestamp() <= now);
-        now = cell.getTimestamp();
-      }
-    } finally {
-      HBaseTestingUtility.closeRegionAndWAL(this.region);
-      this.region = null;
+    NavigableMap<byte[], List<Cell>> deleteMap = new TreeMap<>(Bytes.BYTES_COMPARATOR);
+    deleteMap.put(fam1, kvs);
+    region.delete(deleteMap, Durability.SYNC_WAL);
+
+    // extract the key values out the memstore:
+    // This is kinda hacky, but better than nothing...
+    long now = System.currentTimeMillis();
+    AbstractMemStore memstore = (AbstractMemStore)region.getStore(fam1).memstore;
+    Cell firstCell = memstore.getActive().first();
+    assertTrue(firstCell.getTimestamp() <= now);
+    now = firstCell.getTimestamp();
+    for (Cell cell : memstore.getActive().getCellSet()) {
+      assertTrue(cell.getTimestamp() <= now);
+      now = cell.getTimestamp();
     }
   }
 
@@ -2654,21 +2517,15 @@ public class TestHRegion {
 
     // Setting up region
     this.region = initHRegion(tableName, method, CONF, fam1);
-    try {
-      Get get = new Get(row1);
-      get.addColumn(fam2, col1);
+    Get get = new Get(row1);
+    get.addColumn(fam2, col1);
 
-      // Test
-      try {
-        region.get(get);
-      } catch (org.apache.hadoop.hbase.DoNotRetryIOException e) {
-        assertFalse(false);
-        return;
-      }
-      assertFalse(true);
-    } finally {
-      HBaseTestingUtility.closeRegionAndWAL(this.region);
-      this.region = null;
+    // Test
+    try {
+      region.get(get);
+      fail("Expecting DoNotRetryIOException in get but did not get any");
+    } catch (org.apache.hadoop.hbase.DoNotRetryIOException e) {
+      LOG.info("Got expected DoNotRetryIOException successfully");
     }
   }
 
@@ -2684,43 +2541,38 @@ public class TestHRegion {
 
     // Setting up region
     this.region = initHRegion(tableName, method, CONF, fam1);
-    try {
-      // Add to memstore
-      Put put = new Put(row1);
-      put.addColumn(fam1, col1, null);
-      put.addColumn(fam1, col2, null);
-      put.addColumn(fam1, col3, null);
-      put.addColumn(fam1, col4, null);
-      put.addColumn(fam1, col5, null);
-      region.put(put);
+    // Add to memstore
+    Put put = new Put(row1);
+    put.addColumn(fam1, col1, null);
+    put.addColumn(fam1, col2, null);
+    put.addColumn(fam1, col3, null);
+    put.addColumn(fam1, col4, null);
+    put.addColumn(fam1, col5, null);
+    region.put(put);
 
-      Get get = new Get(row1);
-      get.addColumn(fam1, col2);
-      get.addColumn(fam1, col4);
-      // Expected result
-      KeyValue kv1 = new KeyValue(row1, fam1, col2);
-      KeyValue kv2 = new KeyValue(row1, fam1, col4);
-      KeyValue[] expected = { kv1, kv2 };
-
-      // Test
-      Result res = region.get(get);
-      assertEquals(expected.length, res.size());
-      for (int i = 0; i < res.size(); i++) {
-        assertTrue(CellUtil.matchingRows(expected[i], res.rawCells()[i]));
-        assertTrue(CellUtil.matchingFamily(expected[i], res.rawCells()[i]));
-        assertTrue(CellUtil.matchingQualifier(expected[i], res.rawCells()[i]));
-      }
+    Get get = new Get(row1);
+    get.addColumn(fam1, col2);
+    get.addColumn(fam1, col4);
+    // Expected result
+    KeyValue kv1 = new KeyValue(row1, fam1, col2);
+    KeyValue kv2 = new KeyValue(row1, fam1, col4);
+    KeyValue[] expected = { kv1, kv2 };
 
-      // Test using a filter on a Get
-      Get g = new Get(row1);
-      final int count = 2;
-      g.setFilter(new ColumnCountGetFilter(count));
-      res = region.get(g);
-      assertEquals(count, res.size());
-    } finally {
-      HBaseTestingUtility.closeRegionAndWAL(this.region);
-      this.region = null;
+    // Test
+    Result res = region.get(get);
+    assertEquals(expected.length, res.size());
+    for (int i = 0; i < res.size(); i++) {
+      assertTrue(CellUtil.matchingRows(expected[i], res.rawCells()[i]));
+      assertTrue(CellUtil.matchingFamily(expected[i], res.rawCells()[i]));
+      assertTrue(CellUtil.matchingQualifier(expected[i], res.rawCells()[i]));
     }
+
+    // Test using a filter on a Get
+    Get g = new Get(row1);
+    final int count = 2;
+    g.setFilter(new ColumnCountGetFilter(count));
+    res = region.get(g);
+    assertEquals(count, res.size());
   }
 
   @Test
@@ -2729,16 +2581,11 @@ public class TestHRegion {
     byte[] fam = Bytes.toBytes("fam");
 
     this.region = initHRegion(tableName, method, CONF, fam);
-    try {
-      Get get = new Get(row);
-      get.addFamily(fam);
-      Result r = region.get(get);
+    Get get = new Get(row);
+    get.addFamily(fam);
+    Result r = region.get(get);
 
-      assertTrue(r.isEmpty());
-    } finally {
-      HBaseTestingUtility.closeRegionAndWAL(this.region);
-      this.region = null;
-    }
+    assertTrue(r.isEmpty());
   }
 
   @Test
@@ -2760,47 +2607,42 @@ public class TestHRegion {
     final WAL wal = HBaseTestingUtility.createWal(TEST_UTIL.getConfiguration(), logDir, info);
     this.region = TEST_UTIL.createLocalHRegion(info, htd, wal);
 
-    try {
-      // Put 4 version to memstore
-      long ts = 0;
-      Put put = new Put(row1, ts);
-      put.addColumn(fam1, col1, value1);
-      region.put(put);
-      put = new Put(row1, ts + 1);
-      put.addColumn(fam1, col1, Bytes.toBytes("filter1"));
-      region.put(put);
-      put = new Put(row1, ts + 2);
-      put.addColumn(fam1, col1, Bytes.toBytes("filter2"));
-      region.put(put);
-      put = new Put(row1, ts + 3);
-      put.addColumn(fam1, col1, value2);
-      region.put(put);
-
-      Get get = new Get(row1);
-      get.setMaxVersions();
-      Result res = region.get(get);
-      // Get 3 versions, the oldest version has gone from user view
-      assertEquals(maxVersions, res.size());
+    // Put 4 version to memstore
+    long ts = 0;
+    Put put = new Put(row1, ts);
+    put.addColumn(fam1, col1, value1);
+    region.put(put);
+    put = new Put(row1, ts + 1);
+    put.addColumn(fam1, col1, Bytes.toBytes("filter1"));
+    region.put(put);
+    put = new Put(row1, ts + 2);
+    put.addColumn(fam1, col1, Bytes.toBytes("filter2"));
+    region.put(put);
+    put = new Put(row1, ts + 3);
+    put.addColumn(fam1, col1, value2);
+    region.put(put);
 
-      get.setFilter(new ValueFilter(CompareOp.EQUAL, new SubstringComparator("value")));
-      res = region.get(get);
-      // When use value filter, the oldest version should still gone from user view and it
-      // should only return one key vaule
-      assertEquals(1, res.size());
-      assertTrue(CellUtil.matchingValue(new KeyValue(row1, fam1, col1, value2), res.rawCells()[0]));
-      assertEquals(ts + 3, res.rawCells()[0].getTimestamp());
+    Get get = new Get(row1);
+    get.setMaxVersions();
+    Result res = region.get(get);
+    // Get 3 versions, the oldest version has gone from user view
+    assertEquals(maxVersions, res.size());
+
+    get.setFilter(new ValueFilter(CompareOp.EQUAL, new SubstringComparator("value")));
+    res = region.get(get);
+    // When use value filter, the oldest version should still gone from user view and it
+    // should only return one key vaule
+    assertEquals(1, res.size());
+    assertTrue(CellUtil.matchingValue(new KeyValue(row1, fam1, col1, value2), res.rawCells()[0]));
+    assertEquals(ts + 3, res.rawCells()[0].getTimestamp());
 
-      region.flush(true);
-      region.compact(true);
-      Thread.sleep(1000);
-      res = region.get(get);
-      // After flush and compact, the result should be consistent with previous result
-      assertEquals(1, res.size());
-      assertTrue(CellUtil.matchingValue(new KeyValue(row1, fam1, col1, value2), res.rawCells()[0]));
-    } finally {
-      HBaseTestingUtility.closeRegionAndWAL(this.region);
-      this.region = null;
-    }
+    region.flush(true);
+    region.compact(true);
+    Thread.sleep(1000);
+    res = region.get(get);
+    // After flush and compact, the result should be consistent with previous result
+    assertEquals(1, res.size());
+    assertTrue(CellUtil.matchingValue(new KeyValue(row1, fam1, col1, value2), res.rawCells()[0]));
   }
 
   // ////////////////////////////////////////////////////////////////////////////
@@ -2815,18 +2657,13 @@ public class TestHRegion {
 
     // Setting up region
     this.region = initHRegion(tableName, method, CONF, families);
+    Scan scan = new Scan();
+    scan.addFamily(fam1);
+    scan.addFamily(fam2);
     try {
-      Scan scan = new Scan();
-      scan.addFamily(fam1);
-      scan.addFamily(fam2);
-      try {
-        region.getScanner(scan);
-      } catch (Exception e) {
-        assertTrue("Families could not be found in Region", false);
-      }
-    } finally {
-      HBaseTestingUtility.closeRegionAndWAL(this.region);
-      this.region = null;
+      region.getScanner(scan);
+    } catch (Exception e) {
+      assertTrue("Families could not be found in Region", false);
     }
   }
 
@@ -2839,20 +2676,15 @@ public class TestHRegion {
 
     // Setting up region
     this.region = initHRegion(tableName, method, CONF, families);
+    Scan scan = new Scan();
+    scan.addFamily(fam2);
+    boolean ok = false;
     try {
-      Scan scan = new Scan();
-      scan.addFamily(fam2);
-      boolean ok = false;
-      try {
-        region.getScanner(scan);
-      } catch (Exception e) {
-        ok = true;
-      }
-      assertTrue("Families could not be found in Region", ok);
-    } finally {
-      HBaseTestingUtility.closeRegionAndWAL(this.region);
-      this.region = null;
+      region.getScanner(scan);
+    } catch (Exception e) {
+      ok = true;
     }
+    assertTrue("Families could not be found in Region", ok);
   }
 
   @Test
@@ -2867,35 +2699,29 @@ public class TestHRegion {
 
     // Setting up region
     this.region = initHRegion(tableName, method, CONF, families);
-    try {
+    // Putting data in Region
+    Put put = new Put(row1);
+    put.addColumn(fam1, null, null);
+    put.addColumn(fam2, null, null);
+    put.addColumn(fam3, null, null);
+    put.addColumn(fam4, null, null);
+    region.put(put);
 
-      // Putting data in Region
-      Put put = new Put(row1);
-      put.addColumn(fam1, null, null);
-      put.addColumn(fam2, null, null);
-      put.addColumn(fam3, null, null);
-      put.addColumn(fam4, null, null);
-      region.put(put);
+    Scan scan = null;
+    HRegion.RegionScannerImpl is = null;
 
-      Scan scan = null;
-      HRegion.RegionScannerImpl is = null;
-
-      // Testing to see how many scanners that is produced by getScanner,
-      // starting
-      // with known number, 2 - current = 1
-      scan = new Scan();
-      scan.addFamily(fam2);
-      scan.addFamily(fam4);
-      is = region.getScanner(scan);
-      assertEquals(1, is.storeHeap.getHeap().size());
-
-      scan = new Scan();
-      is = region.getScanner(scan);
-      assertEquals(families.length - 1, is.storeHeap.getHeap().size());
-    } finally {
-      HBaseTestingUtility.closeRegionAndWAL(this.region);
-      this.region = null;
-    }
+    // Testing to see how many scanners that is produced by getScanner,
+    // starting
+    // with known number, 2 - current = 1
+    scan = new Scan();
+    scan.addFamily(fam2);
+    scan.addFamily(fam4);
+    is = region.getScanner(scan);
+    assertEquals(1, is.storeHeap.getHeap().size());
+
+    scan = new Scan();
+    is = region.getScanner(scan);
+    assertEquals(families.length - 1, is.storeHeap.getHeap().size());
   }
 
   /**
@@ -2917,21 +2743,16 @@ public class TestHRegion {
       e.printStackTrace();
       fail("Got IOException during initHRegion, " + e.getMessage());
     }
+    region.closed.set(true);
     try {
-      region.closed.set(true);
-      try {
-        region.getScanner(null);
-        fail("Expected to get an exception during getScanner on a region that is closed");
-      } catch (NotServingRegionException e) {
-        // this is the correct exception that is expected
-      } catch (IOException e) {
-        fail("Got wrong type of exception - should be a NotServingRegionException, " +
-            "but was an IOException: "
-            + e.getMessage());
-      }
-    } finally {
-      HBaseTestingUtility.closeRegionAndWAL(this.region);
-      this.region = null;
+      region.getScanner(null);
+      fail("Expected to get an exception during getScanner on a region that is closed");
+    } c

<TRUNCATED>

[2/2] hbase git commit: HBASE-21138 Close HRegion instance at the end of every test in TestHRegion

Posted by te...@apache.org.
HBASE-21138 Close HRegion instance at the end of every test in TestHRegion

Signed-off-by: tedyu <yu...@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/a37c40fa
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/a37c40fa
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/a37c40fa

Branch: refs/heads/master
Commit: a37c40faa518a66d2bc4c2a2f5def05e38203092
Parents: 855f4bb
Author: Mingliang Liu <li...@apache.org>
Authored: Fri Aug 31 15:23:10 2018 -0700
Committer: tedyu <yu...@gmail.com>
Committed: Thu Sep 6 03:59:44 2018 -0700

----------------------------------------------------------------------
 .../hadoop/hbase/regionserver/TestHRegion.java  | 4438 ++++++++----------
 1 file changed, 2058 insertions(+), 2380 deletions(-)
----------------------------------------------------------------------