@Override
    public ReplicateWALEntryResponse replicateToReplica(RpcController rpcController,
      ReplicateWALEntryRequest replicateWALEntryRequest) throws ServiceException {

      if (!startTest) {
        return super.replicateToReplica(rpcController, replicateWALEntryRequest);
      }

      List<WALEntry> entries = replicateWALEntryRequest.getEntryList();
      if (CollectionUtils.isEmpty(entries)) {
        return ReplicateWALEntryResponse.getDefaultInstance();
      }
      ByteString regionName = entries.get(0).getKey().getEncodedRegionName();

      HRegion region;
      try {
        region = server.getRegionByEncodedName(regionName.toStringUtf8());
      } catch (NotServingRegionException e) {
        throw new ServiceException(e);
      }

      if (
        !region.getRegionInfo().getTable().equals(tableName)
          || region.getRegionInfo().getReplicaId() != 1
      ) {
        return super.replicateToReplica(rpcController, replicateWALEntryRequest);
      }

      /**
       * Simulate the first cell write and {@link FlushAction#START_FLUSH} marker replicating error.
       */
      int count = callCounter.incrementAndGet();
      if (count > 2) {
        return super.replicateToReplica(rpcController, replicateWALEntryRequest);
      }
      throw new ServiceException(new DoNotRetryIOException("Inject error!"));
    }
First flush is {@link FlushAction#START_FLUSH} marker and the second flush is
{@link FlushAction#CANNOT_FLUSH} marker because the memstore is empty.
hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/regionreplication/TestRegionReplicationForFlushMarker.java