use of com.google.cloud.spanner.TransactionRunnerImpl.TransactionContextImpl in project java-spanner by googleapis.
the class TransactionContextImplTest method testCannotCommitTwice.
@Test
public void testCannotCommitTwice() {
try (TransactionContextImpl context = createContext()) {
context.commit();
assertThrows(IllegalStateException.class, () -> context.commit());
}
}
use of com.google.cloud.spanner.TransactionRunnerImpl.TransactionContextImpl in project java-spanner by googleapis.
the class TransactionContextImplTest method testCannotBufferAsyncAfterCommit.
@Test
public void testCannotBufferAsyncAfterCommit() {
try (TransactionContextImpl context = createContext()) {
context.commit();
assertThrows(IllegalStateException.class, () -> context.bufferAsync(Mutation.delete("test", KeySet.all())));
}
}
use of com.google.cloud.spanner.TransactionRunnerImpl.TransactionContextImpl in project java-spanner by googleapis.
the class TransactionContextImplTest method testReturnCommitStats.
@SuppressWarnings("unchecked")
@Test
public void testReturnCommitStats() {
ByteString transactionId = ByteString.copyFromUtf8("test");
try (TransactionContextImpl context = TransactionContextImpl.newBuilder().setSession(session).setRpc(rpc).setTransactionId(transactionId).setOptions(Options.fromTransactionOptions(Options.commitStats())).build()) {
context.commitAsync();
CommitRequest request = CommitRequest.newBuilder().setReturnCommitStats(true).setSession(session.getName()).setTransactionId(transactionId).build();
verify(rpc).commitAsync(Mockito.eq(request), anyMap());
}
}
use of com.google.cloud.spanner.TransactionRunnerImpl.TransactionContextImpl in project java-spanner by googleapis.
the class TransactionContextImplTest method testCannotBufferIterableAfterCommit.
@Test
public void testCannotBufferIterableAfterCommit() {
try (TransactionContextImpl context = createContext()) {
context.commit();
assertThrows(IllegalStateException.class, () -> context.buffer(Collections.singleton(Mutation.delete("test", KeySet.all()))));
}
}
use of com.google.cloud.spanner.TransactionRunnerImpl.TransactionContextImpl in project java-spanner by googleapis.
the class TransactionContextImplTest method batchDml.
@SuppressWarnings("unchecked")
private void batchDml(int status) {
SessionImpl session = mock(SessionImpl.class);
when(session.getName()).thenReturn("test");
SpannerRpc rpc = mock(SpannerRpc.class);
ExecuteBatchDmlResponse response = ExecuteBatchDmlResponse.newBuilder().setStatus(Status.newBuilder().setCode(status).build()).build();
Statement statement = Statement.of("UPDATE FOO SET BAR=1");
when(rpc.executeBatchDml(Mockito.any(ExecuteBatchDmlRequest.class), Mockito.anyMap())).thenReturn(response);
try (TransactionContextImpl impl = TransactionContextImpl.newBuilder().setSession(session).setRpc(rpc).setTransactionId(ByteString.copyFromUtf8("test")).setOptions(Options.fromTransactionOptions()).build()) {
impl.batchUpdate(Collections.singletonList(statement));
}
}
Aggregations