Search in sources :

Example 1 with ByteStreamServiceWriter

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);
}
Also used : Write(build.buildfarm.common.Write) HashCode(com.google.common.hash.HashCode) Digest(build.bazel.remote.execution.v2.Digest) ByteString(com.google.protobuf.ByteString) Channel(io.grpc.Channel) OutputStream(java.io.OutputStream) ByteString(com.google.protobuf.ByteString) UUID(java.util.UUID) ByteStreamServiceWriter(build.buildfarm.common.grpc.ByteStreamServiceWriter) RequestMetadata(build.bazel.remote.execution.v2.RequestMetadata) Test(org.junit.Test)

Aggregations

Digest (build.bazel.remote.execution.v2.Digest)1 RequestMetadata (build.bazel.remote.execution.v2.RequestMetadata)1 Write (build.buildfarm.common.Write)1 ByteStreamServiceWriter (build.buildfarm.common.grpc.ByteStreamServiceWriter)1 HashCode (com.google.common.hash.HashCode)1 ByteString (com.google.protobuf.ByteString)1 Channel (io.grpc.Channel)1 OutputStream (java.io.OutputStream)1 UUID (java.util.UUID)1 Test (org.junit.Test)1