kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 952ea975f811aa4e86baf18f32666186e0dcdb13221f4daad3c18204335ce6b9 |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2014-10-27 17:16 +01:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2014-10-27 17:16 +01:00 |
| Parents | 3850e226dfb0 |
1 file changed
modified driver-core/src/test/java/com/datastax/driver/core/HostConnectionPoolTimeoutTest.java +11 −1
| @@ -35,6 +35,7 @@ | ||
| 35 | 35 | .build(); |
| 36 | 36 | |
| 37 | 37 | PoolingOptions poolingOptions = cluster.getConfiguration().getPoolingOptions(); |
| 38 | + poolingOptions.setMinSimultaneousRequestsPerConnectionThreshold(HostDistance.LOCAL, 1); | |
| 38 | 39 | // Set to the max, which makes it slightly easier to reason about when new connections will be created: |
| 39 | 40 | poolingOptions.setMaxSimultaneousRequestsPerConnectionThreshold(HostDistance.LOCAL, 128); |
| 40 | 41 | int idleTimeoutSeconds = 10; |
| @@ -82,7 +83,16 @@ | ||
| 82 | 83 | assertThat(openConnections.getValue()).isEqualTo(4); |
| 83 | 84 | assertThat(createdConnections.get()).isEqualTo(4); |
| 84 | 85 | |
| 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); | |
| 86 | 96 | pool.returnConnection(nonCoreConnection); |
| 87 | 97 | TimeUnit.SECONDS.sleep(idleTimeoutSeconds * 2); |
| 88 | 98 | assertThat(openConnections.getValue()).isEqualTo(3); |