@Test
  public void testReplicateBlobMaxUnavailableAllowed() throws Exception {
    try {
      MockServerLayout layout = new MockServerLayout(mockClusterMap);
      String serviceId = "replicate-blob-service";
      setRouter(getNonBlockingRouterProperties(localDcName), layout, new LoggingNotificationSystem());
      setOperationParams();
      // PutBlob to the three local replicas
      String blobIdStr =
          router.putBlob(putBlobProperties, putUserMetadata, putChannel, new PutBlobOptionsBuilder().build())
              .get(AWAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
      GetBlobResult localGetBlobResult =
          router.getBlob(blobIdStr, new GetBlobOptionsBuilder().build(), null, null).get();

      // Only one local replica and one remote replica available.
      DataNodeId sourceDataNode = null;
      DataNodeId remoteDataNode = null;
      for (MockServer server : layout.getMockServers()) {
        if (server.getDataCenter().equals(localDcName)) {
          if (sourceDataNode == null) {
            sourceDataNode = mockClusterMap.getDataNodeId(server.getHostName(), server.getHostPort());
          } else {
            server.setServerErrorForAllRequests(ServerErrorCode.ReplicaUnavailable);
          }
        } else {
          if (remoteDataNode == null) {
            remoteDataNode = mockClusterMap.getDataNodeId(server.getHostName(), server.getHostPort());
          } else {
            server.setServerErrorForAllRequests(ServerErrorCode.ReplicaUnavailable);
          }
        }
      }
      router.replicateBlob(blobIdStr, serviceId, sourceDataNode).get();

      // set unavailable to all replicas except for that single remote replica
      for (MockServer server : layout.getMockServers()) {
        if (server.getHostName().equals(remoteDataNode.getHostname()) && server.getHostPort()
            .equals(remoteDataNode.getPort())) {
          server.setServerErrorForAllRequests(null);
        } else {
          server.setServerErrorForAllRequests(ServerErrorCode.ReplicaUnavailable);
        }
      }

      GetBlobResult remoteGetBlobResult =
          router.getBlob(blobIdStr, new GetBlobOptionsBuilder().build(), null, null).get();
      assertEqual(localGetBlobResult, remoteGetBlobResult);
      layout.getMockServers().forEach(mockServer -> mockServer.setServerErrorForAllRequests(null));
    } finally {
      // Since we are using same blob ID for all tests, clear cache which stores blobs that are not found in router.
      router.getNotFoundCache().invalidateAll();
      if (router != null) {
        router.close();
      }
    }
  }
Test for ReplicateBlob success when globally we only have two replicas available.
@throws Exception
ambry-router/src/test/java/com/github/ambry/router/NonBlockingRouterTest.java