@@ -43,15 +43,13 @@ public void connect() throws SQLException {
4343
4444 @ Test
4545 public void testContextCache () throws SQLException {
46- YdbContext ctx ;
47- try (Connection conn1 = DriverManager .getConnection (jdbcURL .build ())) {
48- Assertions .assertTrue (conn1 .isValid (5000 ));
46+ Connection firstConnection = DriverManager .getConnection (jdbcURL .build ());
47+ Assertions .assertTrue (firstConnection .isValid (5000 ));
4948
50- YdbConnection unwrapped = conn1 .unwrap (YdbConnection .class );
51- Assertions .assertNotNull (unwrapped .getCtx ());
49+ YdbConnection first = firstConnection .unwrap (YdbConnection .class );
50+ Assertions .assertNotNull (first .getCtx ());
5251
53- ctx = unwrapped .getCtx ();
54- }
52+ YdbContext ctx = first .getCtx ();
5553
5654 try (Connection conn2 = DriverManager .getConnection (jdbcURL .build ())) {
5755 Assertions .assertTrue (conn2 .isValid (5000 ));
@@ -87,10 +85,7 @@ public void testContextCache() throws SQLException {
8785 Assertions .assertNotSame (ctx , unwrapped .getCtx ());
8886 }
8987
90- if (YdbDriver .isRegistered ()) {
91- YdbDriver .deregister ();
92- YdbDriver .register ();
93- }
88+ firstConnection .close ();
9489
9590 try (Connection conn6 = DriverManager .getConnection (jdbcURL .build ())) {
9691 Assertions .assertTrue (conn6 .isValid (5000 ));
@@ -103,24 +98,27 @@ public void testContextCache() throws SQLException {
10398
10499 @ Test
105100 public void testContextCacheConncurrent () throws SQLException {
106- List <CompletableFuture <YdbContext >> list = new ArrayList <>();
101+ List <CompletableFuture <YdbConnection >> list = new ArrayList <>();
107102
108103 for (int idx = 0 ; idx < 20 ; idx ++) {
109104 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 ();
105+ try {
106+ Connection connection = DriverManager .getConnection (jdbcURL .build ());
107+ return connection .unwrap (YdbConnection .class );
114108 } catch (SQLException ex ) {
115109 throw new RuntimeException ("Cannot connect" , ex );
116110 }
117111 }));
118112 }
119113
120- YdbContext first = list .get (0 ).join ();
114+ YdbContext first = list .get (0 ).join ().getCtx ();
115+
116+ for (CompletableFuture <YdbConnection > future : list ) {
117+ Assertions .assertEquals (first , future .join ().getCtx ());
118+ }
121119
122- for (CompletableFuture <YdbContext > future : list ) {
123- Assertions . assertEquals ( first , future .join ());
120+ for (CompletableFuture <YdbConnection > future : list ) {
121+ future .join (). close ( );
124122 }
125123 }
126124
0 commit comments