use of com.google.cloud.kms.v1.Digest in project bazel-buildfarm by bazelbuild.
the class UtilTest method correctMissingBlobFailsImmediatelyOnUnretriable.
@Test
public void correctMissingBlobFailsImmediatelyOnUnretriable() throws InterruptedException {
String workerName = "worker";
Backplane backplane = mock(Backplane.class);
Set<String> workerSet = ImmutableSet.of(workerName);
Digest digest = Digest.newBuilder().setHash("digest-throws-exception-on-find-missing").setSizeBytes(1).build();
ImmutableList<Digest> digests = ImmutableList.of(digest);
Instance instance = mock(Instance.class);
when(instance.findMissingBlobs(eq(digests), any(RequestMetadata.class))).thenReturn(immediateFailedFuture(Status.INVALID_ARGUMENT.asRuntimeException()));
Function<String, Instance> workerInstanceFactory = worker -> {
if (worker.equals(workerName)) {
return instance;
}
return null;
};
ListenableFuture<Set<String>> correctFuture = correctMissingBlob(backplane, workerSet, /* originalLocationSet=*/
ImmutableSet.of(), workerInstanceFactory, digest, directExecutor(), RequestMetadata.getDefaultInstance());
boolean caughtException = false;
try {
correctFuture.get();
} catch (ExecutionException e) {
caughtException = true;
Status status = Status.fromThrowable(e.getCause());
assertThat(status.getCode()).isEqualTo(Code.INVALID_ARGUMENT);
}
verify(instance, times(1)).findMissingBlobs(eq(digests), any(RequestMetadata.class));
assertThat(caughtException).isTrue();
verifyZeroInteractions(backplane);
}
use of com.google.cloud.kms.v1.Digest in project bazel-buildfarm by bazelbuild.
the class UtilTest method correctMissingBlobIgnoresUnavailableWorkers.
@Test
public void correctMissingBlobIgnoresUnavailableWorkers() throws Exception {
String workerName = "worker";
String unavailableWorkerName = "unavailableWorker";
Backplane backplane = mock(Backplane.class);
Set<String> workerSet = ImmutableSet.of(workerName, unavailableWorkerName);
Digest digest = Digest.newBuilder().setHash("digest").setSizeBytes(1).build();
ImmutableList<Digest> digests = ImmutableList.of(digest);
Instance instance = mock(Instance.class);
when(instance.findMissingBlobs(eq(digests), any(RequestMetadata.class))).thenReturn(immediateFuture(ImmutableList.of()));
Instance unavailableInstance = mock(Instance.class);
when(unavailableInstance.findMissingBlobs(eq(digests), any(RequestMetadata.class))).thenReturn(immediateFailedFuture(Status.UNAVAILABLE.asRuntimeException()));
Function<String, Instance> workerInstanceFactory = worker -> {
if (worker.equals(workerName)) {
return instance;
}
if (worker.equals(unavailableWorkerName)) {
return unavailableInstance;
}
return null;
};
ListenableFuture<Set<String>> correctFuture = correctMissingBlob(backplane, workerSet, /* originalLocationSet=*/
ImmutableSet.of(), workerInstanceFactory, digest, directExecutor(), RequestMetadata.getDefaultInstance());
assertThat(correctFuture.get()).isEqualTo(ImmutableSet.of(workerName));
verify(instance, times(1)).findMissingBlobs(eq(digests), any(RequestMetadata.class));
verify(unavailableInstance, times(1)).findMissingBlobs(eq(digests), any(RequestMetadata.class));
verify(backplane, times(1)).adjustBlobLocations(eq(digest), eq(ImmutableSet.of(workerName)), eq(ImmutableSet.of()));
}
use of com.google.cloud.kms.v1.Digest in project bazel-buildfarm by bazelbuild.
the class StubInstanceTest method inputStreamRetriesOnDeadlineExceededWithProgress.
@Test
public void inputStreamRetriesOnDeadlineExceededWithProgress() throws IOException, InterruptedException {
ByteString content = ByteString.copyFromUtf8("1");
serviceRegistry.addService(new ByteStreamImplBase() {
boolean first = true;
@Override
public void read(ReadRequest request, StreamObserver<ReadResponse> responseObserver) {
if (first && request.getReadOffset() == 0) {
first = false;
responseObserver.onNext(ReadResponse.newBuilder().setData(content).build());
responseObserver.onError(Status.DEADLINE_EXCEEDED.asException());
} else if (request.getReadOffset() == 1) {
responseObserver.onCompleted();
} else {
// all others fail with unimplemented
responseObserver.onError(Status.UNIMPLEMENTED.asException());
}
}
});
Instance instance = newStubInstance("input-stream-stalled");
ByteArrayOutputStream out = new ByteArrayOutputStream();
Digest delayedDigest = Digest.newBuilder().setHash("delayed-blob-name").setSizeBytes(1).build();
try (InputStream in = instance.newBlobInput(delayedDigest, 0, 1, SECONDS, RequestMetadata.getDefaultInstance())) {
ByteStreams.copy(in, out);
}
assertThat(ByteString.copyFrom(out.toByteArray())).isEqualTo(content);
instance.stop();
}
use of com.google.cloud.kms.v1.Digest in project bazel-buildfarm by bazelbuild.
the class StubInstanceTest method inputStreamThrowsNonDeadlineExceededCausal.
@Test
public void inputStreamThrowsNonDeadlineExceededCausal() throws IOException, InterruptedException {
serviceRegistry.addService(new ByteStreamImplBase() {
@Override
public void read(ReadRequest request, StreamObserver<ReadResponse> responseObserver) {
responseObserver.onError(Status.UNAVAILABLE.asException());
}
});
OutputStream out = mock(OutputStream.class);
IOException ioException = null;
Instance instance = newStubInstance("input-stream-non-deadline-exceeded");
Digest unavailableDigest = Digest.newBuilder().setHash("unavailable-blob-name").setSizeBytes(1).build();
try (InputStream in = instance.newBlobInput(unavailableDigest, 0, 1, SECONDS, RequestMetadata.getDefaultInstance())) {
ByteStreams.copy(in, out);
} catch (IOException e) {
ioException = e;
}
assertThat(ioException).isNotNull();
Status status = Status.fromThrowable(ioException);
assertThat(status.getCode()).isEqualTo(Code.UNAVAILABLE);
verifyZeroInteractions(out);
instance.stop();
}
use of com.google.cloud.kms.v1.Digest in project bazel-buildfarm by bazelbuild.
the class StubInstanceTest method putAllBlobsUploadsBlobs.
@Test
public void putAllBlobsUploadsBlobs() throws Exception {
String instanceName = "putAllBlobs-test";
serviceRegistry.addService(new ContentAddressableStorageImplBase() {
@Override
public void batchUpdateBlobs(BatchUpdateBlobsRequest batchRequest, StreamObserver<BatchUpdateBlobsResponse> responseObserver) {
checkState(batchRequest.getInstanceName().equals(instanceName));
responseObserver.onNext(BatchUpdateBlobsResponse.newBuilder().addAllResponses(batchRequest.getRequestsList().stream().map(request -> Response.newBuilder().setDigest(request.getDigest()).build()).collect(Collectors.toList())).build());
responseObserver.onCompleted();
}
});
Instance instance = newStubInstance("putAllBlobs-test");
ByteString first = ByteString.copyFromUtf8("first");
ByteString last = ByteString.copyFromUtf8("last");
ImmutableList<ByteString> blobs = ImmutableList.of(first, last);
ImmutableList<Digest> digests = ImmutableList.of(DIGEST_UTIL.compute(first), DIGEST_UTIL.compute(last));
assertThat(instance.putAllBlobs(blobs, RequestMetadata.getDefaultInstance())).containsAllIn(digests);
}
Aggregations