@Test
  public void testErrorPrecedenceWithOrigDcUnavailability() throws Exception {
    correlationIdToGetOperation.clear();

    // Default all replicas to return not found.
    int serverCount = mockServerLayout.getMockServers().size();
    List<ServerErrorCode> serverErrorCodes = Collections.nCopies(serverCount, ServerErrorCode.BlobNotFound);
    setServerErrorCodes(serverErrorCodes, mockServerLayout);

    // Set Originating DC to be unavailable by setting 1 not found from bootstrap, 2 notFound from standby
    List<MockServer> serversInLocalDc = new ArrayList<>();
    mockServerLayout.getMockServers().forEach(mockServer -> {
      if (mockServer.getDataCenter().equals(localDcName)) {
        serversInLocalDc.add(mockServer);
      }
    });
    MockPartitionId partitionId = (MockPartitionId) blobId.getPartition();
    ReplicaId boostrapReplica = partitionId.replicaIds.stream()
        .filter(replicaId -> replicaId.getDataNodeId().getDatacenterName().equals(localDcName))
        .filter(replicaId -> replicaId.getDataNodeId().getHostname().equals(serversInLocalDc.get(0).getHostName()))
        .findFirst()
        .get();
    partitionId.setReplicaState(boostrapReplica, ReplicaState.BOOTSTRAP);
    serversInLocalDc.get(0).setServerErrorForAllRequests(ServerErrorCode.BlobNotFound);
    serversInLocalDc.get(1).setServerErrorForAllRequests(ServerErrorCode.BlobNotFound);
    serversInLocalDc.get(2).setServerErrorForAllRequests(ServerErrorCode.BlobNotFound);

    // Set one remote server to return Blob_Deleted
    MockServer serverInRemoteDc = mockServerLayout.getMockServers()
        .stream()
        .filter(mockServer -> !mockServer.getDataCenter().equals(localDcName))
        .findAny()
        .get();
    serverInRemoteDc.setServerErrorForAllRequests(ServerErrorCode.BlobDeleted);

    router.currentOperationsCount.incrementAndGet();
    GetBlobInfoOperation op =
        new GetBlobInfoOperation(routerConfig, routerMetrics, mockClusterMap, responseHandler, blobId, options, null,
            routerCallback, kms, cryptoService, cryptoJobHandler, time, false, quotaChargeCallback, router);
    requestRegistrationCallback.setRequestsToSend(new ArrayList<>());
    completeOp(op);

    // error code should be BlobDeleted
    RouterException routerException = (RouterException) op.getOperationException();
    Assert.assertEquals(RouterErrorCode.BlobDeleted, routerException.getErrorCode());
  }
Test the case when error precedence is maintained with unavailability in originating DC.
@throws Exception
ambry-router/src/test/java/com/github/ambry/router/GetBlobInfoOperationTest.java