Esempio n. 1
0
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()
Esempio n. 2
0
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()
Esempio n. 3
0
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()