@@ -406,7 +406,6 @@ def refresh_and_validate_added_hosts():
406406 [None , None , "a" , "dc1" , "rack1" , ["1" , "101" , "201" ], 'uuid1' ],
407407 ["192.168.1.7" , "10.0.0.1" , "a" , None , "rack1" , ["1" , "101" , "201" ], 'uuid2' ],
408408 ["192.168.1.6" , "10.0.0.1" , "a" , "dc1" , None , ["1" , "101" , "201" ], 'uuid3' ],
409- ["192.168.1.5" , "10.0.0.1" , "a" , "dc1" , "rack1" , None , 'uuid4' ],
410409 ["192.168.1.4" , "10.0.0.1" , "a" , "dc1" , "rack1" , ["1" , "101" , "201" ], None ]]])
411410 refresh_and_validate_added_hosts ()
412411
@@ -420,10 +419,57 @@ def refresh_and_validate_added_hosts():
420419 [None , 9042 , None , 7040 , "a" , "dc1" , "rack1" , ["2" , "102" , "202" ], "uuid2" ],
421420 ["192.168.1.5" , 9042 , "10.0.0.2" , 7040 , "a" , None , "rack1" , ["2" , "102" , "202" ], "uuid2" ],
422421 ["192.168.1.5" , 9042 , "10.0.0.2" , 7040 , "a" , "dc1" , None , ["2" , "102" , "202" ], "uuid2" ],
423- ["192.168.1.5" , 9042 , "10.0.0.2" , 7040 , "a" , "dc1" , "rack1" , None , "uuid2" ],
424422 ["192.168.1.5" , 9042 , "10.0.0.2" , 7040 , "a" , "dc1" , "rack1" , ["2" , "102" , "202" ], None ]]])
425423 refresh_and_validate_added_hosts ()
426424
425+ def test_refresh_nodes_and_tokens_keeps_zero_token_peer_for_load_balancing (self ):
426+ self .connection .peer_results [1 ].append (
427+ ["192.168.1.3" , "10.0.0.3" , "a" , "dc1" , "rack1" , None , "uuid4" ]
428+ )
429+ self .cluster .scheduler .schedule = lambda delay , f , * args , ** kwargs : f (* args , ** kwargs )
430+
431+ self .control_connection .refresh_node_list_and_token_map ()
432+
433+ zero_token_host = self .cluster .metadata .get_host_by_host_id ("uuid4" )
434+ assert zero_token_host is not None
435+ assert zero_token_host in self .cluster .metadata .all_hosts ()
436+ assert zero_token_host not in self .cluster .metadata .token_map
437+
438+ def test_refresh_nodes_and_tokens_keeps_zero_token_local_host_for_load_balancing (self ):
439+ self .connection .local_results [1 ][0 ][7 ] = None
440+
441+ self .control_connection .refresh_node_list_and_token_map ()
442+
443+ local_host = self .cluster .metadata .get_host_by_host_id ("uuid1" )
444+ assert local_host is not None
445+ assert local_host in self .cluster .metadata .all_hosts ()
446+ assert local_host not in self .cluster .metadata .token_map
447+
448+ def test_refresh_nodes_and_tokens_rebuilds_token_map_when_existing_host_loses_tokens (self ):
449+ self .control_connection .refresh_node_list_and_token_map ()
450+
451+ zero_token_host = self .cluster .metadata .get_host_by_host_id ("uuid2" )
452+ assert zero_token_host in self .cluster .metadata .token_map
453+
454+ self .connection .peer_results [1 ][0 ][5 ] = None
455+ self .control_connection .refresh_node_list_and_token_map ()
456+
457+ assert zero_token_host in self .cluster .metadata .all_hosts ()
458+ assert zero_token_host not in self .cluster .metadata .token_map
459+
460+ def test_refresh_nodes_and_tokens_rebuilds_token_map_when_existing_host_gains_tokens (self ):
461+ self .connection .peer_results [1 ][0 ][5 ] = None
462+ self .control_connection .refresh_node_list_and_token_map ()
463+
464+ token_host = self .cluster .metadata .get_host_by_host_id ("uuid2" )
465+ assert token_host in self .cluster .metadata .all_hosts ()
466+ assert token_host not in self .cluster .metadata .token_map
467+
468+ self .connection .peer_results [1 ][0 ][5 ] = ["1" , "101" , "201" ]
469+ self .control_connection .refresh_node_list_and_token_map ()
470+
471+ assert token_host in self .cluster .metadata .token_map
472+
427473 def test_change_ip (self ):
428474 """
429475 Tests node IPs are updated while the nodes themselves are not
0 commit comments