|
20 | 20 | import java.time.Duration; |
21 | 21 | import java.util.ArrayList; |
22 | 22 | import java.util.HashMap; |
| 23 | +import java.util.HashSet; |
23 | 24 | import java.util.List; |
24 | 25 | import java.util.Map; |
25 | 26 | import java.util.Set; |
@@ -272,6 +273,13 @@ public void every_statement_should_deliver_tablet_info() { |
272 | 273 | String.format( |
273 | 274 | "Statement %s on session %s did not trigger session tablets update", |
274 | 275 | 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())); |
275 | 283 | } |
276 | 284 | } |
277 | 285 | } |
@@ -341,6 +349,20 @@ private static boolean waitSessionLearnedTabletInfo(CqlSession session) { |
341 | 349 | return isSessionLearnedTabletInfo(session); |
342 | 350 | } |
343 | 351 |
|
| 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 | + |
344 | 366 | private static boolean isSessionLearnedTabletInfo(CqlSession session) { |
345 | 367 | if (!session.getMetadata().getTabletMap().isPresent()) { |
346 | 368 | return false; |
|
0 commit comments