File tree Expand file tree Collapse file tree
core/src/main/java/com/datastax/oss/driver/internal/core/session
integration-tests/src/test/java/com/datastax/oss/driver/api/core Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44
55### 4.0.0-beta2 (in progress)
66
7+ - [ bug] JAVA-1948: Close session properly when LBP fails to initialize
78- [ improvement] JAVA-1949: Improve error message when contact points are wrong
89- [ improvement] JAVA-1956: Add statementsCount accessor to BatchStatementBuilder
910- [ bug] JAVA-1946: Ignore protocol version in equals comparison for UdtValue/TupleValue
Original file line number Diff line number Diff line change @@ -366,7 +366,11 @@ private void afterInitialSchemaRefresh(CqlIdentifier keyspace) {
366366 }
367367 });
368368 } catch (Throwable throwable ) {
369- initFuture .completeExceptionally (throwable );
369+ forceCloseAsync ()
370+ .whenComplete (
371+ (v , error ) -> {
372+ initFuture .completeExceptionally (throwable );
373+ });
370374 }
371375 }
372376
Original file line number Diff line number Diff line change 1515 */
1616package com .datastax .oss .driver .api .core ;
1717
18+ import static com .datastax .oss .driver .api .testinfra .utils .ConditionChecker .checkThat ;
19+ import static java .util .concurrent .TimeUnit .SECONDS ;
20+ import static junit .framework .TestCase .fail ;
1821import static org .assertj .core .api .Assertions .assertThat ;
1922
2023import com .datastax .oss .driver .api .core .config .DefaultDriverOption ;
@@ -98,6 +101,30 @@ public void should_wait_for_contact_points_if_reconnection_enabled() throws Exce
98101 session .close ();
99102 }
100103
104+ /**
105+ * Test for JAVA-1948. This ensures that when the LBP initialization fails that any connections
106+ * are cleaned up appropriately.
107+ */
108+ @ Test
109+ public void should_cleanup_on_lbp_init_failure () {
110+ try {
111+ DriverConfigLoader loader =
112+ SessionUtils .configLoaderBuilder ()
113+ .without (DefaultDriverOption .LOAD_BALANCING_LOCAL_DATACENTER )
114+ .build ();
115+ CqlSession .builder ()
116+ .addContactPoints (simulacronRule .getContactPoints ())
117+ .withConfigLoader (loader )
118+ .build ();
119+ fail ("Should have thrown a DriverException for no DC with explicit contact point" );
120+ } catch (DriverException ignored ) {
121+ }
122+ // One second should be plenty of time for connections to close server side
123+ checkThat (() -> simulacronRule .cluster ().getConnections ().getConnections ().isEmpty ())
124+ .before (1 , SECONDS )
125+ .becomesTrue ();
126+ }
127+
101128 @ SuppressWarnings ("unchecked" )
102129 private CompletionStage <? extends Session > newSessionAsync (
103130 SimulacronRule serverRule , DriverConfigLoader loader ) {
You can’t perform that action at this time.
0 commit comments