@@ -1313,6 +1313,102 @@ mod tests {
13131313 . group ( [ B , C , E ] ) // remote nodes
13141314 . build ( ) ,
13151315 } ,
1316+ // Keyspace SS with RF=2 with enabled DC failover and rack-awareness
1317+ Test {
1318+ policy : DefaultPolicy {
1319+ preferred_datacenter : Some ( "eu" . to_owned ( ) ) ,
1320+ preferred_rack : Some ( "r1" . to_owned ( ) ) ,
1321+ is_token_aware : true ,
1322+ permit_dc_failover : true ,
1323+ ..Default :: default ( )
1324+ } ,
1325+ routing_info : RoutingInfo {
1326+ token : Some ( Token { value : 160 } ) ,
1327+ keyspace : Some ( KEYSPACE_NTS_RF_3 ) ,
1328+ consistency : Consistency :: One ,
1329+ ..Default :: default ( )
1330+ } ,
1331+ // going though the ring, we get order: F , A , C , D , G , B , E
1332+ // us eu eu us eu eu us
1333+ // r2 r1 r1 r1 r2 r1 r1
1334+ expected_groups : ExpectedGroupsBuilder :: new ( )
1335+ . group ( [ A , C ] ) // pick local rack replicas
1336+ . group ( [ G ] ) // local DC replicas
1337+ . group ( [ F , D , E ] ) // remote replicas
1338+ . group ( [ B ] ) // local nodes
1339+ . build ( ) ,
1340+ } ,
1341+ // Keyspace SS with RF=2 with enabled rack-awareness, shuffling replicas disabled
1342+ Test {
1343+ policy : DefaultPolicy {
1344+ preferred_datacenter : Some ( "eu" . to_owned ( ) ) ,
1345+ preferred_rack : Some ( "r1" . to_owned ( ) ) ,
1346+ is_token_aware : true ,
1347+ permit_dc_failover : false ,
1348+ fixed_shuffle_seed : Some ( 123 ) ,
1349+ ..Default :: default ( )
1350+ } ,
1351+ routing_info : RoutingInfo {
1352+ token : Some ( Token { value : 560 } ) ,
1353+ keyspace : Some ( KEYSPACE_SS_RF_2 ) ,
1354+ consistency : Consistency :: Two ,
1355+ ..Default :: default ( )
1356+ } ,
1357+ // going though the ring, we get order: B , C , E , G , A , F , D
1358+ // eu eu us eu eu us us
1359+ // r1 r1 r1 r2 r1 r2 r1
1360+ expected_groups : ExpectedGroupsBuilder :: new ( )
1361+ . deterministic ( [ B ] ) // pick local rack replicas
1362+ . deterministic ( [ C ] ) // fallback replicas
1363+ . group ( [ A , G ] ) // local nodes
1364+ . build ( ) ,
1365+ } ,
1366+ // Keyspace SS with RF=2 with enabled rack-awareness and no local-rack replica
1367+ Test {
1368+ policy : DefaultPolicy {
1369+ preferred_datacenter : Some ( "eu" . to_owned ( ) ) ,
1370+ preferred_rack : Some ( "r2" . to_owned ( ) ) ,
1371+ is_token_aware : true ,
1372+ permit_dc_failover : false ,
1373+ ..Default :: default ( )
1374+ } ,
1375+ routing_info : RoutingInfo {
1376+ token : Some ( Token { value : 160 } ) ,
1377+ keyspace : Some ( KEYSPACE_SS_RF_2 ) ,
1378+ consistency : Consistency :: One ,
1379+ ..Default :: default ( )
1380+ } ,
1381+ // going though the ring, we get order: F , A , C , D , G , B , E
1382+ // us eu eu us eu eu us
1383+ // r2 r1 r1 r1 r2 r1 r1
1384+ expected_groups : ExpectedGroupsBuilder :: new ( )
1385+ . group ( [ A ] ) // pick local DC
1386+ . group ( [ C , G , B ] ) // local nodes
1387+ . build ( ) ,
1388+ } ,
1389+ // No preferred DC, preferred rack should be ignored, failover permitted
1390+ Test {
1391+ policy : DefaultPolicy {
1392+ preferred_datacenter : None ,
1393+ preferred_rack : Some ( "r2" . to_owned ( ) ) ,
1394+ is_token_aware : true ,
1395+ permit_dc_failover : true ,
1396+ ..Default :: default ( )
1397+ } ,
1398+ routing_info : RoutingInfo {
1399+ token : Some ( Token { value : 160 } ) ,
1400+ keyspace : Some ( KEYSPACE_NTS_RF_2 ) ,
1401+ consistency : Consistency :: Quorum ,
1402+ ..Default :: default ( )
1403+ } ,
1404+ // going though the ring, we get order: F , A , C , D , G , B , E
1405+ // us eu eu us eu eu us
1406+ // r2 r1 r1 r1 r2 r1 r1
1407+ expected_groups : ExpectedGroupsBuilder :: new ( )
1408+ . group ( [ A , D , F , G ] ) // remote replicas
1409+ . group ( [ B , C , E ] ) // remote nodes
1410+ . build ( ) ,
1411+ } ,
13161412 ] ;
13171413
13181414 for Test {
0 commit comments