@Test
  public void testMemstoreSnapshotSize() throws IOException {
    class MyFaultyFSLog extends FaultyFSLog {
      StoreFlushContext storeFlushCtx;

      public MyFaultyFSLog(FileSystem fs, Path rootDir, String logName, Configuration conf)
        throws IOException {
        super(fs, rootDir, logName, conf);
      }

      void setStoreFlushCtx(StoreFlushContext storeFlushCtx) {
        this.storeFlushCtx = storeFlushCtx;
      }

      @Override
      protected void doSync(long txid, boolean forceSync) throws IOException {
        storeFlushCtx.prepare();
        super.doSync(txid, forceSync);
      }
    }

    FileSystem fs = FileSystem.get(CONF);
    Path rootDir = new Path(dir + "testMemstoreSnapshotSize");
    MyFaultyFSLog faultyLog = new MyFaultyFSLog(fs, rootDir, "testMemstoreSnapshotSize", CONF);
    faultyLog.init();
    region = initHRegion(tableName, null, null, CONF, false, Durability.SYNC_WAL, faultyLog,
      COLUMN_FAMILY_BYTES);

    HStore store = region.getStore(COLUMN_FAMILY_BYTES);
    // Get some random bytes.
    byte[] value = Bytes.toBytes(method);
    faultyLog.setStoreFlushCtx(store.createFlushContext(12345, FlushLifeCycleTracker.DUMMY));

    Put put = new Put(value);
    put.addColumn(COLUMN_FAMILY_BYTES, Bytes.toBytes("abc"), value);
    faultyLog.setFailureType(FaultyFSLog.FailureType.SYNC);
    boolean threwIOE = false;
    try {
      region.put(put);
    } catch (IOException ioe) {
      threwIOE = true;
    } finally {
      assertTrue("The regionserver should have thrown an exception", threwIOE);
    }
    MemStoreSize mss = store.getFlushableSize();
    assertTrue("flushable size should be zero, but it is " + mss, mss.getDataSize() == 0);
  }
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