Program: 110726
Project: 110726
Buggy source:
@Test public void testUploadCacheMissesWithRetries() throws Exception {
  final GrpcRemoteCache client=newClient();
  final Digest fooDigest=fakeFileCache.createScratchInput(ActionInputHelper.fromPath("String_Node_Str"),"String_Node_Str");
  final Digest barDigest=fakeFileCache.createScratchInput(ActionInputHelper.fromPath("String_Node_Str"),"String_Node_Str");
  final Digest bazDigest=fakeFileCache.createScratchInput(ActionInputHelper.fromPath("String_Node_Str"),"String_Node_Str");
  final Path fooFile=execRoot.getRelative("String_Node_Str");
  final Path barFile=execRoot.getRelative("String_Node_Str");
  final Path bazFile=execRoot.getRelative("String_Node_Str");
  ActionKey actionKey=Digests.unsafeActionKeyFromDigest(fooDigest);
  barFile.setExecutable(true);
  serviceRegistry.addService(new ContentAddressableStorageImplBase(){
    private int numErrors=4;
    @Override public void findMissingBlobs(    FindMissingBlobsRequest request,    StreamObserver<FindMissingBlobsResponse> responseObserver){
      if (numErrors-- <= 0) {
        responseObserver.onNext(FindMissingBlobsResponse.getDefaultInstance());
        responseObserver.onCompleted();
      }
 else {
        responseObserver.onError(Status.UNAVAILABLE.asRuntimeException());
      }
    }
  }
);
  ActionResult.Builder rb=ActionResult.newBuilder();
  rb.addOutputFilesBuilder().setPath("String_Node_Str").setDigest(fooDigest);
  rb.addOutputFilesBuilder().setPath("String_Node_Str").setDigest(barDigest).setIsExecutable(true);
  rb.addOutputFilesBuilder().setPath("String_Node_Str").setDigest(bazDigest);
  ActionResult result=rb.build();
  serviceRegistry.addService(new ActionCacheImplBase(){
    private int numErrors=4;
    @Override public void updateActionResult(    UpdateActionResultRequest request,    StreamObserver<ActionResult> responseObserver){
      assertThat(request).isEqualTo(UpdateActionResultRequest.newBuilder().setActionDigest(fooDigest).setActionResult(result).build());
      if (numErrors-- <= 0) {
        responseObserver.onNext(result);
        responseObserver.onCompleted();
      }
 else {
        responseObserver.onError(Status.UNAVAILABLE.asRuntimeException());
      }
    }
  }
);
  ByteStreamImplBase mockByteStreamImpl=Mockito.mock(ByteStreamImplBase.class);
  serviceRegistry.addService(mockByteStreamImpl);
  when(mockByteStreamImpl.write(Mockito.<StreamObserver<WriteResponse>>anyObject())).thenAnswer(blobChunkedWriteAnswerError()).thenAnswer(blobChunkedWriteAnswer("String_Node_Str",1)).thenAnswer(blobChunkedWriteAnswerError()).thenAnswer(blobChunkedWriteAnswer("String_Node_Str",3)).thenAnswer(blobChunkedWriteAnswerError()).thenAnswer(blobChunkedWriteAnswer("String_Node_Str",1));
  client.upload(actionKey,execRoot,ImmutableList.<Path>of(fooFile,barFile,bazFile),outErr);
}

Fixed version (ground truth):
@Test public void testUploadCacheMissesWithRetries() throws Exception {
  final GrpcRemoteCache client=newClient();
  final Digest fooDigest=fakeFileCache.createScratchInput(ActionInputHelper.fromPath("String_Node_Str"),"String_Node_Str");
  final Digest barDigest=fakeFileCache.createScratchInput(ActionInputHelper.fromPath("String_Node_Str"),"String_Node_Str");
  final Digest bazDigest=fakeFileCache.createScratchInput(ActionInputHelper.fromPath("String_Node_Str"),"String_Node_Str");
  final Path fooFile=execRoot.getRelative("String_Node_Str");
  final Path barFile=execRoot.getRelative("String_Node_Str");
  final Path bazFile=execRoot.getRelative("String_Node_Str");
  ActionKey actionKey=Digests.unsafeActionKeyFromDigest(fooDigest);
  barFile.setExecutable(true);
  serviceRegistry.addService(new ContentAddressableStorageImplBase(){
    private int numErrors=4;
    @Override public void findMissingBlobs(    FindMissingBlobsRequest request,    StreamObserver<FindMissingBlobsResponse> responseObserver){
      if (numErrors-- <= 0) {
        responseObserver.onNext(FindMissingBlobsResponse.newBuilder().addMissingBlobDigests(fooDigest).addMissingBlobDigests(barDigest).addMissingBlobDigests(bazDigest).build());
        responseObserver.onCompleted();
      }
 else {
        responseObserver.onError(Status.UNAVAILABLE.asRuntimeException());
      }
    }
  }
);
  ActionResult.Builder rb=ActionResult.newBuilder();
  rb.addOutputFilesBuilder().setPath("String_Node_Str").setDigest(fooDigest);
  rb.addOutputFilesBuilder().setPath("String_Node_Str").setDigest(barDigest).setIsExecutable(true);
  rb.addOutputFilesBuilder().setPath("String_Node_Str").setDigest(bazDigest);
  ActionResult result=rb.build();
  serviceRegistry.addService(new ActionCacheImplBase(){
    private int numErrors=4;
    @Override public void updateActionResult(    UpdateActionResultRequest request,    StreamObserver<ActionResult> responseObserver){
      assertThat(request).isEqualTo(UpdateActionResultRequest.newBuilder().setActionDigest(fooDigest).setActionResult(result).build());
      if (numErrors-- <= 0) {
        responseObserver.onNext(result);
        responseObserver.onCompleted();
      }
 else {
        responseObserver.onError(Status.UNAVAILABLE.asRuntimeException());
      }
    }
  }
);
  ByteStreamImplBase mockByteStreamImpl=Mockito.mock(ByteStreamImplBase.class);
  serviceRegistry.addService(mockByteStreamImpl);
  when(mockByteStreamImpl.write(Mockito.<StreamObserver<WriteResponse>>anyObject())).thenAnswer(new Answer<StreamObserver<WriteRequest>>(){
    private int numErrors=4;
    @Override @SuppressWarnings("String_Node_Str") public StreamObserver<WriteRequest> answer(    InvocationOnMock invocation){
      StreamObserver<WriteResponse> responseObserver=(StreamObserver<WriteResponse>)invocation.getArguments()[0];
      return new StreamObserver<WriteRequest>(){
        @Override public void onNext(        WriteRequest request){
          numErrors--;
          if (numErrors >= 0) {
            responseObserver.onError(Status.UNAVAILABLE.asRuntimeException());
            return;
          }
          assertThat(request.getFinishWrite()).isTrue();
          String resourceName=request.getResourceName();
          String dataStr=request.getData().toStringUtf8();
          int size=0;
          if (resourceName.contains(fooDigest.getHash())) {
            assertThat(dataStr).isEqualTo("String_Node_Str");
            size=3;
          }
 else           if (resourceName.contains(barDigest.getHash())) {
            assertThat(dataStr).isEqualTo("String_Node_Str");
            size=1;
          }
 else           if (resourceName.contains(bazDigest.getHash())) {
            assertThat(dataStr).isEqualTo("String_Node_Str");
            size=1;
          }
 else {
            fail("String_Node_Str" + resourceName);
          }
          responseObserver.onNext(WriteResponse.newBuilder().setCommittedSize(size).build());
        }
        @Override public void onCompleted(){
          responseObserver.onCompleted();
        }
        @Override public void onError(        Throwable t){
          fail("String_Node_Str" + t);
        }
      }
;
    }
  }
);
  client.upload(actionKey,execRoot,ImmutableList.<Path>of(fooFile,barFile,bazFile),outErr);
  Mockito.verify(mockByteStreamImpl,Mockito.times(7)).write(Mockito.<StreamObserver<WriteResponse>>anyObject());
}