kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 0648dd431f7f91e6aa7419d67ef136718e620d675a5222ed45473ad81759bf30 |
|---|---|
| Author | Andrew Tolbert <andrew.tolbert@datastax.com> · 2015-08-12 23:45 -05:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2015-08-14 18:59 +02:00 |
| Parents | 0c8a5cae871c |
9 files changed
modified driver-core/src/test/java/com/datastax/driver/core/ClusterInitTest.java +4 −2
| @@ -47,6 +47,7 @@ | ||
| 47 | 47 | import static com.datastax.driver.core.Host.State.DOWN; |
| 48 | 48 | import static com.datastax.driver.core.Host.State.UP; |
| 49 | 49 | import static com.datastax.driver.core.HostDistance.LOCAL; |
| 50 | +import static com.datastax.driver.core.TestUtils.nonDebouncingQueryOptions; | |
| 50 | 51 | |
| 51 | 52 | public class ClusterInitTest { |
| 52 | 53 | private static final Logger logger = LoggerFactory.getLogger(ClusterInitTest.class); |
| @@ -66,7 +67,7 @@ | ||
| 66 | 67 | // - 1 is an actual Scassandra instance that will accept connections: |
| 67 | 68 | scassandra = TestUtils.createScassandraServer(); |
| 68 | 69 | scassandra.start(); |
| 69 | - String realHostAddress = "localhost"; | |
| 70 | + String realHostAddress = "127.0.0.1"; | |
| 70 | 71 | int port = scassandra.getBinaryPort(); |
| 71 | 72 | |
| 72 | 73 | // - the remaining 4 are fake servers that will throw connect timeouts: |
| @@ -108,6 +109,7 @@ | ||
| 108 | 109 | .withReconnectionPolicy(reconnectionPolicy) |
| 109 | 110 | .withPoolingOptions(poolingOptions) |
| 110 | 111 | .withProtocolVersion(TestUtils.getDesiredProtocolVersion()) |
| 112 | + .withQueryOptions(nonDebouncingQueryOptions()) | |
| 111 | 113 | .build(); |
| 112 | 114 | cluster.connect(); |
| 113 | 115 | |
| @@ -124,7 +126,7 @@ | ||
| 124 | 126 | verify(socketOptions, atLeast(6)).getKeepAlive(); |
| 125 | 127 | verify(socketOptions, atMost(7)).getKeepAlive(); |
| 126 | 128 | |
| 127 | - assertThat(cluster).host(realHostAddress).hasState(UP); | |
| 129 | + assertThat(cluster).host(realHostAddress).isNotNull().hasState(UP); | |
| 128 | 130 | for (FakeHost failingHost : failingHosts) |
| 129 | 131 | assertThat(cluster).host(failingHost.address).hasState(DOWN); |
| 130 | 132 | assertThat(cluster).host(missingHostAddress).isNull(); |
modified driver-core/src/test/java/com/datastax/driver/core/MetadataTest.java +2 −0
| @@ -21,6 +21,7 @@ | ||
| 21 | 21 | import org.testng.annotations.Test; |
| 22 | 22 | |
| 23 | 23 | import static com.datastax.driver.core.Assertions.assertThat; |
| 24 | +import static com.datastax.driver.core.TestUtils.nonDebouncingQueryOptions; | |
| 24 | 25 | import static com.datastax.driver.core.TestUtils.waitFor; |
| 25 | 26 | |
| 26 | 27 | public class MetadataTest { |
| @@ -58,6 +59,7 @@ | ||
| 58 | 59 | |
| 59 | 60 | cluster = Cluster.builder() |
| 60 | 61 | .addContactPoint(CCMBridge.ipOfNode(1)) |
| 62 | + .withQueryOptions(nonDebouncingQueryOptions()) | |
| 61 | 63 | .build(); |
| 62 | 64 | Session session = cluster.connect(); |
| 63 | 65 |
modified driver-core/src/test/java/com/datastax/driver/core/PreparedStatementTest.java +12 −12
| @@ -110,11 +110,7 @@ | ||
| 110 | 110 | |
| 111 | 111 | @Override |
| 112 | 112 | 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()); | |
| 118 | 114 | } |
| 119 | 115 | |
| 120 | 116 | @Test(groups = "short") |
| @@ -331,12 +327,12 @@ | ||
| 331 | 327 | } |
| 332 | 328 | } |
| 333 | 329 | |
| 334 | - @Test(groups = "long") | |
| 330 | + @Test(groups = "long", priority = Integer.MAX_VALUE) | |
| 335 | 331 | public void reprepareOnNewlyUpNodeTest() throws Exception { |
| 336 | 332 | reprepareOnNewlyUpNodeTest(null, session); |
| 337 | 333 | } |
| 338 | 334 | |
| 339 | - @Test(groups = "long") | |
| 335 | + @Test(groups = "long", priority = Integer.MAX_VALUE) | |
| 340 | 336 | public void reprepareOnNewlyUpNodeNoKeyspaceTest() throws Exception { |
| 341 | 337 | |
| 342 | 338 | // This is the same test than reprepareOnNewlyUpNodeTest, except that the |
| @@ -451,10 +447,14 @@ | ||
| 451 | 447 | Cluster otherCluster = Cluster.builder() |
| 452 | 448 | .addContactPointsWithPorts(ImmutableList.of(hostAddress)) |
| 453 | 449 | .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 | + } | |
| 459 | 459 | } |
| 460 | 460 | } |
modified driver-core/src/test/java/com/datastax/driver/core/RecommissionedNodeTest.java +9 −5
| @@ -28,7 +28,7 @@ | ||
| 28 | 28 | import static com.datastax.driver.core.Assertions.*; |
| 29 | 29 | import static com.datastax.driver.core.Host.State.DOWN; |
| 30 | 30 | import static com.datastax.driver.core.Host.State.UP; |
| 31 | - | |
| 31 | +import static com.datastax.driver.core.TestUtils.nonDebouncingQueryOptions; | |
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | 34 | * Due to C* gossip bugs, system.peers may report nodes that are gone from the cluster. |
| @@ -50,7 +50,8 @@ | ||
| 50 | 50 | mainCcm.waitForDown(1); |
| 51 | 51 | |
| 52 | 52 | // 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(); | |
| 54 | 55 | mainCluster.connect(); |
| 55 | 56 | waitForCountUpHosts(mainCluster, 2); |
| 56 | 57 | // From that point, reconnections to node1 have been scheduled. |
| @@ -72,7 +73,8 @@ | ||
| 72 | 73 | mainCcm.waitForDown(1); |
| 73 | 74 | |
| 74 | 75 | // 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(); | |
| 76 | 78 | mainCluster.connect(); |
| 77 | 79 | waitForCountUpHosts(mainCluster, 1); |
| 78 | 80 | |
| @@ -99,7 +101,8 @@ | ||
| 99 | 101 | otherCcm.waitForUp(1); |
| 100 | 102 | |
| 101 | 103 | // 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(); | |
| 103 | 106 | |
| 104 | 107 | // When we first initialize the Cluster, all hosts are marked UP |
| 105 | 108 | assertThat(mainCluster).host(2).hasState(UP); |
| @@ -127,7 +130,8 @@ | ||
| 127 | 130 | otherCcm.waitForUp(1); |
| 128 | 131 | |
| 129 | 132 | // 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(); | |
| 131 | 135 | |
| 132 | 136 | // Create a session. This will try to open a pool to node 1 and find that it doesn't support protocol version. |
| 133 | 137 | mainCluster.connect(); |
modified driver-core/src/test/java/com/datastax/driver/core/RefreshConnectedHostTest.java +1 −0
| @@ -53,6 +53,7 @@ | ||
| 53 | 53 | .withPoolingOptions(poolingOptions) |
| 54 | 54 | .withLoadBalancingPolicy(loadBalancingPolicy) |
| 55 | 55 | .withReconnectionPolicy(new ConstantReconnectionPolicy(1000)) |
| 56 | + .withQueryOptions(TestUtils.nonDebouncingQueryOptions()) | |
| 56 | 57 | .build(); |
| 57 | 58 | |
| 58 | 59 | Session session = cluster.connect(); |
modified driver-core/src/test/java/com/datastax/driver/core/SchemaChangesTest.java +5 −17
| @@ -32,6 +32,7 @@ | ||
| 32 | 32 | |
| 33 | 33 | import static com.datastax.driver.core.Assertions.assertThat; |
| 34 | 34 | import static com.datastax.driver.core.Metadata.handleId; |
| 35 | +import static com.datastax.driver.core.TestUtils.nonDebouncingQueryOptions; | |
| 35 | 36 | |
| 36 | 37 | public class SchemaChangesTest extends CCMBridge.PerClassSingleNodeCluster { |
| 37 | 38 | |
| @@ -74,20 +75,13 @@ | ||
| 74 | 75 | public void setup() throws InterruptedException { |
| 75 | 76 | Cluster.Builder builder = configure(Cluster.builder()) |
| 76 | 77 | .addContactPointsWithPorts(Collections.singletonList(hostAddress)) |
| 77 | - .withQueryOptions(new QueryOptions() | |
| 78 | - .setRefreshNodeIntervalMillis(0) | |
| 79 | - .setRefreshNodeListIntervalMillis(0) | |
| 80 | - .setRefreshSchemaIntervalMillis(0) | |
| 81 | - ); | |
| 78 | + .withQueryOptions(nonDebouncingQueryOptions()); | |
| 82 | 79 | cluster1 = builder.build(); |
| 83 | 80 | cluster2 = builder.build(); |
| 84 | 81 | schemaDisabledCluster = spy(configure(Cluster.builder()) |
| 85 | 82 | .addContactPointsWithPorts(Collections.singletonList(hostAddress)) |
| 86 | 83 | .withClusterName("schema-disabled") |
| 87 | - .withQueryOptions(new QueryOptions() | |
| 88 | - .setRefreshNodeIntervalMillis(0) | |
| 89 | - .setRefreshNodeListIntervalMillis(0) | |
| 90 | - .setRefreshSchemaIntervalMillis(0) | |
| 84 | + .withQueryOptions(nonDebouncingQueryOptions() | |
| 91 | 85 | .setMetadataEnabled(false) |
| 92 | 86 | ).build()); |
| 93 | 87 | |
| @@ -292,10 +286,7 @@ | ||
| 292 | 286 | public void should_throw_illegal_state_exception_on_newToken_with_metadata_disabled() { |
| 293 | 287 | Cluster cluster = configure(Cluster.builder()) |
| 294 | 288 | .addContactPointsWithPorts(Collections.singletonList(hostAddress)) |
| 295 | - .withQueryOptions(new QueryOptions() | |
| 296 | - .setRefreshNodeIntervalMillis(0) | |
| 297 | - .setRefreshNodeListIntervalMillis(0) | |
| 298 | - .setRefreshSchemaIntervalMillis(0) | |
| 289 | + .withQueryOptions(nonDebouncingQueryOptions() | |
| 299 | 290 | .setMetadataEnabled(false) |
| 300 | 291 | ).build(); |
| 301 | 292 | |
| @@ -319,10 +310,7 @@ | ||
| 319 | 310 | public void should_throw_illegal_state_exception_on_newTokenRange_with_metadata_disabled() { |
| 320 | 311 | Cluster cluster = configure(Cluster.builder()) |
| 321 | 312 | .addContactPointsWithPorts(Collections.singletonList(hostAddress)) |
| 322 | - .withQueryOptions(new QueryOptions() | |
| 323 | - .setRefreshNodeIntervalMillis(0) | |
| 324 | - .setRefreshNodeListIntervalMillis(0) | |
| 325 | - .setRefreshSchemaIntervalMillis(0) | |
| 313 | + .withQueryOptions(nonDebouncingQueryOptions() | |
| 326 | 314 | .setMetadataEnabled(false) |
| 327 | 315 | ).build(); |
| 328 | 316 |
modified driver-core/src/test/java/com/datastax/driver/core/SessionLeakTest.java +4 −2
| @@ -32,7 +32,7 @@ | ||
| 32 | 32 | import com.datastax.driver.core.exceptions.InvalidQueryException; |
| 33 | 33 | |
| 34 | 34 | import static com.datastax.driver.core.Assertions.assertThat; |
| 35 | - | |
| 35 | +import static com.datastax.driver.core.TestUtils.nonDebouncingQueryOptions; | |
| 36 | 36 | |
| 37 | 37 | public class SessionLeakTest { |
| 38 | 38 | |
| @@ -53,7 +53,9 @@ | ||
| 53 | 53 | cluster = Cluster.builder() |
| 54 | 54 | .addContactPointsWithPorts(Collections.singletonList( |
| 55 | 55 | new InetSocketAddress(CCMBridge.IP_PREFIX + '1', 9042))) |
| 56 | - .withNettyOptions(channelMonitor.nettyOptions()).build(); | |
| 56 | + .withNettyOptions(channelMonitor.nettyOptions()) | |
| 57 | + .withQueryOptions(nonDebouncingQueryOptions()) | |
| 58 | + .build(); | |
| 57 | 59 | |
| 58 | 60 | cluster.init(); |
| 59 | 61 |
modified driver-core/src/test/java/com/datastax/driver/core/TestUtils.java +9 −0
| @@ -456,4 +456,13 @@ | ||
| 456 | 456 | .withLoadBalancingPolicy(new WhiteListPolicy(new RoundRobinPolicy(), singleAddress)) |
| 457 | 457 | .build(); |
| 458 | 458 | } |
| 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 | + } | |
| 459 | 468 | } |
modified driver-core/src/test/java/com/datastax/driver/core/policies/TokenAwarePolicyTest.java +3 −0
| @@ -25,6 +25,8 @@ | ||
| 25 | 25 | import com.datastax.driver.core.*; |
| 26 | 26 | import com.datastax.driver.core.utils.Bytes; |
| 27 | 27 | |
| 28 | +import static com.datastax.driver.core.TestUtils.nonDebouncingQueryOptions; | |
| 29 | + | |
| 28 | 30 | public class TokenAwarePolicyTest { |
| 29 | 31 | @Test(groups = "long") |
| 30 | 32 | public void should_shuffle_replicas_when_requested() { |
| @@ -46,6 +48,7 @@ | ||
| 46 | 48 | cluster = Cluster.builder() |
| 47 | 49 | .addContactPoint(CCMBridge.ipOfNode(1)) |
| 48 | 50 | .withLoadBalancingPolicy(loadBalancingPolicy) |
| 51 | + .withQueryOptions(nonDebouncingQueryOptions()) | |
| 49 | 52 | .build(); |
| 50 | 53 | |
| 51 | 54 | String keyspace = "ks"; |