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();
}
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);
}
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");
}
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");
}
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);
}
Aggregations