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