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


Python Server.requestVotes方法代码示例

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


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

示例1: testClientConnectionToWithoutLeadershipChangeInCluster

# 需要导入模块: from Server import Server [as 别名]
# 或者: from Server.Server import requestVotes [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

示例2: testSingleServerDoesNotReceiveMajorityVotesShouldNotBecomeLeader

# 需要导入模块: from Server import Server [as 别名]
# 或者: from Server.Server import requestVotes [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

示例3: testSingleServerBecomesLeaderVoteRequest

# 需要导入模块: from Server import Server [as 别名]
# 或者: from Server.Server import requestVotes [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

示例4: testClientLoop

# 需要导入模块: from Server import Server [as 别名]
# 或者: from Server.Server import requestVotes [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

示例5: testLeaderStateMachineLogReplication

# 需要导入模块: from Server import Server [as 别名]
# 或者: from Server.Server import requestVotes [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

示例6: testIncorrectClientCommandsToCluster

# 需要导入模块: from Server import Server [as 别名]
# 或者: from Server.Server import requestVotes [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

示例7: testCorrectClientCommandsToCluster

# 需要导入模块: from Server import Server [as 别名]
# 或者: from Server.Server import requestVotes [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.requestVotes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。