20
20
import static org .assertj .core .api .Assertions .assertThat ;
21
21
import static org .mockito .ArgumentMatchers .any ;
22
22
import static org .mockito .ArgumentMatchers .eq ;
23
- import static org .mockito .BDDMockito .then ;
24
23
import static org .mockito .Mockito .atLeast ;
25
24
import static org .mockito .Mockito .never ;
26
25
import static org .mockito .Mockito .spy ;
36
35
import com .datastax .oss .driver .shaded .guava .common .collect .ImmutableMap ;
37
36
import com .datastax .oss .driver .shaded .guava .common .collect .ImmutableSet ;
38
37
import java .util .ArrayList ;
39
- import java .util .Collections ;
40
38
import java .util .Map ;
41
39
import java .util .UUID ;
42
40
import org .junit .Test ;
@@ -52,15 +50,29 @@ public class BasicLoadBalancingPolicyPreferredRemoteDcsTest
52
50
53
51
@ Override
54
52
@ Test
55
- public void
56
- should_use_round_robin_when_token_map_returns_no_replicas_using_request_keyspace_and_routing_key () {
53
+ public void should_prioritize_single_replica () {
57
54
when (request .getRoutingKeyspace ()).thenReturn (KEYSPACE );
58
55
when (request .getRoutingKey ()).thenReturn (ROUTING_KEY );
59
- when (tokenMap .getReplicas (KEYSPACE , ROUTING_KEY )).thenReturn (Collections . emptySet ( ));
56
+ when (tokenMap .getReplicas (KEYSPACE , ROUTING_KEY )).thenReturn (ImmutableSet . of ( node3 ));
60
57
61
- assertRoundRobinQueryPlans ();
58
+ // node3 always first, round-robin on the rest
59
+ assertThat (policy .newQueryPlan (request , session ))
60
+ .containsExactly (
61
+ node3 , node1 , node2 , node4 , node5 , node9 , node10 , node6 , node7 , node12 , node13 );
62
+ assertThat (policy .newQueryPlan (request , session ))
63
+ .containsExactly (
64
+ node3 , node2 , node4 , node5 , node1 , node9 , node10 , node6 , node7 , node12 , node13 );
65
+ assertThat (policy .newQueryPlan (request , session ))
66
+ .containsExactly (
67
+ node3 , node4 , node5 , node1 , node2 , node9 , node10 , node6 , node7 , node12 , node13 );
68
+ assertThat (policy .newQueryPlan (request , session ))
69
+ .containsExactly (
70
+ node3 , node5 , node1 , node2 , node4 , node9 , node10 , node6 , node7 , node12 , node13 );
62
71
63
- then (tokenMap ).should (atLeast (1 )).getReplicas (KEYSPACE , ROUTING_KEY );
72
+ // Should not shuffle replicas since there is only one
73
+ verify (policy , never ()).shuffleHead (any (), eq (1 ));
74
+ // But should shuffle remote nodes
75
+ verify (policy , times (12 )).shuffleHead (any (), eq (2 ));
64
76
}
65
77
66
78
@ Override
@@ -87,33 +99,6 @@ public void should_prioritize_and_shuffle_replicas() {
87
99
verify (session , never ()).getPools ();
88
100
}
89
101
90
- @ Override
91
- @ Test
92
- public void should_prioritize_single_replica () {
93
- when (request .getRoutingKeyspace ()).thenReturn (KEYSPACE );
94
- when (request .getRoutingKey ()).thenReturn (ROUTING_KEY );
95
- when (tokenMap .getReplicas (KEYSPACE , ROUTING_KEY )).thenReturn (ImmutableSet .of (node3 ));
96
-
97
- // node3 always first, round-robin on the rest
98
- assertThat (policy .newQueryPlan (request , session ))
99
- .containsExactly (
100
- node3 , node1 , node2 , node4 , node5 , node9 , node10 , node6 , node7 , node12 , node13 );
101
- assertThat (policy .newQueryPlan (request , session ))
102
- .containsExactly (
103
- node3 , node2 , node4 , node5 , node1 , node9 , node10 , node6 , node7 , node12 , node13 );
104
- assertThat (policy .newQueryPlan (request , session ))
105
- .containsExactly (
106
- node3 , node4 , node5 , node1 , node2 , node9 , node10 , node6 , node7 , node12 , node13 );
107
- assertThat (policy .newQueryPlan (request , session ))
108
- .containsExactly (
109
- node3 , node5 , node1 , node2 , node4 , node9 , node10 , node6 , node7 , node12 , node13 );
110
-
111
- // Should not shuffle replicas since there is only one
112
- verify (policy , never ()).shuffleHead (any (), eq (1 ));
113
- // But should shuffle remote nodes
114
- verify (policy , times (12 )).shuffleHead (any (), eq (2 ));
115
- }
116
-
117
102
@ Override
118
103
protected void assertRoundRobinQueryPlans () {
119
104
for (int i = 0 ; i < 3 ; i ++) {
0 commit comments