Search in sources :

Example 1 with PartitionReadRequest

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

the class SpannerClientTest method partitionReadTest.

@Test
public void partitionReadTest() throws Exception {
    PartitionResponse expectedResponse = PartitionResponse.newBuilder().addAllPartitions(new ArrayList<Partition>()).setTransaction(Transaction.newBuilder().build()).build();
    mockSpanner.addResponse(expectedResponse);
    PartitionReadRequest request = PartitionReadRequest.newBuilder().setSession(SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]").toString()).setTransaction(TransactionSelector.newBuilder().build()).setTable("table110115790").setIndex("index100346066").addAllColumns(new ArrayList<String>()).setKeySet(KeySet.newBuilder().build()).setPartitionOptions(PartitionOptions.newBuilder().build()).build();
    PartitionResponse actualResponse = client.partitionRead(request);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockSpanner.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    PartitionReadRequest actualRequest = ((PartitionReadRequest) actualRequests.get(0));
    Assert.assertEquals(request.getSession(), actualRequest.getSession());
    Assert.assertEquals(request.getTransaction(), actualRequest.getTransaction());
    Assert.assertEquals(request.getTable(), actualRequest.getTable());
    Assert.assertEquals(request.getIndex(), actualRequest.getIndex());
    Assert.assertEquals(request.getColumnsList(), actualRequest.getColumnsList());
    Assert.assertEquals(request.getKeySet(), actualRequest.getKeySet());
    Assert.assertEquals(request.getPartitionOptions(), actualRequest.getPartitionOptions());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : PartitionResponse(com.google.spanner.v1.PartitionResponse) Partition(com.google.spanner.v1.Partition) AbstractMessage(com.google.protobuf.AbstractMessage) ArrayList(java.util.ArrayList) PartitionReadRequest(com.google.spanner.v1.PartitionReadRequest) Test(org.junit.Test)

Example 2 with PartitionReadRequest

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

the class SpannerClientTest method partitionReadExceptionTest.

@Test
public void partitionReadExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockSpanner.addException(exception);
    try {
        PartitionReadRequest request = PartitionReadRequest.newBuilder().setSession(SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]").toString()).setTransaction(TransactionSelector.newBuilder().build()).setTable("table110115790").setIndex("index100346066").addAllColumns(new ArrayList<String>()).setKeySet(KeySet.newBuilder().build()).setPartitionOptions(PartitionOptions.newBuilder().build()).build();
        client.partitionRead(request);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) ArrayList(java.util.ArrayList) PartitionReadRequest(com.google.spanner.v1.PartitionReadRequest) Test(org.junit.Test)

Example 3 with PartitionReadRequest

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

the class GcpManagedChannelTest method testGetKeysFromRequest.

@Test
public void testGetKeysFromRequest() {
    String expected = "thisisaname";
    TransactionSelector selector = TransactionSelector.getDefaultInstance();
    PartitionReadRequest req = PartitionReadRequest.newBuilder().setSession(expected).setTable("jenny").setTransaction(selector).addColumns("users").build();
    List<String> result = getKeysFromMessage(req, "session");
    assertEquals(expected, result.get(0));
    result = getKeysFromMessage(req, "fakesession");
    assertEquals(0, result.size());
}
Also used : TransactionSelector(com.google.spanner.v1.TransactionSelector) PartitionReadRequest(com.google.spanner.v1.PartitionReadRequest) Test(org.junit.Test)

Aggregations

PartitionReadRequest (com.google.spanner.v1.PartitionReadRequest)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)1 AbstractMessage (com.google.protobuf.AbstractMessage)1 Partition (com.google.spanner.v1.Partition)1 PartitionResponse (com.google.spanner.v1.PartitionResponse)1 TransactionSelector (com.google.spanner.v1.TransactionSelector)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1