Search in sources :

Example 6 with PartialResultSet

use of com.google.spanner.v1.PartialResultSet in project google-cloud-java by GoogleCloudPlatform.

the class GrpcResultSetTest method metadata.

@Test
public void metadata() {
    Type rowType = Type.struct(Type.StructField.of("f", Type.string()));
    ResultSetMetadata.Builder metadataBuilder = ResultSetMetadata.newBuilder();
    metadataBuilder.setRowType(rowType.toProto().getStructType()).getTransactionBuilder().setId(ByteString.copyFromUtf8("t1"));
    PartialResultSet partialResultSet = PartialResultSet.newBuilder().setMetadata(metadataBuilder.build()).build();
    consumer.onPartialResultSet(partialResultSet);
    consumer.onCompleted();
    assertThat(resultSet.next()).isFalse();
    assertThat(resultSet.getType()).isEqualTo(rowType);
}
Also used : ResultSetMetadata(com.google.spanner.v1.ResultSetMetadata) PartialResultSet(com.google.spanner.v1.PartialResultSet) Test(org.junit.Test)

Example 7 with PartialResultSet

use of com.google.spanner.v1.PartialResultSet in project google-cloud-java by GoogleCloudPlatform.

the class GrpcSpannerRpc method doStreamingCall.

private <T> StreamingCall doStreamingCall(MethodDescriptor<T, PartialResultSet> method, T request, ResultStreamConsumer consumer, @Nullable String resource, @Nullable Long channelHint) {
    final Context context = Context.current();
    // TODO: Add deadline based on context.
    CallOptions callOptions = credentials == null ? CallOptions.DEFAULT : CallOptions.DEFAULT.withCallCredentials(credentials);
    final ClientCall<T, PartialResultSet> call = new MetadataClientCall<>(pick(channelHint, channels).newCall(method, callOptions), newMetadata(resource));
    ResultSetStreamObserver<T> observer = new ResultSetStreamObserver<T>(consumer, context, call);
    ClientCalls.asyncServerStreamingCall(call, request, observer);
    return observer;
}
Also used : Context(io.grpc.Context) CallOptions(io.grpc.CallOptions) PartialResultSet(com.google.spanner.v1.PartialResultSet)

Example 8 with PartialResultSet

use of com.google.spanner.v1.PartialResultSet in project google-cloud-java by GoogleCloudPlatform.

the class SessionImplTest method multiUseReadOnlyTransactionReturnsMissingTransactionId.

@Test
public void multiUseReadOnlyTransactionReturnsMissingTransactionId() throws ParseException {
    com.google.protobuf.Timestamp t = Timestamps.parse("2015-10-01T10:54:20.021Z");
    Transaction txnMetadata = Transaction.newBuilder().setReadTimestamp(t).build();
    PartialResultSet resultSet = PartialResultSet.newBuilder().setMetadata(newMetadata(Type.struct(Type.StructField.of("C", Type.string())))).build();
    Mockito.when(rpc.beginTransaction(Mockito.<BeginTransactionRequest>any(), Mockito.eq(options))).thenReturn(txnMetadata);
    mockRead(resultSet);
    ReadOnlyTransaction txn = session.readOnlyTransaction(TimestampBound.strong());
    expectedException.expect(SpannerMatchers.isSpannerException(ErrorCode.INTERNAL));
    txn.readRow("Dummy", Key.of(), Arrays.asList("C"));
}
Also used : Transaction(com.google.spanner.v1.Transaction) PartialResultSet(com.google.spanner.v1.PartialResultSet) Test(org.junit.Test)

Example 9 with PartialResultSet

use of com.google.spanner.v1.PartialResultSet in project google-cloud-java by GoogleCloudPlatform.

the class SessionImplTest method multiUseReadOnlyTransactionReturnsMissingTimestamp.

@Test
public void multiUseReadOnlyTransactionReturnsMissingTimestamp() {
    Transaction txnMetadata = Transaction.newBuilder().setId(ByteString.copyFromUtf8("x")).build();
    PartialResultSet resultSet = PartialResultSet.newBuilder().setMetadata(newMetadata(Type.struct(Type.StructField.of("C", Type.string())))).build();
    Mockito.when(rpc.beginTransaction(Mockito.<BeginTransactionRequest>any(), Mockito.eq(options))).thenReturn(txnMetadata);
    mockRead(resultSet);
    ReadOnlyTransaction txn = session.readOnlyTransaction(TimestampBound.strong());
    expectedException.expect(SpannerMatchers.isSpannerException(ErrorCode.INTERNAL));
    txn.readRow("Dummy", Key.of(), Arrays.asList("C"));
}
Also used : Transaction(com.google.spanner.v1.Transaction) PartialResultSet(com.google.spanner.v1.PartialResultSet) Test(org.junit.Test)

Aggregations

PartialResultSet (com.google.spanner.v1.PartialResultSet)9 Test (org.junit.Test)8 Transaction (com.google.spanner.v1.Transaction)3 ResultSetMetadata (com.google.spanner.v1.ResultSetMetadata)1 CallOptions (io.grpc.CallOptions)1 Context (io.grpc.Context)1