|
19 | 19 | import static org.hamcrest.CoreMatchers.is; |
20 | 20 | import static org.hamcrest.CoreMatchers.notNullValue; |
21 | 21 | import static org.hamcrest.MatcherAssert.assertThat; |
| 22 | +import static org.junit.Assert.assertNull; |
| 23 | +import static org.junit.Assert.assertTrue; |
22 | 24 |
|
23 | 25 | import com.google.cloud.spanner.ResultSet; |
24 | 26 | import com.google.cloud.spanner.SerialIntegrationTest; |
|
28 | 30 | import java.util.List; |
29 | 31 | import java.util.concurrent.ExecutorService; |
30 | 32 | import java.util.concurrent.Executors; |
| 33 | +import java.util.concurrent.Future; |
31 | 34 | import java.util.concurrent.TimeUnit; |
32 | 35 | import org.junit.Test; |
33 | 36 | import org.junit.experimental.categories.Category; |
@@ -65,22 +68,27 @@ public void testBulkCreateConnectionsSingleThreaded() { |
65 | 68 | } |
66 | 69 |
|
67 | 70 | @Test |
68 | | - public void testBulkCreateConnectionsMultiThreaded() throws InterruptedException { |
| 71 | + public void testBulkCreateConnectionsMultiThreaded() throws Exception { |
69 | 72 | ExecutorService executor = Executors.newFixedThreadPool(50); |
| 73 | + List<Future<?>> futures = new ArrayList<>(NUMBER_OF_TEST_CONNECTIONS); |
70 | 74 | for (int i = 0; i < NUMBER_OF_TEST_CONNECTIONS; i++) { |
71 | | - executor.submit( |
72 | | - () -> { |
73 | | - try (ITConnection connection = createConnection()) { |
74 | | - try (ResultSet rs = connection.executeQuery(Statement.of("select 1"))) { |
75 | | - assertThat(rs.next(), is(true)); |
76 | | - assertThat(connection.getReadTimestamp(), is(notNullValue())); |
77 | | - } |
78 | | - } |
79 | | - return null; |
80 | | - }); |
| 75 | + futures.add( |
| 76 | + executor.submit( |
| 77 | + () -> { |
| 78 | + try (ITConnection connection = createConnection()) { |
| 79 | + try (ResultSet rs = connection.executeQuery(Statement.of("select 1"))) { |
| 80 | + assertThat(rs.next(), is(true)); |
| 81 | + assertThat(connection.getReadTimestamp(), is(notNullValue())); |
| 82 | + } |
| 83 | + } |
| 84 | + return null; |
| 85 | + })); |
81 | 86 | } |
82 | 87 | executor.shutdown(); |
83 | | - executor.awaitTermination(10L, TimeUnit.SECONDS); |
| 88 | + assertTrue(executor.awaitTermination(60L, TimeUnit.SECONDS)); |
| 89 | + for (Future<?> future : futures) { |
| 90 | + assertNull(future.get()); |
| 91 | + } |
84 | 92 | // close Spanner instances explicitly. This method will throw an exception if there are any |
85 | 93 | // connections still open in the pool |
86 | 94 | closeSpanner(); |
|
0 commit comments