Elffuss BraidHub

kikocis/java-driver public

Update StateListenerTest#listenerTest to handle duplicate events.

Since there are no guarantees that a StateListener does not emit the
same event multiple times, this test has been updated to check the
number of hosts an event type was emitted for instead of the number of
events.  For example, if the control connection host changes around an
event change (like a node being removed), it's possible that the toplogy
change will be received on each host.
Changeset9694702a25f2627618512bf30beb7295bcfa549956617be5f466ac19e356fd0c
AuthorAndrew Tolbert <andrew.tolbert@datastax.com> · 2014-12-22 19:51 -05:00
CommitterAndrew Tolbert <andrew.tolbert@datastax.com> · 2014-12-23 08:45 -05:00
Parents2f7ab0de2ec4

Browse the files at this changeset

1 file changed

modified driver-core/src/test/java/com/datastax/driver/core/StateListenerTest.java +17 −22
@@ -15,7 +15,11 @@
1515 */
1616 package com.datastax.driver.core;
1717
18+import com.google.common.collect.Sets;
1819 import org.testng.annotations.Test;
20+
21+import java.util.Set;
22+
1923 import static org.testng.Assert.assertEquals;
2024
2125 import static com.datastax.driver.core.TestUtils.*;
@@ -42,22 +46,22 @@
4246 // just before the listeners are called, and since waitFor is based on isUP,
4347 // it can return *just* before the listener are called.
4448 Thread.sleep(500);
45- assertEquals(listener.adds, 1);
49+ assertEquals(listener.adds.size(), 1);
4650
4751 c.cassandraCluster.forceStop(1);
4852 waitForDown(CCMBridge.IP_PREFIX + '1', cluster);
4953 Thread.sleep(500);
50- assertEquals(listener.downs, 1);
54+ assertEquals(listener.downs.size(), 1);
5155
5256 c.cassandraCluster.start(1);
5357 waitFor(CCMBridge.IP_PREFIX + '1', cluster);
5458 Thread.sleep(500);
55- assertEquals(listener.ups, 1);
59+ assertEquals(listener.ups.size(), 1);
5660
5761 c.cassandraCluster.decommissionNode(2);
5862 waitForDecommission(CCMBridge.IP_PREFIX + '2', cluster);
5963 Thread.sleep(500);
60- assertEquals(listener.removes, 1);
64+ assertEquals(listener.removes.size(), 1);
6165 } catch (Throwable e) {
6266 c.errorOut();
6367 throw e;
@@ -68,28 +72,19 @@
6872
6973 private static class CountingListener implements Host.StateListener {
7074
71- public int adds;
72- public int removes;
73- public int ups;
74- public int downs;
75+ public Set<Host> adds = Sets.newHashSet();
76+ public Set<Host> removes = Sets.newHashSet();
77+ public Set<Host> ups = Sets.newHashSet();
78+ public Set<Host> downs = Sets.newHashSet();
7579
76- public void onAdd(Host host) {
77- adds++;
78- }
80+ public void onAdd(Host host) { adds.add(host); }
7981
80- public void onUp(Host host) {
81- ups++;
82- }
82+ public void onUp(Host host) { ups.add(host); }
8383
84- public void onSuspected(Host host) {
85- }
84+ public void onSuspected(Host host) {}
8685
87- public void onDown(Host host) {
88- downs++;
89- }
86+ public void onDown(Host host) { downs.add(host); }
9087
91- public void onRemove(Host host) {
92- removes++;
93- }
88+ public void onRemove(Host host) { removes.add(host); }
9489 }
9590 }