@Test
  public void testReplicateBlobAlreadyExist() 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);
      router.getBlob(blobIdStr, new GetBlobOptionsBuilder().build(), null, null).get();

      // Replicate Blob but target DataNode has the Blob already.
      DataNodeId sourceDataNode = 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.BlobAlreadyExists);
          }
        } else {
          server.setServerErrorForAllRequests(ServerErrorCode.ReplicaUnavailable);
        }
      }

      router.replicateBlob(blobIdStr, serviceId, sourceDataNode).get();
      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 when replica already has the Blob
replicateBlob should return success status
@throws Exception
ambry-router/src/test/java/com/github/ambry/router/NonBlockingRouterTest.java