Search in sources :

Example 61 with Digest

use of com.google.cloud.kms.v1.Digest in project bazel-buildfarm by bazelbuild.

the class CASFileCacheTest method setUp.

@Before
public void setUp() throws IOException, InterruptedException {
    MockitoAnnotations.initMocks(this);
    when(delegate.getWrite(any(Digest.class), any(UUID.class), any(RequestMetadata.class))).thenReturn(new NullWrite());
    when(delegate.newInput(any(Digest.class), any(Long.class))).thenThrow(new NoSuchFileException("null sink delegate"));
    blobs = Maps.newHashMap();
    putService = newSingleThreadExecutor();
    storage = Maps.newConcurrentMap();
    expireService = newSingleThreadExecutor();
    fileCache = new CASFileCache(root, /* maxSizeInBytes=*/
    1024, /* maxEntrySizeInBytes=*/
    1024, /* hexBucketLevels=*/
    1, storeFileDirsIndexInMemory, DIGEST_UTIL, expireService, /* accessRecorder=*/
    directExecutor(), storage, /* directoriesIndexDbName=*/
    ":memory:", onPut, onExpire, delegate) {

        @Override
        protected InputStream newExternalInput(Digest digest) throws IOException {
            ByteString content = blobs.get(digest);
            if (content == null) {
                return fileCache.newTransparentInput(digest, 0);
            }
            return content.substring((int) (long) 0).newInput();
        }
    };
    // do this so that we can remove the cache root dir
    fileCache.initializeRootDirectory();
}
Also used : Digest(build.bazel.remote.execution.v2.Digest) InputStream(java.io.InputStream) ByteString(com.google.protobuf.ByteString) NullWrite(build.buildfarm.common.Write.NullWrite) NoSuchFileException(java.nio.file.NoSuchFileException) Utils.getInterruptiblyOrIOException(build.buildfarm.common.io.Utils.getInterruptiblyOrIOException) IOException(java.io.IOException) UUID(java.util.UUID) RequestMetadata(build.bazel.remote.execution.v2.RequestMetadata) Before(org.junit.Before)

Example 62 with Digest

use of com.google.cloud.kms.v1.Digest in project bazel-buildfarm by bazelbuild.

the class DigestUtilTest method builtDigestMatchesFields.

@Test
public void builtDigestMatchesFields() {
    DigestUtil digestUtil = new DigestUtil(HashFunction.MD5);
    String bazelMd5Hash = "24ef4c36ec66c15ef9f0c96fe27c0e0b";
    long payloadSizeInBytes = 5;
    Digest digest = digestUtil.build(bazelMd5Hash, payloadSizeInBytes);
    assertThat(digest.getHash()).isEqualTo(bazelMd5Hash);
    assertThat(digest.getSizeBytes()).isEqualTo(payloadSizeInBytes);
}
Also used : Digest(build.bazel.remote.execution.v2.Digest) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 63 with Digest

use of com.google.cloud.kms.v1.Digest in project bazel-buildfarm by bazelbuild.

the class DigestUtilTest method computesSha256Hash.

@Test
public void computesSha256Hash() {
    ByteString content = ByteString.copyFromUtf8("bazel");
    DigestUtil digestUtil = new DigestUtil(HashFunction.SHA256);
    Digest digest = digestUtil.compute(content);
    assertThat(digest.getHash()).isEqualTo("aa0e09c406dd0db1a3bb250216045e81644d26c961c0e8c34e8a0354476ca6d4");
}
Also used : Digest(build.bazel.remote.execution.v2.Digest) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 64 with Digest

use of com.google.cloud.kms.v1.Digest in project bazel-buildfarm by bazelbuild.

the class DigestUtilTest method computesMd5Hash.

@Test
public void computesMd5Hash() {
    ByteString content = ByteString.copyFromUtf8("bazel");
    DigestUtil digestUtil = new DigestUtil(HashFunction.MD5);
    Digest digest = digestUtil.compute(content);
    assertThat(digest.getHash()).isEqualTo("24ef4c36ec66c15ef9f0c96fe27c0e0b");
}
Also used : Digest(build.bazel.remote.execution.v2.Digest) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 65 with Digest

use of com.google.cloud.kms.v1.Digest in project bazel-buildfarm by bazelbuild.

the class ShardInstanceTest method requeueFailsOnMissingDirectory.

@Test
public void requeueFailsOnMissingDirectory() throws Exception {
    String operationName = "missing-directory-operation";
    Digest missingDirectoryDigest = Digest.newBuilder().setHash("missing-directory").setSizeBytes(1).build();
    when(mockBackplane.propertiesEligibleForQueue(Matchers.anyList())).thenReturn(true);
    when(mockBackplane.getOperation(eq(operationName))).thenReturn(Operation.newBuilder().setName(operationName).setMetadata(Any.pack(ExecuteOperationMetadata.newBuilder().setStage(QUEUED).build())).build());
    Action action = createAction(true, true, missingDirectoryDigest, SIMPLE_COMMAND);
    Digest actionDigest = DIGEST_UTIL.compute(action);
    QueueEntry queueEntry = QueueEntry.newBuilder().setExecuteEntry(ExecuteEntry.newBuilder().setOperationName(operationName).setSkipCacheLookup(true).setActionDigest(actionDigest)).build();
    instance.requeueOperation(queueEntry, Durations.fromSeconds(60)).get();
    ArgumentCaptor<Operation> operationCaptor = ArgumentCaptor.forClass(Operation.class);
    verify(mockBackplane, times(1)).putOperation(operationCaptor.capture(), eq(COMPLETED));
    Operation operation = operationCaptor.getValue();
    assertThat(operation.getResponse().is(ExecuteResponse.class)).isTrue();
    ExecuteResponse executeResponse = operation.getResponse().unpack(ExecuteResponse.class);
    com.google.rpc.Status status = executeResponse.getStatus();
    PreconditionFailure preconditionFailure = PreconditionFailure.newBuilder().addViolations(Violation.newBuilder().setType(VIOLATION_TYPE_MISSING).setSubject("blobs/" + DigestUtil.toString(missingDirectoryDigest)).setDescription("The directory `/` was not found in the CAS.")).build();
    com.google.rpc.Status expectedStatus = com.google.rpc.Status.newBuilder().setCode(Code.FAILED_PRECONDITION.getNumber()).setMessage(invalidActionVerboseMessage(actionDigest, preconditionFailure)).addDetails(Any.pack(preconditionFailure)).build();
    assertThat(status).isEqualTo(expectedStatus);
}
Also used : Action(build.bazel.remote.execution.v2.Action) PreconditionFailure(com.google.rpc.PreconditionFailure) Digest(build.bazel.remote.execution.v2.Digest) ExecuteResponse(build.bazel.remote.execution.v2.ExecuteResponse) ByteString(com.google.protobuf.ByteString) QueuedOperation(build.buildfarm.v1test.QueuedOperation) Operation(com.google.longrunning.Operation) QueueEntry(build.buildfarm.v1test.QueueEntry) Test(org.junit.Test)

Aggregations

Digest (build.bazel.remote.execution.v2.Digest)191 ByteString (com.google.protobuf.ByteString)110 Test (org.junit.Test)99 IOException (java.io.IOException)55 Directory (build.bazel.remote.execution.v2.Directory)42 ImmutableList (com.google.common.collect.ImmutableList)35 Path (java.nio.file.Path)33 Status (io.grpc.Status)30 ExecutionException (java.util.concurrent.ExecutionException)29 RequestMetadata (build.bazel.remote.execution.v2.RequestMetadata)27 InputStream (java.io.InputStream)25 Instance (build.buildfarm.instance.Instance)24 Action (build.bazel.remote.execution.v2.Action)22 DigestUtil (build.buildfarm.common.DigestUtil)22 OutputStream (java.io.OutputStream)22 Write (build.buildfarm.common.Write)21 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)21 Operation (com.google.longrunning.Operation)21 UUID (java.util.UUID)20 ExecuteResponse (build.bazel.remote.execution.v2.ExecuteResponse)19