Skip to content

Commit

Permalink
Add test for remote cache early return during compressed blob upload
Browse files Browse the repository at this point in the history
Adds a test for bazelbuild@d184e48

Closes bazelbuild#14655.

PiperOrigin-RevId: 442798627
  • Loading branch information
bduffany authored and copybara-github committed Apr 19, 2022
1 parent 317375d commit 9ad3511
Showing 1 changed file with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,70 @@ public void singleBlobUploadShouldWork() throws Exception {
Mockito.verifyNoInteractions(mockBackoff);
}

@Test
public void singleChunkCompressedUploadAlreadyExists() throws Exception {
RemoteRetrier retrier =
TestUtils.newRemoteRetrier(() -> mockBackoff, (e) -> true, retryService);
ByteStreamUploader uploader =
new ByteStreamUploader(
INSTANCE_NAME,
new ReferenceCountedChannel(channelConnectionFactory),
CallCredentialsProvider.NO_CREDENTIALS,
/* callTimeoutSecs= */ 60,
retrier,
/* maximumOpenFiles= */ -1);

byte[] blob = {'A'};

// Set a chunk size that should have no problem accomodating the compressed
// blob, even though the blob most likely has a compression ratio >= 1.
Chunker chunker =
Chunker.builder().setInput(blob).setCompressed(true).setChunkSize(100).build();
Digest digest = DIGEST_UTIL.compute(blob);

serviceRegistry.addService(
new ByteStreamImplBase() {
@Override
public StreamObserver<WriteRequest> write(StreamObserver<WriteResponse> streamObserver) {
return new StreamObserver<WriteRequest>() {
private int numChunksReceived = 0;

@Override
public void onNext(WriteRequest writeRequest) {
// This should be the first and only chunk written.
numChunksReceived++;
assertThat(numChunksReceived).isEqualTo(1);
ByteString data = writeRequest.getData();
assertThat(data.size()).isGreaterThan(0);
assertThat(writeRequest.getFinishWrite()).isTrue();

// On receiving the chunk, respond with a committed size of -1
// to indicate that the blob already exists (per the remote API
// spec) and close the stream.
WriteResponse response = WriteResponse.newBuilder().setCommittedSize(-1).build();
streamObserver.onNext(response);
streamObserver.onCompleted();
}

@Override
public void onError(Throwable throwable) {
fail("onError should never be called.");
}

@Override
public void onCompleted() {
streamObserver.onCompleted();
}
};
}
});

uploader.uploadBlob(context, digest, chunker);

// This test should not have triggered any retries.
Mockito.verifyNoInteractions(mockBackoff);
}

@Test
public void progressiveUploadShouldWork() throws Exception {
Mockito.when(mockBackoff.getRetryAttempts()).thenReturn(0);
Expand Down

0 comments on commit 9ad3511

Please sign in to comment.