@Test
  public void testRegionReplicaSecondaryIsReadOnly() throws IOException {
    // create a primary region, load some data and flush
    // create a secondary region, and do a put against that
    Path rootDir = new Path(dir + name.getMethodName());
    CommonFSUtils.setRootDir(TEST_UTIL.getConfiguration(), rootDir);

    byte[][] families =
      new byte[][] { Bytes.toBytes("cf1"), Bytes.toBytes("cf2"), Bytes.toBytes("cf3") };
    byte[] cq = Bytes.toBytes("cq");
    TableDescriptorBuilder builder =
      TableDescriptorBuilder.newBuilder(TableName.valueOf(name.getMethodName()));
    for (byte[] family : families) {
      builder.setColumnFamily(ColumnFamilyDescriptorBuilder.of(family));
    }
    TableDescriptor tableDescriptor = builder.build();
    long time = EnvironmentEdgeManager.currentTime();
    RegionInfo primaryHri = RegionInfoBuilder.newBuilder(tableDescriptor.getTableName())
      .setRegionId(time).setReplicaId(0).build();
    RegionInfo secondaryHri = RegionInfoBuilder.newBuilder(tableDescriptor.getTableName())
      .setRegionId(time).setReplicaId(1).build();

    HRegion primaryRegion = null, secondaryRegion = null;

    try {
      primaryRegion = HBaseTestingUtil.createRegionAndWAL(primaryHri, rootDir,
        TEST_UTIL.getConfiguration(), tableDescriptor);

      // load some data
      putData(primaryRegion, 0, 1000, cq, families);

      // flush region
      primaryRegion.flush(true);

      // open secondary region
      secondaryRegion = HRegion.openHRegion(rootDir, secondaryHri, tableDescriptor, null, CONF);

      try {
        putData(secondaryRegion, 0, 1000, cq, families);
        fail("Should have thrown exception");
      } catch (IOException ex) {
        // expected
      }
    } finally {
      if (primaryRegion != null) {
        HBaseTestingUtil.closeRegionAndWAL(primaryRegion);
      }
      if (secondaryRegion != null) {
        HBaseTestingUtil.closeRegionAndWAL(secondaryRegion);
      }
    }
  }
For this test,the spied {@link AsyncFSWAL} can not work properly because of a Mockito defect
that can not deal with classes which have a field of an inner class. See discussions in
HBASE-15536.When we reuse the code of {@link AsyncFSWAL} for {@link FSHLog}, this test could
not work for {@link FSHLog} also.
hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java