use of build.buildfarm.common.grpc.ByteStreamServiceWriter in project bazel-buildfarm by bazelbuild.
the class GrpcCASTest method writeIsResumable.
@Test
public void writeIsResumable() throws Exception {
UUID uuid = UUID.randomUUID();
ByteString writeContent = ByteString.copyFromUtf8("written");
Digest digest = DIGEST_UTIL.compute(writeContent);
String instanceName = "test";
HashCode hash = HashCode.fromString(digest.getHash());
String resourceName = ByteStreamUploader.uploadResourceName(instanceName, uuid, hash, digest.getSizeBytes());
// better test might just put a full gRPC CAS behind an in-process and validate state
SettableFuture<ByteString> content = SettableFuture.create();
serviceRegistry.addService(new ByteStreamServiceWriter(resourceName, content, (int) digest.getSizeBytes()));
Channel channel = InProcessChannelBuilder.forName(fakeServerName).directExecutor().build();
GrpcCAS cas = new GrpcCAS(instanceName, channel, /* uploader=*/
null, onExpirations);
RequestMetadata requestMetadata = RequestMetadata.getDefaultInstance();
Write initialWrite = cas.getWrite(digest, uuid, requestMetadata);
try (OutputStream writeOut = initialWrite.getOutput(1, SECONDS, () -> {
})) {
writeContent.substring(0, 4).writeTo(writeOut);
}
Write finalWrite = cas.getWrite(digest, uuid, requestMetadata);
try (OutputStream writeOut = finalWrite.getOutput(1, SECONDS, () -> {
})) {
writeContent.substring(4).writeTo(writeOut);
}
assertThat(content.get(1, TimeUnit.SECONDS)).isEqualTo(writeContent);
}
Aggregations