Elffuss BraidHub

kikocis/java-driver public

Update tests for 1.2.x compatibility.

MissingRpcAddressTest: The v1 native protocol (what 1.2.x uses) does not
support executing statements with bind variables.  Updated the query that
deletes the rpc address for host 2 to no longer use them and also moved the
deleteNode2RpcAddressFromNode1() method into the try block so if it
fails the CCM cluster is cleaned up.

ClusterInitTest: Change fakePeerRowsInNode1 to use query building instead of
bind variables.  Use desired protocol version to prevent additional
connection attempt which causes a check to be off by 1.

QueryBuilderExecutionTest: Change batchNonBuiltStatementTest to no longer use
bind variables.

ReconnectionTest: Increment the authentication counter on getCredentials as
this is what is used for ProtocolV1Authenticator.

LargeDataTest: Skip wide row and large batch tests for 1.2.

SchemaChangesTest: Remove 'IF EXISTS' in cleanup.
Changesetac197a0a34d1316ee4ceb547c673322fc601aa7498ec69d22d3ae1f22fc73694
AuthorAndrew Tolbert <andrew.tolbert@datastax.com> · 2015-02-01 23:01 -06:00
CommitterAndrew Tolbert <andrew.tolbert@datastax.com> · 2015-02-13 07:25 -06:00
Parentsd68e339cb5b7

Browse the files at this changeset

7 files changed

modified driver-core/src/test/java/com/datastax/driver/core/ClusterInitTest.java +15 −9
@@ -18,10 +18,13 @@
1818 import static org.mockito.Mockito.verify;
1919
2020 import com.datastax.driver.core.policies.ConstantReconnectionPolicy;
21+import com.datastax.driver.core.querybuilder.Insert;
2122 import com.datastax.driver.core.utils.UUIDs;
2223
2324 import static com.datastax.driver.core.FakeHost.Behavior.THROWING_CONNECT_TIMEOUTS;
2425
26+import static com.datastax.driver.core.querybuilder.QueryBuilder.insertInto;
27+
2528 public class ClusterInitTest {
2629 private static final Logger logger = LoggerFactory.getLogger(ClusterInitTest.class);
2730
@@ -68,6 +71,7 @@
6871 CCMBridge.ipOfNode(4), CCMBridge.ipOfNode(5), CCMBridge.ipOfNode(6))
6972 .withSocketOptions(socketOptions)
7073 .withReconnectionPolicy(reconnectionPolicy)
74+ .withProtocolVersion(TestUtils.getDesiredProtocolVersion())
7175 .build();
7276 cluster.connect();
7377
@@ -100,15 +104,17 @@
100104 String releaseVersion = session.execute("SELECT release_version FROM local")
101105 .one().getString("release_version");
102106
103- for (int i = 2; i <= 6; i++)
104- session.execute("INSERT INTO peers (peer, data_center, host_id, rack, release_version, rpc_address, schema_version) " +
105- "VALUES (?, 'datacenter1', ?, 'rack1', ?, ?, ?)",
106- InetAddress.getByName(CCMBridge.ipOfNode(i)),
107- UUIDs.random(),
108- releaseVersion,
109- InetAddress.getByName(CCMBridge.ipOfNode(i)),
110- UUIDs.random()
111- );
107+ for (int i = 2; i <= 6; i++) {
108+ Insert insertStmt = insertInto("peers")
109+ .value("peer", InetAddress.getByName(CCMBridge.ipOfNode(i)))
110+ .value("data_center", "datacenter1")
111+ .value("host_id", UUIDs.random())
112+ .value("rack", "rack1")
113+ .value("release_version", releaseVersion)
114+ .value("rpc_address", InetAddress.getByName(CCMBridge.ipOfNode(i)))
115+ .value("schema_version", UUIDs.random());
116+ session.execute(insertStmt);
117+ }
112118 } catch (Exception e) {
113119 fail("Error while inserting fake peer rows", e);
114120 } finally {
modified driver-core/src/test/java/com/datastax/driver/core/LargeDataTest.java +2 −0
@@ -181,6 +181,7 @@
181181 */
182182 @Test(groups = "long")
183183 public void wideRows() throws Throwable {
184+ TestUtils.versionCheck(2, 0, "< 2.0 is skipped as 1.2 does not handle reading wide rows well.");
184185 Cluster.Builder builder = Cluster.builder();
185186 CCMBridge.CCMCluster c = CCMBridge.buildCluster(1, builder);
186187
@@ -204,6 +205,7 @@
204205 */
205206 @Test(groups = "short")
206207 public void wideBatchRows() throws Throwable {
208+ TestUtils.versionCheck(2, 0, "< 2.0 is skipped as 1.2 does not handle large batches well.");
207209 Cluster.Builder builder = Cluster.builder();
208210 CCMBridge.CCMCluster c = CCMBridge.buildCluster(1, builder);
209211
modified driver-core/src/test/java/com/datastax/driver/core/MissingRpcAddressTest.java +4 −2
@@ -22,10 +22,10 @@
2222 @Test(groups = "short")
2323 public void testMissingRpcAddressAtStartup() throws Exception {
2424 CCMBridge ccm = CCMBridge.create("ccm", 2);
25- deleteNode2RpcAddressFromNode1();
2625
2726 Cluster cluster = null;
2827 try {
28+ deleteNode2RpcAddressFromNode1();
2929 // Use only one contact point to make sure that the control connection is on node1
3030 cluster = Cluster.builder()
3131 .addContactPoint(CCMBridge.IP_PREFIX + "1")
@@ -53,7 +53,9 @@
5353 Lists.newArrayList(socketAddress(1))))
5454 .build();
5555 Session session = cluster.connect();
56- session.execute("DELETE rpc_address FROM system.peers WHERE peer = ?", InetAddress.getByName(CCMBridge.IP_PREFIX + "2"));
56+ String deleteStmt = String.format("DELETE rpc_address FROM system.peers WHERE peer = '%s'",
57+ InetAddress.getByName(CCMBridge.IP_PREFIX + "2").getHostName());
58+ session.execute(deleteStmt);
5759 session.close();
5860 } finally {
5961 if (cluster != null)
modified driver-core/src/test/java/com/datastax/driver/core/ReconnectionTest.java +1 −0
@@ -260,6 +260,7 @@
260260
261261 @Override
262262 Map<String, String> getCredentials() {
263+ count.incrementAndGet();
263264 return ImmutableMap.of("username", username,
264265 "password", password);
265266 }
modified driver-core/src/test/java/com/datastax/driver/core/SchemaChangesTest.java +8 −2
@@ -9,6 +9,7 @@
99 import org.testng.annotations.BeforeClass;
1010 import org.testng.annotations.Test;
1111
12+import com.datastax.driver.core.exceptions.InvalidQueryException;
1213 import com.datastax.driver.core.utils.Bytes;
1314
1415 import static com.datastax.driver.core.Assertions.assertThat;
@@ -101,8 +102,13 @@
101102
102103 @AfterMethod(groups = "short")
103104 public void cleanup() {
104- session.execute("DROP TABLE IF EXISTS ks.table1");
105- session.execute("DROP KEYSPACE IF EXISTS ks2");
105+ try {
106+ session.execute("DROP TABLE ks.table1");
107+ } catch(InvalidQueryException ex) {}
108+
109+ try {
110+ session.execute("DROP KEYSPACE ks2");
111+ } catch(InvalidQueryException ex) {}
106112 }
107113
108114 @AfterClass(groups = "short")
modified driver-core/src/test/java/com/datastax/driver/core/TestUtils.java +16 −2
@@ -183,7 +183,7 @@
183183 case FLOAT:
184184 return 3.142519f;
185185 case INET:
186- return InetAddress.getByAddress(new byte[]{(byte)127, (byte)0, (byte)0, (byte)1});
186+ return InetAddress.getByAddress(new byte[]{ (byte)127, (byte)0, (byte)0, (byte)1 });
187187 case INT:
188188 return 24;
189189 case TEXT:
@@ -406,7 +406,7 @@
406406 */
407407 public static int findAvailablePort(int startingWith) {
408408 IOException last = null;
409- for(int port = startingWith; port < startingWith+100; port++) {
409+ for (int port = startingWith; port < startingWith + 100; port++) {
410410 try {
411411 ServerSocket s = new ServerSocket(port);
412412 s.close();
@@ -418,4 +418,18 @@
418418 // If for whatever reason a port could not be acquired throw the last encountered exception.
419419 throw new RuntimeException("Could not acquire an available port", last);
420420 }
421+
422+ /**
423+ * @return The desired target protocol version based on the 'cassandra.version' System property.
424+ */
425+ public static int getDesiredProtocolVersion() {
426+ String version = System.getProperty("cassandra.version");
427+ String[] versionArray = version.split("\\.|-");
428+ double major = Double.parseDouble(versionArray[0] + "." + versionArray[1]);
429+ if(major < 2.0) {
430+ return 1;
431+ } else {
432+ return 2;
433+ }
434+ }
421435 }
modified driver-core/src/test/java/com/datastax/driver/core/querybuilder/QueryBuilderExecutionTest.java +1 −2
@@ -85,8 +85,7 @@
8585
8686 @Test(groups = "short")
8787 public void batchNonBuiltStatementTest() throws Exception {
88-
89- SimpleStatement simple = new SimpleStatement("INSERT INTO " + TABLE1 + " (k, t) VALUES (?, ?)", "batchTest1", "val1");
88+ SimpleStatement simple = new SimpleStatement("INSERT INTO " + TABLE1 + " (k, t) VALUES ('batchTest1', 'val1')");
9089 RegularStatement built = insertInto(TABLE1).value("k", "batchTest2").value("t", "val2");
9190 session.execute(batch().add(simple).add(built));
9291