Search in sources :

Example 6 with ByteString

use of com.google.protobuf.ByteString in project grpc-java by grpc.

the class AsyncClient method newRequest.

private SimpleRequest newRequest() {
    ByteString body = ByteString.copyFrom(new byte[config.clientPayload]);
    Payload payload = Payload.newBuilder().setType(config.payloadType).setBody(body).build();
    return SimpleRequest.newBuilder().setResponseType(config.payloadType).setResponseSize(config.serverPayload).setPayload(payload).build();
}
Also used : ByteString(com.google.protobuf.ByteString) Payload(io.grpc.benchmarks.proto.Messages.Payload)

Example 7 with ByteString

use of com.google.protobuf.ByteString in project grpc-java by grpc.

the class TestServiceImpl method generatePayload.

/**
   * Generates a payload of desired type and size. Reads compressableBuffer or
   * uncompressableBuffer as a circular buffer.
   */
private ByteString generatePayload(ByteString dataBuffer, int offset, int size) {
    ByteString payload = ByteString.EMPTY;
    // This offset would never pass the array boundary.
    int begin = offset;
    int end = 0;
    int bytesLeft = size;
    while (bytesLeft > 0) {
        end = Math.min(begin + bytesLeft, dataBuffer.size());
        // ByteString.substring returns the substring from begin, inclusive, to end, exclusive.
        payload = payload.concat(dataBuffer.substring(begin, end));
        bytesLeft -= (end - begin);
        begin = end % dataBuffer.size();
    }
    return payload;
}
Also used : ByteString(com.google.protobuf.ByteString)

Example 8 with ByteString

use of com.google.protobuf.ByteString in project grpc-java by grpc.

the class TestServiceImpl method createBufferFromFile.

/**
   * Creates a buffer with data read from a file.
   */
// Not concerned about suppression; expected to be exceedingly rare
@SuppressWarnings("Finally")
private ByteString createBufferFromFile(String fileClassPath) {
    ByteString buffer = ByteString.EMPTY;
    InputStream inputStream = getClass().getResourceAsStream(fileClassPath);
    if (inputStream == null) {
        throw new IllegalArgumentException("Unable to locate file on classpath: " + fileClassPath);
    }
    try {
        buffer = ByteString.readFrom(inputStream);
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        try {
            inputStream.close();
        } catch (IOException ignorable) {
        // ignore
        }
    }
    return buffer;
}
Also used : ByteString(com.google.protobuf.ByteString) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 9 with ByteString

use of com.google.protobuf.ByteString in project grpc-java by grpc.

the class ProtoReflectionServiceTest method fileContainingExtension.

@Test
public void fileContainingExtension() throws Exception {
    ServerReflectionRequest request = ServerReflectionRequest.newBuilder().setHost(TEST_HOST).setFileContainingExtension(ExtensionRequest.newBuilder().setContainingType("grpc.reflection.testing.ThirdLevelType").setExtensionNumber(100).build()).build();
    List<ByteString> goldenResponse = Arrays.asList(ReflectionTestProto.getDescriptor().toProto().toByteString(), ReflectionTestDepthTwoProto.getDescriptor().toProto().toByteString(), ReflectionTestDepthTwoAlternateProto.getDescriptor().toProto().toByteString(), ReflectionTestDepthThreeProto.getDescriptor().toProto().toByteString());
    StreamRecorder<ServerReflectionResponse> responseObserver = StreamRecorder.create();
    StreamObserver<ServerReflectionRequest> requestObserver = stub.serverReflectionInfo(responseObserver);
    requestObserver.onNext(request);
    requestObserver.onCompleted();
    List<ByteString> response = responseObserver.firstValue().get().getFileDescriptorResponse().getFileDescriptorProtoList();
    assertEquals(goldenResponse.size(), response.size());
    assertEquals(new HashSet<ByteString>(goldenResponse), new HashSet<ByteString>(response));
}
Also used : ByteString(com.google.protobuf.ByteString) ServerReflectionRequest(io.grpc.reflection.v1alpha.ServerReflectionRequest) ServerReflectionResponse(io.grpc.reflection.v1alpha.ServerReflectionResponse) Test(org.junit.Test)

Example 10 with ByteString

use of com.google.protobuf.ByteString in project grpc-java by grpc.

the class ProtoReflectionServiceTest method fileContainingSymbol.

@Test
public void fileContainingSymbol() throws Exception {
    ServerReflectionRequest request = ServerReflectionRequest.newBuilder().setHost(TEST_HOST).setFileContainingSymbol("grpc.reflection.testing.ReflectableService.Method").build();
    List<ByteString> goldenResponse = Arrays.asList(ReflectionTestProto.getDescriptor().toProto().toByteString(), ReflectionTestDepthTwoProto.getDescriptor().toProto().toByteString(), ReflectionTestDepthTwoAlternateProto.getDescriptor().toProto().toByteString(), ReflectionTestDepthThreeProto.getDescriptor().toProto().toByteString());
    StreamRecorder<ServerReflectionResponse> responseObserver = StreamRecorder.create();
    StreamObserver<ServerReflectionRequest> requestObserver = stub.serverReflectionInfo(responseObserver);
    requestObserver.onNext(request);
    requestObserver.onCompleted();
    List<ByteString> response = responseObserver.firstValue().get().getFileDescriptorResponse().getFileDescriptorProtoList();
    assertEquals(goldenResponse.size(), response.size());
    assertEquals(new HashSet<ByteString>(goldenResponse), new HashSet<ByteString>(response));
}
Also used : ByteString(com.google.protobuf.ByteString) ServerReflectionRequest(io.grpc.reflection.v1alpha.ServerReflectionRequest) ServerReflectionResponse(io.grpc.reflection.v1alpha.ServerReflectionResponse) Test(org.junit.Test)

Aggregations

ByteString (com.google.protobuf.ByteString)159 Test (org.junit.Test)36 ArrayList (java.util.ArrayList)31 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