本文整理汇总了Python中Client.Client.connectClientToLeader方法的典型用法代码示例。如果您正苦于以下问题:Python Client.connectClientToLeader方法的具体用法?Python Client.connectClientToLeader怎么用?Python Client.connectClientToLeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Client.Client
的用法示例。
在下文中一共展示了Client.connectClientToLeader方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from Client import Client [as 别名]
# 或者: from Client.Client import connectClientToLeader [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()
示例2: testClientLoop
# 需要导入模块: from Client import Client [as 别名]
# 或者: from Client.Client import connectClientToLeader [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()
示例3: testClientConnectionToWithoutLeadershipChangeInCluster
# 需要导入模块: from Client import Client [as 别名]
# 或者: from Client.Client import connectClientToLeader [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.")
示例4: testIncorrectClientCommandsToCluster
# 需要导入模块: from Client import Client [as 别名]
# 或者: from Client.Client import connectClientToLeader [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.")
示例5: testClientLoopWithTimeout
# 需要导入模块: from Client import Client [as 别名]
# 或者: from Client.Client import connectClientToLeader [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()
示例6: testClientAndServerTimeout
# 需要导入模块: from Client import Client [as 别名]
# 或者: from Client.Client import connectClientToLeader [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.")
示例7: testCorrectClientCommandsToCluster
# 需要导入模块: from Client import Client [as 别名]
# 或者: from Client.Client import connectClientToLeader [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.")