@Test
  public void testMemstoreSizeAccountingWithFailedPostBatchMutate() throws IOException {
    String testName = "testMemstoreSizeAccountingWithFailedPostBatchMutate";
    FileSystem fs = FileSystem.get(CONF);
    Path rootDir = new Path(dir + testName);
    FSHLog hLog = new FSHLog(fs, rootDir, testName, CONF);
    hLog.init();
    region = initHRegion(tableName, null, null, CONF, false, Durability.SYNC_WAL, hLog,
      COLUMN_FAMILY_BYTES);
    HStore store = region.getStore(COLUMN_FAMILY_BYTES);
    assertEquals(0, region.getMemStoreDataSize());

    // Put one value
    byte[] value = Bytes.toBytes(method);
    Put put = new Put(value);
    put.addColumn(COLUMN_FAMILY_BYTES, Bytes.toBytes("abc"), value);
    region.put(put);
    long onePutSize = region.getMemStoreDataSize();
    assertTrue(onePutSize > 0);

    RegionCoprocessorHost mockedCPHost = mock(RegionCoprocessorHost.class);
    doThrow(new IOException()).when(mockedCPHost).postBatchMutate(any());
    region.setCoprocessorHost(mockedCPHost);

    put = new Put(value);
    put.addColumn(COLUMN_FAMILY_BYTES, Bytes.toBytes("dfg"), value);
    try {
      region.put(put);
      fail("Should have failed with IOException");
    } catch (IOException expected) {
    }
    long expectedSize = onePutSize * 2;
    assertEquals("memstoreSize should be incremented", expectedSize, region.getMemStoreDataSize());
    assertEquals("flushable size should be incremented", expectedSize,
      store.getFlushableSize().getDataSize());

    region.setCoprocessorHost(null);
  }
Create a WAL outside of the usual helper in
{@link HBaseTestingUtil#createWal(Configuration, Path, RegionInfo)} because that method doesn't
play nicely with FaultyFileSystem. Call this method before overriding {@code fs.file.impl}.
@param callingMethod a unique component for the path, probably the name of the test method.
hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java