use of com.google.spanner.v1.TransactionOptions in project java-spanner by googleapis.
the class SpannerClientTest method commitTest4.
@Test
public void commitTest4() throws Exception {
CommitResponse expectedResponse = CommitResponse.newBuilder().setCommitTimestamp(Timestamp.newBuilder().build()).setCommitStats(CommitResponse.CommitStats.newBuilder().build()).build();
mockSpanner.addResponse(expectedResponse);
String session = "session1984987798";
TransactionOptions singleUseTransaction = TransactionOptions.newBuilder().build();
List<Mutation> mutations = new ArrayList<>();
CommitResponse actualResponse = client.commit(session, singleUseTransaction, mutations);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockSpanner.getRequests();
Assert.assertEquals(1, actualRequests.size());
CommitRequest actualRequest = ((CommitRequest) actualRequests.get(0));
Assert.assertEquals(session, actualRequest.getSession());
Assert.assertEquals(singleUseTransaction, actualRequest.getSingleUseTransaction());
Assert.assertEquals(mutations, actualRequest.getMutationsList());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.spanner.v1.TransactionOptions in project java-spanner by googleapis.
the class SpannerClientTest method commitExceptionTest4.
@Test
public void commitExceptionTest4() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockSpanner.addException(exception);
try {
String session = "session1984987798";
TransactionOptions singleUseTransaction = TransactionOptions.newBuilder().build();
List<Mutation> mutations = new ArrayList<>();
client.commit(session, singleUseTransaction, mutations);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
use of com.google.spanner.v1.TransactionOptions in project java-spanner by googleapis.
the class SpannerClientTest method beginTransactionTest.
@Test
public void beginTransactionTest() throws Exception {
Transaction expectedResponse = Transaction.newBuilder().setId(ByteString.EMPTY).setReadTimestamp(Timestamp.newBuilder().build()).build();
mockSpanner.addResponse(expectedResponse);
SessionName session = SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]");
TransactionOptions options = TransactionOptions.newBuilder().build();
Transaction actualResponse = client.beginTransaction(session, options);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockSpanner.getRequests();
Assert.assertEquals(1, actualRequests.size());
BeginTransactionRequest actualRequest = ((BeginTransactionRequest) actualRequests.get(0));
Assert.assertEquals(session.toString(), actualRequest.getSession());
Assert.assertEquals(options, actualRequest.getOptions());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.spanner.v1.TransactionOptions in project java-spanner by googleapis.
the class SpannerClientTest method commitTest2.
@Test
public void commitTest2() throws Exception {
CommitResponse expectedResponse = CommitResponse.newBuilder().setCommitTimestamp(Timestamp.newBuilder().build()).setCommitStats(CommitResponse.CommitStats.newBuilder().build()).build();
mockSpanner.addResponse(expectedResponse);
SessionName session = SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]");
TransactionOptions singleUseTransaction = TransactionOptions.newBuilder().build();
List<Mutation> mutations = new ArrayList<>();
CommitResponse actualResponse = client.commit(session, singleUseTransaction, mutations);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockSpanner.getRequests();
Assert.assertEquals(1, actualRequests.size());
CommitRequest actualRequest = ((CommitRequest) actualRequests.get(0));
Assert.assertEquals(session.toString(), actualRequest.getSession());
Assert.assertEquals(singleUseTransaction, actualRequest.getSingleUseTransaction());
Assert.assertEquals(mutations, actualRequest.getMutationsList());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.spanner.v1.TransactionOptions in project java-spanner by googleapis.
the class SpannerClientTest method beginTransactionTest2.
@Test
public void beginTransactionTest2() throws Exception {
Transaction expectedResponse = Transaction.newBuilder().setId(ByteString.EMPTY).setReadTimestamp(Timestamp.newBuilder().build()).build();
mockSpanner.addResponse(expectedResponse);
String session = "session1984987798";
TransactionOptions options = TransactionOptions.newBuilder().build();
Transaction actualResponse = client.beginTransaction(session, options);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockSpanner.getRequests();
Assert.assertEquals(1, actualRequests.size());
BeginTransactionRequest actualRequest = ((BeginTransactionRequest) actualRequests.get(0));
Assert.assertEquals(session, actualRequest.getSession());
Assert.assertEquals(options, actualRequest.getOptions());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Aggregations