Elffuss BraidHub

kikocis/java-driver public

Disable debouncing for some tests that need metadata immediately.

Also changed ordering of PreparedStatementTest to execute long
repreprepare tests last since they may temporarily break the control
connection causing subsequent tests to fail.
Changeset0648dd431f7f91e6aa7419d67ef136718e620d675a5222ed45473ad81759bf30
AuthorAndrew Tolbert <andrew.tolbert@datastax.com> · 2015-08-12 23:45 -05:00
Committerolim7t <omichallat+github@gmail.com> · 2015-08-14 18:59 +02:00
Parents0c8a5cae871c

Browse the files at this changeset

9 files changed

modified driver-core/src/test/java/com/datastax/driver/core/ClusterInitTest.java +4 −2
@@ -47,6 +47,7 @@
4747 import static com.datastax.driver.core.Host.State.DOWN;
4848 import static com.datastax.driver.core.Host.State.UP;
4949 import static com.datastax.driver.core.HostDistance.LOCAL;
50+import static com.datastax.driver.core.TestUtils.nonDebouncingQueryOptions;
5051
5152 public class ClusterInitTest {
5253 private static final Logger logger = LoggerFactory.getLogger(ClusterInitTest.class);
@@ -66,7 +67,7 @@
6667 // - 1 is an actual Scassandra instance that will accept connections:
6768 scassandra = TestUtils.createScassandraServer();
6869 scassandra.start();
69- String realHostAddress = "localhost";
70+ String realHostAddress = "127.0.0.1";
7071 int port = scassandra.getBinaryPort();
7172
7273 // - the remaining 4 are fake servers that will throw connect timeouts:
@@ -108,6 +109,7 @@
108109 .withReconnectionPolicy(reconnectionPolicy)
109110 .withPoolingOptions(poolingOptions)
110111 .withProtocolVersion(TestUtils.getDesiredProtocolVersion())
112+ .withQueryOptions(nonDebouncingQueryOptions())
111113 .build();
112114 cluster.connect();
113115
@@ -124,7 +126,7 @@
124126 verify(socketOptions, atLeast(6)).getKeepAlive();
125127 verify(socketOptions, atMost(7)).getKeepAlive();
126128
127- assertThat(cluster).host(realHostAddress).hasState(UP);
129+ assertThat(cluster).host(realHostAddress).isNotNull().hasState(UP);
128130 for (FakeHost failingHost : failingHosts)
129131 assertThat(cluster).host(failingHost.address).hasState(DOWN);
130132 assertThat(cluster).host(missingHostAddress).isNull();
modified driver-core/src/test/java/com/datastax/driver/core/MetadataTest.java +2 −0
@@ -21,6 +21,7 @@
2121 import org.testng.annotations.Test;
2222
2323 import static com.datastax.driver.core.Assertions.assertThat;
24+import static com.datastax.driver.core.TestUtils.nonDebouncingQueryOptions;
2425 import static com.datastax.driver.core.TestUtils.waitFor;
2526
2627 public class MetadataTest {
@@ -58,6 +59,7 @@
5859
5960 cluster = Cluster.builder()
6061 .addContactPoint(CCMBridge.ipOfNode(1))
62+ .withQueryOptions(nonDebouncingQueryOptions())
6163 .build();
6264 Session session = cluster.connect();
6365
modified driver-core/src/test/java/com/datastax/driver/core/PreparedStatementTest.java +12 −12
@@ -110,11 +110,7 @@
110110
111111 @Override
112112 protected Cluster.Builder configure(Cluster.Builder builder) {
113- return builder.withQueryOptions(new QueryOptions()
114- .setRefreshNodeIntervalMillis(0)
115- .setRefreshNodeListIntervalMillis(0)
116- .setRefreshSchemaIntervalMillis(0)
117- );
113+ return builder.withQueryOptions(TestUtils.nonDebouncingQueryOptions());
118114 }
119115
120116 @Test(groups = "short")
@@ -331,12 +327,12 @@
331327 }
332328 }
333329
334- @Test(groups = "long")
330+ @Test(groups = "long", priority = Integer.MAX_VALUE)
335331 public void reprepareOnNewlyUpNodeTest() throws Exception {
336332 reprepareOnNewlyUpNodeTest(null, session);
337333 }
338334
339- @Test(groups = "long")
335+ @Test(groups = "long", priority = Integer.MAX_VALUE)
340336 public void reprepareOnNewlyUpNodeNoKeyspaceTest() throws Exception {
341337
342338 // This is the same test than reprepareOnNewlyUpNodeTest, except that the
@@ -451,10 +447,14 @@
451447 Cluster otherCluster = Cluster.builder()
452448 .addContactPointsWithPorts(ImmutableList.of(hostAddress))
453449 .build();
454- PreparedStatement pst = otherCluster.connect().prepare("select * from system.peers where inet = ?");
455- BoundStatement bs = pst.bind().setInet(0, InetAddress.getByName("localhost"));
456-
457- // We expect that the error gets detected without a roundtrip to the server, so use executeAsync
458- session.executeAsync(bs);
450+ try {
451+ PreparedStatement pst = otherCluster.connect().prepare("select * from system.peers where inet = ?");
452+ BoundStatement bs = pst.bind().setInet(0, InetAddress.getByName("localhost"));
453+
454+ // We expect that the error gets detected without a roundtrip to the server, so use executeAsync
455+ session.executeAsync(bs);
456+ } finally {
457+ otherCluster.close();
458+ }
459459 }
460460 }
modified driver-core/src/test/java/com/datastax/driver/core/RecommissionedNodeTest.java +9 −5
@@ -28,7 +28,7 @@
2828 import static com.datastax.driver.core.Assertions.*;
2929 import static com.datastax.driver.core.Host.State.DOWN;
3030 import static com.datastax.driver.core.Host.State.UP;
31-
31+import static com.datastax.driver.core.TestUtils.nonDebouncingQueryOptions;
3232
3333 /**
3434 * Due to C* gossip bugs, system.peers may report nodes that are gone from the cluster.
@@ -50,7 +50,8 @@
5050 mainCcm.waitForDown(1);
5151
5252 // Now start the driver that will connect to node2 and node3, and consider node1 down
53- mainCluster = Cluster.builder().addContactPoint(CCMBridge.IP_PREFIX + "2").build();
53+ mainCluster = Cluster.builder().addContactPoint(CCMBridge.IP_PREFIX + "2")
54+ .withQueryOptions(nonDebouncingQueryOptions()).build();
5455 mainCluster.connect();
5556 waitForCountUpHosts(mainCluster, 2);
5657 // From that point, reconnections to node1 have been scheduled.
@@ -72,7 +73,8 @@
7273 mainCcm.waitForDown(1);
7374
7475 // Start the driver, the control connection will be on node2
75- mainCluster = Cluster.builder().addContactPoint(CCMBridge.IP_PREFIX + "2").build();
76+ mainCluster = Cluster.builder().addContactPoint(CCMBridge.IP_PREFIX + "2")
77+ .withQueryOptions(nonDebouncingQueryOptions()).build();
7678 mainCluster.connect();
7779 waitForCountUpHosts(mainCluster, 1);
7880
@@ -99,7 +101,8 @@
99101 otherCcm.waitForUp(1);
100102
101103 // Start the driver, it should only connect to node 2
102- mainCluster = Cluster.builder().addContactPoint(CCMBridge.IP_PREFIX + "2").build();
104+ mainCluster = Cluster.builder().addContactPoint(CCMBridge.IP_PREFIX + "2")
105+ .withQueryOptions(nonDebouncingQueryOptions()).build();
103106
104107 // When we first initialize the Cluster, all hosts are marked UP
105108 assertThat(mainCluster).host(2).hasState(UP);
@@ -127,7 +130,8 @@
127130 otherCcm.waitForUp(1);
128131
129132 // Start the driver, it should only connect to node 2
130- mainCluster = Cluster.builder().addContactPoint(CCMBridge.IP_PREFIX + "2").build();
133+ mainCluster = Cluster.builder().addContactPoint(CCMBridge.IP_PREFIX + "2")
134+ .withQueryOptions(nonDebouncingQueryOptions()).build();
131135
132136 // Create a session. This will try to open a pool to node 1 and find that it doesn't support protocol version.
133137 mainCluster.connect();
modified driver-core/src/test/java/com/datastax/driver/core/RefreshConnectedHostTest.java +1 −0
@@ -53,6 +53,7 @@
5353 .withPoolingOptions(poolingOptions)
5454 .withLoadBalancingPolicy(loadBalancingPolicy)
5555 .withReconnectionPolicy(new ConstantReconnectionPolicy(1000))
56+ .withQueryOptions(TestUtils.nonDebouncingQueryOptions())
5657 .build();
5758
5859 Session session = cluster.connect();
modified driver-core/src/test/java/com/datastax/driver/core/SchemaChangesTest.java +5 −17
@@ -32,6 +32,7 @@
3232
3333 import static com.datastax.driver.core.Assertions.assertThat;
3434 import static com.datastax.driver.core.Metadata.handleId;
35+import static com.datastax.driver.core.TestUtils.nonDebouncingQueryOptions;
3536
3637 public class SchemaChangesTest extends CCMBridge.PerClassSingleNodeCluster {
3738
@@ -74,20 +75,13 @@
7475 public void setup() throws InterruptedException {
7576 Cluster.Builder builder = configure(Cluster.builder())
7677 .addContactPointsWithPorts(Collections.singletonList(hostAddress))
77- .withQueryOptions(new QueryOptions()
78- .setRefreshNodeIntervalMillis(0)
79- .setRefreshNodeListIntervalMillis(0)
80- .setRefreshSchemaIntervalMillis(0)
81- );
78+ .withQueryOptions(nonDebouncingQueryOptions());
8279 cluster1 = builder.build();
8380 cluster2 = builder.build();
8481 schemaDisabledCluster = spy(configure(Cluster.builder())
8582 .addContactPointsWithPorts(Collections.singletonList(hostAddress))
8683 .withClusterName("schema-disabled")
87- .withQueryOptions(new QueryOptions()
88- .setRefreshNodeIntervalMillis(0)
89- .setRefreshNodeListIntervalMillis(0)
90- .setRefreshSchemaIntervalMillis(0)
84+ .withQueryOptions(nonDebouncingQueryOptions()
9185 .setMetadataEnabled(false)
9286 ).build());
9387
@@ -292,10 +286,7 @@
292286 public void should_throw_illegal_state_exception_on_newToken_with_metadata_disabled() {
293287 Cluster cluster = configure(Cluster.builder())
294288 .addContactPointsWithPorts(Collections.singletonList(hostAddress))
295- .withQueryOptions(new QueryOptions()
296- .setRefreshNodeIntervalMillis(0)
297- .setRefreshNodeListIntervalMillis(0)
298- .setRefreshSchemaIntervalMillis(0)
289+ .withQueryOptions(nonDebouncingQueryOptions()
299290 .setMetadataEnabled(false)
300291 ).build();
301292
@@ -319,10 +310,7 @@
319310 public void should_throw_illegal_state_exception_on_newTokenRange_with_metadata_disabled() {
320311 Cluster cluster = configure(Cluster.builder())
321312 .addContactPointsWithPorts(Collections.singletonList(hostAddress))
322- .withQueryOptions(new QueryOptions()
323- .setRefreshNodeIntervalMillis(0)
324- .setRefreshNodeListIntervalMillis(0)
325- .setRefreshSchemaIntervalMillis(0)
313+ .withQueryOptions(nonDebouncingQueryOptions()
326314 .setMetadataEnabled(false)
327315 ).build();
328316
modified driver-core/src/test/java/com/datastax/driver/core/SessionLeakTest.java +4 −2
@@ -32,7 +32,7 @@
3232 import com.datastax.driver.core.exceptions.InvalidQueryException;
3333
3434 import static com.datastax.driver.core.Assertions.assertThat;
35-
35+import static com.datastax.driver.core.TestUtils.nonDebouncingQueryOptions;
3636
3737 public class SessionLeakTest {
3838
@@ -53,7 +53,9 @@
5353 cluster = Cluster.builder()
5454 .addContactPointsWithPorts(Collections.singletonList(
5555 new InetSocketAddress(CCMBridge.IP_PREFIX + '1', 9042)))
56- .withNettyOptions(channelMonitor.nettyOptions()).build();
56+ .withNettyOptions(channelMonitor.nettyOptions())
57+ .withQueryOptions(nonDebouncingQueryOptions())
58+ .build();
5759
5860 cluster.init();
5961
modified driver-core/src/test/java/com/datastax/driver/core/TestUtils.java +9 −0
@@ -456,4 +456,13 @@
456456 .withLoadBalancingPolicy(new WhiteListPolicy(new RoundRobinPolicy(), singleAddress))
457457 .build();
458458 }
459+
460+ /**
461+ * @return a {@QueryOptions} that disables debouncing by setting intervals to 0ms.
462+ */
463+ public static QueryOptions nonDebouncingQueryOptions() {
464+ return new QueryOptions().setRefreshNodeIntervalMillis(0)
465+ .setRefreshNodeListIntervalMillis(0)
466+ .setRefreshSchemaIntervalMillis(0);
467+ }
459468 }
modified driver-core/src/test/java/com/datastax/driver/core/policies/TokenAwarePolicyTest.java +3 −0
@@ -25,6 +25,8 @@
2525 import com.datastax.driver.core.*;
2626 import com.datastax.driver.core.utils.Bytes;
2727
28+import static com.datastax.driver.core.TestUtils.nonDebouncingQueryOptions;
29+
2830 public class TokenAwarePolicyTest {
2931 @Test(groups = "long")
3032 public void should_shuffle_replicas_when_requested() {
@@ -46,6 +48,7 @@
4648 cluster = Cluster.builder()
4749 .addContactPoint(CCMBridge.ipOfNode(1))
4850 .withLoadBalancingPolicy(loadBalancingPolicy)
51+ .withQueryOptions(nonDebouncingQueryOptions())
4952 .build();
5053
5154 String keyspace = "ks";