Search in sources :

Example 6 with PartitionQueryRequest

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

the class SpannerTestCases method testPartitionQueryAsync.

void testPartitionQueryAsync() throws InterruptedException {
    System.out.println("\nTestPartitionQueryAsync");
    ManagedChannel channel = getChannel();
    SpannerStub stub = getStub(channel);
    AsyncResponseObserver<Session> sessionObs = new AsyncResponseObserver<>();
    stub.createSession(CreateSessionRequest.newBuilder().setDatabase(database).build(), sessionObs);
    TransactionOptions options = TransactionOptions.newBuilder().setReadOnly(TransactionOptions.ReadOnly.getDefaultInstance()).build();
    TransactionSelector selector = TransactionSelector.newBuilder().setBegin(options).build();
    PartitionQueryRequest request = PartitionQueryRequest.newBuilder().setSession(sessionObs.get().getName()).setSql("select * FROM " + LARGE_TABLE).setTransaction(selector).build();
    AsyncCall<PartitionQueryRequest, PartitionResponse> asyncCall = (PartitionQueryRequest req, AsyncResponseObserver<PartitionResponse> resp) -> stub.partitionQuery(req, resp);
    doTestAsync(channel, request, asyncCall);
    deleteAndCloseAsync(stub, channel, sessionObs.get().getName());
}
Also used : PartitionResponse(com.google.spanner.v1.PartitionResponse) SpannerStub(com.google.spanner.v1.SpannerGrpc.SpannerStub) TransactionOptions(com.google.spanner.v1.TransactionOptions) TransactionSelector(com.google.spanner.v1.TransactionSelector) PartitionQueryRequest(com.google.spanner.v1.PartitionQueryRequest) ManagedChannel(io.grpc.ManagedChannel) GcpManagedChannel(com.google.grpc.gcp.GcpManagedChannel) Session(com.google.spanner.v1.Session)

Example 7 with PartitionQueryRequest

use of com.google.spanner.v1.PartitionQueryRequest in project beam by apache.

the class FirestoreV1FnPartitionQueryTest method resumeFromLastReadValue.

@Override
public void resumeFromLastReadValue() throws Exception {
    when(ff.getFirestoreStub(any())).thenReturn(stub);
    when(ff.getRpcQos(any())).thenReturn(rpcQos);
    when(rpcQos.newReadAttempt(any())).thenReturn(attempt);
    when(attempt.awaitSafeToProceed(any())).thenReturn(true);
    // First page of the response
    PartitionQueryRequest request1 = PartitionQueryRequest.newBuilder().setParent(String.format("projects/%s/databases/(default)/document", projectId)).build();
    PartitionQueryResponse response1 = PartitionQueryResponse.newBuilder().addPartitions(Cursor.newBuilder().addValues(Value.newBuilder().setReferenceValue("doc-100"))).addPartitions(Cursor.newBuilder().addValues(Value.newBuilder().setReferenceValue("doc-200"))).addPartitions(Cursor.newBuilder().addValues(Value.newBuilder().setReferenceValue("doc-300"))).setNextPageToken("page2").build();
    when(page1.getResponse()).thenReturn(response1);
    when(callable.call(request1)).thenReturn(pagedResponse1);
    doNothing().when(attempt).checkCanRetry(any(), eq(RETRYABLE_ERROR));
    when(pagedResponse1.iteratePages()).thenAnswer(invocation -> new Iterable<PartitionQueryPage>() {

        @Override
        public Iterator<PartitionQueryPage> iterator() {
            return new AbstractIterator<PartitionQueryPage>() {

                private boolean first = true;

                @Override
                protected PartitionQueryPage computeNext() {
                    if (first) {
                        first = false;
                        return page1;
                    } else {
                        throw RETRYABLE_ERROR;
                    }
                }
            };
        }
    });
    // Second page of the response
    PartitionQueryRequest request2 = PartitionQueryRequest.newBuilder().setParent(String.format("projects/%s/databases/(default)/document", projectId)).setPageToken("page2").build();
    PartitionQueryResponse response2 = PartitionQueryResponse.newBuilder().addPartitions(Cursor.newBuilder().addValues(Value.newBuilder().setReferenceValue("doc-400"))).build();
    PartitionQueryResponse expectedResponse = response1.toBuilder().clearNextPageToken().addAllPartitions(response2.getPartitionsList()).build();
    when(page2.getResponse()).thenReturn(response2);
    when(page2.hasNextPage()).thenReturn(false);
    when(callable.call(request2)).thenReturn(pagedResponse2);
    when(pagedResponse2.iteratePages()).thenReturn(ImmutableList.of(page2));
    when(stub.partitionQueryPagedCallable()).thenReturn(callable);
    when(ff.getFirestoreStub(any())).thenReturn(stub);
    ArgumentCaptor<PartitionQueryPair> responses = ArgumentCaptor.forClass(PartitionQueryPair.class);
    doNothing().when(processContext).output(responses.capture());
    when(processContext.element()).thenReturn(request1);
    PartitionQueryFn fn = new PartitionQueryFn(clock, ff, rpcQosOptions);
    runFunction(fn);
    List<PartitionQueryPair> expected = newArrayList(new PartitionQueryPair(request1, expectedResponse));
    List<PartitionQueryPair> allValues = responses.getAllValues();
    assertEquals(expected, allValues);
}
Also used : PartitionQueryPage(com.google.cloud.firestore.v1.FirestoreClient.PartitionQueryPage) PartitionQueryPair(org.apache.beam.sdk.io.gcp.firestore.FirestoreV1ReadFn.PartitionQueryPair) PartitionQueryRequest(com.google.firestore.v1.PartitionQueryRequest) Iterator(java.util.Iterator) AbstractIterator(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.AbstractIterator) PartitionQueryResponse(com.google.firestore.v1.PartitionQueryResponse) PartitionQueryFn(org.apache.beam.sdk.io.gcp.firestore.FirestoreV1ReadFn.PartitionQueryFn)

Example 8 with PartitionQueryRequest

use of com.google.spanner.v1.PartitionQueryRequest in project beam by apache.

the class FirestoreV1FnPartitionQueryTest method endToEnd_emptyCursors.

@Test
public void endToEnd_emptyCursors() throws Exception {
    // First page of the response
    PartitionQueryRequest request1 = PartitionQueryRequest.newBuilder().setParent(String.format("projects/%s/databases/(default)/document", projectId)).build();
    PartitionQueryResponse response1 = PartitionQueryResponse.newBuilder().build();
    when(callable.call(request1)).thenReturn(pagedResponse1);
    when(page1.getResponse()).thenReturn(response1);
    when(pagedResponse1.iteratePages()).thenReturn(ImmutableList.of(page1));
    when(stub.partitionQueryPagedCallable()).thenReturn(callable);
    when(ff.getFirestoreStub(any())).thenReturn(stub);
    RpcQosOptions options = RpcQosOptions.defaultOptions();
    when(ff.getRpcQos(any())).thenReturn(FirestoreStatefulComponentFactory.INSTANCE.getRpcQos(options));
    ArgumentCaptor<PartitionQueryPair> responses = ArgumentCaptor.forClass(PartitionQueryPair.class);
    doNothing().when(processContext).output(responses.capture());
    when(processContext.element()).thenReturn(request1);
    PartitionQueryFn fn = new PartitionQueryFn(clock, ff, options);
    runFunction(fn);
    List<PartitionQueryPair> expected = newArrayList(new PartitionQueryPair(request1, response1));
    List<PartitionQueryPair> allValues = responses.getAllValues();
    assertEquals(expected, allValues);
}
Also used : PartitionQueryPair(org.apache.beam.sdk.io.gcp.firestore.FirestoreV1ReadFn.PartitionQueryPair) PartitionQueryRequest(com.google.firestore.v1.PartitionQueryRequest) PartitionQueryResponse(com.google.firestore.v1.PartitionQueryResponse) PartitionQueryFn(org.apache.beam.sdk.io.gcp.firestore.FirestoreV1ReadFn.PartitionQueryFn) Test(org.junit.Test)

Example 9 with PartitionQueryRequest

use of com.google.spanner.v1.PartitionQueryRequest in project beam by apache.

the class FirestoreV1FnPartitionQueryTest method endToEnd.

@Test
public void endToEnd() throws Exception {
    // First page of the response
    PartitionQueryRequest request1 = PartitionQueryRequest.newBuilder().setParent(String.format("projects/%s/databases/(default)/document", projectId)).build();
    PartitionQueryResponse response1 = PartitionQueryResponse.newBuilder().addPartitions(Cursor.newBuilder().addValues(Value.newBuilder().setReferenceValue("doc-100"))).addPartitions(Cursor.newBuilder().addValues(Value.newBuilder().setReferenceValue("doc-200"))).addPartitions(Cursor.newBuilder().addValues(Value.newBuilder().setReferenceValue("doc-300"))).addPartitions(Cursor.newBuilder().addValues(Value.newBuilder().setReferenceValue("doc-400"))).build();
    when(callable.call(request1)).thenReturn(pagedResponse1);
    when(page1.getResponse()).thenReturn(response1);
    when(pagedResponse1.iteratePages()).thenReturn(ImmutableList.of(page1));
    when(stub.partitionQueryPagedCallable()).thenReturn(callable);
    when(ff.getFirestoreStub(any())).thenReturn(stub);
    RpcQosOptions options = RpcQosOptions.defaultOptions();
    when(ff.getRpcQos(any())).thenReturn(FirestoreStatefulComponentFactory.INSTANCE.getRpcQos(options));
    ArgumentCaptor<PartitionQueryPair> responses = ArgumentCaptor.forClass(PartitionQueryPair.class);
    doNothing().when(processContext).output(responses.capture());
    when(processContext.element()).thenReturn(request1);
    PartitionQueryFn fn = new PartitionQueryFn(clock, ff, options);
    runFunction(fn);
    List<PartitionQueryPair> expected = newArrayList(new PartitionQueryPair(request1, response1));
    List<PartitionQueryPair> allValues = responses.getAllValues();
    assertEquals(expected, allValues);
}
Also used : PartitionQueryPair(org.apache.beam.sdk.io.gcp.firestore.FirestoreV1ReadFn.PartitionQueryPair) PartitionQueryRequest(com.google.firestore.v1.PartitionQueryRequest) PartitionQueryResponse(com.google.firestore.v1.PartitionQueryResponse) PartitionQueryFn(org.apache.beam.sdk.io.gcp.firestore.FirestoreV1ReadFn.PartitionQueryFn) Test(org.junit.Test)

Example 10 with PartitionQueryRequest

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

the class SpannerClientTest method partitionQueryExceptionTest.

@Test
public void partitionQueryExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockSpanner.addException(exception);
    try {
        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();
        client.partitionQuery(request);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : Type(com.google.spanner.v1.Type) InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) PartitionQueryRequest(com.google.spanner.v1.PartitionQueryRequest) StatusRuntimeException(io.grpc.StatusRuntimeException) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Aggregations

PartitionQueryRequest (com.google.firestore.v1.PartitionQueryRequest)10 Test (org.junit.Test)9 PartitionQueryResponse (com.google.firestore.v1.PartitionQueryResponse)7 PartitionQueryPagedResponse (com.google.cloud.firestore.v1.FirestoreClient.PartitionQueryPagedResponse)5 PartitionQueryRequest (com.google.spanner.v1.PartitionQueryRequest)5 PartitionResponse (com.google.spanner.v1.PartitionResponse)4 Session (com.google.spanner.v1.Session)3 TransactionOptions (com.google.spanner.v1.TransactionOptions)3 TransactionSelector (com.google.spanner.v1.TransactionSelector)3 PartitionQueryFn (org.apache.beam.sdk.io.gcp.firestore.FirestoreV1ReadFn.PartitionQueryFn)3 PartitionQueryPair (org.apache.beam.sdk.io.gcp.firestore.FirestoreV1ReadFn.PartitionQueryPair)3 ApiException (com.google.api.gax.rpc.ApiException)2 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)2 GcpManagedChannel (com.google.grpc.gcp.GcpManagedChannel)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 ByteString (com.google.protobuf.ByteString)2 Type (com.google.spanner.v1.Type)2 ManagedChannel (io.grpc.ManagedChannel)2 StatusRuntimeException (io.grpc.StatusRuntimeException)2 Scope (io.opencensus.common.Scope)2