Elffuss BraidHub

kikocis/java-driver public

Improve test for control connection reconnection (JAVA-497).
Changeset3850e226dfb02e150a7ae46dc2c2abad2e069dbaeb19e989f183e1fc4e531d26
Authorolim7t <omichallat+github@gmail.com> · 2014-10-27 16:28 +01:00
Committerolim7t <omichallat+github@gmail.com> · 2014-10-27 16:28 +01:00
Parentse196892375ed

Browse the files at this changeset

1 file changed

modified driver-core/src/test/java/com/datastax/driver/core/ControlConnectionTest.java +12 −7
@@ -23,6 +23,7 @@
2323 // Since we don't open any session from our Cluster, only the control connection reattempts are calling this
2424 // method, therefore the invocation count is equal to the number of attempts.
2525 QueryPlanCountingPolicy loadBalancingPolicy = new QueryPlanCountingPolicy(Policies.defaultLoadBalancingPolicy());
26+ AtomicInteger reconnectionAttempts = loadBalancingPolicy.counter;
2627
2728 // Custom reconnection policy with a very large delay (longer than the test duration), to make sure we count
2829 // only the first reconnection attempt of each reconnection handler.
@@ -39,18 +40,23 @@
3940 };
4041
4142 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
4345 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();
4850 cluster.init();
4951
52+ // Kill the control connection host, there should be exactly one reconnection attempt
5053 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);
5156
52- // Sleep for a while to make sure our final count is not the result of lucky timing
57+ ccm.stop(2);
5358 TimeUnit.SECONDS.sleep(1);
59+ assertThat(reconnectionAttempts.get()).isEqualTo(2);
5460
5561 } finally {
5662 if (cluster != null)
@@ -58,7 +64,6 @@
5864 if (ccm != null)
5965 ccm.remove();
6066 }
61- assertThat(loadBalancingPolicy.counter.get()).isEqualTo(1);
6267 }
6368
6469 static class QueryPlanCountingPolicy extends DelegatingLoadBalancingPolicy {