@@ -44,6 +44,32 @@ func TestRoundRobbin(t *testing.T) {
44
44
}
45
45
}
46
46
47
+ func TestRoundRobbinSameConnectAddress (t * testing.T ) {
48
+ policy := RoundRobinHostPolicy ()
49
+
50
+ hosts := [... ]* HostInfo {
51
+ {hostId : "0" , connectAddress : net .IPv4 (0 , 0 , 0 , 1 ), port : 9042 },
52
+ {hostId : "1" , connectAddress : net .IPv4 (0 , 0 , 0 , 1 ), port : 9043 },
53
+ }
54
+
55
+ for _ , host := range hosts {
56
+ policy .AddHost (host )
57
+ }
58
+
59
+ got := make (map [string ]bool )
60
+ it := policy .Pick (nil )
61
+ for h := it (); h != nil ; h = it () {
62
+ id := h .Info ().hostId
63
+ if got [id ] {
64
+ t .Fatalf ("got duplicate host: %v" , id )
65
+ }
66
+ got [id ] = true
67
+ }
68
+ if len (got ) != len (hosts ) {
69
+ t .Fatalf ("expected %d hosts got %d" , len (hosts ), len (got ))
70
+ }
71
+ }
72
+
47
73
// Tests of the token-aware host selection policy implementation with a
48
74
// round-robin host selection policy fallback.
49
75
func TestHostPolicy_TokenAware_SimpleStrategy (t * testing.T ) {
@@ -132,47 +158,47 @@ func TestHostPolicy_TokenAware_LWT_DisablesHostShuffling(t *testing.T) {
132
158
{hostId : "3" , connectAddress : net .IPv4 (10 , 0 , 0 , 4 ), tokens : []string {"25" , "35" , "45" }},
133
159
{hostId : "4" , connectAddress : net .IPv4 (10 , 0 , 0 , 3 ), tokens : []string {"50" , "60" , "70" }},
134
160
{hostId : "5" , connectAddress : net .IPv4 (10 , 0 , 0 , 4 ), tokens : []string {"50" , "60" , "70" }},
135
- }, routingKey : "8" , lwt : true , shuffle : true , want : []string {"0" , "2" , "3" , "1" }},
161
+ }, routingKey : "8" , lwt : true , shuffle : true , want : []string {"0" , "2" , "3" , "4" , "5" , " 1" }},
136
162
"token 08 shuffling not configured" : {hosts : []* HostInfo {
137
163
{hostId : "0" , connectAddress : net .IPv4 (10 , 0 , 0 , 1 ), tokens : []string {"00" , "10" , "20" }},
138
164
{hostId : "1" , connectAddress : net .IPv4 (10 , 0 , 0 , 3 ), tokens : []string {"25" , "35" , "45" }},
139
165
{hostId : "2" , connectAddress : net .IPv4 (10 , 0 , 0 , 2 ), tokens : []string {"00" , "10" , "20" }},
140
166
{hostId : "3" , connectAddress : net .IPv4 (10 , 0 , 0 , 4 ), tokens : []string {"25" , "35" , "45" }},
141
167
{hostId : "4" , connectAddress : net .IPv4 (10 , 0 , 0 , 3 ), tokens : []string {"50" , "60" , "70" }},
142
168
{hostId : "5" , connectAddress : net .IPv4 (10 , 0 , 0 , 4 ), tokens : []string {"50" , "60" , "70" }},
143
- }, routingKey : "8" , lwt : true , shuffle : false , want : []string {"0" , "2" , "3" , "1" }},
169
+ }, routingKey : "8" , lwt : true , shuffle : false , want : []string {"0" , "2" , "3" , "4" , "5" , " 1" }},
144
170
"token 30 shuffling configured" : {hosts : []* HostInfo {
145
171
{hostId : "0" , connectAddress : net .IPv4 (10 , 0 , 0 , 1 ), tokens : []string {"00" , "10" , "20" }},
146
172
{hostId : "1" , connectAddress : net .IPv4 (10 , 0 , 0 , 3 ), tokens : []string {"25" , "35" , "45" }},
147
173
{hostId : "2" , connectAddress : net .IPv4 (10 , 0 , 0 , 2 ), tokens : []string {"00" , "10" , "20" }},
148
174
{hostId : "3" , connectAddress : net .IPv4 (10 , 0 , 0 , 4 ), tokens : []string {"25" , "35" , "45" }},
149
175
{hostId : "4" , connectAddress : net .IPv4 (10 , 0 , 0 , 3 ), tokens : []string {"50" , "60" , "70" }},
150
176
{hostId : "5" , connectAddress : net .IPv4 (10 , 0 , 0 , 4 ), tokens : []string {"50" , "60" , "70" }},
151
- }, routingKey : "30" , lwt : true , shuffle : true , want : []string {"1" , "3" , "2" , "0" }},
177
+ }, routingKey : "30" , lwt : true , shuffle : true , want : []string {"1" , "3" , "2" , "4" , "5" , " 0" }},
152
178
"token 30 shuffling not configured" : {hosts : []* HostInfo {
153
179
{hostId : "0" , connectAddress : net .IPv4 (10 , 0 , 0 , 1 ), tokens : []string {"00" , "10" , "20" }},
154
180
{hostId : "1" , connectAddress : net .IPv4 (10 , 0 , 0 , 3 ), tokens : []string {"25" , "35" , "45" }},
155
181
{hostId : "2" , connectAddress : net .IPv4 (10 , 0 , 0 , 2 ), tokens : []string {"00" , "10" , "20" }},
156
182
{hostId : "3" , connectAddress : net .IPv4 (10 , 0 , 0 , 4 ), tokens : []string {"25" , "35" , "45" }},
157
183
{hostId : "4" , connectAddress : net .IPv4 (10 , 0 , 0 , 3 ), tokens : []string {"50" , "60" , "70" }},
158
184
{hostId : "5" , connectAddress : net .IPv4 (10 , 0 , 0 , 4 ), tokens : []string {"50" , "60" , "70" }},
159
- }, routingKey : "30" , lwt : true , shuffle : false , want : []string {"1" , "3" , "2" , "0" }},
185
+ }, routingKey : "30" , lwt : true , shuffle : false , want : []string {"1" , "3" , "2" , "4" , "5" , " 0" }},
160
186
"token 55 shuffling configured" : {hosts : []* HostInfo {
161
187
{hostId : "0" , connectAddress : net .IPv4 (10 , 0 , 0 , 1 ), tokens : []string {"00" , "10" , "20" }},
162
188
{hostId : "1" , connectAddress : net .IPv4 (10 , 0 , 0 , 3 ), tokens : []string {"25" , "35" , "45" }},
163
189
{hostId : "2" , connectAddress : net .IPv4 (10 , 0 , 0 , 2 ), tokens : []string {"00" , "10" , "20" }},
164
190
{hostId : "3" , connectAddress : net .IPv4 (10 , 0 , 0 , 4 ), tokens : []string {"25" , "35" , "45" }},
165
191
{hostId : "4" , connectAddress : net .IPv4 (10 , 0 , 0 , 3 ), tokens : []string {"50" , "60" , "70" }},
166
192
{hostId : "5" , connectAddress : net .IPv4 (10 , 0 , 0 , 4 ), tokens : []string {"50" , "60" , "70" }},
167
- }, routingKey : "55" , lwt : true , shuffle : true , want : []string {"0 " , "2" , "3" , "1" }},
193
+ }, routingKey : "55" , lwt : true , shuffle : true , want : []string {"4 " , "5" , " 2" , "3" , "0 " , "1" }},
168
194
"token 55 shuffling not configured" : {hosts : []* HostInfo {
169
195
{hostId : "0" , connectAddress : net .IPv4 (10 , 0 , 0 , 1 ), tokens : []string {"00" , "10" , "20" }},
170
196
{hostId : "1" , connectAddress : net .IPv4 (10 , 0 , 0 , 3 ), tokens : []string {"25" , "35" , "45" }},
171
197
{hostId : "2" , connectAddress : net .IPv4 (10 , 0 , 0 , 2 ), tokens : []string {"00" , "10" , "20" }},
172
198
{hostId : "3" , connectAddress : net .IPv4 (10 , 0 , 0 , 4 ), tokens : []string {"25" , "35" , "45" }},
173
199
{hostId : "4" , connectAddress : net .IPv4 (10 , 0 , 0 , 3 ), tokens : []string {"50" , "60" , "70" }},
174
200
{hostId : "5" , connectAddress : net .IPv4 (10 , 0 , 0 , 4 ), tokens : []string {"50" , "60" , "70" }},
175
- }, routingKey : "55" , lwt : true , shuffle : false , want : []string {"0 " , "2" , "3" , "1" }},
201
+ }, routingKey : "55" , lwt : true , shuffle : false , want : []string {"4 " , "5" , " 2" , "3" , "0 " , "1" }},
176
202
}
177
203
const keyspace = "myKeyspace"
178
204
for name , tc := range tests {
0 commit comments