@Test
  public void testCloseCarryingSnapshot() throws IOException {
    region = initHRegion(tableName, method, CONF, COLUMN_FAMILY_BYTES);
    HStore store = region.getStore(COLUMN_FAMILY_BYTES);
    // Get some random bytes.
    byte[] value = Bytes.toBytes(method);
    // Make a random put against our cf.
    Put put = new Put(value);
    put.addColumn(COLUMN_FAMILY_BYTES, null, value);
    // First put something in current memstore, which will be in snapshot after flusher.prepare()
    region.put(put);
    StoreFlushContext storeFlushCtx = store.createFlushContext(12345, FlushLifeCycleTracker.DUMMY);
    storeFlushCtx.prepare();
    // Second put something in current memstore
    put.addColumn(COLUMN_FAMILY_BYTES, Bytes.toBytes("abc"), value);
    region.put(put);
    // Close with something in memstore and something in the snapshot. Make sure all is cleared.
    HBaseTestingUtil.closeRegionAndWAL(region);
    assertEquals(0, region.getMemStoreDataSize());
    region = null;
  }
Test for Bug 2 of HBASE-10466. "Bug 2: Conditions for the first flush of region close
(so-called pre-flush) If memstoreSize is smaller than a certain value, or when region close
starts a flush is ongoing, the first flush is skipped and only the second flush takes place.
However, two flushes are required in case previous flush fails and leaves some data in
snapshot. The bug could cause loss of data in current memstore. The fix is removing all
conditions except abort check so we ensure 2 flushes for region close."
hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java