public void reset(boolean errorBeforeUpdate) throws ReplicationException {
      addPeerCalled = false;
      removePeerCalled = false;
      updatePeerConfigCalled = false;
      enablePeerCalled = false;
      disablePeerCalled = false;
      ReplicationPeerManager m = super.getReplicationPeerManager();
      manager = spy(m);
      doAnswer(invocation -> {
        if (!addPeerCalled) {
          addPeerCalled = true;
          return invokeWithError(invocation, errorBeforeUpdate);
        } else {
          return invocation.callRealMethod();
        }
      }).when(manager).addPeer(anyString(), any(ReplicationPeerConfig.class), anyBoolean());
      doAnswer(invocation -> {
        if (!removePeerCalled) {
          removePeerCalled = true;
          return invokeWithError(invocation, errorBeforeUpdate);
        } else {
          return invocation.callRealMethod();
        }
      }).when(manager).removePeer(anyString());
      doAnswer(invocation -> {
        if (!updatePeerConfigCalled) {
          updatePeerConfigCalled = true;
          return invokeWithError(invocation, errorBeforeUpdate);
        } else {
          return invocation.callRealMethod();
        }
      }).when(manager).updatePeerConfig(anyString(), any(ReplicationPeerConfig.class));
      doAnswer(invocation -> {
        if (!enablePeerCalled) {
          enablePeerCalled = true;
          return invokeWithError(invocation, errorBeforeUpdate);
        } else {
          return invocation.callRealMethod();
        }
      }).when(manager).enablePeer(anyString());
      doAnswer(invocation -> {
        if (!disablePeerCalled) {
          disablePeerCalled = true;
          return invokeWithError(invocation, errorBeforeUpdate);
        } else {
          return invocation.callRealMethod();
        }
      }).when(manager).disablePeer(anyString());
    }
All the modification method will fail once in the test and should finally succeed.
hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationProcedureRetry.java