Search in sources :

Example 1 with PartitionResponse

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());
    }
}
Also used : ByteString(com.google.protobuf.ByteString) StatusRuntimeException(io.grpc.StatusRuntimeException) Session(com.google.spanner.v1.Session)

Example 2 with PartitionResponse

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()));
}
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 3 with PartitionResponse

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()));
}
Also used : PartitionResponse(com.google.spanner.v1.PartitionResponse) Partition(com.google.spanner.v1.Partition) Type(com.google.spanner.v1.Type) AbstractMessage(com.google.protobuf.AbstractMessage) PartitionQueryRequest(com.google.spanner.v1.PartitionQueryRequest) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Aggregations

AbstractMessage (com.google.protobuf.AbstractMessage)2 ByteString (com.google.protobuf.ByteString)2 Partition (com.google.spanner.v1.Partition)2 PartitionResponse (com.google.spanner.v1.PartitionResponse)2 Test (org.junit.Test)2 PartitionQueryRequest (com.google.spanner.v1.PartitionQueryRequest)1 PartitionReadRequest (com.google.spanner.v1.PartitionReadRequest)1 Session (com.google.spanner.v1.Session)1 Type (com.google.spanner.v1.Type)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1 ArrayList (java.util.ArrayList)1