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()));
}
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.
}
}
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());
}
Aggregations