use of build.buildfarm.common.DigestUtil in project bazel-buildfarm by bazelbuild.
the class IndexWorker method main.
public static void main(String[] args) throws Exception {
String host = args[0];
String instanceName = args[1];
DigestUtil digestUtil = DigestUtil.forHash(args[2]);
String reindexworker = args[3];
ManagedChannel channel = createChannel(host);
Instance instance = new StubInstance(instanceName, digestUtil, channel);
CasIndexResults results = instance.reindexCas(reindexworker);
System.out.println(results.toMessage());
instance.stop();
}
use of build.buildfarm.common.DigestUtil in project bazel-buildfarm by bazelbuild.
the class Mount method main.
@SuppressWarnings("BusyWait")
public static void main(String[] args) throws Exception {
String host = args[0];
String instanceName = args[1];
DigestUtil digestUtil = DigestUtil.forHash(args[2]);
ManagedChannel channel = createChannel(host);
Instance instance = new StubInstance(instanceName, digestUtil, channel);
Path cwd = Paths.get(".");
FuseCAS fuse = new FuseCAS(cwd.resolve(args[3]), new InputStreamFactory() {
final Map<Digest, ByteString> cache = new HashMap<>();
public synchronized InputStream newInput(Digest blobDigest, long offset) {
if (cache.containsKey(blobDigest)) {
return cache.get(blobDigest).substring((int) offset).newInput();
}
try {
ByteString value = getBlob(instance, blobDigest, RequestMetadata.getDefaultInstance());
if (offset == 0) {
cache.put(blobDigest, value);
}
return value.newInput();
} catch (IOException e) {
return null;
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return null;
}
}
});
// FIXME make bettar
fuse.createInputRoot(args[5], DigestUtil.parseDigest(args[4]));
try {
// noinspection InfiniteLoopStatement
for (; ; ) {
Thread.sleep(1000);
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} finally {
fuse.stop();
}
}
use of build.buildfarm.common.DigestUtil in project bazel-buildfarm by bazelbuild.
the class MemoryCASTest method duplicateEntryRegistersMultipleOnExpiration.
@Test
public void duplicateEntryRegistersMultipleOnExpiration() throws IOException, InterruptedException {
ContentAddressableStorage storage = new MemoryCAS(10);
DigestUtil digestUtil = new DigestUtil(DigestUtil.HashFunction.SHA256);
Runnable mockOnExpiration = mock(Runnable.class);
storage.put(new Blob(ByteString.copyFromUtf8("stdout"), digestUtil), mockOnExpiration);
storage.put(new Blob(ByteString.copyFromUtf8("stdout"), digestUtil), mockOnExpiration);
verify(mockOnExpiration, never()).run();
storage.put(new Blob(ByteString.copyFromUtf8("stderr"), digestUtil));
verify(mockOnExpiration, times(2)).run();
}
use of build.buildfarm.common.DigestUtil in project bazel-buildfarm by bazelbuild.
the class MemoryCASTest method expireShouldOccurAtLimitExactly.
@Test
public void expireShouldOccurAtLimitExactly() throws IOException, InterruptedException {
ContentAddressableStorage storage = new MemoryCAS(11);
DigestUtil digestUtil = new DigestUtil(DigestUtil.HashFunction.SHA256);
Runnable mockOnExpiration = mock(Runnable.class);
storage.put(new Blob(ByteString.copyFromUtf8("stdin"), digestUtil), mockOnExpiration);
storage.put(new Blob(ByteString.copyFromUtf8("stdout"), digestUtil), mockOnExpiration);
verify(mockOnExpiration, never()).run();
storage.put(new Blob(ByteString.copyFromUtf8("a"), digestUtil));
verify(mockOnExpiration, times(1)).run();
}
use of build.buildfarm.common.DigestUtil in project bazel-buildfarm by bazelbuild.
the class BuildFarmServerTest method progressiveUploadCompletes.
@Test
public void progressiveUploadCompletes() throws Exception {
DigestUtil digestUtil = new DigestUtil(HashFunction.SHA256);
ByteString content = ByteString.copyFromUtf8("Hello, World!");
Digest digest = digestUtil.compute(content);
HashCode hash = HashCode.fromString(digest.getHash());
UUID uuid = UUID.randomUUID();
String resourceName = ByteStreamUploader.uploadResourceName(INSTANCE_NAME, uuid, hash, content.size());
assertThat(getBlob(digest)).isNull();
FutureWriteResponseObserver futureResponder = new FutureWriteResponseObserver();
StreamObserver<WriteRequest> requestObserver = ByteStreamGrpc.newStub(inProcessChannel).write(futureResponder);
ByteString shortContent = content.substring(0, 6);
requestObserver.onNext(WriteRequest.newBuilder().setWriteOffset(0).setResourceName(resourceName).setData(shortContent).build());
requestObserver.onError(Status.CANCELLED.asException());
// should be done
assertThat(futureResponder.isDone()).isTrue();
futureResponder = new FutureWriteResponseObserver();
requestObserver = ByteStreamGrpc.newStub(inProcessChannel).write(futureResponder);
requestObserver.onNext(WriteRequest.newBuilder().setWriteOffset(6).setResourceName(resourceName).setData(content.substring(6)).setFinishWrite(true).build());
requestObserver.onCompleted();
assertThat(futureResponder.get()).isEqualTo(WriteResponse.newBuilder().setCommittedSize(content.size()).build());
assertThat(getBlob(digest)).isEqualTo(content);
}
Aggregations