Skip to content

Commit 58d2072

Browse files
committed
Add integration test for zero token nodes
Adds ZeroTokenNodesIT that checks the behaviour of the driver when zero-token nodes are involved. Currently has one method `should_ignore_zero_token_peer` in which driver expects a normal contact point and as a result it should not populate the metadata with zero-token node from the peers table.
1 parent 204be3a commit 58d2072

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package com.datastax.driver.core;
2+
3+
import static org.apache.log4j.Level.WARN;
4+
import static org.assertj.core.api.Assertions.assertThat;
5+
6+
import com.datastax.driver.core.utils.ScyllaVersion;
7+
import java.net.InetSocketAddress;
8+
import java.util.Set;
9+
import java.util.stream.Collectors;
10+
import org.apache.log4j.Level;
11+
import org.apache.log4j.Logger;
12+
import org.testng.annotations.AfterMethod;
13+
import org.testng.annotations.BeforeMethod;
14+
import org.testng.annotations.Test;
15+
16+
public class ZeroTokenNodesIT {
17+
private Logger logger = Logger.getLogger(ControlConnection.class);
18+
private MemoryAppender appender;
19+
private Level originalLevel;
20+
21+
@BeforeMethod(groups = "short")
22+
public void startCapturingLogs() {
23+
originalLevel = logger.getLevel();
24+
logger.setLevel(WARN);
25+
logger.addAppender(appender = new MemoryAppender());
26+
}
27+
28+
@AfterMethod(groups = "short")
29+
public void stopCapturingLogs() {
30+
logger.setLevel(originalLevel);
31+
logger.removeAppender(appender);
32+
}
33+
34+
@Test(groups = "short")
35+
@ScyllaVersion(
36+
minOSS = "6.2.0",
37+
minEnterprise = "2024.2.2",
38+
description = "Zero-token nodes introduced in scylladb/19684")
39+
public void should_ignore_zero_token_peer() {
40+
// Given 4 node cluster with 1 zero-token node and normal contact point,
41+
// make sure that it's not included in the metadata.
42+
// By extension, it won't be included in the query planning.
43+
Cluster cluster = null;
44+
Session session = null;
45+
CCMBridge bridgeA = null;
46+
try {
47+
bridgeA =
48+
CCMBridge.builder().withNodes(3).withIpPrefix("127.0.1.").withBinaryPort(9042).build();
49+
bridgeA.start();
50+
bridgeA.add(4);
51+
bridgeA.updateNodeConfig(4, "join_ring", false);
52+
bridgeA.start(4);
53+
bridgeA.waitForUp(4);
54+
55+
cluster =
56+
Cluster.builder()
57+
.addContactPointsWithPorts(new InetSocketAddress(bridgeA.ipOfNode(1), 9042))
58+
.withPort(9042)
59+
.withoutAdvancedShardAwareness()
60+
.build();
61+
session = cluster.connect();
62+
63+
ResultSet rs = session.execute("select * from system.local");
64+
Row row = rs.one();
65+
String address = row.getInet("broadcast_address").toString();
66+
assertThat(address).endsWith(bridgeA.ipOfNode(1));
67+
String line = null;
68+
try {
69+
line = appender.waitAndGet(5000);
70+
} catch (InterruptedException e) {
71+
throw new RuntimeException(e);
72+
}
73+
assertThat(line).contains("Found invalid row in system.peers");
74+
assertThat(line).contains("tokens=null");
75+
Set<Host> hosts = cluster.getMetadata().getAllHosts();
76+
Set<String> toStrings = hosts.stream().map(Host::toString).collect(Collectors.toSet());
77+
assertThat(toStrings).containsOnly("/127.0.1.1:9042", "/127.0.1.2:9042", "/127.0.1.3:9042");
78+
} finally {
79+
assert bridgeA != null;
80+
bridgeA.close();
81+
if (session != null) session.close();
82+
if (cluster != null) cluster.close();
83+
}
84+
}
85+
}

0 commit comments

Comments
 (0)