|
36 | 36 | import com.google.cloud.spanner.MockSpannerServiceImpl.SimulatedExecutionTime;
|
37 | 37 | import com.google.cloud.spanner.MockSpannerServiceImpl.StatementResult;
|
38 | 38 | import com.google.cloud.spanner.Options.ReadOption;
|
| 39 | +import com.google.cloud.spanner.TransactionRunnerImpl.TransactionContextImpl; |
39 | 40 | import com.google.common.base.Function;
|
| 41 | +import com.google.common.base.Predicate; |
40 | 42 | import com.google.common.collect.ImmutableList;
|
41 | 43 | import com.google.common.collect.Iterables;
|
42 | 44 | import com.google.common.collect.Range;
|
|
47 | 49 | import com.google.spanner.v1.CommitRequest;
|
48 | 50 | import com.google.spanner.v1.ExecuteBatchDmlRequest;
|
49 | 51 | import com.google.spanner.v1.ExecuteSqlRequest;
|
| 52 | +import com.google.spanner.v1.RollbackRequest; |
| 53 | +import com.google.spanner.v1.TransactionSelector; |
50 | 54 | import io.grpc.Status;
|
51 | 55 | import java.util.Arrays;
|
52 | 56 | import java.util.Collection;
|
@@ -181,6 +185,30 @@ public void onSuccess(long[] input) {
|
181 | 185 | }
|
182 | 186 | }
|
183 | 187 |
|
| 188 | + @Test |
| 189 | + public void asyncTransactionManager_shouldRollbackOnCloseAsync() throws Exception { |
| 190 | + AsyncTransactionManager manager = client().transactionManagerAsync(); |
| 191 | + TransactionContext txn = manager.beginAsync().get(); |
| 192 | + txn.executeUpdateAsync(UPDATE_STATEMENT).get(); |
| 193 | + final TransactionSelector selector = ((TransactionContextImpl) txn).getTransactionSelector(); |
| 194 | + |
| 195 | + SpannerApiFutures.get(manager.closeAsync()); |
| 196 | + // The mock server should already have the Rollback request, as we are waiting for the returned |
| 197 | + // ApiFuture to be done. |
| 198 | + mockSpanner.waitForRequestsToContain( |
| 199 | + new Predicate<AbstractMessage>() { |
| 200 | + @Override |
| 201 | + public boolean apply(AbstractMessage input) { |
| 202 | + if (input instanceof RollbackRequest) { |
| 203 | + RollbackRequest request = (RollbackRequest) input; |
| 204 | + return request.getTransactionId().equals(selector.getId()); |
| 205 | + } |
| 206 | + return false; |
| 207 | + } |
| 208 | + }, |
| 209 | + 0L); |
| 210 | + } |
| 211 | + |
184 | 212 | @Test
|
185 | 213 | public void asyncTransactionManagerUpdate() throws Exception {
|
186 | 214 | final SettableApiFuture<Long> updateCount = SettableApiFuture.create();
|
|
0 commit comments