Elffuss BraidHub

kikocis/java-driver public

Extend test for JAVA-419.
Changeset196d7c54d175af0785186caab6038e36b8692a37ee6670c84acc199dc20c4277
Authorolim7t <omichallat+github@gmail.com> · 2014-10-22 14:02 +02:00
Committerolim7t <omichallat+github@gmail.com> · 2014-10-22 14:05 +02:00
Parentsecff4b6c7db3

Browse the files at this changeset

1 file changed

modified driver-core/src/test/java/com/datastax/driver/core/HostConnectionPoolTimeoutTest.java +14 −4
@@ -24,7 +24,7 @@
2424
2525 // Hijack the auth provider to be notified each time a connection instance is built
2626 CountingAuthProvider authProvider = new CountingAuthProvider("cassandra", "cassandra");
27- AtomicInteger createdConnections = authProvider.count;
27+ AtomicInteger createdConnections = authProvider.newAuthenticatorCount;
2828
2929 cluster = Cluster.builder()
3030 .addContactPoint(CCMBridge.ipOfNode(1))
@@ -61,7 +61,7 @@
6161 assertThat(openConnections.getValue()).isEqualTo(3);
6262 assertThat(createdConnections.get()).isEqualTo(3);
6363
64- // Borrow one more time, which should spawn a new connection
64+ // Borrow one more stream, which should spawn a new connection
6565 PooledConnection nonCoreConnection = pool.borrowConnection(1, TimeUnit.SECONDS);
6666 assertThat(coreConnections).doesNotContain(nonCoreConnection);
6767 assertThat(openConnections.getValue()).isEqualTo(4);
@@ -85,6 +85,16 @@
8585 assertThat(openConnections.getValue()).isEqualTo(3);
8686 assertThat(createdConnections.get()).isEqualTo(4);
8787
88+ // Return all the streams of the core connections, they should not get trashed
89+ for (PooledConnection coreConnection : coreConnections)
90+ for (int i = 0; i < 128; i++)
91+ pool.returnConnection(coreConnection);
92+ assertThat(session.getState().getInFlightQueries(host1)).isEqualTo(0);
93+
94+ TimeUnit.SECONDS.sleep(idleTimeoutSeconds * 2);
95+ assertThat(openConnections.getValue()).isEqualTo(3);
96+ assertThat(createdConnections.get()).isEqualTo(4);
97+
8898 } finally {
8999 if (cluster != null)
90100 cluster.close();
@@ -97,14 +107,14 @@
97107 * An auth provider that counts how many authenticators it has returned.
98108 */
99109 static class CountingAuthProvider extends PlainTextAuthProvider {
100- final AtomicInteger count = new AtomicInteger();
110+ final AtomicInteger newAuthenticatorCount = new AtomicInteger();
101111
102112 public CountingAuthProvider(String username, String password) {
103113 super(username, password);
104114 }
105115
106116 @Override public Authenticator newAuthenticator(InetSocketAddress host) {
107- count.incrementAndGet();
117+ newAuthenticatorCount.incrementAndGet();
108118 return super.newAuthenticator(host);
109119 }
110120 }