Search in sources :

Example 46 with Digest

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();
}
Also used : Digest(build.bazel.remote.execution.v2.Digest) AtomicReference(java.util.concurrent.atomic.AtomicReference) Operation(com.google.longrunning.Operation) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 47 with Digest

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);
}
Also used : Path(java.nio.file.Path) FileStore(java.nio.file.FileStore) Digest(build.bazel.remote.execution.v2.Digest) ByteString(com.google.protobuf.ByteString) StartupCacheResults(build.buildfarm.cas.cfc.CASFileCache.StartupCacheResults) Test(org.junit.Test)

Example 48 with Digest

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();
}
Also used : Path(java.nio.file.Path) Digest(build.bazel.remote.execution.v2.Digest) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 49 with Digest

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();
}
Also used : Path(java.nio.file.Path) FileStore(java.nio.file.FileStore) Digest(build.bazel.remote.execution.v2.Digest) ByteString(com.google.protobuf.ByteString) StartupCacheResults(build.buildfarm.cas.cfc.CASFileCache.StartupCacheResults) Test(org.junit.Test)

Example 50 with Digest

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();
}
Also used : ContentAddressableStorage(build.buildfarm.cas.ContentAddressableStorage) Digest(build.bazel.remote.execution.v2.Digest) ByteString(com.google.protobuf.ByteString) InputStream(java.io.InputStream) NoSuchFileException(java.nio.file.NoSuchFileException) 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