Skip to content

Commit de10f2f

Browse files
authored
Enhance tablets integration test to check stmt routing (#509)
Ensure that queries are routed according to learned tablet information.
1 parent 9ed546c commit de10f2f

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

integration-tests/src/test/java/com/datastax/oss/driver/core/metadata/DefaultMetadataTabletMapIT.java

+22
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.time.Duration;
2121
import java.util.ArrayList;
2222
import java.util.HashMap;
23+
import java.util.HashSet;
2324
import java.util.List;
2425
import java.util.Map;
2526
import java.util.Set;
@@ -272,6 +273,13 @@ public void every_statement_should_deliver_tablet_info() {
272273
String.format(
273274
"Statement %s on session %s did not trigger session tablets update",
274275
stmtEntry.getKey(), sessionEntry.getKey()));
276+
continue;
277+
}
278+
if (!checkIfRoutedProperly(session, stmt)) {
279+
testErrors.add(
280+
String.format(
281+
"Statement %s on session %s was routed to different nodes",
282+
stmtEntry.getKey(), sessionEntry.getKey()));
275283
}
276284
}
277285
}
@@ -341,6 +349,20 @@ private static boolean waitSessionLearnedTabletInfo(CqlSession session) {
341349
return isSessionLearnedTabletInfo(session);
342350
}
343351

352+
private static boolean checkIfRoutedProperly(CqlSession session, Statement stmt) {
353+
// DefaultLoadBalancingPolicy suppose to prioritize nodes from replica list randomly shuffling
354+
// them
355+
// If routing goes wrong you will see more than REPLICATION_FACTOR unique first nodes in
356+
// execution plan
357+
358+
int expectedNodesCount = stmt.isLWT() ? 1 : REPLICATION_FACTOR;
359+
Set<Node> nodes = new HashSet<>();
360+
for (int i = 0; i < REPLICATION_FACTOR * 3; i++) {
361+
nodes.add(session.execute(stmt).getExecutionInfo().getCoordinator());
362+
}
363+
return nodes.size() <= expectedNodesCount;
364+
}
365+
344366
private static boolean isSessionLearnedTabletInfo(CqlSession session) {
345367
if (!session.getMetadata().getTabletMap().isPresent()) {
346368
return false;

0 commit comments

Comments
 (0)