Skip to content

Commit 4a9bad0

Browse files
authored
JAVA-3099: Fix failing integration tests (#1701)
should_extract_hosts_using_native_transport_address_port_ssl_from_peers - use testng style ignore should_function_with_snappy_compression - skip for cassandra 4.0.0 and greater (not supported) should_handle_failing_or_missing_contact_points - use V4 protocol to avoid initial retry with default V5 should_ignore_and_warn_peers_with_null_entries_by_default - encode expected "missing native_transport_*" strings when not using v2-style peers should_init_policy_with_up_contact_points - since adding SNI support for astra, only contact points will have state INIT should_throw_proper_read_timeout_exception - update expected error message string should_throw_exception_when_frame_exceeds_configured_max - use V4 protocol for cassandra 4.0+ OPPTokenIntegrationTest/OPPTokenVnodeIntegrationTest - not applicable for cassandra 4.0+ MailboxServiceSnappyIT - not applicable for cassandra 4.0+ osgi/BundleOptions - add missing dependencies for recent library upgrades override org.ops4j.pax.url.mvn.repositories in osgi tests because https is now required by maven central
1 parent 916c4b8 commit 4a9bad0

File tree

15 files changed

+81
-11
lines changed

15 files changed

+81
-11
lines changed

driver-core/src/test/java/com/datastax/driver/core/CCMTestsSupport.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import org.slf4j.Logger;
5757
import org.slf4j.LoggerFactory;
5858
import org.testng.ITestResult;
59+
import org.testng.SkipException;
5960
import org.testng.annotations.AfterClass;
6061
import org.testng.annotations.AfterMethod;
6162
import org.testng.annotations.BeforeClass;
@@ -1137,4 +1138,13 @@ private static <T> T instantiate(Class<? extends T> clazz)
11371138
return (T) constructor.newInstance(enclosingInstance);
11381139
}
11391140
}
1141+
1142+
protected void skipTestWithCassandraVersionOrHigher(String version, String testKind) {
1143+
if (CCMBridge.getGlobalCassandraVersion().compareTo(VersionNumber.parse(version)) >= 0) {
1144+
throw new SkipException(
1145+
String.format(
1146+
"%s tests not applicable to cassandra version >= %s (configured: %s)",
1147+
testKind, version, CCMBridge.getGlobalCassandraVersion()));
1148+
}
1149+
}
11401150
}

driver-core/src/test/java/com/datastax/driver/core/ClusterInitTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ public void should_handle_failing_or_missing_contact_points() throws UnknownHost
107107
cluster =
108108
Cluster.builder()
109109
.withPort(scassandra.getBinaryPort())
110+
// scassandra supports max V4 protocol
111+
.withProtocolVersion(ProtocolVersion.V4)
110112
.addContactPoints(
111113
ipOfNode(1),
112114
failingHosts.get(0).address,

driver-core/src/test/java/com/datastax/driver/core/ControlConnectionTest.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
import java.util.concurrent.TimeUnit;
5353
import java.util.concurrent.atomic.AtomicInteger;
5454
import org.apache.log4j.Level;
55-
import org.junit.Ignore;
5655
import org.scassandra.http.client.PrimingClient;
5756
import org.scassandra.http.client.PrimingRequest;
5857
import org.scassandra.http.client.Result;
@@ -335,11 +334,17 @@ static void run_with_null_peer_info(String columns, boolean expectPeer2, boolean
335334
cluster.init();
336335

337336
InetAddress node2Address = scassandraCluster.address(2).getAddress();
337+
String invalidValues =
338+
withPeersV2
339+
? columnData
340+
: String.format(
341+
"missing native_transport_address, missing native_transport_port, missing native_transport_port_ssl, %s",
342+
columnData);
338343
String expectedError =
339344
String.format(
340345
"Found invalid row in system.peers: [peer=%s, %s]. "
341346
+ "This is likely a gossip or snitch issue, this host will be ignored.",
342-
node2Address, columnData);
347+
node2Address, invalidValues);
343348
String log = logs.get();
344349
// then: A peer with a null rack should not show up in host metadata, unless allowed via
345350
// system property.
@@ -614,9 +619,8 @@ public void should_extract_hosts_using_native_transport_address_port_from_peers(
614619
* be selected if the Cluster is created with SSL support (i.e. if {@link
615620
* Cluster.Builder#withSSL()} is used).
616621
*/
617-
@Test(groups = "short")
622+
@Test(groups = "short", enabled = false /* Requires SSL support in scassandra */)
618623
@CCMConfig(createCcm = false)
619-
@Ignore("Requires SSL support in scassandra")
620624
public void should_extract_hosts_using_native_transport_address_port_ssl_from_peers()
621625
throws UnknownHostException {
622626

driver-core/src/test/java/com/datastax/driver/core/DirectCompressionTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class DirectCompressionTest extends CompressionTest {
2929
*/
3030
@Test(groups = "short")
3131
public void should_function_with_snappy_compression() throws Exception {
32+
skipTestWithCassandraVersionOrHigher("4.0.0", "snappy");
3233
compressionTest(ProtocolOptions.Compression.SNAPPY);
3334
}
3435

driver-core/src/test/java/com/datastax/driver/core/FrameLengthTest.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.datastax.driver.core.querybuilder.Insert;
2727
import com.datastax.driver.core.schemabuilder.Create;
2828
import com.datastax.driver.core.schemabuilder.SchemaBuilder;
29+
import com.datastax.driver.core.utils.CassandraVersion;
2930
import java.nio.ByteBuffer;
3031
import java.util.Collection;
3132
import java.util.Random;
@@ -105,22 +106,42 @@ public void onTestContextInitialized() {
105106
*/
106107
@Test(groups = "isolated")
107108
public void should_throw_exception_when_frame_exceeds_configured_max() {
109+
skipTestWithCassandraVersionOrHigher("4.0.0", "frame-size exceeding with default-protocol");
110+
run_frame_size_exceeding_queries(session());
111+
}
112+
113+
/**
114+
* With cassandra 4.0.0+, V5 protocol is default which breaks requests into segments. Force V4
115+
* protocol to allow us to test frame-size limitation code.
116+
*/
117+
@CassandraVersion("4.0.0")
118+
@Test(groups = "isolated")
119+
public void should_throw_exception_when_frame_exceeds_configured_max_v4_protocol_cassandra4() {
120+
Cluster cluster =
121+
register(createClusterBuilder().withProtocolVersion(ProtocolVersion.V4).build());
122+
Session session = register(cluster.connect());
123+
useKeyspace(session, keyspace);
124+
125+
run_frame_size_exceeding_queries(session);
126+
}
127+
128+
private void run_frame_size_exceeding_queries(Session session) {
108129
try {
109-
session().execute(select().from(tableName).where(eq("k", 0)));
130+
session.execute(select().from(tableName).where(eq("k", 0)));
110131
fail("Exception expected");
111132
} catch (FrameTooLongException ftle) {
112133
// Expected.
113134
}
114135

115136
// Both hosts should remain up.
116-
Collection<Host> hosts = session().getState().getConnectedHosts();
137+
Collection<Host> hosts = session.getState().getConnectedHosts();
117138
assertThat(hosts).hasSize(2).extractingResultOf("isUp").containsOnly(true);
118139

119140
// Should be able to make a query that is less than the max frame size.
120141
// Execute multiple time to exercise all hosts.
121142
for (int i = 0; i < 10; i++) {
122143
ResultSet result =
123-
session().execute(select().from(tableName).where(eq("k", 0)).and(eq("c", 0)));
144+
session.execute(select().from(tableName).where(eq("k", 0)).and(eq("c", 0)));
124145
assertThat(result.getAvailableWithoutFetching()).isEqualTo(1);
125146
}
126147
}

driver-core/src/test/java/com/datastax/driver/core/HeapCompressionTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public void beforeTestClass() throws Exception {
3737
*/
3838
@Test(groups = "isolated")
3939
public void should_function_with_snappy_compression() throws Exception {
40+
skipTestWithCassandraVersionOrHigher("4.0.0", "snappy");
4041
compressionTest(ProtocolOptions.Compression.SNAPPY);
4142
}
4243

driver-core/src/test/java/com/datastax/driver/core/LoadBalancingPolicyBootstrapTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,13 @@ public void should_init_policy_with_up_contact_points() throws Exception {
5757
try {
5858
cluster.init();
5959

60+
// To support astra, only hosts in Metadata#getContactPoints are passed to init()
61+
// TestUtils#configureClusterBuilder only uses the first host as the contact point
62+
// Remaining hosts are learned after connection via onAdd()
6063
assertThat(policy.history)
6164
.containsOnly(
6265
entry(INIT, TestUtils.findHost(cluster, 1)),
63-
entry(INIT, TestUtils.findHost(cluster, 2)));
66+
entry(ADD, TestUtils.findHost(cluster, 2)));
6467
} finally {
6568
cluster.close();
6669
}

driver-core/src/test/java/com/datastax/driver/core/OPPTokenIntegrationTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,10 @@ public OPPTokenIntegrationTest() {
2828
protected Token.Factory tokenFactory() {
2929
return OPPToken.FACTORY;
3030
}
31+
32+
@Override
33+
public void beforeTestClass(Object testInstance) throws Exception {
34+
skipTestWithCassandraVersionOrHigher("4.0.0", "ByteOrderedPartitioner");
35+
super.beforeTestClass(testInstance);
36+
}
3137
}

driver-core/src/test/java/com/datastax/driver/core/OPPTokenVnodeIntegrationTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,10 @@ public OPPTokenVnodeIntegrationTest() {
2626
protected Token.Factory tokenFactory() {
2727
return Token.OPPToken.FACTORY;
2828
}
29+
30+
@Override
31+
public void beforeTestClass(Object testInstance) throws Exception {
32+
skipTestWithCassandraVersionOrHigher("4.0.0", "ByteOrderedPartitioner");
33+
super.beforeTestClass(testInstance);
34+
}
2935
}

driver-core/src/test/java/com/datastax/driver/core/exceptions/ExceptionsScassandraTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public void should_throw_proper_read_timeout_exception() {
7878
} catch (ReadTimeoutException e) {
7979
assertThat(e.getMessage())
8080
.isEqualTo(
81-
"Cassandra timeout during read query at consistency LOCAL_ONE (1 responses were required but only 0 replica responded)");
81+
"Cassandra timeout during read query at consistency LOCAL_ONE (1 responses were required but only 0 replica responded). In case this was generated during read repair, the consistency level is not representative of the actual consistency.");
8282
assertThat(e.getConsistencyLevel()).isEqualTo(LOCAL_ONE);
8383
assertThat(e.getReceivedAcknowledgements()).isEqualTo(0);
8484
assertThat(e.getRequiredAcknowledgements()).isEqualTo(1);

0 commit comments

Comments
 (0)