use of com.google.spanner.v1.PartitionResponse in project java-spanner by googleapis.
the class MockSpannerServiceImpl method partition.
private void partition(String sessionName, TransactionSelector transactionSelector, StreamObserver<PartitionResponse> responseObserver) {
Session session = sessions.get(sessionName);
if (session == null) {
setSessionNotFound(sessionName, responseObserver);
return;
}
sessionLastUsed.put(session.getName(), Instant.now());
try {
ByteString transactionId = getTransactionId(session, transactionSelector);
responseObserver.onNext(PartitionResponse.newBuilder().addPartitions(Partition.newBuilder().setPartitionToken(generatePartitionToken(session.getName(), transactionId)).build()).build());
responseObserver.onCompleted();
} catch (StatusRuntimeException e) {
responseObserver.onError(e);
} catch (Throwable t) {
responseObserver.onError(Status.INTERNAL.asRuntimeException());
}
}
use of com.google.spanner.v1.PartitionResponse 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.PartitionResponse in project java-spanner by googleapis.
the class SpannerClientTest method partitionQueryTest.
@Test
public void partitionQueryTest() throws Exception {
PartitionResponse expectedResponse = PartitionResponse.newBuilder().addAllPartitions(new ArrayList<Partition>()).setTransaction(Transaction.newBuilder().build()).build();
mockSpanner.addResponse(expectedResponse);
PartitionQueryRequest request = PartitionQueryRequest.newBuilder().setSession(SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]").toString()).setTransaction(TransactionSelector.newBuilder().build()).setSql("sql114126").setParams(Struct.newBuilder().build()).putAllParamTypes(new HashMap<String, Type>()).setPartitionOptions(PartitionOptions.newBuilder().build()).build();
PartitionResponse actualResponse = client.partitionQuery(request);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockSpanner.getRequests();
Assert.assertEquals(1, actualRequests.size());
PartitionQueryRequest actualRequest = ((PartitionQueryRequest) actualRequests.get(0));
Assert.assertEquals(request.getSession(), actualRequest.getSession());
Assert.assertEquals(request.getTransaction(), actualRequest.getTransaction());
Assert.assertEquals(request.getSql(), actualRequest.getSql());
Assert.assertEquals(request.getParams(), actualRequest.getParams());
Assert.assertEquals(request.getParamTypesMap(), actualRequest.getParamTypesMap());
Assert.assertEquals(request.getPartitionOptions(), actualRequest.getPartitionOptions());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Aggregations