kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 3850e226dfb02e150a7ae46dc2c2abad2e069dbaeb19e989f183e1fc4e531d26 |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2014-10-27 16:28 +01:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2014-10-27 16:28 +01:00 |
| Parents | e196892375ed |
1 file changed
modified driver-core/src/test/java/com/datastax/driver/core/ControlConnectionTest.java +12 −7
| @@ -23,6 +23,7 @@ | ||
| 23 | 23 | // Since we don't open any session from our Cluster, only the control connection reattempts are calling this |
| 24 | 24 | // method, therefore the invocation count is equal to the number of attempts. |
| 25 | 25 | QueryPlanCountingPolicy loadBalancingPolicy = new QueryPlanCountingPolicy(Policies.defaultLoadBalancingPolicy()); |
| 26 | + AtomicInteger reconnectionAttempts = loadBalancingPolicy.counter; | |
| 26 | 27 | |
| 27 | 28 | // Custom reconnection policy with a very large delay (longer than the test duration), to make sure we count |
| 28 | 29 | // only the first reconnection attempt of each reconnection handler. |
| @@ -39,18 +40,23 @@ | ||
| 39 | 40 | }; |
| 40 | 41 | |
| 41 | 42 | try { |
| 42 | - ccm = CCMBridge.create("test", 1); | |
| 43 | + ccm = CCMBridge.create("test", 2); | |
| 44 | + // We pass only the first host as contact point, so we know the control connection will be on this host | |
| 43 | 45 | cluster = Cluster.builder() |
| 44 | - .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 45 | - .withReconnectionPolicy(reconnectionPolicy) | |
| 46 | - .withLoadBalancingPolicy(loadBalancingPolicy) | |
| 47 | - .build(); | |
| 46 | + .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 47 | + .withReconnectionPolicy(reconnectionPolicy) | |
| 48 | + .withLoadBalancingPolicy(loadBalancingPolicy) | |
| 49 | + .build(); | |
| 48 | 50 | cluster.init(); |
| 49 | 51 | |
| 52 | + // Kill the control connection host, there should be exactly one reconnection attempt | |
| 50 | 53 | ccm.stop(1); |
| 54 | + TimeUnit.SECONDS.sleep(1); // Sleep for a while to make sure our final count is not the result of lucky timing | |
| 55 | + assertThat(reconnectionAttempts.get()).isEqualTo(1); | |
| 51 | 56 | |
| 52 | - // Sleep for a while to make sure our final count is not the result of lucky timing | |
| 57 | + ccm.stop(2); | |
| 53 | 58 | TimeUnit.SECONDS.sleep(1); |
| 59 | + assertThat(reconnectionAttempts.get()).isEqualTo(2); | |
| 54 | 60 | |
| 55 | 61 | } finally { |
| 56 | 62 | if (cluster != null) |
| @@ -58,7 +64,6 @@ | ||
| 58 | 64 | if (ccm != null) |
| 59 | 65 | ccm.remove(); |
| 60 | 66 | } |
| 61 | - assertThat(loadBalancingPolicy.counter.get()).isEqualTo(1); | |
| 62 | 67 | } |
| 63 | 68 | |
| 64 | 69 | static class QueryPlanCountingPolicy extends DelegatingLoadBalancingPolicy { |