use of com.google.spanner.v1.ResultSet in project google-cloud-java by GoogleCloudPlatform.
the class GrpcResultSetTest method statsUnavailableError.
@Test
public void statsUnavailableError() {
ResultSetStats stats = ResultSetStats.newBuilder().build();
consumer.onPartialResultSet(PartialResultSet.newBuilder().setMetadata(makeMetadata(Type.struct(new ArrayList<Type.StructField>()))).setChunkedValue(false).setStats(stats).build());
resultSet = resultSetWithMode(QueryMode.PROFILE);
consumer.onCompleted();
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("ResultSetStats requested before consuming the entire ResultSet");
resultSet.getStats();
}
use of com.google.spanner.v1.ResultSet in project google-cloud-java by GoogleCloudPlatform.
the class SessionImplTest method multiUseReadOnlyTransactionReturnsEmptyTransactionMetadata.
@Test
public void multiUseReadOnlyTransactionReturnsEmptyTransactionMetadata() {
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"));
}
use of com.google.spanner.v1.ResultSet in project google-cloud-java by GoogleCloudPlatform.
the class SessionImplTest method singleUseReadOnlyTransactionReturnsEmptyTransactionMetadata.
@Test
public void singleUseReadOnlyTransactionReturnsEmptyTransactionMetadata() {
PartialResultSet resultSet = PartialResultSet.newBuilder().setMetadata(newMetadata(Type.struct(Type.StructField.of("C", Type.string()))).toBuilder().setTransaction(Transaction.getDefaultInstance())).build();
mockRead(resultSet);
ReadOnlyTransaction txn = session.singleUseReadOnlyTransaction(TimestampBound.strong());
expectedException.expect(SpannerMatchers.isSpannerException(ErrorCode.INTERNAL));
txn.readRow("Dummy", Key.of(), Arrays.asList("C"));
}
use of com.google.spanner.v1.ResultSet in project google-cloud-java by GoogleCloudPlatform.
the class SessionImplTest method singleUseReadOnlyTransactionDoesntReturnTransactionMetadata.
@Test
public void singleUseReadOnlyTransactionDoesntReturnTransactionMetadata() {
PartialResultSet resultSet = PartialResultSet.newBuilder().setMetadata(newMetadata(Type.struct(Type.StructField.of("C", Type.string())))).build();
mockRead(resultSet);
ReadOnlyTransaction txn = session.singleUseReadOnlyTransaction(TimestampBound.strong());
assertThat(txn.readRow("Dummy", Key.of(), Arrays.asList("C"))).isNull();
// For now, getReadTimestamp() will raise an ISE because it hasn't seen a timestamp. It would
// be better for the read to fail with an INTERNAL error, but we can't do that until txn
// metadata is returned for failed reads (e.g., table-not-found) as well as successful ones.
// TODO(user): Fix this.
expectedException.expect(IllegalStateException.class);
txn.getReadTimestamp();
}
use of com.google.spanner.v1.ResultSet in project google-cloud-java by GoogleCloudPlatform.
the class GrpcResultSetTest method profileResultInFinalResultSet.
@Test
public void profileResultInFinalResultSet() {
Map<String, com.google.protobuf.Value> statsMap = ImmutableMap.of("f1", Value.string("").toProto(), "f2", Value.string("").toProto());
ResultSetStats stats = ResultSetStats.newBuilder().setQueryPlan(QueryPlan.newBuilder().build()).setQueryStats(com.google.protobuf.Struct.newBuilder().putAllFields(statsMap).build()).build();
ArrayList<Type.StructField> dataType = new ArrayList<>();
dataType.add(Type.StructField.of("data", Type.string()));
consumer.onPartialResultSet(PartialResultSet.newBuilder().setMetadata(makeMetadata(Type.struct(dataType))).addValues(Value.string("d1").toProto()).setChunkedValue(false).setStats(stats).build());
resultSet = resultSetWithMode(QueryMode.PROFILE);
consumer.onCompleted();
assertThat(resultSet.next()).isTrue();
assertThat(resultSet.next()).isFalse();
ResultSetStats receivedStats = resultSet.getStats();
assertThat(stats).isEqualTo(receivedStats);
resultSet.close();
}
Aggregations