Search in sources :

Example 1 with PartialResultSet

use of com.google.spanner.v1.PartialResultSet 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"));
}
Also used : Transaction(com.google.spanner.v1.Transaction) PartialResultSet(com.google.spanner.v1.PartialResultSet) Test(org.junit.Test)

Example 2 with PartialResultSet

use of com.google.spanner.v1.PartialResultSet 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"));
}
Also used : PartialResultSet(com.google.spanner.v1.PartialResultSet) Test(org.junit.Test)

Example 3 with PartialResultSet

use of com.google.spanner.v1.PartialResultSet 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();
}
Also used : PartialResultSet(com.google.spanner.v1.PartialResultSet) Test(org.junit.Test)

Example 4 with PartialResultSet

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

the class GrpcResultSetTest method emptyMultipleResponses.

@Test
public void emptyMultipleResponses() {
    PartialResultSet partialResultSet = PartialResultSet.newBuilder().setMetadata(makeMetadata(Type.struct(Type.StructField.of("f", Type.string())))).build();
    consumer.onPartialResultSet(partialResultSet);
    consumer.onPartialResultSet(PartialResultSet.getDefaultInstance());
    consumer.onPartialResultSet(PartialResultSet.getDefaultInstance());
    consumer.onCompleted();
    assertThat(resultSet.next()).isFalse();
}
Also used : PartialResultSet(com.google.spanner.v1.PartialResultSet) Test(org.junit.Test)

Example 5 with PartialResultSet

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

the class GrpcResultSetTest method empty.

@Test
public void empty() {
    Type type = Type.struct(Type.StructField.of("f", Type.string()));
    PartialResultSet partialResultSet = PartialResultSet.newBuilder().setMetadata(makeMetadata(type)).build();
    consumer.onPartialResultSet(partialResultSet);
    consumer.onCompleted();
    assertThat(resultSet.next()).isFalse();
    assertThat(resultSet.getType()).isEqualTo(type);
}
Also used : PartialResultSet(com.google.spanner.v1.PartialResultSet) Test(org.junit.Test)

Aggregations

PartialResultSet (com.google.spanner.v1.PartialResultSet)10 Test (org.junit.Test)8 Transaction (com.google.spanner.v1.Transaction)3 RetrySettings (com.google.api.gax.retrying.RetrySettings)1 ServerStreamingCallSettings (com.google.api.gax.rpc.ServerStreamingCallSettings)1 UnaryCallSettings (com.google.api.gax.rpc.UnaryCallSettings)1 BatchClient (com.google.cloud.spanner.BatchClient)1 DatabaseAdminClient (com.google.cloud.spanner.DatabaseAdminClient)1 DatabaseClient (com.google.cloud.spanner.DatabaseClient)1 Spanner (com.google.cloud.spanner.Spanner)1 SpannerOptions (com.google.cloud.spanner.SpannerOptions)1 CommitRequest (com.google.spanner.v1.CommitRequest)1 CommitResponse (com.google.spanner.v1.CommitResponse)1 ExecuteSqlRequest (com.google.spanner.v1.ExecuteSqlRequest)1 ResultSetMetadata (com.google.spanner.v1.ResultSetMetadata)1 CallOptions (io.grpc.CallOptions)1 Context (io.grpc.Context)1 Duration (org.joda.time.Duration)1