Search in sources :

Example 11 with ReadRequest

use of com.google.spanner.v1.ReadRequest in project java-spanner by googleapis.

the class DatabaseClientImplTest method testExecuteReadWithPriority.

@Test
public void testExecuteReadWithPriority() {
    DatabaseClient client = spanner.getDatabaseClient(DatabaseId.of(TEST_PROJECT, TEST_INSTANCE, TEST_DATABASE));
    try (ResultSet resultSet = client.singleUse().read(READ_TABLE_NAME, KeySet.singleKey(Key.of(1L)), READ_COLUMN_NAMES, Options.priority(RpcPriority.HIGH))) {
        while (resultSet.next()) {
        }
    }
    List<ReadRequest> requests = mockSpanner.getRequestsOfType(ReadRequest.class);
    assertThat(requests).hasSize(1);
    ReadRequest request = requests.get(0);
    assertNotNull(request.getRequestOptions());
    assertEquals(Priority.PRIORITY_HIGH, request.getRequestOptions().getPriority());
}
Also used : ReadRequest(com.google.spanner.v1.ReadRequest) Test(org.junit.Test)

Example 12 with ReadRequest

use of com.google.spanner.v1.ReadRequest in project grpc-gcp-java by GoogleCloudPlatform.

the class SpannerClientV1TestCases method testRead.

void testRead() throws InterruptedException {
    System.out.println("\nTestRead");
    SpannerClient client = getClient();
    Session session = client.createSession(CreateSessionRequest.newBuilder().setDatabase(database).build());
    ReadRequest request = ReadRequest.newBuilder().setSession(session.getName()).setTable(TABLE).setKeySet(KeySet.newBuilder().setAll(true).build()).addColumns("users").addColumns("firstname").addColumns("lastname").build();
    RpcCall<ReadRequest, ResultSet> rpcCall = (ReadRequest req) -> client.read(req);
    doTestBlocking(request, rpcCall);
    cleanUpClient(client, session.getName());
}
Also used : PartialResultSet(com.google.spanner.v1.PartialResultSet) ResultSet(com.google.spanner.v1.ResultSet) SpannerClient(com.google.cloud.spanner.v1.SpannerClient) Session(com.google.spanner.v1.Session) ReadRequest(com.google.spanner.v1.ReadRequest)

Example 13 with ReadRequest

use of com.google.spanner.v1.ReadRequest in project grpc-gcp-java by GoogleCloudPlatform.

the class SpannerTestCases method testReadAsync.

void testReadAsync() throws InterruptedException {
    System.out.println("\nTestReadAsync");
    ManagedChannel channel = getChannel();
    SpannerStub stub = getStub(channel);
    AsyncResponseObserver<Session> sessionObs = new AsyncResponseObserver<>();
    stub.createSession(CreateSessionRequest.newBuilder().setDatabase(database).build(), sessionObs);
    ReadRequest request = ReadRequest.newBuilder().setSession(sessionObs.get().getName()).setTable("small_table").setKeySet(KeySet.newBuilder().setAll(true).build()).addColumns("users").addColumns("firstname").addColumns("lastname").build();
    AsyncCall<ReadRequest, ResultSet> asyncCall = (ReadRequest req, AsyncResponseObserver<ResultSet> resp) -> stub.read(req, resp);
    doTestAsync(channel, request, asyncCall);
    deleteAndCloseAsync(stub, channel, sessionObs.get().getName());
}
Also used : SpannerStub(com.google.spanner.v1.SpannerGrpc.SpannerStub) PartialResultSet(com.google.spanner.v1.PartialResultSet) ResultSet(com.google.spanner.v1.ResultSet) ManagedChannel(io.grpc.ManagedChannel) GcpManagedChannel(com.google.grpc.gcp.GcpManagedChannel) Session(com.google.spanner.v1.Session) ReadRequest(com.google.spanner.v1.ReadRequest)

Aggregations

ReadRequest (com.google.spanner.v1.ReadRequest)11 Test (org.junit.Test)8 ByteString (com.google.protobuf.ByteString)6 PartialResultSet (com.google.spanner.v1.PartialResultSet)6 Session (com.google.spanner.v1.Session)5 PartitionReadRequest (com.google.spanner.v1.PartitionReadRequest)4 ResultSet (com.google.spanner.v1.ResultSet)4 StatusRuntimeException (io.grpc.StatusRuntimeException)4 MockStreamObserver (com.google.api.gax.grpc.testing.MockStreamObserver)2 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)2 GcpManagedChannel (com.google.grpc.gcp.GcpManagedChannel)2 ListValue (com.google.protobuf.ListValue)2 ManagedChannel (io.grpc.ManagedChannel)2 SpannerClient (com.google.cloud.spanner.v1.SpannerClient)1 AbstractMessage (com.google.protobuf.AbstractMessage)1 Value (com.google.protobuf.Value)1 SpannerBlockingStub (com.google.spanner.v1.SpannerGrpc.SpannerBlockingStub)1 SpannerStub (com.google.spanner.v1.SpannerGrpc.SpannerStub)1 ExecutionException (java.util.concurrent.ExecutionException)1