Exemplo n.º 1
0
def clusters():
    for id in raft.default_clusters:
        spawn_client_thread(id)
    time.sleep(1)
    yield raft.default_clusters
    for (id, _) in raft.clusters.items():
        kick_off(id)
    time.sleep(0.1)
Exemplo n.º 2
0
def test_change_ownership(clusters):
    time.sleep(3)
    leaders = find_leaders(clusters)
    assert len(leaders) == 1
    leader = leaders[0]
    
    spawn_client_thread("test6")
    spawn_client_thread("test7")
    spawn_client_thread("test8")
    spawn_client_thread("test9")
    time.sleep(1)

    append_log(leader, new_config())
    time.sleep(10)
    
    leaders = find_leaders(clusters)
    assert len(leaders) == 1
    leader = leaders[0]
    append_log(leader, "test")

    time.sleep(3)

    d_logs = request_all_logs(raft.default_clusters)
    e_logs = request_all_logs(raft.extra_clusters)
    for k in raft.default_clusters:
        assert d_logs[k].logs[1] == "test"
        if k != leader:
            assert d_logs[k].role == "follower"
    for k in raft.extra_clusters:
        assert e_logs[k].logs[1] == "test"
        if k != leader:
            assert e_logs[k].role == "follower"
Exemplo n.º 3
0
def test_sync_log_after_follower_kickoff(clusters):
    leaders = find_leaders(clusters)
    assert leaders != []
    leader = leaders[0]
    append_logs(leader, ["test1", "test2", "test3"])
    time.sleep(3)
    followers = find_followers(clusters)
    kicked_off_follower = followers[0]
    kick_off(kicked_off_follower)
    spawn_client_thread(kicked_off_follower)
    time.sleep(3)
    logs = request_all_logs(clusters)
    assert logs[leader].logs == ["test1", "test2", "test3"]
    for k in clusters:
        assert logs[k].logs == ["test1", "test2", "test3"]
Exemplo n.º 4
0
def test_sync_log_after_leader_kickoff(clusters):
    leaders = find_leaders(clusters)
    assert len(leaders) == 1
    leader = leaders[0]
    append_logs(leader, ["test1", "test2", "test3"])
    time.sleep(3)
    logs = request_all_logs(clusters)
    for k in clusters:
        assert logs[k].logs == ["test1", "test2", "test3"]
    kick_off(leader)
    spawn_client_thread(leader)
    time.sleep(3)
    leaders = find_leaders(clusters)
    assert len(leaders) == 1
    leader = leaders[0]
    logs = request_all_logs(clusters)
    assert logs[leader].logs == ["test1", "test2", "test3"]
    for k in clusters:
        assert logs[k].logs == ["test1", "test2", "test3"]
Exemplo n.º 5
0
def test_extra_nodes(clusters):
    spawn_client_thread("test6")
    time.sleep(1)
    kick_off("test6")
Exemplo n.º 6
0
def test_restart(clusters):
    kick_off("test3")
    spawn_client_thread("test3")