Elffuss BraidHub

kikocis/java-driver public

Improve test for connection idle timeout (JAVA-419).
Changeset952ea975f811aa4e86baf18f32666186e0dcdb13221f4daad3c18204335ce6b9
Authorolim7t <omichallat+github@gmail.com> · 2014-10-27 17:16 +01:00
Committerolim7t <omichallat+github@gmail.com> · 2014-10-27 17:16 +01:00
Parents3850e226dfb0

Browse the files at this changeset

1 file changed

modified driver-core/src/test/java/com/datastax/driver/core/HostConnectionPoolTimeoutTest.java +11 −1
@@ -35,6 +35,7 @@
3535 .build();
3636
3737 PoolingOptions poolingOptions = cluster.getConfiguration().getPoolingOptions();
38+ poolingOptions.setMinSimultaneousRequestsPerConnectionThreshold(HostDistance.LOCAL, 1);
3839 // Set to the max, which makes it slightly easier to reason about when new connections will be created:
3940 poolingOptions.setMaxSimultaneousRequestsPerConnectionThreshold(HostDistance.LOCAL, 128);
4041 int idleTimeoutSeconds = 10;
@@ -82,7 +83,16 @@
8283 assertThat(openConnections.getValue()).isEqualTo(4);
8384 assertThat(createdConnections.get()).isEqualTo(4);
8485
85- // If we return and wait long enough, it should eventually get trashed
86+ // Borrow two more and return 1 to reach inFlight = 2 (above the min). The connection should not be trashed.
87+ assertThat(pool.borrowConnection(1, TimeUnit.SECONDS)).isSameAs(nonCoreConnection2);
88+ assertThat(pool.borrowConnection(1, TimeUnit.SECONDS)).isSameAs(nonCoreConnection2);
89+ pool.returnConnection(nonCoreConnection2); // (we need to return one because we cancel the timeout on return)
90+ TimeUnit.SECONDS.sleep(idleTimeoutSeconds * 2);
91+ assertThat(openConnections.getValue()).isEqualTo(4);
92+ assertThat(createdConnections.get()).isEqualTo(4);
93+
94+ // Return everything for the non-core connection and wait long enough, it should eventually get trashed
95+ pool.returnConnection(nonCoreConnection);
8696 pool.returnConnection(nonCoreConnection);
8797 TimeUnit.SECONDS.sleep(idleTimeoutSeconds * 2);
8898 assertThat(openConnections.getValue()).isEqualTo(3);