kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 196d7c54d175af0785186caab6038e36b8692a37ee6670c84acc199dc20c4277 |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2014-10-22 14:02 +02:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2014-10-22 14:05 +02:00 |
| Parents | ecff4b6c7db3 |
1 file changed
modified driver-core/src/test/java/com/datastax/driver/core/HostConnectionPoolTimeoutTest.java +14 −4
| @@ -24,7 +24,7 @@ | ||
| 24 | 24 | |
| 25 | 25 | // Hijack the auth provider to be notified each time a connection instance is built |
| 26 | 26 | CountingAuthProvider authProvider = new CountingAuthProvider("cassandra", "cassandra"); |
| 27 | - AtomicInteger createdConnections = authProvider.count; | |
| 27 | + AtomicInteger createdConnections = authProvider.newAuthenticatorCount; | |
| 28 | 28 | |
| 29 | 29 | cluster = Cluster.builder() |
| 30 | 30 | .addContactPoint(CCMBridge.ipOfNode(1)) |
| @@ -61,7 +61,7 @@ | ||
| 61 | 61 | assertThat(openConnections.getValue()).isEqualTo(3); |
| 62 | 62 | assertThat(createdConnections.get()).isEqualTo(3); |
| 63 | 63 | |
| 64 | - // Borrow one more time, which should spawn a new connection | |
| 64 | + // Borrow one more stream, which should spawn a new connection | |
| 65 | 65 | PooledConnection nonCoreConnection = pool.borrowConnection(1, TimeUnit.SECONDS); |
| 66 | 66 | assertThat(coreConnections).doesNotContain(nonCoreConnection); |
| 67 | 67 | assertThat(openConnections.getValue()).isEqualTo(4); |
| @@ -85,6 +85,16 @@ | ||
| 85 | 85 | assertThat(openConnections.getValue()).isEqualTo(3); |
| 86 | 86 | assertThat(createdConnections.get()).isEqualTo(4); |
| 87 | 87 | |
| 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 | + | |
| 88 | 98 | } finally { |
| 89 | 99 | if (cluster != null) |
| 90 | 100 | cluster.close(); |
| @@ -97,14 +107,14 @@ | ||
| 97 | 107 | * An auth provider that counts how many authenticators it has returned. |
| 98 | 108 | */ |
| 99 | 109 | static class CountingAuthProvider extends PlainTextAuthProvider { |
| 100 | - final AtomicInteger count = new AtomicInteger(); | |
| 110 | + final AtomicInteger newAuthenticatorCount = new AtomicInteger(); | |
| 101 | 111 | |
| 102 | 112 | public CountingAuthProvider(String username, String password) { |
| 103 | 113 | super(username, password); |
| 104 | 114 | } |
| 105 | 115 | |
| 106 | 116 | @Override public Authenticator newAuthenticator(InetSocketAddress host) { |
| 107 | - count.incrementAndGet(); | |
| 117 | + newAuthenticatorCount.incrementAndGet(); | |
| 108 | 118 | return super.newAuthenticator(host); |
| 109 | 119 | } |
| 110 | 120 | } |