Search in sources :

Example 21 with ByteString

use of com.google.protobuf.ByteString in project bazel by bazelbuild.

the class GrpcActionCache method createFileFromStream.

private ContentDigest createFileFromStream(Map<ContentDigest, Pair<Path, FileMetadata>> metadataMap, Iterator<CasDownloadReply> replies) throws IOException, CacheNotFoundException {
    Preconditions.checkArgument(replies.hasNext());
    CasDownloadReply reply = replies.next();
    if (reply.hasStatus()) {
        handleDownloadStatus(reply.getStatus());
    }
    BlobChunk chunk = reply.getData();
    ContentDigest digest = chunk.getDigest();
    Preconditions.checkArgument(metadataMap.containsKey(digest));
    Pair<Path, FileMetadata> metadata = metadataMap.get(digest);
    Path path = metadata.first;
    FileSystemUtils.createDirectoryAndParents(path.getParentDirectory());
    try (OutputStream stream = path.getOutputStream()) {
        ByteString data = chunk.getData();
        data.writeTo(stream);
        long bytesLeft = digest.getSizeBytes() - data.size();
        while (bytesLeft > 0) {
            Preconditions.checkArgument(replies.hasNext());
            reply = replies.next();
            if (reply.hasStatus()) {
                handleDownloadStatus(reply.getStatus());
            }
            chunk = reply.getData();
            data = chunk.getData();
            Preconditions.checkArgument(!chunk.hasDigest());
            Preconditions.checkArgument(chunk.getOffset() == digest.getSizeBytes() - bytesLeft);
            data.writeTo(stream);
            bytesLeft -= data.size();
        }
        path.setExecutable(metadata.second.getExecutable());
    }
    return digest;
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) BlobChunk(com.google.devtools.build.lib.remote.RemoteProtocol.BlobChunk) CasDownloadReply(com.google.devtools.build.lib.remote.RemoteProtocol.CasDownloadReply) ByteString(com.google.protobuf.ByteString) OutputStream(java.io.OutputStream) FileMetadata(com.google.devtools.build.lib.remote.RemoteProtocol.FileMetadata) ContentDigest(com.google.devtools.build.lib.remote.RemoteProtocol.ContentDigest)

Example 22 with ByteString

use of com.google.protobuf.ByteString in project bazel by bazelbuild.

the class DigestTest method testFromVirtualInput.

@Test
public void testFromVirtualInput() throws Exception {
    Pair<ByteString, Long> result = Digest.fromVirtualActionInput(new VirtualActionInput() {

        @Override
        public void writeTo(OutputStream out) throws IOException {
            out.write(UGLY.getBytes(UTF_8));
        }

        @Override
        public String getExecPathString() {
            throw new UnsupportedOperationException();
        }

        @Override
        public PathFragment getExecPath() {
            throw new UnsupportedOperationException();
        }
    });
    assertEquals(UGLY_DIGEST, result.first.toStringUtf8());
    assertEquals(UGLY.length(), result.second.longValue());
}
Also used : VirtualActionInput(com.google.devtools.build.lib.actions.cache.VirtualActionInput) ByteString(com.google.protobuf.ByteString) OutputStream(java.io.OutputStream) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) IOException(java.io.IOException) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 23 with ByteString

use of com.google.protobuf.ByteString in project bazel by bazelbuild.

the class SingleBuildFileCacheTest method testUnreadableFileWhenFileSystemSupportsDigest.

@Test
public void testUnreadableFileWhenFileSystemSupportsDigest() throws Exception {
    byte[] expectedDigestRaw = MessageDigest.getInstance("md5").digest("randomtext".getBytes(StandardCharsets.UTF_8));
    ByteString expectedDigest = ByteString.copyFrom(expectedDigestRaw);
    md5Overrides.put("/unreadable", expectedDigestRaw);
    ActionInput input = ActionInputHelper.fromPath("/unreadable");
    Path file = fs.getPath("/unreadable");
    file.getOutputStream().close();
    file.chmod(0);
    ByteString actualDigest = ByteString.copyFrom(underTest.getDigest(input));
    assertThat(expectedDigest).isEqualTo(actualDigest);
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) ActionInput(com.google.devtools.build.lib.actions.ActionInput) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 24 with ByteString

use of com.google.protobuf.ByteString in project bazel by bazelbuild.

the class SingleBuildFileCacheTest method testBasic.

@Test
public void testBasic() throws Exception {
    ActionInput empty = ActionInputHelper.fromPath("/empty");
    assertEquals(0, underTest.getSizeInBytes(empty));
    byte[] digestBytes = underTest.getDigest(empty);
    ByteString digest = ByteString.copyFromUtf8(BaseEncoding.base16().lowerCase().encode(digestBytes));
    assertEquals(EMPTY_MD5, digest.toStringUtf8());
    assertEquals("/empty", underTest.getInputFromDigest(digest).getExecPathString());
    assert (underTest.contentsAvailableLocally(digest));
    ByteString other = ByteString.copyFrom("f41d8cd98f00b204e9800998ecf8427e", "UTF-16");
    assert (!underTest.contentsAvailableLocally(other));
    assert (calls.containsKey("/empty"));
}
Also used : ActionInput(com.google.devtools.build.lib.actions.ActionInput) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 25 with ByteString

use of com.google.protobuf.ByteString in project j2objc by google.

the class CompatibilityTest method checkGetExtensions.

private void checkGetExtensions(TypicalDataOrBuilder data) {
    assertEquals(123, ((Integer) data.getExtension(Typical.myPrimitiveExtension)).intValue());
    Object msg = data.getExtension(Typical.myExtension);
    assertTrue(msg instanceof TypicalDataMessage);
    assertEquals(321, ((TypicalDataMessage) msg).getMyMessageInt());
    Object result = data.getExtension(Typical.myRepeatedPrimitiveExtension);
    assertTrue(result instanceof List);
    assertTrue(((List) result).get(0) instanceof Integer);
    assertEquals(3, data.getExtensionCount(Typical.myRepeatedPrimitiveExtension));
    assertEquals(2, ((Integer) data.getExtension(Typical.myRepeatedPrimitiveExtension, 1)).intValue());
    assertEquals(3, ((Integer) data.getExtension(Typical.myRepeatedPrimitiveExtension, 2)).intValue());
    assertEquals(2, data.getExtensionCount(Typical.myRepeatedExtension));
    result = data.getExtension(Typical.myRepeatedExtension, 1);
    assertTrue(result instanceof TypicalDataMessage);
    assertEquals(543, ((TypicalDataMessage) result).getMyMessageInt());
    assertEquals(TypicalData.EnumType.VALUE1, data.getExtension(Typical.myEnumExtension));
    result = data.getExtension(Typical.myBytesExtension);
    assertTrue(result instanceof ByteString);
    assertEquals("abc", new String(((ByteString) result).toByteArray()));
    result = data.getExtension(Typical.myBoolExtension);
    assertEquals(Boolean.TRUE, result);
    assertEquals(456, ((Integer) data.getExtension(MsgWithNestedExtensions.intExt)).intValue());
}
Also used : TypicalDataMessage(protos.TypicalDataMessage) ByteString(com.google.protobuf.ByteString) ArrayList(java.util.ArrayList) List(java.util.List) ByteString(com.google.protobuf.ByteString)

Aggregations

ByteString (com.google.protobuf.ByteString)151 Test (org.junit.Test)35 ArrayList (java.util.ArrayList)30 IOException (java.io.IOException)27 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)18 ServerRequest (com.pokegoapi.main.ServerRequest)13 RequestFailedException (com.pokegoapi.exceptions.request.RequestFailedException)10 Map (java.util.Map)10 HashMap (java.util.HashMap)9 List (java.util.List)9 AggregateResponse (org.apache.hadoop.hbase.protobuf.generated.AggregateProtos.AggregateResponse)9 BeforeTest (org.testng.annotations.BeforeTest)9 Test (org.testng.annotations.Test)9 Connection (org.apache.hadoop.hbase.client.Connection)8 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)7 Scan (org.apache.hadoop.hbase.client.Scan)7 DeleteRangeResponse (com.coreos.jetcd.api.DeleteRangeResponse)6 RangeResponse (com.coreos.jetcd.api.RangeResponse)6 RpcCallback (com.google.protobuf.RpcCallback)6 RpcController (com.google.protobuf.RpcController)6