use of com.google.cloud.kms.v1.Digest in project bazel-buildfarm by bazelbuild.
the class MemoryInstanceTest method executeRespectsSkipCacheLookup.
@Test
public void executeRespectsSkipCacheLookup() throws InterruptedException {
Digest actionDigest = createAction(Action.newBuilder());
// populate actionDigest in AC
instance.putActionResult(DigestUtil.asActionKey(actionDigest), ActionResult.getDefaultInstance());
AtomicReference<Operation> operation = new AtomicReference<>(null);
instance.execute(actionDigest, /* skipCacheLookup=*/
true, ExecutionPolicy.getDefaultInstance(), ResultsCachePolicy.getDefaultInstance(), RequestMetadata.getDefaultInstance(), o -> operation.compareAndSet(null, o));
String operationName = operation.get().getName();
assertThat(outstandingOperations.contains(operationName)).isTrue();
Operation queuedOperation = outstandingOperations.get(operationName);
assertThat(AbstractServerInstance.isQueued(queuedOperation)).isTrue();
}
use of com.google.cloud.kms.v1.Digest in project bazel-buildfarm by bazelbuild.
the class CASFileCacheTest method startSkipsLoadingExistingBlob.
@Test
public void startSkipsLoadingExistingBlob() throws IOException, InterruptedException {
FileStore fileStore = Files.getFileStore(root);
ByteString blob = ByteString.copyFromUtf8("blob");
Digest blobDigest = DIGEST_UTIL.compute(blob);
Path path = fileCache.getPath(fileCache.getKey(blobDigest, false));
Path execPath = fileCache.getPath(fileCache.getKey(blobDigest, true));
Files.write(path, blob.toByteArray());
EvenMoreFiles.setReadOnlyPerms(path, false, fileStore);
Files.write(execPath, blob.toByteArray());
EvenMoreFiles.setReadOnlyPerms(execPath, true, fileStore);
StartupCacheResults results = fileCache.start(/* skipLoad=*/
true);
// check the startup results to ensure our two files were processed
assertThat(results.load.loadSkipped).isTrue();
assertThat(results.load.scan.computeDirs.size()).isEqualTo(0);
assertThat(results.load.scan.deleteFiles.size()).isEqualTo(0);
assertThat(results.load.scan.fileKeys.size()).isEqualTo(0);
assertThat(results.load.invalidDirectories.size()).isEqualTo(0);
}
use of com.google.cloud.kms.v1.Digest in project bazel-buildfarm by bazelbuild.
the class CASFileCacheTest method startRemovesInvalidEntries.
@Test
public void startRemovesInvalidEntries() throws IOException, InterruptedException {
Path tooFewComponents = root.resolve("00").resolve("toofewcomponents");
Path tooManyComponents = root.resolve("00").resolve("too_many_components_here");
Path invalidDigest = root.resolve("00").resolve("digest");
ByteString validBlob = ByteString.copyFromUtf8("valid");
Digest validDigest = DIGEST_UTIL.compute(ByteString.copyFromUtf8("valid"));
Path invalidExec = fileCache.getPath(CASFileCache.getFileName(validDigest, false) + "_regular");
Files.write(tooFewComponents, ImmutableList.of("Too Few Components"), StandardCharsets.UTF_8);
Files.write(tooManyComponents, ImmutableList.of("Too Many Components"), StandardCharsets.UTF_8);
Files.write(invalidDigest, ImmutableList.of("Digest is not valid"), StandardCharsets.UTF_8);
Files.write(invalidExec, // content would match but for invalid exec field
validBlob.toByteArray());
fileCache.start(/* skipLoad=*/
false);
assertThat(!Files.exists(tooFewComponents)).isTrue();
assertThat(!Files.exists(tooManyComponents)).isTrue();
assertThat(!Files.exists(invalidDigest)).isTrue();
assertThat(!Files.exists(invalidExec)).isTrue();
}
use of com.google.cloud.kms.v1.Digest in project bazel-buildfarm by bazelbuild.
the class CASFileCacheTest method startLoadsExistingBlob.
@Test
public void startLoadsExistingBlob() throws IOException, InterruptedException {
FileStore fileStore = Files.getFileStore(root);
ByteString blob = ByteString.copyFromUtf8("blob");
Digest blobDigest = DIGEST_UTIL.compute(blob);
Path path = fileCache.getPath(fileCache.getKey(blobDigest, false));
Path execPath = fileCache.getPath(fileCache.getKey(blobDigest, true));
Files.write(path, blob.toByteArray());
EvenMoreFiles.setReadOnlyPerms(path, false, fileStore);
Files.write(execPath, blob.toByteArray());
EvenMoreFiles.setReadOnlyPerms(execPath, true, fileStore);
StartupCacheResults results = fileCache.start(false);
// check the startup results to ensure our two files were processed
assertThat(results.load.loadSkipped).isFalse();
assertThat(results.load.scan.computeDirs.size()).isEqualTo(0);
assertThat(results.load.scan.deleteFiles.size()).isEqualTo(0);
assertThat(results.load.scan.fileKeys.size()).isEqualTo(2);
assertThat(results.load.invalidDirectories.size()).isEqualTo(0);
// explicitly not providing blob via blobs, this would throw if fetched from factory
//
// FIXME https://github.com/google/truth/issues/285 assertThat(Path) is ambiguous
assertThat(fileCache.put(blobDigest, false).equals(path)).isTrue();
assertThat(fileCache.put(blobDigest, true).equals(execPath)).isTrue();
}
use of com.google.cloud.kms.v1.Digest in project bazel-buildfarm by bazelbuild.
the class CASFileCacheTest method newInputThrowsNoSuchFileExceptionWithoutDelegate.
@Test
public void newInputThrowsNoSuchFileExceptionWithoutDelegate() throws Exception {
ContentAddressableStorage undelegatedCAS = new CASFileCache(root, /* maxSizeInBytes=*/
1024, /* maxEntrySizeInBytes=*/
1024, /* hexBucketLevels=*/
1, storeFileDirsIndexInMemory, DIGEST_UTIL, expireService, /* accessRecorder=*/
directExecutor(), storage, /* directoriesIndexDbName=*/
":memory:", /* onPut=*/
digest -> {
}, /* onExpire=*/
digests -> {
}, /* delegate=*/
null) {
@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();
}
};
ByteString blob = ByteString.copyFromUtf8("Missing Entry");
Digest blobDigest = DIGEST_UTIL.compute(blob);
NoSuchFileException expected = null;
try (InputStream in = undelegatedCAS.newInput(blobDigest, /* offset=*/
0)) {
fail("should not get here");
} catch (NoSuchFileException e) {
expected = e;
}
assertThat(expected).isNotNull();
}
Aggregations