|
61 | 61 | import java.util.concurrent.Future; |
62 | 62 | import java.util.concurrent.ThreadLocalRandom; |
63 | 63 | import java.util.concurrent.TimeUnit; |
64 | | -import java.util.function.Supplier; |
65 | 64 | import org.junit.AfterClass; |
66 | 65 | import org.junit.Before; |
67 | 66 | import org.junit.BeforeClass; |
@@ -146,8 +145,7 @@ public void testGlobalOpenTelemetry() throws Exception { |
146 | 145 | } |
147 | 146 |
|
148 | 147 | @Test |
149 | | - public void testOpenTelemetryInProperties() |
150 | | - throws Exception { |
| 148 | + public void testOpenTelemetryInProperties() throws Exception { |
151 | 149 | // Make sure there is no Global OpenTelemetry. |
152 | 150 | GlobalOpenTelemetry.resetForTest(); |
153 | 151 | Properties info = new Properties(); |
@@ -225,30 +223,35 @@ private void testOpenTelemetry(Connection connection) |
225 | 223 | assertUpdateResult(statement.executeLargeUpdate(), spannerSql); |
226 | 224 | } |
227 | 225 | } |
228 | | - |
| 226 | + |
229 | 227 | private interface ConnectionProducer { |
230 | 228 | Connection createConnection() throws SQLException; |
231 | 229 | } |
232 | | - |
233 | | - private void testOpenTelemetryConcurrency(ConnectionProducer connectionProducer) throws Exception { |
| 230 | + |
| 231 | + private void testOpenTelemetryConcurrency(ConnectionProducer connectionProducer) |
| 232 | + throws Exception { |
234 | 233 | int numThreads = 16; |
235 | 234 | int numIterations = 1000; |
236 | 235 | ExecutorService executor = Executors.newFixedThreadPool(16); |
237 | 236 | List<Future<?>> futures = new ArrayList<>(numThreads); |
238 | | - for (int n=0; n<numThreads; n++) { |
239 | | - futures.add(executor.submit((Callable<Void>) () -> { |
240 | | - try (Connection connection = connectionProducer.createConnection(); Statement statement = connection.createStatement()) { |
241 | | - for (int i = 0; i < numIterations; i++) { |
242 | | - UUID uuid = UUID.randomUUID(); |
243 | | - String sql = "select '" + uuid + "'"; |
244 | | - |
245 | | - try (ResultSet resultSet = statement.executeQuery(sql)) { |
246 | | - assertQueryResult(resultSet, sql, uuid, false); |
247 | | - } |
248 | | - } |
249 | | - } |
250 | | - return null; |
251 | | - })); |
| 237 | + for (int n = 0; n < numThreads; n++) { |
| 238 | + futures.add( |
| 239 | + executor.submit( |
| 240 | + (Callable<Void>) |
| 241 | + () -> { |
| 242 | + try (Connection connection = connectionProducer.createConnection(); |
| 243 | + Statement statement = connection.createStatement()) { |
| 244 | + for (int i = 0; i < numIterations; i++) { |
| 245 | + UUID uuid = UUID.randomUUID(); |
| 246 | + String sql = "select '" + uuid + "'"; |
| 247 | + |
| 248 | + try (ResultSet resultSet = statement.executeQuery(sql)) { |
| 249 | + assertQueryResult(resultSet, sql, uuid, false); |
| 250 | + } |
| 251 | + } |
| 252 | + } |
| 253 | + return null; |
| 254 | + })); |
252 | 255 | } |
253 | 256 | executor.shutdown(); |
254 | 257 | assertTrue(executor.awaitTermination(600L, TimeUnit.SECONDS)); |
|
0 commit comments