Elffuss BraidHub

kikocis/java-driver public

Merge pull request #261 from tolbertam/StateListenerTest-fix

Update StateListenerTest#listenerTest to handle duplicate events.
Changeset9b8c4af009aa1ac2d4e7cf79888ad1928160e4afb5363d7eaa0f099307428d48
AuthorOlivier Michallat <olim7t@users.noreply.github.com> · 2014-12-23 15:36 +01:00
CommitterOlivier Michallat <olim7t@users.noreply.github.com> · 2014-12-23 15:36 +01:00
Parentsfa2eec157ac1, 9694702a25f2

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 }