|
36 | 36 | import com.google.cloud.spanner.MockSpannerServiceImpl.StatementResult; |
37 | 37 | import com.google.cloud.spanner.TransactionRunner.TransactionCallable; |
38 | 38 | import com.google.cloud.spanner.TransactionRunnerImpl.TransactionContextImpl; |
39 | | -import com.google.common.base.Predicate; |
40 | 39 | import com.google.common.collect.ImmutableList; |
41 | 40 | import com.google.common.util.concurrent.MoreExecutors; |
42 | 41 | import com.google.protobuf.AbstractMessage; |
|
61 | 60 | import java.util.Collection; |
62 | 61 | import java.util.List; |
63 | 62 | import java.util.concurrent.Callable; |
64 | | -import java.util.concurrent.CountDownLatch; |
65 | 63 | import java.util.concurrent.ExecutionException; |
66 | 64 | import java.util.concurrent.Executor; |
67 | 65 | import java.util.concurrent.ExecutorService; |
68 | 66 | import java.util.concurrent.Executors; |
69 | 67 | import java.util.concurrent.Future; |
70 | 68 | import java.util.concurrent.ScheduledExecutorService; |
71 | 69 | import java.util.concurrent.ScheduledThreadPoolExecutor; |
72 | | -import java.util.concurrent.TimeUnit; |
73 | 70 | import java.util.concurrent.TimeoutException; |
74 | 71 | import java.util.concurrent.atomic.AtomicBoolean; |
75 | 72 | import org.junit.After; |
@@ -1501,76 +1498,6 @@ public Void run(TransactionContext transaction) throws Exception { |
1501 | 1498 | assertThat(countRequests(CommitRequest.class)).isEqualTo(1); |
1502 | 1499 | } |
1503 | 1500 |
|
1504 | | - @Test |
1505 | | - public void testCloseResultSetWhileRequestInFlight() throws Exception { |
1506 | | - DatabaseClient client = spanner.getDatabaseClient(DatabaseId.of("p", "i", "d")); |
1507 | | - final ExecutorService service = Executors.newSingleThreadExecutor(); |
1508 | | - try { |
1509 | | - client |
1510 | | - .readWriteTransaction() |
1511 | | - .run( |
1512 | | - new TransactionCallable<Void>() { |
1513 | | - @Override |
1514 | | - public Void run(TransactionContext transaction) throws Exception { |
1515 | | - final ResultSet rs = transaction.executeQuery(SELECT1); |
1516 | | - // Prevent the server from executing the query. |
1517 | | - final CountDownLatch latch = new CountDownLatch(1); |
1518 | | - mockSpanner.freeze(); |
1519 | | - service.submit( |
1520 | | - new Runnable() { |
1521 | | - @Override |
1522 | | - public void run() { |
1523 | | - try { |
1524 | | - // This call will be stuck on the server until the mock server is |
1525 | | - // unfrozen. |
1526 | | - rs.next(); |
1527 | | - } finally { |
1528 | | - latch.countDown(); |
1529 | | - } |
1530 | | - } |
1531 | | - }); |
1532 | | - |
1533 | | - // First wait for the request to be on the server and then close the result set |
1534 | | - // while the request is in flight. |
1535 | | - mockSpanner.waitForRequestsToContain( |
1536 | | - new Predicate<AbstractMessage>() { |
1537 | | - @Override |
1538 | | - public boolean apply(AbstractMessage input) { |
1539 | | - return input instanceof ExecuteSqlRequest |
1540 | | - && ((ExecuteSqlRequest) input).getTransaction().hasBegin(); |
1541 | | - } |
1542 | | - }, |
1543 | | - 1000L); |
1544 | | - rs.close(); |
1545 | | - // The next statement should now fail before it is sent to the server because |
1546 | | - // the first statement failed to return a transaction while the result set was |
1547 | | - // still open. |
1548 | | - mockSpanner.unfreeze(); |
1549 | | - latch.await(1L, TimeUnit.SECONDS); |
1550 | | - try { |
1551 | | - transaction.executeUpdate(UPDATE_STATEMENT); |
1552 | | - fail("missing expected exception"); |
1553 | | - } catch (SpannerException e) { |
1554 | | - assertThat(e.getErrorCode()).isEqualTo(ErrorCode.FAILED_PRECONDITION); |
1555 | | - assertThat(e.getMessage()) |
1556 | | - .contains("ResultSet was closed before a transaction id was returned"); |
1557 | | - } |
1558 | | - return null; |
1559 | | - } |
1560 | | - }); |
1561 | | - fail("missing expected exception"); |
1562 | | - } catch (SpannerException e) { |
1563 | | - // The commit request will also fail, which means that the entire transaction will fail. |
1564 | | - assertThat(e.getErrorCode()).isEqualTo(ErrorCode.FAILED_PRECONDITION); |
1565 | | - assertThat(e.getMessage()) |
1566 | | - .contains("ResultSet was closed before a transaction id was returned"); |
1567 | | - } |
1568 | | - service.shutdown(); |
1569 | | - assertThat(countRequests(BeginTransactionRequest.class)).isEqualTo(0); |
1570 | | - assertThat(countRequests(ExecuteSqlRequest.class)).isEqualTo(1); |
1571 | | - assertThat(countRequests(CommitRequest.class)).isEqualTo(0); |
1572 | | - } |
1573 | | - |
1574 | 1501 | @Test |
1575 | 1502 | public void testQueryWithInlineBeginDidNotReturnTransaction() { |
1576 | 1503 | DatabaseClient client = spanner.getDatabaseClient(DatabaseId.of("p", "i", "d")); |
|
0 commit comments