当前位置: 首页>>代码示例>>Python>>正文


Python Server.setNeighbors方法代码示例

本文整理汇总了Python中Server.Server.setNeighbors方法的典型用法代码示例。如果您正苦于以下问题:Python Server.setNeighbors方法的具体用法?Python Server.setNeighbors怎么用?Python Server.setNeighbors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Server.Server的用法示例。


在下文中一共展示了Server.setNeighbors方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from Server import Server [as 别名]
# 或者: from Server.Server import setNeighbors [as 别名]
def main():

    # Establish the server cluster
    s1 = Server()
    s2 = Server()
    s3 = Server()
    s4 = Server()
    s5 = Server()

    s1.setNeighbors([s2, s3, s4, s5])
    s2.setNeighbors([s1, s3, s4, s5])
    s3.setNeighbors([s2, s1, s4, s5])
    s4.setNeighbors([s2, s3, s1, s5])
    s5.setNeighbors([s2, s3, s4, s1])

    t1 = Thread(target=s1.electionTimeout)
    t1.start()
    time.sleep(5)
    t2 = Thread(target=s2.electionTimeout)
    t2.start()
    t3 = Thread(target=s3.electionTimeout)
    t3.start()
    t4 = Thread(target=s4.electionTimeout)
    t4.start()
    t5 = Thread(target=s5.electionTimeout)
    t5.start()

    # Connect the client to the cluster leader
    c1 = Client()
    c1.connectClientToLeader(s2.neighbors)

    # Use the command line
    c1.waitForCommands()
开发者ID:gddmkr42171822,项目名称:csci5673,代码行数:35,代码来源:Main.py

示例2: testClientConnectionToWithoutLeadershipChangeInCluster

# 需要导入模块: from Server import Server [as 别名]
# 或者: from Server.Server import setNeighbors [as 别名]
def testClientConnectionToWithoutLeadershipChangeInCluster():
    # Establish cluster
    s1 = Server()
    s2 = Server()
    s3 = Server()
    
    # Set cluster membership
    s1.setNeighbors([s2, s3])
    s2.setNeighbors([s1, s3])
    s3.setNeighbors([s1, s2])
    
    # Create cluster leader
    # Request an election
    s2.requestVotes()
    
    # Connect the client to the cluster leader through a non-leader
    c1 = Client()
    c1.connectClientToLeader(s1.neighbors)
    assertion(c1.clusterLeader.uuid == s2.uuid, "Client is connected to the leader.")
    
    c1.connectClientToLeader(s2.neighbors)
    assertion(c1.clusterLeader.uuid == s2.uuid, "Client is connected to the leader.")
    
    c1.connectClientToLeader(s3.neighbors)
    assertion(c1.clusterLeader.uuid == s2.uuid, "Client is connected to the leader.")
开发者ID:gddmkr42171822,项目名称:csci5673,代码行数:27,代码来源:ClientTest.py

示例3: testElectionTimeout

# 需要导入模块: from Server import Server [as 别名]
# 或者: from Server.Server import setNeighbors [as 别名]
def testElectionTimeout():
    s1 = Server()
    s2 = Server()
    s3 = Server()
    
    s1.setNeighbors([s2, s3])
    s2.setNeighbors([s1, s3])
    s3.setNeighbors([s1, s2])
    
    t1 = Thread(target=s1.electionTimeout)
    t1.start()
    time.sleep(5)
    t2 = Thread(target=s2.electionTimeout)
    t2.start()
    t3 = Thread(target=s3.electionTimeout)
    t3.start()
    
    # Add to the leaders log a command no none else has
    s1.clusterLeader.log.append(("test", 1, False, 0))
    
    # Add a state machine no one else has
    s1.clusterLeader.stateMachine[1] = "test"

    time.sleep(5)
    assertion(s1.state == ServerState.leader, "Server should be the leader.")
    assertion(s2.state == ServerState.follower, "Server should be the follower.")
    assertion(s3.state == ServerState.follower, "Server should be the follower.")
    
    assertion(len(s1.clusterLeader.log) == 2, "Server has the right size log.")
    assertion(s1.log == s2.log, "Server has the right log.")
    assertion(s3.log == s2.log, "Server has the right log.")
    assertion(s2.log == s3.log, "Server has the right log.")
    
    assertion(len(s1.stateMachine) == 1, "Server has the right size state machine.")
    assertion(s1.stateMachine[1] == s2.stateMachine[1], "Server has the right state machine")
开发者ID:gddmkr42171822,项目名称:csci5673,代码行数:37,代码来源:ServerTest.py

示例4: testSingleServerDoesNotReceiveMajorityVotesShouldNotBecomeLeader

# 需要导入模块: from Server import Server [as 别名]
# 或者: from Server.Server import setNeighbors [as 别名]
def testSingleServerDoesNotReceiveMajorityVotesShouldNotBecomeLeader():
    s1 = Server()
    s2 = Server()
    s3 = Server()
    
    s1.setNeighbors([s2, s3])
    s2.setNeighbors([s1, s3])
    s3.setNeighbors([s1, s2])
    
    s2.voted = True
    s3.voted = True
    
    # Request an election
    s1.requestVotes()
    
    assertion(s1.state == ServerState.candidate, "Server should remain candidate.")
    assertion(s1.votesReceived == 1, "Server should have the correct number of votes.")
开发者ID:gddmkr42171822,项目名称:csci5673,代码行数:19,代码来源:ServerTest.py

示例5: testSingleServerBecomesLeaderVoteRequest

# 需要导入模块: from Server import Server [as 别名]
# 或者: from Server.Server import setNeighbors [as 别名]
def testSingleServerBecomesLeaderVoteRequest():
    s1 = Server()
    s2 = Server()
    s3 = Server()
    
    s1.setNeighbors([s2, s3])
    s2.setNeighbors([s1, s3])
    s3.setNeighbors([s1, s2])
    
    assertion(len(s1.neighbors) - 1 == 2, "Server should have the right number of neighbors.")
    
    # Request an election
    s1.requestVotes()
    
    assertion(s1.votesReceived == 3, "Server have received the right number of votes.")
    assertion(s1.state == ServerState.leader, "Server should have been elected the leader.")
    assertion(s2.voted == True, "Server should have voted.")
    assertion(s3.voted == True, "Server should have voted.")
    assertion(s1.voted == True, "Server should have voted for itself.")
    assertion(s1.log[0][1] == 0, "Server has the right term in the log.")
开发者ID:gddmkr42171822,项目名称:csci5673,代码行数:22,代码来源:ServerTest.py

示例6: testClientLoop

# 需要导入模块: from Server import Server [as 别名]
# 或者: from Server.Server import setNeighbors [as 别名]
def testClientLoop():
    # Establish cluster
    s1 = Server()
    s2 = Server()
    s3 = Server()
    
    # Set cluster membership
    s1.setNeighbors([s2, s3])
    s2.setNeighbors([s1, s3])
    s3.setNeighbors([s1, s2])
    
    # Create cluster leader
    # Request an election
    s3.requestVotes()
    
    # Connect the client to the cluster leader through a non-leader
    c1 = Client()
    c1.connectClientToLeader(s3.neighbors)
    
    # Use the command line
    c1.waitForCommands()
开发者ID:gddmkr42171822,项目名称:csci5673,代码行数:23,代码来源:ClientTest.py

示例7: testLeaderStateMachineLogReplication

# 需要导入模块: from Server import Server [as 别名]
# 或者: from Server.Server import setNeighbors [as 别名]
def testLeaderStateMachineLogReplication():
    s1 = Server()
    s2 = Server()
    s3 = Server()
    
    s1.setNeighbors([s2, s3])
    s2.setNeighbors([s1, s3])
    s3.setNeighbors([s1, s2])
    
    # Add a state machine no one else has
    s2.stateMachine[1] = "test"
    
    # Request an election
    s2.requestVotes()
    
    # Add to the leaders log a command no none else has
    #s2.log.append(("test", 1, False, 0))
    
    assertion(s1.log[-1][0] == "New Term", "Server has the correct log.")
    assertion(s1.log[-1][1] == 1, "Server is in right term.")
    assertion(s3.clusterLeader.uuid == s2.uuid, "Server has the correct leader.")
    assertion(s1.stateMachine[1] == "test", "Server has the correct state machine.")
开发者ID:gddmkr42171822,项目名称:csci5673,代码行数:24,代码来源:ServerTest.py

示例8: testIncorrectClientCommandsToCluster

# 需要导入模块: from Server import Server [as 别名]
# 或者: from Server.Server import setNeighbors [as 别名]
def testIncorrectClientCommandsToCluster():
    # Establish cluster
    s1 = Server()
    s2 = Server()
    s3 = Server()
    
    # Set cluster membership
    s1.setNeighbors([s2, s3])
    s2.setNeighbors([s1, s3])
    s3.setNeighbors([s1, s2])
    
    # Create cluster leader
    # Request an election
    s3.requestVotes()
    
    # Connect the client to the cluster leader through a non-leader
    c1 = Client()
    c1.connectClientToLeader(s1.neighbors)
    assertion(c1.clusterLeader.uuid == s3.uuid, "Client is connected to the leader.")
    
    # Test queue creation
    label1 = 1
    label2 = 2
    qid1 = c1.clusterLeader.create_Queue(label1)
    qid2 = c1.clusterLeader.create_Queue(label2)
    assertion(len(c1.clusterLeader.stateMachine) == 2, "Client successfully created queue.")
    
    # Test getting qid
    assertion(c1.clusterLeader.get_qid(label1) == qid1, "Client successfully retrieved queue id.")
    assertion(c1.clusterLeader.get_qid(label2) == qid2, "Client successfully retrieved queue id.")
    
    # Test pushing, popping, top, and qsize
    c1.clusterLeader.push(qid1, 5)
    c1.clusterLeader.push(qid1, 10)
    assertion(c1.clusterLeader.qsize(qid1) == 2, "Queue has the right size.")
    assertion(c1.clusterLeader.pop(qid1) == 5, "Client popped the right item off the queue.")
    assertion(c1.clusterLeader.top(qid1) == 10, "Queue top returned the right item off the queue.")
    assertion(c1.clusterLeader.qsize(qid1) == 1, "Queue remains the right size.")
开发者ID:gddmkr42171822,项目名称:csci5673,代码行数:40,代码来源:ClientTest.py

示例9: testClientLoopWithTimeout

# 需要导入模块: from Server import Server [as 别名]
# 或者: from Server.Server import setNeighbors [as 别名]
def testClientLoopWithTimeout():
    s1 = Server()
    s2 = Server()
    s3 = Server()
    
    s1.setNeighbors([s2, s3])
    s2.setNeighbors([s1, s3])
    s3.setNeighbors([s1, s2])
    
    t1 = Thread(target=s1.electionTimeout)
    t1.start()
    time.sleep(5)
    t2 = Thread(target=s2.electionTimeout)
    t2.start()
    t3 = Thread(target=s3.electionTimeout)
    t3.start()
    
    # Connect the client to the cluster leader through a non-leader
    c1 = Client()
    c1.connectClientToLeader(s2.neighbors)
    
    # Use the command line
    c1.waitForCommands()
开发者ID:gddmkr42171822,项目名称:csci5673,代码行数:25,代码来源:ClientTest.py

示例10: testClientAndServerTimeout

# 需要导入模块: from Server import Server [as 别名]
# 或者: from Server.Server import setNeighbors [as 别名]
def testClientAndServerTimeout():
    s1 = Server()
    s2 = Server()
    s3 = Server()
    
    s1.setNeighbors([s2, s3])
    s2.setNeighbors([s1, s3])
    s3.setNeighbors([s1, s2])
    
    t1 = Thread(target=s1.electionTimeout)
    t1.start()
    time.sleep(5)
    t2 = Thread(target=s2.electionTimeout)
    t2.start()
    t3 = Thread(target=s3.electionTimeout)
    t3.start()
    
    # Connect the client to the cluster leader through a non-leader
    c1 = Client()
    c1.connectClientToLeader(s3.neighbors)
    
    assertion(c1.clusterLeader.uuid == s1.uuid, "Client is connected to the leader.")
    
    # Test queue creation
    label1 = 1
    label2 = 2
    qid1 = c1.clusterLeader.clientCommand("create_Queue", label1)
    qid2 = c1.clusterLeader.clientCommand("create_Queue", label2)
    assertion(len(c1.clusterLeader.stateMachine) == 2, "Client successfully created queue.")
    
    # Test getting qid
    assertion(c1.clusterLeader.clientCommand("get_qid", label1) == qid1, "Client successfully retrieved queue id.")
    assertion(c1.clusterLeader.clientCommand("get_qid", label2) == qid2, "Client successfully retrieved queue id.")
    
    # Test pushing, popping, top, and qsize
    c1.clusterLeader.clientCommand("push", qid1, 5)
    c1.clusterLeader.clientCommand("push", qid1, 10)
    assertion(c1.clusterLeader.clientCommand("qsize", qid1) == 2, "Queue has the right size.")
    assertion(c1.clusterLeader.clientCommand("pop", qid1) == 5, "Client popped the right item off the queue.")
    assertion(c1.clusterLeader.clientCommand("top", qid1) == 10, "Queue top returned the right item off the queue.")
    assertion(c1.clusterLeader.clientCommand("qsize", qid1) == 1, "Queue remains the right size.")
    
    assertion(("create_Queue {0}".format(label1), 1, False, 0) in c1.clusterLeader.log, "Leader has the right command in the log.")
    assertion(("create_Queue {0}".format(label2), 1, False, 0) in c1.clusterLeader.log, "Leader has the right command in the log.")
    
    assertion(("get_qid {0}".format(label1), 1, False, 0) in c1.clusterLeader.log, "Leader has the right command in the log.")
    assertion(("get_qid {0}".format(label2), 1, False, 0) in c1.clusterLeader.log, "Leader has the right command in the log.")
    
    assertion(("push {0} {1}".format(qid1, 5), 1, False, 0) in c1.clusterLeader.log, "Leader has the right command in the log.")
    assertion(("push {0} {1}".format(qid1, 10), 1, False, 0) in c1.clusterLeader.log, "Leader has the right command in the log.")
    
    assertion(("qsize {0}".format(qid1), 1, False, 0) in c1.clusterLeader.log, "Leader has the right command in the log.")
    
    assertion(("pop {0}".format(qid1), 1, False, 0) in c1.clusterLeader.log, "Leader has the right command in the log.")
    
    assertion(("top {0}".format(qid1), 1, False, 0) in c1.clusterLeader.log, "Leader has the right command in the log.")
    
    assertion(("qsize {0}".format(qid1), 1, False, 0) in c1.clusterLeader.log, "Leader has the right command in the log.")
    
    assertion(("create_Queue {0}".format(label1), 1, False, 0) in s2.log, "Follower has the right command in the log.")
    assertion(("create_Queue {0}".format(label2), 1, False, 0) in s2.log, "Follower has the right command in the log.")
    
    assertion(("get_qid {0}".format(label1), 1, False, 0) in s2.log, "Follower has the right command in the log.")
    assertion(("get_qid {0}".format(label2), 1, False, 0) in s2.log, "Follower has the right command in the log.")
    
    assertion(("push {0} {1}".format(qid1, 5), 1, False, 0) in s2.log, "Follower has the right command in the log.")
    assertion(("push {0} {1}".format(qid1, 10), 1, False, 0) in s2.log, "Follower has the right command in the log.")
    
    assertion(("qsize {0}".format(qid1), 1, False, 0) in s2.log, "Follower has the right command in the log.")
    
    assertion(("pop {0}".format(qid1), 1, False, 0) in s2.log, "Follower has the right command in the log.")
    
    assertion(("top {0}".format(qid1), 1, False, 0) in s2.log, "Follower has the right command in the log.")
    
    assertion(("qsize {0}".format(qid1), 1, False, 0) in s2.log, "Follower has the right command in the log.")
    
    assertion(len(s2.stateMachine) == 2, "Follower has the right size state machine.")
    
    # Test the killing of the server and re-election
    c1.clusterLeader.clientCommand("kill")
    time.sleep(5)
    
    assertion(c1.clusterLeader != s1.uuid, "Client is connected to the new leader.")
    assertion(len(c1.clusterLeader.neighbors) == 2, "New leader has the right number of neighbors.")
    time.sleep(5)
    assertion(c1.clusterLeader.log[-1][1] == 2, "The cluster is in the right term.")    
开发者ID:gddmkr42171822,项目名称:csci5673,代码行数:88,代码来源:ClientTest.py

示例11: testCorrectClientCommandsToCluster

# 需要导入模块: from Server import Server [as 别名]
# 或者: from Server.Server import setNeighbors [as 别名]
def testCorrectClientCommandsToCluster():
    # Establish cluster
    s1 = Server()
    s2 = Server()
    s3 = Server()
    
    # Set cluster membership
    s1.setNeighbors([s2, s3])
    s2.setNeighbors([s1, s3])
    s3.setNeighbors([s1, s2])
    
    # Create cluster leader
    # Request an election
    s3.requestVotes()
    
    # Connect the client to the cluster leader through a non-leader
    c1 = Client()
    c1.connectClientToLeader(s1.neighbors)
    assertion(c1.clusterLeader.uuid == s3.uuid, "Client is connected to the leader.")
    
    # Test queue creation
    label1 = 1
    label2 = 2
    qid1 = c1.clusterLeader.clientCommand("create_Queue", label1)
    qid2 = c1.clusterLeader.clientCommand("create_Queue", label2)
    assertion(len(c1.clusterLeader.stateMachine) == 2, "Client successfully created queue.")
    
    # Test getting qid
    assertion(c1.clusterLeader.clientCommand("get_qid", label1) == qid1, "Client successfully retrieved queue id.")
    assertion(c1.clusterLeader.clientCommand("get_qid", label2) == qid2, "Client successfully retrieved queue id.")
    
    # Test pushing, popping, top, and qsize
    c1.clusterLeader.clientCommand("push", qid1, 5)
    c1.clusterLeader.clientCommand("push", qid1, 10)
    assertion(c1.clusterLeader.clientCommand("qsize", qid1) == 2, "Queue has the right size.")
    assertion(c1.clusterLeader.clientCommand("pop", qid1) == 5, "Client popped the right item off the queue.")
    assertion(c1.clusterLeader.clientCommand("top", qid1) == 10, "Queue top returned the right item off the queue.")
    assertion(c1.clusterLeader.clientCommand("qsize", qid1) == 1, "Queue remains the right size.")
    
    assertion(("create_Queue {0}".format(label1), 1, False, 0) in c1.clusterLeader.log, "Leader has the right command in the log.")
    assertion(("create_Queue {0}".format(label2), 1, False, 0) in c1.clusterLeader.log, "Leader has the right command in the log.")
    
    assertion(("get_qid {0}".format(label1), 1, False, 0) in c1.clusterLeader.log, "Leader has the right command in the log.")
    assertion(("get_qid {0}".format(label2), 1, False, 0) in c1.clusterLeader.log, "Leader has the right command in the log.")
    
    assertion(("push {0} {1}".format(qid1, 5), 1, False, 0) in c1.clusterLeader.log, "Leader has the right command in the log.")
    assertion(("push {0} {1}".format(qid1, 10), 1, False, 0) in c1.clusterLeader.log, "Leader has the right command in the log.")
    
    assertion(("qsize {0}".format(qid1), 1, False, 0) in c1.clusterLeader.log, "Leader has the right command in the log.")
    
    assertion(("pop {0}".format(qid1), 1, False, 0) in c1.clusterLeader.log, "Leader has the right command in the log.")
    
    assertion(("top {0}".format(qid1), 1, False, 0) in c1.clusterLeader.log, "Leader has the right command in the log.")
    
    assertion(("qsize {0}".format(qid1), 1, False, 0) in c1.clusterLeader.log, "Leader has the right command in the log.")
    
    assertion(("create_Queue {0}".format(label1), 1, False, 0) in s2.log, "Follower has the right command in the log.")
    assertion(("create_Queue {0}".format(label2), 1, False, 0) in s2.log, "Follower has the right command in the log.")
    
    assertion(("get_qid {0}".format(label1), 1, False, 0) in s2.log, "Follower has the right command in the log.")
    assertion(("get_qid {0}".format(label2), 1, False, 0) in s2.log, "Follower has the right command in the log.")
    
    assertion(("push {0} {1}".format(qid1, 5), 1, False, 0) in s2.log, "Follower has the right command in the log.")
    assertion(("push {0} {1}".format(qid1, 10), 1, False, 0) in s2.log, "Follower has the right command in the log.")
    
    assertion(("qsize {0}".format(qid1), 1, False, 0) in s2.log, "Follower has the right command in the log.")
    
    assertion(("pop {0}".format(qid1), 1, False, 0) in s2.log, "Follower has the right command in the log.")
    
    assertion(("top {0}".format(qid1), 1, False, 0) in s2.log, "Follower has the right command in the log.")
    
    assertion(("qsize {0}".format(qid1), 1, False, 0) in s2.log, "Follower has the right command in the log.")
    
    assertion(len(s2.stateMachine) == 2, "Follower has the right size state machine.")
开发者ID:gddmkr42171822,项目名称:csci5673,代码行数:76,代码来源:ClientTest.py


注:本文中的Server.Server.setNeighbors方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。