You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ap...@apache.org on 2018/09/07 18:31:05 UTC

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

http://git-wip-us.apache.org/repos/asf/hbase/blob/d3c9723c/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 296ccf4..729adc9 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
@@ -233,6 +233,8 @@ public class TestHRegion {
 
   @After
   public void tearDown() throws Exception {
+    // 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();
@@ -248,7 +250,7 @@ public class TestHRegion {
    */
   @Test (timeout = 100000)
   public void testSequenceId() throws IOException {
-    HRegion region = initHRegion(tableName, name.getMethodName(), CONF, COLUMN_FAMILY_BYTES);
+    region = initHRegion(tableName, name.getMethodName(), 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));
@@ -267,7 +269,6 @@ public class TestHRegion {
     assertEquals(0, (long)region.getMaxStoreSeqId().get(COLUMN_FAMILY_BYTES));
     region.flush(true);
     long max = region.getMaxFlushedSeqId();
-    region.close();
     assertEquals(max, region.getMaxFlushedSeqId());
   }
 
@@ -283,7 +284,7 @@ public class TestHRegion {
    */
   @Test (timeout=60000)
   public void testCloseCarryingSnapshot() throws IOException {
-    HRegion region = initHRegion(tableName, name.getMethodName(), CONF, COLUMN_FAMILY_BYTES);
+    region = initHRegion(tableName, name.getMethodName(), CONF, COLUMN_FAMILY_BYTES);
     Store store = region.getStore(COLUMN_FAMILY_BYTES);
     // Get some random bytes.
     byte [] value = Bytes.toBytes(name.getMethodName());
@@ -300,11 +301,8 @@ public class TestHRegion {
     // Close with something in memstore and something in the snapshot.  Make sure all is cleared.
     region.close();
     assertEquals(0, region.getMemstoreSize());
-    HRegion.closeHRegion(region);
   }
 
-
-
   /*
    * This test is for verifying memstore snapshot size is correctly updated in case of rollback
    * See HBASE-10845
@@ -332,7 +330,7 @@ public class TestHRegion {
     FileSystem fs = FileSystem.get(CONF);
     Path rootDir = new Path(dir + "testMemstoreSnapshotSize");
     MyFaultyFSLog faultyLog = new MyFaultyFSLog(fs, rootDir, "testMemstoreSnapshotSize", CONF);
-    HRegion region = initHRegion(tableName, null, null, name.getMethodName(),
+    region = initHRegion(tableName, null, null, name.getMethodName(),
         CONF, false, Durability.SYNC_WAL, faultyLog, COLUMN_FAMILY_BYTES);
 
     Store store = region.getStore(COLUMN_FAMILY_BYTES);
@@ -354,7 +352,6 @@ public class TestHRegion {
     }
     long sz = store.getFlushableSize();
     assertTrue("flushable size should be zero, but it is " + sz, sz == 0);
-    HRegion.closeHRegion(region);
   }
 
   /**
@@ -365,7 +362,7 @@ public class TestHRegion {
     FileSystem fs = FileSystem.get(CONF);
     Path rootDir = new Path(dir + "testMemstoreSizeWithFlushCanceling");
     FSHLog hLog = new FSHLog(fs, rootDir, "testMemstoreSizeWithFlushCanceling", CONF);
-    HRegion region = initHRegion(tableName, null, null, name.getMethodName(),
+    region = initHRegion(tableName, null, null, name.getMethodName(),
         CONF, false, Durability.SYNC_WAL, hLog, COLUMN_FAMILY_BYTES);
     Store store = region.getStore(COLUMN_FAMILY_BYTES);
     assertEquals(0, region.getMemstoreSize());
@@ -397,7 +394,6 @@ public class TestHRegion {
     region.flush(true);
     assertEquals("memstoreSize should be zero", 0, region.getMemstoreSize());
     assertEquals("flushable size should be zero", 0, store.getFlushableSize());
-    HRegion.closeHRegion(region);
   }
 
   @Test
@@ -406,7 +402,7 @@ public class TestHRegion {
     FileSystem fs = FileSystem.get(CONF);
     Path rootDir = new Path(dir + testName);
     FSHLog hLog = new FSHLog(fs, rootDir, testName, CONF);
-    HRegion region = initHRegion(tableName, null, null, name.getMethodName(),
+    region = initHRegion(tableName, null, null, name.getMethodName(),
         CONF, false, Durability.SYNC_WAL, hLog, COLUMN_FAMILY_BYTES);
     Store store = region.getStore(COLUMN_FAMILY_BYTES);
     assertEquals(0, region.getMemstoreSize());
@@ -435,7 +431,6 @@ public class TestHRegion {
     assertEquals("flushable size should be incremented", onePutSize * 2, store.getFlushableSize());
 
     region.setCoprocessorHost(null);
-    HBaseTestingUtility.closeRegionAndWAL(region);
   }
 
   /**
@@ -772,32 +767,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<byte[], Long>(Bytes.BYTES_COMPARATOR);
-      for (Store store : region.getStores()) {
-        maxSeqIdInStores.put(store.getColumnFamilyName().getBytes(), minSeqId);
-      }
-      long seqId = region.replayRecoveredEditsIfAny(regiondir, maxSeqIdInStores, null, null);
-      assertEquals(minSeqId, seqId);
-    } finally {
-      HRegion.closeHRegion(this.region);
-      this.region = null;
+    Map<byte[], Long> maxSeqIdInStores = new TreeMap<byte[], Long>(Bytes.BYTES_COMPARATOR);
+    for (Store store : region.getStores()) {
+      maxSeqIdInStores.put(store.getColumnFamilyName().getBytes(), minSeqId);
     }
+    long seqId = region.replayRecoveredEditsIfAny(regiondir, maxSeqIdInStores, null, null);
+    assertEquals(minSeqId, seqId);
   }
 
   @Test
@@ -1196,57 +1186,51 @@ public class TestHRegion {
         getName(), walConf);
     this.region = initHRegion(tableName.getName(), HConstants.EMPTY_START_ROW,
       HConstants.EMPTY_END_ROW, method, CONF, 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.add(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.add(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),
-            getName(), walConf);
-      this.region = initHRegion(tableName.getName(), HConstants.EMPTY_START_ROW,
-        HConstants.EMPTY_END_ROW, method, CONF, 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),
+          getName(), walConf);
+    this.region = initHRegion(tableName.getName(), HConstants.EMPTY_START_ROW,
+      HConstants.EMPTY_END_ROW, method, CONF, 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 {
-      HRegion.closeHRegion(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 +1244,45 @@ public class TestHRegion {
     // Setting up region
     String method = name.getMethodName();
     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) {
-          HRegion.closeHRegion(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 {
-      HRegion.closeHRegion(this.region);
-      this.region = null;
+      if (this.region != null) {
+        HRegion.closeHRegion(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);
+      }
     }
   }
 
@@ -1347,41 +1326,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(TABLE, getName(), 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 {
-      HRegion.closeHRegion(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
@@ -1397,11 +1371,8 @@ public class TestHRegion {
       region.append(append);
     } catch (IOException e) {
       exceptionCaught = true;
-    } finally {
-      HRegion.closeHRegion(this.region);
-      this.region = null;
     }
-    assertTrue(exceptionCaught == true);
+    assertTrue(exceptionCaught);
   }
 
   @Test
@@ -1416,11 +1387,8 @@ public class TestHRegion {
       region.increment(inc);
     } catch (IOException e) {
       exceptionCaught = true;
-    } finally {
-      HRegion.closeHRegion(this.region);
-      this.region = null;
     }
-    assertTrue(exceptionCaught == true);
+    assertTrue(exceptionCaught);
   }
 
   private void deleteColumns(HRegion r, String value, String keyPrefix) throws IOException {
@@ -1501,21 +1469,16 @@ public class TestHRegion {
     byte[] b = Bytes.toBytes(getName());
     byte[] cf = Bytes.toBytes(COLUMN_FAMILY);
     this.region = initHRegion(b, getName(), CONF, cf);
+    Put p = new Put(b);
+    byte[] cfwithcolon = Bytes.toBytes(COLUMN_FAMILY + ":");
+    p.add(cfwithcolon, cfwithcolon, cfwithcolon);
+    boolean exception = false;
     try {
-      Put p = new Put(b);
-      byte[] cfwithcolon = Bytes.toBytes(COLUMN_FAMILY + ":");
-      p.add(cfwithcolon, cfwithcolon, cfwithcolon);
-      boolean exception = false;
-      try {
-        this.region.put(p);
-      } catch (NoSuchColumnFamilyException e) {
-        exception = true;
-      }
-      assertTrue(exception);
-    } finally {
-      HRegion.closeHRegion(this.region);
-      this.region = null;
+      this.region.put(p);
+    } catch (NoSuchColumnFamilyException e) {
+      exception = true;
     }
+    assertTrue(exception);
   }
 
   @Test
@@ -1525,38 +1488,33 @@ public class TestHRegion {
     byte[] val = Bytes.toBytes("val");
     this.region = initHRegion(Bytes.toBytes(getName()), getName(), CONF, cf);
     MetricsWALSource source = CompatibilitySingletonFactory.getInstance(MetricsWALSource.class);
-    try {
-      long syncs = metricsAssertHelper.getCounter("syncTimeNumOps", source);
-      metricsAssertHelper.assertCounter("syncTimeNumOps", syncs, source);
-
-      LOG.info("First a batch put with all valid puts");
-      final Put[] puts = new Put[10];
-      for (int i = 0; i < 10; i++) {
-        puts[i] = new Put(Bytes.toBytes("row_" + i));
-        puts[i].add(cf, qual, val);
-      }
+    long syncs = metricsAssertHelper.getCounter("syncTimeNumOps", source);
+    metricsAssertHelper.assertCounter("syncTimeNumOps", syncs, source);
 
-      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].add(Bytes.toBytes("BAD_CF"), qual, val);
-      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());
-      }
+    LOG.info("First a batch put with all valid puts");
+    final Put[] puts = new Put[10];
+    for (int i = 0; i < 10; i++) {
+      puts[i] = new Put(Bytes.toBytes("row_" + i));
+      puts[i].add(cf, qual, val);
+    }
 
-      metricsAssertHelper.assertCounter("syncTimeNumOps", syncs + 2, source);
-    } finally {
-      HRegion.closeHRegion(this.region);
-      this.region = null;
+    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].add(Bytes.toBytes("BAD_CF"), qual, val);
+    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
@@ -1566,86 +1524,81 @@ public class TestHRegion {
     byte[] val = Bytes.toBytes("val");
     this.region = initHRegion(Bytes.toBytes(getName()), getName(), CONF, cf);
     MetricsWALSource source = CompatibilitySingletonFactory.getInstance(MetricsWALSource.class);
-    try {
-      long syncs = metricsAssertHelper.getCounter("syncTimeNumOps", source);
-      metricsAssertHelper.assertCounter("syncTimeNumOps", syncs, source);
-
-      final Put[] puts = new Put[10];
-      for (int i = 0; i < 10; i++) {
-        puts[i] = new Put(Bytes.toBytes("row_" + i));
-        puts[i].add(cf, qual, val);
-      }
-      puts[5].add(Bytes.toBytes("BAD_CF"), qual, val);
+    long syncs = metricsAssertHelper.getCounter("syncTimeNumOps", source);
+    metricsAssertHelper.assertCounter("syncTimeNumOps", syncs, source);
 
-      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);
+    final Put[] puts = new Put[10];
+    for (int i = 0; i < 10; i++) {
+      puts[i] = new Put(Bytes.toBytes("row_" + i));
+      puts[i].add(cf, qual, val);
+    }
+    puts[5].add(Bytes.toBytes("BAD_CF"), qual, val);
 
+    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<OperationStatus[]>();
-      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 {
-      HRegion.closeHRegion(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)
@@ -1672,29 +1625,22 @@ public class TestHRegion {
     CONF.setInt("hbase.hregion.keyvalue.timestamp.slop.millisecs", 1000);
     this.region = initHRegion(b, getName(), CONF, cf);
 
-    try {
-      MetricsWALSource source = CompatibilitySingletonFactory.getInstance(MetricsWALSource.class);
-      long syncs = metricsAssertHelper.getCounter("syncTimeNumOps", source);
-      metricsAssertHelper.assertCounter("syncTimeNumOps", syncs, source);
-
-      final Put[] puts = new Put[10];
-      for (int i = 0; i < 10; i++) {
-        puts[i] = new Put(Bytes.toBytes("row_" + i), Long.MAX_VALUE - 100);
-        puts[i].add(cf, qual, val);
-      }
-
-      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);
+    MetricsWALSource source = CompatibilitySingletonFactory.getInstance(MetricsWALSource.class);
+    long syncs = metricsAssertHelper.getCounter("syncTimeNumOps", source);
+    metricsAssertHelper.assertCounter("syncTimeNumOps", syncs, source);
 
-    } finally {
-      HRegion.closeHRegion(this.region);
-      this.region = null;
+    final Put[] puts = new Put[10];
+    for (int i = 0; i < 10; i++) {
+      puts[i] = new Put(Bytes.toBytes("row_" + i), Long.MAX_VALUE - 100);
+      puts[i].add(cf, qual, val);
     }
 
+    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);
   }
 
   // ////////////////////////////////////////////////////////////////////////////
@@ -1712,67 +1658,62 @@ public class TestHRegion {
     // Setting up region
     String method = this.getName();
     this.region = initHRegion(tableName, method, CONF, fam1);
-    try {
-      // Putting empty data in key
-      Put put = new Put(row1);
-      put.add(fam1, qf1, emptyVal);
-
-      // checkAndPut with empty value
-      boolean res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, new BinaryComparator(
-          emptyVal), put, true);
-      assertTrue(res);
-
-      // Putting data in key
-      put = new Put(row1);
-      put.add(fam1, qf1, val1);
-
-      // checkAndPut with correct value
-      res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, new BinaryComparator(emptyVal),
-          put, true);
-      assertTrue(res);
-
-      // not empty anymore
-      res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, new BinaryComparator(emptyVal),
-          put, true);
-      assertFalse(res);
-
-      Delete delete = new Delete(row1);
-      delete.deleteColumn(fam1, qf1);
-      res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, new BinaryComparator(emptyVal),
-          delete, true);
-      assertFalse(res);
-
-      put = new Put(row1);
-      put.add(fam1, qf1, val2);
-      // checkAndPut with correct value
-      res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, new BinaryComparator(val1),
-          put, true);
-      assertTrue(res);
-
-      // checkAndDelete with correct value
-      delete = new Delete(row1);
-      delete.deleteColumn(fam1, qf1);
-      delete.deleteColumn(fam1, qf1);
-      res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, new BinaryComparator(val2),
-          delete, true);
-      assertTrue(res);
-
-      delete = new Delete(row1);
-      res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, new BinaryComparator(emptyVal),
-          delete, true);
-      assertTrue(res);
-
-      // checkAndPut looking for a null value
-      put = new Put(row1);
-      put.add(fam1, qf1, val1);
-
-      res = region
-          .checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, new NullComparator(), put, true);
-      assertTrue(res);
-    } finally {
-      HRegion.closeHRegion(this.region);
-      this.region = null;
-    }
+    // Putting empty data in key
+    Put put = new Put(row1);
+    put.add(fam1, qf1, emptyVal);
+
+    // checkAndPut with empty value
+    boolean res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, new BinaryComparator(
+        emptyVal), put, true);
+    assertTrue(res);
+
+    // Putting data in key
+    put = new Put(row1);
+    put.add(fam1, qf1, val1);
+
+    // checkAndPut with correct value
+    res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, new BinaryComparator(emptyVal),
+        put, true);
+    assertTrue(res);
+
+    // not empty anymore
+    res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, new BinaryComparator(emptyVal),
+        put, true);
+    assertFalse(res);
+
+    Delete delete = new Delete(row1);
+    delete.deleteColumn(fam1, qf1);
+    res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, new BinaryComparator(emptyVal),
+        delete, true);
+    assertFalse(res);
+
+    put = new Put(row1);
+    put.add(fam1, qf1, val2);
+    // checkAndPut with correct value
+    res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, new BinaryComparator(val1),
+        put, true);
+    assertTrue(res);
+
+    // checkAndDelete with correct value
+    delete = new Delete(row1);
+    delete.deleteColumn(fam1, qf1);
+    delete.deleteColumn(fam1, qf1);
+    res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, new BinaryComparator(val2),
+        delete, true);
+    assertTrue(res);
+
+    delete = new Delete(row1);
+    res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, new BinaryComparator(emptyVal),
+        delete, true);
+    assertTrue(res);
+
+    // checkAndPut looking for a null value
+    put = new Put(row1);
+    put.add(fam1, qf1, val1);
+
+    res = region
+        .checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, new NullComparator(), put, true);
+    assertTrue(res);
   }
 
   @Test
@@ -1786,27 +1727,22 @@ public class TestHRegion {
     // Setting up region
     String method = this.getName();
     this.region = initHRegion(tableName, method, CONF, fam1);
-    try {
-      // Putting data in key
-      Put put = new Put(row1);
-      put.add(fam1, qf1, val1);
-      region.put(put);
+    // Putting data in key
+    Put put = new Put(row1);
+    put.add(fam1, qf1, val1);
+    region.put(put);
 
-      // checkAndPut with wrong value
-      boolean res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, new BinaryComparator(
-          val2), put, true);
-      assertEquals(false, res);
-
-      // checkAndDelete with wrong value
-      Delete delete = new Delete(row1);
-      delete.deleteFamily(fam1);
-      res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, new BinaryComparator(val2),
-          put, true);
-      assertEquals(false, res);
-    } finally {
-      HRegion.closeHRegion(this.region);
-      this.region = null;
-    }
+    // checkAndPut with wrong value
+    boolean res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, new BinaryComparator(
+        val2), put, true);
+    assertFalse(res);
+
+    // checkAndDelete with wrong value
+    Delete delete = new Delete(row1);
+    delete.deleteFamily(fam1);
+    res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, new BinaryComparator(val2),
+        put, true);
+    assertFalse(res);
   }
 
   @Test
@@ -1819,27 +1755,22 @@ public class TestHRegion {
     // Setting up region
     String method = this.getName();
     this.region = initHRegion(tableName, method, CONF, fam1);
-    try {
-      // Putting data in key
-      Put put = new Put(row1);
-      put.add(fam1, qf1, val1);
-      region.put(put);
+    // Putting data in key
+    Put put = new Put(row1);
+    put.add(fam1, qf1, val1);
+    region.put(put);
 
-      // checkAndPut with correct value
-      boolean res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, new BinaryComparator(
-          val1), put, true);
-      assertEquals(true, res);
-
-      // checkAndDelete with correct value
-      Delete delete = new Delete(row1);
-      delete.deleteColumn(fam1, qf1);
-      res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, new BinaryComparator(val1),
-          delete, true);
-      assertEquals(true, res);
-    } finally {
-      HRegion.closeHRegion(this.region);
-      this.region = null;
-    }
+    // checkAndPut with correct value
+    boolean res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, new BinaryComparator(
+        val1), put, true);
+    assertTrue( res);
+
+    // checkAndDelete with correct value
+    Delete delete = new Delete(row1);
+    delete.deleteColumn(fam1, qf1);
+    res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, new BinaryComparator(val1),
+        delete, true);
+    assertTrue(res);
   }
 
   @Test
@@ -1855,86 +1786,81 @@ public class TestHRegion {
     // Setting up region
     String method = this.getName();
     this.region = initHRegion(tableName, method, CONF, fam1);
-    try {
-      // Putting val3 in key
-      Put put = new Put(row1);
-      put.add(fam1, qf1, val3);
-      region.put(put);
+    // Putting val3 in key
+    Put put = new Put(row1);
+    put.add(fam1, qf1, val3);
+    region.put(put);
 
-      // Test CompareOp.LESS: original = val3, compare with val3, fail
-      boolean res = region.checkAndMutate(row1, fam1, qf1, CompareOp.LESS,
-          new BinaryComparator(val3), put, true);
-      assertEquals(false, res);
-
-      // Test CompareOp.LESS: original = val3, compare with val4, fail
-      res = region.checkAndMutate(row1, fam1, qf1, CompareOp.LESS,
-          new BinaryComparator(val4), put, true);
-      assertEquals(false, res);
-
-      // Test CompareOp.LESS: original = val3, compare with val2,
-      // succeed (now value = val2)
-      put = new Put(row1);
-      put.add(fam1, qf1, val2);
-      res = region.checkAndMutate(row1, fam1, qf1, CompareOp.LESS,
-          new BinaryComparator(val2), put, true);
-      assertEquals(true, res);
-
-      // Test CompareOp.LESS_OR_EQUAL: original = val2, compare with val3, fail
-      res = region.checkAndMutate(row1, fam1, qf1, CompareOp.LESS_OR_EQUAL,
-          new BinaryComparator(val3), put, true);
-      assertEquals(false, res);
-
-      // Test CompareOp.LESS_OR_EQUAL: original = val2, compare with val2,
-      // succeed (value still = val2)
-      res = region.checkAndMutate(row1, fam1, qf1, CompareOp.LESS_OR_EQUAL,
-          new BinaryComparator(val2), put, true);
-      assertEquals(true, res);
-
-      // Test CompareOp.LESS_OR_EQUAL: original = val2, compare with val1,
-      // succeed (now value = val3)
-      put = new Put(row1);
-      put.add(fam1, qf1, val3);
-      res = region.checkAndMutate(row1, fam1, qf1, CompareOp.LESS_OR_EQUAL,
-          new BinaryComparator(val1), put, true);
-      assertEquals(true, res);
-
-      // Test CompareOp.GREATER: original = val3, compare with val3, fail
-      res = region.checkAndMutate(row1, fam1, qf1, CompareOp.GREATER,
-          new BinaryComparator(val3), put, true);
-      assertEquals(false, res);
-
-      // Test CompareOp.GREATER: original = val3, compare with val2, fail
-      res = region.checkAndMutate(row1, fam1, qf1, CompareOp.GREATER,
-          new BinaryComparator(val2), put, true);
-      assertEquals(false, res);
-
-      // Test CompareOp.GREATER: original = val3, compare with val4,
-      // succeed (now value = val2)
-      put = new Put(row1);
-      put.add(fam1, qf1, val2);
-      res = region.checkAndMutate(row1, fam1, qf1, CompareOp.GREATER,
-          new BinaryComparator(val4), put, true);
-      assertEquals(true, res);
-
-      // Test CompareOp.GREATER_OR_EQUAL: original = val2, compare with val1, fail
-      res = region.checkAndMutate(row1, fam1, qf1, CompareOp.GREATER_OR_EQUAL,
-          new BinaryComparator(val1), put, true);
-      assertEquals(false, res);
-
-      // Test CompareOp.GREATER_OR_EQUAL: original = val2, compare with val2,
-      // succeed (value still = val2)
-      res = region.checkAndMutate(row1, fam1, qf1, CompareOp.GREATER_OR_EQUAL,
-          new BinaryComparator(val2), put, true);
-      assertEquals(true, res);
-
-      // Test CompareOp.GREATER_OR_EQUAL: original = val2, compare with val3, succeed
-      res = region.checkAndMutate(row1, fam1, qf1, CompareOp.GREATER_OR_EQUAL,
-          new BinaryComparator(val3), put, true);
-      assertEquals(true, res);
-    } finally {
-      HRegion.closeHRegion(this.region);
-      this.region = null;
-    }
+    // Test CompareOp.LESS: original = val3, compare with val3, fail
+    boolean res = region.checkAndMutate(row1, fam1, qf1, CompareOp.LESS,
+        new BinaryComparator(val3), put, true);
+    assertEquals(false, res);
+
+    // Test CompareOp.LESS: original = val3, compare with val4, fail
+    res = region.checkAndMutate(row1, fam1, qf1, CompareOp.LESS,
+        new BinaryComparator(val4), put, true);
+    assertEquals(false, res);
+
+    // Test CompareOp.LESS: original = val3, compare with val2,
+    // succeed (now value = val2)
+    put = new Put(row1);
+    put.add(fam1, qf1, val2);
+    res = region.checkAndMutate(row1, fam1, qf1, CompareOp.LESS,
+        new BinaryComparator(val2), put, true);
+    assertEquals(true, res);
+
+    // Test CompareOp.LESS_OR_EQUAL: original = val2, compare with val3, fail
+    res = region.checkAndMutate(row1, fam1, qf1, CompareOp.LESS_OR_EQUAL,
+        new BinaryComparator(val3), put, true);
+    assertEquals(false, res);
+
+    // Test CompareOp.LESS_OR_EQUAL: original = val2, compare with val2,
+    // succeed (value still = val2)
+    res = region.checkAndMutate(row1, fam1, qf1, CompareOp.LESS_OR_EQUAL,
+        new BinaryComparator(val2), put, true);
+    assertEquals(true, res);
+
+    // Test CompareOp.LESS_OR_EQUAL: original = val2, compare with val1,
+    // succeed (now value = val3)
+    put = new Put(row1);
+    put.add(fam1, qf1, val3);
+    res = region.checkAndMutate(row1, fam1, qf1, CompareOp.LESS_OR_EQUAL,
+        new BinaryComparator(val1), put, true);
+    assertEquals(true, res);
+
+    // Test CompareOp.GREATER: original = val3, compare with val3, fail
+    res = region.checkAndMutate(row1, fam1, qf1, CompareOp.GREATER,
+        new BinaryComparator(val3), put, true);
+    assertEquals(false, res);
+
+    // Test CompareOp.GREATER: original = val3, compare with val2, fail
+    res = region.checkAndMutate(row1, fam1, qf1, CompareOp.GREATER,
+        new BinaryComparator(val2), put, true);
+    assertEquals(false, res);
+
+    // Test CompareOp.GREATER: original = val3, compare with val4,
+    // succeed (now value = val2)
+    put = new Put(row1);
+    put.add(fam1, qf1, val2);
+    res = region.checkAndMutate(row1, fam1, qf1, CompareOp.GREATER,
+        new BinaryComparator(val4), put, true);
+    assertEquals(true, res);
+
+    // Test CompareOp.GREATER_OR_EQUAL: original = val2, compare with val1, fail
+    res = region.checkAndMutate(row1, fam1, qf1, CompareOp.GREATER_OR_EQUAL,
+        new BinaryComparator(val1), put, true);
+    assertEquals(false, res);
+
+    // Test CompareOp.GREATER_OR_EQUAL: original = val2, compare with val2,
+    // succeed (value still = val2)
+    res = region.checkAndMutate(row1, fam1, qf1, CompareOp.GREATER_OR_EQUAL,
+        new BinaryComparator(val2), put, true);
+    assertEquals(true, res);
+
+    // Test CompareOp.GREATER_OR_EQUAL: original = val2, compare with val3, succeed
+    res = region.checkAndMutate(row1, fam1, qf1, CompareOp.GREATER_OR_EQUAL,
+        new BinaryComparator(val3), put, true);
+    assertEquals(true, res);
   }
 
   @Test
@@ -1951,36 +1877,31 @@ public class TestHRegion {
     // Setting up region
     String method = this.getName();
     this.region = initHRegion(tableName, method, CONF, families);
-    try {
-      // Putting data in the key to check
-      Put put = new Put(row1);
-      put.add(fam1, qf1, val1);
-      region.put(put);
+    // Putting data in the key to check
+    Put put = new Put(row1);
+    put.add(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, CompareOp.EQUAL, new BinaryComparator(
-          val1), put, true);
-      assertEquals(true, res);
+    // checkAndPut with wrong value
+    boolean res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, new BinaryComparator(
+        val1), put, true);
+    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 {
-      HRegion.closeHRegion(this.region);
-      this.region = null;
+    assertEquals(expected.length, actual.length);
+    for (int i = 0; i < actual.length; i++) {
+      assertEquals(expected[i], actual[i]);
     }
   }
 
@@ -1988,19 +1909,14 @@ public class TestHRegion {
   public void testCheckAndPut_wrongRowInPut() throws IOException {
     TableName tableName = TableName.valueOf(name.getMethodName());
     this.region = initHRegion(tableName, this.getName(), CONF, COLUMNS);
+    Put put = new Put(row2);
+    put.add(fam1, qual1, value1);
     try {
-      Put put = new Put(row2);
-      put.add(fam1, qual1, value1);
-      try {
-        region.checkAndMutate(row, fam1, qual1, CompareOp.EQUAL,
-            new BinaryComparator(value2), put, false);
-        fail();
-      } catch (org.apache.hadoop.hbase.DoNotRetryIOException expected) {
-        // expected exception.
-      }
-    } finally {
-      HRegion.closeHRegion(this.region);
-      this.region = null;
+      region.checkAndMutate(row, fam1, qual1, CompareOp.EQUAL,
+          new BinaryComparator(value2), put, false);
+      fail();
+    } catch (org.apache.hadoop.hbase.DoNotRetryIOException expected) {
+      // expected exception.
     }
   }
 
@@ -2022,63 +1938,58 @@ public class TestHRegion {
     // Setting up region
     String method = this.getName();
     this.region = initHRegion(tableName, method, CONF, families);
-    try {
-      // Put content
-      Put put = new Put(row1);
-      put.add(fam1, qf1, val1);
-      region.put(put);
-      Threads.sleep(2);
-
-      put = new Put(row1);
-      put.add(fam1, qf1, val2);
-      put.add(fam2, qf1, val3);
-      put.add(fam2, qf2, val2);
-      put.add(fam2, qf3, val1);
-      put.add(fam1, qf3, val1);
-      region.put(put);
+    // Put content
+    Put put = new Put(row1);
+    put.add(fam1, qf1, val1);
+    region.put(put);
+    Threads.sleep(2);
+
+    put = new Put(row1);
+    put.add(fam1, qf1, val2);
+    put.add(fam2, qf1, val3);
+    put.add(fam2, qf2, val2);
+    put.add(fam2, qf3, val1);
+    put.add(fam1, qf3, val1);
+    region.put(put);
 
-      // Multi-column delete
-      Delete delete = new Delete(row1);
-      delete.deleteColumn(fam1, qf1);
-      delete.deleteColumn(fam2, qf1);
-      delete.deleteColumn(fam1, qf3);
-      boolean res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, new BinaryComparator(
-          val2), delete, true);
-      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.deleteFamily(fam2);
-      res = region.checkAndMutate(row1, fam2, qf1, CompareOp.EQUAL, new BinaryComparator(emptyVal),
-          delete, true);
-      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, CompareOp.EQUAL, new BinaryComparator(val1),
-          delete, true);
-      assertEquals(true, res);
-      get = new Get(row1);
-      r = region.get(get);
-      assertEquals(0, r.size());
-    } finally {
-      HRegion.closeHRegion(this.region);
-      this.region = null;
-    }
+    // Multi-column delete
+    Delete delete = new Delete(row1);
+    delete.deleteColumn(fam1, qf1);
+    delete.deleteColumn(fam2, qf1);
+    delete.deleteColumn(fam1, qf3);
+    boolean res = region.checkAndMutate(row1, fam1, qf1, CompareOp.EQUAL, new BinaryComparator(
+        val2), delete, true);
+    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.deleteFamily(fam2);
+    res = region.checkAndMutate(row1, fam2, qf1, CompareOp.EQUAL, new BinaryComparator(emptyVal),
+        delete, true);
+    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, CompareOp.EQUAL, new BinaryComparator(val1),
+        delete, true);
+    assertEquals(true, res);
+    get = new Get(row1);
+    r = region.get(get);
+    assertEquals(0, r.size());
   }
 
   // ////////////////////////////////////////////////////////////////////////////
@@ -2097,23 +2008,18 @@ public class TestHRegion {
 
     String method = this.getName();
     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.deleteColumn(fam1, qual);
-      delete.deleteColumn(fam1, qual);
-      region.delete(delete);
+    // We do support deleting more than 1 'latest' version
+    Delete delete = new Delete(row1);
+    delete.deleteColumn(fam1, qual);
+    delete.deleteColumn(fam1, qual);
+    region.delete(delete);
 
-      Get get = new Get(row1);
-      get.addFamily(fam1);
-      Result r = region.get(get);
-      assertEquals(0, r.size());
-    } finally {
-      HRegion.closeHRegion(this.region);
-      this.region = null;
-    }
+    Get get = new Get(row1);
+    get.addFamily(fam1);
+    Result r = region.get(get);
+    assertEquals(0, r.size());
   }
 
   @Test
@@ -2127,37 +2033,32 @@ public class TestHRegion {
     // Setting up region
     String method = this.getName();
     this.region = initHRegion(tableName, method, CONF, fam1, fam2, fam3);
-    try {
-      List<Cell> kvs = new ArrayList<Cell>();
-      kvs.add(new KeyValue(row1, fam4, null, null));
+    List<Cell> kvs = new ArrayList<Cell>();
+    kvs.add(new KeyValue(row1, fam4, null, null));
 
-      // testing existing family
-      byte[] family = fam2;
-      try {
-        NavigableMap<byte[], List<Cell>> deleteMap = new TreeMap<byte[], List<Cell>>(
-            Bytes.BYTES_COMPARATOR);
-        deleteMap.put(family, kvs);
-        region.delete(deleteMap, Durability.SYNC_WAL);
-      } catch (Exception e) {
-        assertTrue("Family " + new String(family) + " does not exist", false);
-      }
+    // testing existing family
+    byte[] family = fam2;
+    try {
+      NavigableMap<byte[], List<Cell>> deleteMap = new TreeMap<byte[], List<Cell>>(
+          Bytes.BYTES_COMPARATOR);
+      deleteMap.put(family, kvs);
+      region.delete(deleteMap, Durability.SYNC_WAL);
+    } catch (Exception e) {
+      assertTrue("Family " + new String(family) + " does not exist", false);
+    }
 
-      // testing non existing family
-      boolean ok = false;
-      family = fam4;
-      try {
-        NavigableMap<byte[], List<Cell>> deleteMap = new TreeMap<byte[], List<Cell>>(
-            Bytes.BYTES_COMPARATOR);
-        deleteMap.put(family, kvs);
-        region.delete(deleteMap, Durability.SYNC_WAL);
-      } catch (Exception e) {
-        ok = true;
-      }
-      assertEquals("Family " + new String(family) + " does exist", true, ok);
-    } finally {
-      HRegion.closeHRegion(this.region);
-      this.region = null;
+    // testing non existing family
+    boolean ok = false;
+    family = fam4;
+    try {
+      NavigableMap<byte[], List<Cell>> deleteMap = new TreeMap<byte[], List<Cell>>(
+          Bytes.BYTES_COMPARATOR);
+      deleteMap.put(family, kvs);
+      region.delete(deleteMap, Durability.SYNC_WAL);
+    } catch (Exception e) {
+      ok = true;
     }
+    assertTrue("Family " + new String(family) + " does exist", ok);
   }
 
   @Test
@@ -2166,66 +2067,61 @@ public class TestHRegion {
     byte[][] families = { fam };
     String method = this.getName();
     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.add(fam, splitA, Bytes.toBytes("reference_A"));
-      region.put(put);
+    // add some data:
+    Put put = new Put(row);
+    put.add(fam, splitA, Bytes.toBytes("reference_A"));
+    region.put(put);
 
-      put = new Put(row);
-      put.add(fam, splitB, Bytes.toBytes("reference_B"));
-      region.put(put);
+    put = new Put(row);
+    put.add(fam, splitB, Bytes.toBytes("reference_B"));
+    region.put(put);
 
-      put = new Put(row);
-      put.add(fam, serverinfo, Bytes.toBytes("ip_address"));
-      region.put(put);
+    put = new Put(row);
+    put.add(fam, serverinfo, Bytes.toBytes("ip_address"));
+    region.put(put);
 
-      // ok now delete a split:
-      Delete delete = new Delete(row);
-      delete.deleteColumns(fam, splitA);
-      region.delete(delete);
+    // ok now delete a split:
+    Delete delete = new Delete(row);
+    delete.deleteColumns(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.add(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).add(fam, splitA, Bytes.toBytes("reference_A")));
-      result = region.get(get);
-      assertEquals(1, result.size());
-    } finally {
-      HRegion.closeHRegion(this.region);
-      this.region = null;
-    }
+    // Assert that after a delete, I can put.
+    put = new Put(row);
+    put.add(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).add(fam, splitA, Bytes.toBytes("reference_A")));
+    result = region.get(get);
+    assertEquals(1, result.size());
   }
 
   @Test
@@ -2234,37 +2130,32 @@ public class TestHRegion {
     byte[][] families = { fam };
     String method = this.getName();
     this.region = initHRegion(tableName, method, CONF, families);
-    try {
-      byte[] row = Bytes.toBytes("table_name");
-      // column names
-      byte[] serverinfo = Bytes.toBytes("serverinfo");
+    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.add(fam, serverinfo, HConstants.LATEST_TIMESTAMP - 5, Bytes.toBytes("value"));
-      region.put(put);
+    // add data in the far future
+    Put put = new Put(row);
+    put.add(fam, serverinfo, HConstants.LATEST_TIMESTAMP - 5, Bytes.toBytes("value"));
+    region.put(put);
 
-      // now delete something in the present
-      Delete delete = new Delete(row);
-      region.delete(delete);
+    // now delete something in the present
+    Delete delete = new Delete(row);
+    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 we still see our data
+    Get get = new Get(row).addColumn(fam, serverinfo);
+    Result result = region.get(get);
+    assertEquals(1, result.size());
 
-      // delete the future row
-      delete = new Delete(row, HConstants.LATEST_TIMESTAMP - 3);
-      region.delete(delete);
+    // 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());
-    } finally {
-      HRegion.closeHRegion(this.region);
-      this.region = null;
-    }
+    // make sure it is gone
+    get = new Get(row).addColumn(fam, serverinfo);
+    result = region.get(get);
+    assertEquals(0, result.size());
   }
 
   /**
@@ -2277,45 +2168,39 @@ public class TestHRegion {
     byte[][] families = { fam };
     String method = this.getName();
     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.add(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.add(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.add(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 {
-      HRegion.closeHRegion(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.add(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);
   }
 
   /**
@@ -2334,22 +2219,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).add(fam, Bytes.toBytes("qual"), Bytes.toBytes("value")));
-        // TS out of range. should error
-        region.put(new Put(row).add(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 {
-      HRegion.closeHRegion(this.region);
-      this.region = null;
+      // no TS specified == use latest. should not error
+      region.put(new Put(row).add(fam, Bytes.toBytes("qual"), Bytes.toBytes("value")));
+      // TS out of range. should error
+      region.put(new Put(row).add(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
@@ -2357,41 +2237,36 @@ public class TestHRegion {
     byte[] fam1 = Bytes.toBytes("columnA");
     byte[] fam2 = Bytes.toBytes("columnB");
     this.region = initHRegion(tableName, getName(), 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.deleteFamily(fam1);
+    Delete delete = new Delete(rowA);
+    delete.deleteFamily(fam1);
 
-      region.delete(delete);
+    region.delete(delete);
 
-      // now create data.
-      Put put = new Put(rowA);
-      put.add(fam2, null, value);
-      region.put(put);
+    // now create data.
+    Put put = new Put(rowA);
+    put.add(fam2, null, value);
+    region.put(put);
 
-      put = new Put(rowB);
-      put.add(fam1, null, value);
-      put.add(fam2, null, value);
-      region.put(put);
+    put = new Put(rowB);
+    put.add(fam1, null, value);
+    put.add(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<Cell>();
-      s.next(results);
-      assertTrue(CellUtil.matchingRow(results.get(0), rowA));
+    Scan scan = new Scan();
+    scan.addFamily(fam1).addFamily(fam2);
+    InternalScanner s = region.getScanner(scan);
+    List<Cell> results = new ArrayList<Cell>();
+    s.next(results);
+    assertTrue(CellUtil.matchingRow(results.get(0), rowA));
 
-      results.clear();
-      s.next(results);
-      assertTrue(CellUtil.matchingRow(results.get(0), rowB));
-    } finally {
-      HRegion.closeHRegion(this.region);
-      this.region = null;
-    }
+    results.clear();
+    s.next(results);
+    assertTrue(CellUtil.matchingRow(results.get(0), rowB));
   }
 
   @Test
@@ -2411,46 +2286,41 @@ public class TestHRegion {
   public void doTestDelete_AndPostInsert(Delete delete) throws IOException, InterruptedException {
     TableName tableName = TableName.valueOf(name.getMethodName());
     this.region = initHRegion(tableName, getName(), CONF, fam1);
-    try {
-      EnvironmentEdgeManagerTestHelper.injectEdge(new IncrementingEnvironmentEdge());
-      Put put = new Put(row);
-      put.add(fam1, qual1, value1);
-      region.put(put);
+    EnvironmentEdgeManagerTestHelper.injectEdge(new IncrementingEnvironmentEdge());
+    Put put = new Put(row);
+    put.add(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.add(fam1, qual1, value2);
-      region.put(put);
+    // ok put data:
+    put = new Put(row);
+    put.add(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<Cell>();
-      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 {
-      HRegion.closeHRegion(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<Cell>();
+    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
@@ -2464,32 +2334,27 @@ public class TestHRegion {
     // Setting up region
     String method = this.getName();
     this.region = initHRegion(tableName, method, CONF, fam1);
-    try {
-      // Building checkerList
-      List<Cell> kvs = new ArrayList<Cell>();
-      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<byte[], List<Cell>>(
-          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();
-      DefaultMemStore memstore = (DefaultMemStore) ((HStore) region.getStore(fam1)).memstore;
-      Cell firstCell = memstore.activeSection.getCellSkipListSet().first();
-      assertTrue(firstCell.getTimestamp() <= now);
-      now = firstCell.getTimestamp();
-      for (Cell cell : memstore.activeSection.getCellSkipListSet()) {
-        assertTrue(cell.getTimestamp() <= now);
-        now = cell.getTimestamp();
-      }
-    } finally {
-      HRegion.closeHRegion(this.region);
-      this.region = null;
+    // Building checkerList
+    List<Cell> kvs = new ArrayList<Cell>();
+    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<byte[], List<Cell>>(
+        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();
+    DefaultMemStore memstore = (DefaultMemStore) ((HStore) region.getStore(fam1)).memstore;
+    Cell firstCell = memstore.activeSection.getCellSkipListSet().first();
+    assertTrue(firstCell.getTimestamp() <= now);
+    now = firstCell.getTimestamp();
+    for (Cell cell : memstore.activeSection.getCellSkipListSet()) {
+      assertTrue(cell.getTimestamp() <= now);
+      now = cell.getTimestamp();
     }
   }
 
@@ -2506,21 +2371,15 @@ public class TestHRegion {
     // Setting up region
     String method = this.getName();
     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 {
-      HRegion.closeHRegion(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");
     }
   }
 
@@ -2537,43 +2396,38 @@ public class TestHRegion {
     // Setting up region
     String method = this.getName();
     this.region = initHRegion(tableName, method, CONF, fam1);
-    try {
-      // Add to memstore
-      Put put = new Put(row1);
-      put.add(fam1, col1, null);
-      put.add(fam1, col2, null);
-      put.add(fam1, col3, null);
-      put.add(fam1, col4, null);
-      put.add(fam1, col5, null);
-      region.put(put);
+    // Add to memstore
+    Put put = new Put(row1);
+    put.add(fam1, col1, null);
+    put.add(fam1, col2, null);
+    put.add(fam1, col3, null);
+    put.add(fam1, col4, null);
+    put.add(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.matchingRow(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 {
-      HRegion.closeHRegion(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.matchingRow(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
@@ -2583,16 +2437,11 @@ public class TestHRegion {
 
     String method = this.getName();
     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 {
-      HRegion.closeHRegion(this.region);
-      this.region = null;
-    }
+    assertTrue(r.isEmpty());
   }
 
   // ////////////////////////////////////////////////////////////////////////////
@@ -2605,51 +2454,46 @@ public class TestHRegion {
     // Setting up region
     String method = this.getName();
     this.region = initHRegion(tableName, method, hc, families);
+    LOG.info("" + HBaseTestCase.addContent(region, fam3));
+    region.flush(true);
+    region.compactStores();
+    region.waitForFlushesAndCompactions();
+    for(Store s:region.getStores()) {
+      s.closeAndArchiveCompactedFiles();
+    }
+    byte[] splitRow = region.checkSplit();
+    assertNotNull(splitRow);
+    LOG.info("SplitRow: " + Bytes.toString(splitRow));
+    HRegion[] subregions = splitRegion(region, splitRow);
     try {
-      LOG.info("" + HBaseTestCase.addContent(region, fam3));
-      region.flush(true);
-      region.compactStores();
-      region.waitForFlushesAndCompactions();
-      for(Store s:region.getStores()) {
-        s.closeAndArchiveCompactedFiles();
-      }
-      byte[] splitRow = region.checkSplit();
-      assertNotNull(splitRow);
-      LOG.info("SplitRow: " + Bytes.toString(splitRow));
-      HRegion[] subregions = splitRegion(region, splitRow);
-      try {
-        // Need to open the regions.
-        for (int i = 0; i < subregions.length; i++) {
-          HRegion.openHRegion(subregions[i], null);
-          subregions[i].compactStores();
-          subregions[i].waitForFlushesAndCompactions();
-          for(Store s:subregions[i].getStores()) {
-            s.closeAndArchiveCompactedFiles();
-          }
-        }
-        Path oldRegionPath = region.getRegionFileSystem().getRegionDir();
-        Path oldRegion1 = subregions[0].getRegionFileSystem().getRegionDir();
-        Path oldRegion2 = subregions[1].getRegionFileSystem().getRegionDir();
-        long startTime = System.currentTimeMillis();
-        region = HRegion.mergeAdjacent(subregions[0], subregions[1]);
-        LOG.info("Merge regions elapsed time: "
-            + ((System.currentTimeMillis() - startTime) / 1000.0));
-        FILESYSTEM.delete(oldRegion1, true);
-        FILESYSTEM.delete(oldRegion2, true);
-        FILESYSTEM.delete(oldRegionPath, true);
-        LOG.info("splitAndMerge completed.");
-      } finally {
-        for (int i = 0; i < subregions.length; i++) {
-          try {
-            HRegion.closeHRegion(subregions[i]);
-          } catch (IOException e) {
-            // Ignore.
-          }
+      // Need to open the regions.
+      for (int i = 0; i < subregions.length; i++) {
+        HRegion.openHRegion(subregions[i], null);
+        subregions[i].compactStores();
+        subregions[i].waitForFlushesAndCompactions();
+        for(Store s:subregions[i].getStores()) {
+          s.closeAndArchiveCompactedFiles();
         }
       }
+      Path oldRegionPath = region.getRegionFileSystem().getRegionDir();
+      Path oldRegion1 = subregions[0].getRegionFileSystem().getRegionDir();
+      Path oldRegion2 = subregions[1].getRegionFileSystem().getRegionDir();
+      long startTime = System.currentTimeMillis();
+      region = HRegion.mergeAdjacent(subregions[0], subregions[1]);
+      LOG.info("Merge regions elapsed time: "
+          + ((System.currentTimeMillis() - startTime) / 1000.0));
+      FILESYSTEM.delete(oldRegion1, true);
+      FILESYSTEM.delete(oldRegion2, true);
+      FILESYSTEM.delete(oldRegionPath, true);
+      LOG.info("splitAndMerge completed.");
     } finally {
-      HRegion.closeHRegion(this.region);
-      this.region = null;
+      for (int i = 0; i < subregions.length; i++) {
+        try {
+          HRegion.closeHRegion(subregions[i]);
+        } catch (IOException e) {
+          // Ignore.
+        }
+      }
     }
   }
 
@@ -2705,18 +2549,13 @@ public class TestHRegion {
     // Setting up region
     String method = this.getName();
     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 {
-      HRegion.closeHRegion(this.region);
-      this.region = null;
+      region.getScanner(scan);
+    } catch (Exception e) {
+      assertTrue("Families could not be found in Region", false);
     }
   }
 
@@ -2730,20 +2569,15 @@ public class TestHRegion {
     // Setting up region
     String method = this.getName();
     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 {
-      HRegion.closeHRegion(this.region);
-      this.region = null;
+      region.getScanner(scan);
+    } catch (Exception e) {
+      ok = true;
     }
+    assertTrue("Families could not be found in Region", ok);
   }
 
   @Test
@@ -2759,35 +2593,29 @@ public class TestHRegion {
     // Setting up region
     String method = this.getName();
     this.region = initHRegion(tableName, method, CONF, families);
-    try {
+    // Putting data in Region
+    Put put = new Put(row1);
+    put.add(fam1, null, null);
+    put.add(fam2, null, null);
+    put.add(fam3, null, null);
+    put.add(fam4, null, null);
+    region.put(put);
 
-      // Putting data in Region
-      Put put = new Put(row1);
-      put.add(fam1, null, null);
-      put.add(fam2, null, null);
-      put.add(fam3, null, null);
-      put.add(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 = (RegionScannerImpl) region.getScanner(scan);
-      assertEquals(1, ((RegionScannerImpl) is).storeHeap.getHeap().size());
-
-      scan = new Scan();
-      is = (RegionScannerImpl) region.getScanner(scan);
-      assertEquals(families.length - 1, ((RegionScannerImpl) is).storeHeap.getHeap().size());
-    } finally {
-      HRegion.closeHRegion(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 = (RegionScannerImpl) region.getScanner(scan);
+    assertEquals(1, ((RegionScannerImpl) is).storeHeap.getHeap().size());
+
+    scan = new Scan();
+    is = (RegionScannerImpl) region.getScanner(scan);
+    assertEquals(families.length - 1, ((RegionScannerImpl) is).storeHeap.getHeap().size());
   }
 
   /**
@@ -2810,20 +2638,15 @@ 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 {
-      HRegion.closeHRegion(this.region);
-      this.region = null;
+      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());
     }
   }
 
@@ -2842,54 +2665,49 @@ public class TestHRegion {
     // Setting up region
     String method = this.getName();
     this.region = initHRegion(tableName, method, CONF, families);
-    try {
-      // Putting data in Region
-      Put put = null;
-      put = new Put(row1);
-      put.add(fam1, (byte[]) null, ts, null);
-      put.add(fam2, (byte[]) null, ts, null);
-      put.add(fam3, (byte[]) null, ts, null);
-      put.add(fam4, (byte[]) null, ts, null);
-      region.put(put);
+    // Putting data in Region
+    Put put = null;
+    put = new Put(row1);
+    put.add(fam1, (byte[]) null, ts, null);
+    put.add(fam2, (byte[]) null, ts, null);
+    put.add(fam3, (byte[]) null, ts, null);
+    put.add(fam4, (byte[]) null, ts, null);
+    region.put(put);
 
-      put = new Put(row2);
-      put.add(fam1, (byte[]) null, ts, null);
-      put.add(fam2, (byte[]) null, ts, null);
-      put.add(fam3, (byte[]) null, ts, null);
-      put.add(fam4, (byte[]) null, ts, null);
-      region.put(put);
+    put = new Put(row2);
+    put.add(fam1, (byte[]) null, ts, null);
+    put.add(fam2, (byte[]) null, ts, null);
+    put.add(fam3, (byte[]) null, ts, null);
+    put.add(fam4, (byte[]) null, ts, null);
+    region.put(put);
 
-      Scan scan = new Scan();
-      scan.addFamily(fam2);
-      scan.addFamily(fam4);
-      InternalScanner is = region.getScanner(scan);
+    Scan scan = new Scan();
+    scan.addFamily(fam2);
+    scan.addFamily(fam4);
+    InternalScanner is = region.getScanner(scan);
 
-      List<Cell> res = null;
+    List<Cell> res = null;
 
-      // Result 1
-      List<Cell> expected1 = new ArrayList<Cell>();
-      expected1.add(new KeyValue(row1, fam2, null, ts, KeyValue.Type.Put, null));
-      expected1.add(new KeyValue(row1, fam4, null, ts, KeyValue.Type.Put, null));
+    // Result 1
+    List<Cell> expected1 = new ArrayList<Cell>();
+    expected1.add(new KeyValue(row1, fam2, null, ts, KeyValue.Type.Put, null));
+    expected1.add(new KeyValue(row1, fam4, null, ts, KeyValue.Type.Put, null));
 
-      res = new ArrayList<Cell>();
-      is.next(res);
-      for (int i = 0; i < res.size(); i++) {
-        assertTrue(CellComparator.equalsIgnoreMvccVersion(expected1.get(i), res.get(i)));
-      }
+    res = new ArrayList<Cell>();
+    is.next(res);
+    for (int i = 0; i < res.size(); i++) {
+      assertTrue(CellComparator.equalsIgnoreMvccVersion(expected1.get(i), res.get(i)));
+    }
 
-      // Result 2
-      List<Cell> expected2 = new ArrayList<Cell>();
-      expected2.add(new KeyValue(row2, fam2, null, ts, KeyValue.Type.Put, null));
-      expected2.add(new KeyValue(row2, fam4, null, ts, KeyValue.Type.Put, null));
+    // Result 2
+    List<Cell> expected2 = new ArrayList<Cell>();
+    expected2.add(new KeyValue(row2, fam2, null, ts, KeyValue.Type.Put, null));
+    expected2.add(new KeyValue(row2, fam4, null, ts, KeyValue.Type.Put, null));
 
-      res = new ArrayList<Cell>();
-      is.next(res);
-      for (int i = 0; i < res.size(); i++) {
-        assertTrue(CellComparator.equalsIgnoreMvccVersion(expected2.get(i), res.get(i)));
-      }
-    } finally {
-      HRegion.closeHRegion(this.region);
-      this.region = null;
+    res = new ArrayList<Cell>();
+    is.next(res);
+    for (int i = 0; i < res.size(); i++) {
+      assertTrue(CellComparator.equalsIgnoreMvccVersion(expected2.get(i), res.get(i)));
     }
   }
 
@@ -2908,47 +2726,42 @@ public class TestHRegion {
     // Setting up region
     String method = this.getName();
     this.region = initHRegion(tableName, method, CONF, families);
-    try {
-      // Putting data in Region
-      Put put = null;
-      KeyValue kv13 = new KeyValue(row1, fam1, qf1, ts3, KeyValue.Type.Put, null);
-      KeyValue kv12 = new 

<TRUNCATED>