|
4 | 4 | import java.sql.DriverManager; |
5 | 5 | import java.sql.SQLException; |
6 | 6 | import java.util.ArrayDeque; |
| 7 | +import java.util.ArrayList; |
7 | 8 | import java.util.Deque; |
| 9 | +import java.util.List; |
8 | 10 | import java.util.Properties; |
| 11 | +import java.util.concurrent.CompletableFuture; |
9 | 12 |
|
10 | 13 | import org.junit.jupiter.api.Assertions; |
11 | 14 | import org.junit.jupiter.api.Test; |
@@ -98,6 +101,29 @@ public void testContextCache() throws SQLException { |
98 | 101 | } |
99 | 102 | } |
100 | 103 |
|
| 104 | + @Test |
| 105 | + public void testContextCacheConncurrent() throws SQLException { |
| 106 | + List<CompletableFuture<YdbContext>> list = new ArrayList<>(); |
| 107 | + |
| 108 | + for (int idx = 0; idx < 20; idx++) { |
| 109 | + list.add(CompletableFuture.supplyAsync(() -> { |
| 110 | + try (Connection conn1 = DriverManager.getConnection(jdbcURL.build())) { |
| 111 | + YdbConnection unwrapped = conn1.unwrap(YdbConnection.class); |
| 112 | + Assertions.assertNotNull(unwrapped.getCtx()); |
| 113 | + return unwrapped.getCtx(); |
| 114 | + } catch (SQLException ex) { |
| 115 | + throw new RuntimeException("Cannot connect", ex); |
| 116 | + } |
| 117 | + })); |
| 118 | + } |
| 119 | + |
| 120 | + YdbContext first = list.get(0).join(); |
| 121 | + |
| 122 | + for (CompletableFuture<YdbContext> future: list) { |
| 123 | + Assertions.assertEquals(first, future.join()); |
| 124 | + } |
| 125 | + } |
| 126 | + |
101 | 127 | @Test |
102 | 128 | public void testResizeSessionPool() throws SQLException { |
103 | 129 | String url = jdbcURL.build(); |
|
0 commit comments