def run_test(): ''' Tests Waldo's capability of propagating an exception back through nested sequences. Here we have two pairs of endpoints: (a,b), (c,d). Endpoint a begins a sequence with b, which makes and endpoint call to c, which initiates a sequence with d, which raises an exception. Returns true if the exception is propagated back to the root of the event and handled and false otherwise. ''' Waldo.tcp_accept(InnerPong, HOST, PORT_INNER, throw_func) inner_ping = Waldo.tcp_connect(InnerPing, HOST, PORT_INNER) Waldo.tcp_accept(OuterPong, HOST, PORT_OUTER, inner_ping) outer_ping = Waldo.tcp_connect(OuterPing, HOST, PORT_OUTER) return outer_ping.testNestedSequencePropagation()
def add_single_dht_node(node_host_port_pair): # first: connect to discovery service requester = Waldo.tcp_connect( Requester, conf.COORDINATOR_HOST_PORT_PAIR.host, conf.COORDINATOR_HOST_PORT_PAIR.port, # the host and port that our new dht node will listen on for # connections to other dht nodes. node_host_port_pair.host, node_host_port_pair.port) # request request addresses of other nodes to contact from # discovery service, plus register self with discovery service. uuid, finger_table, next, prev = requester.register() dht_node = Waldo.no_partner_create(Node, uuid, util_funcs.distance, util_funcs.hashed_uuid, util_funcs.between, util_funcs.debug_print) # listen for connections to my node def on_connected(sidea_endpoint): sidea_endpoint.add_connection_to_node() Waldo.tcp_accept(NodeSideA, node_host_port_pair.host, node_host_port_pair.port, dht_node, node_host_port_pair.host, node_host_port_pair.port, connected_callback=on_connected) # connect to other nodes in my finger table for uuid in finger_table.keys(): # table_entry has form: # host: <text> # port: <number> # valid: <bool> # uuid: <text> table_entry = finger_table[uuid] host_to_connect_to = table_entry['host'] port_to_connect_to = table_entry['port'] connection_to_finger_table_node = Waldo.tcp_connect( NodeSideB, host_to_connect_to, port_to_connect_to, dht_node, node_host_port_pair.host, node_host_port_pair.port) return dht_node
def run_test(): accept_stoppable = Waldo.tcp_accept( SideA, SIDEA_HOST, SIDEA_PORT, connected_callback=sidea_connected) sideb = Waldo.tcp_connect( SideB,SIDEA_HOST,SIDEA_PORT) sidea = sidea_wait_queue.get() sidea.add_stop_listener(sidea_stop_listener) sideb.add_stop_listener(sideb_stop_listener_1) sideb.add_stop_listener(sideb_stop_listener_2) listener_id = sideb.add_stop_listener(sideb_stop_listener_2) sideb.remove_stop_listener(listener_id) sideb.remove_stop_listener(listener_id) sidea.do_nothing() sideb.do_nothing() sidea.stop() time.sleep(1) if sidea_stop_counter != 1: return False if sideb_stop_counter != 3: return False return True
def main(): #Connecting + Starting client = Waldo.tcp_connect(Client, HOSTNAME, PORT) print 'Started' startTime = time.time() #Sending all messages try: for n in range(0, numMessages): client.send_msg() except: print 'Sending message failed.' #Packaging time and sending it totalTime = time.time() - startTime print "Finished: " + str(totalTime) numClients = 1 if(len(sys.argv) >= 2): #assume numClients is only one unless the number of clients is given numClients = int(sys.argv[1]) #Writing and closing client.stop() f = open('clientLog', 'a') f.write(str(numClients) + ' ' + str(numClients * numMessages) + ' ' + str(totalTime) + '\n') f.close()
def main(): # Connecting + Starting client = Waldo.tcp_connect(Client, HOSTNAME, PORT) print "Started" startTime = time.time() # Sending all messages try: for n in range(0, 100): client.send_msg(str(100)) time.sleep(DELAY) for n in range(100, numMessages): client.send_msg(str(n)) time.sleep(DELAY) except: print "Sending message failed." # Packaging time and sending it totalTime = time.time() - startTime print "Finished: " + str(totalTime) numClients = 1 if len(sys.argv) >= 2: # assume numClients is only one unless the number of clients is given numClients = int(sys.argv[1]) # Writing and closing client.stop() f = open("clientLog", "a") f.write(str(numClients) + " " + str(numClients * numMessages) + " " + str(totalTime) + "\n") f.close()
def run_test(): accept_stoppable = Waldo.tcp_accept( SideA, SIDEA_HOST, SIDEA_PORT, connected_callback=sidea_connected) sideb = Waldo.tcp_connect( SideB,SIDEA_HOST,SIDEA_PORT) sidea = sidea_wait_queue.get() sidea.do_nothing() sideb.do_nothing() sidea.stop() time.sleep(1) # ensure that stop fires on single host. try: sidea.do_nothing() return False except Waldo.StoppedException as inst: pass # ensure that the other side also sees the stop. try: sideb.do_nothing() return False except Waldo.StoppedException as inst: pass return True
def add_single_dht_node(node_host_port_pair): # first: connect to discovery service requester = Waldo.tcp_connect( Requester, conf.COORDINATOR_HOST_PORT_PAIR.host, conf.COORDINATOR_HOST_PORT_PAIR.port, # the host and port that our new dht node will listen on for # connections to other dht nodes. node_host_port_pair.host, node_host_port_pair.port) # request request addresses of other nodes to contact from # discovery service, plus register self with discovery service. uuid, finger_table, next, prev = requester.register() dht_node = Waldo.no_partner_create( Node,uuid,util_funcs.distance,util_funcs.hashed_uuid, util_funcs.between, util_funcs.debug_print) # listen for connections to my node def on_connected(sidea_endpoint): sidea_endpoint.add_connection_to_node() Waldo.tcp_accept( NodeSideA, node_host_port_pair.host, node_host_port_pair.port, dht_node, node_host_port_pair.host, node_host_port_pair.port, connected_callback = on_connected) # connect to other nodes in my finger table for uuid in finger_table.keys(): # table_entry has form: # host: <text> # port: <number> # valid: <bool> # uuid: <text> table_entry = finger_table[uuid] host_to_connect_to = table_entry['host'] port_to_connect_to = table_entry['port'] connection_to_finger_table_node = Waldo.tcp_connect( NodeSideB, host_to_connect_to, port_to_connect_to, dht_node,node_host_port_pair.host, node_host_port_pair.port) return dht_node
def run_test(): ''' Tests Waldo's ability to detect an application exception on the partner endpoint mid-sequence and propagate that exception back to the root endpoint for handling. Returns true if the exception is caught and handled, and false otherwise. ''' Waldo.tcp_accept(Pong,HOST,PORT) connector = Waldo.tcp_connect(Ping,HOST,PORT) return connector.testPropagateException()
def run_test(): ''' Tests Waldo's ability to detect an application exception on the partner endpoint mid-sequence and propagate that exception back to the root endpoint for handling. Returns true if the exception is caught and handled, and false otherwise. ''' Waldo.tcp_accept(Pong, HOST, PORT) connector = Waldo.tcp_connect(Ping, HOST, PORT) return connector.testPropagateException()
def run_test(): Waldo.tcp_accept(Pt2, HOST, PORT, connected_callback=pt2_connected) pt1 = Waldo.tcp_connect(Pt1, HOST, PORT,createList); pt2 = pt2_wait_queue.get() returned_list = pt1.start_seq() time.sleep(1) list_to_return.append('wo') if returned_list != list_to_return: return False return True
def run_test(): ''' Tests Waldo's ability to propagate an exception back through a sequence within an endpoint call. Returns true if the exception is caught and handled, and false otherwise. ''' Waldo.tcp_accept(Pong,HOST,PORT) connector = Waldo.tcp_connect(Ping,HOST,PORT) catcher = Waldo.no_partner_create(Catcher) catcher.addEndpoint(connector) return catcher.testCatchApplicationExceptionFromSequence()
def run_test(): ''' Tests Waldo's ability to propagate an ApplicationException back through an endpoint call on the remote partner in a sequence. The exception should be passed back to the root endpoint which initiates the sequence. Returns true if the exception is caught and handled, and false otherwise. ''' thrower = Waldo.no_partner_create(Pong,None) catcher_partner = Waldo.tcp_accept(Pong,HOST,PORT,thrower) catcher = Waldo.tcp_connect(Ping,HOST,PORT) return catcher.testExceptionPropagation()
def ask(): """ Asks the listening endpoint for a list of its users, parses it, and prints a unique list of users logged on at the other endpoint. """ sender = Waldo.tcp_connect(EndpointA, HOSTNAME, PORT) print "Users on", HOSTNAME users = sender.ask_for_list() user_list = users.strip("\n").split(" ") user_list = list(set(user_list)) for user in user_list: print "\t", user
def run_test(): ''' Tests Waldo's capability of propagating a network exception back through a sequence. Here we have two pairs of endpoints: (a,b), (c,d). Endpoint a begins a sequence with b, which makes and endpoint call to c, which initiates a sequence with d. Endpoint d is in a separate process which is manually terminated mid-sequence, thus a network exception should be detected by c and propagated back to a. Returns true if the exception is propagated back to the root of the event and handled and false otherwise. ''' global acceptor_proc Waldo.set_default_heartbeat_period(1) Waldo.set_default_partner_timeout(2) acceptor_proc.start() time.sleep(SLEEP_TIME) # make sure process is ready for tcp_connect inner_ping = Waldo.tcp_connect(InnerPing, HOST, PORT_INNER) Waldo.tcp_accept(OuterPong, HOST, PORT_OUTER, inner_ping) outer_ping = Waldo.tcp_connect(OuterPing, HOST, PORT_OUTER) result = outer_ping.testNestedSequencePropagation() acceptor_proc.terminate() return result
def run_test(): ''' Tests Waldo's ability to detect a network failure between two endpoints mid-sequence, thrown a NetworkException, and catch that exception using a try-catch. Returns true if the exception is caught and handled, and false otherwise. ''' Waldo.set_default_heartbeat_period(1) Waldo.set_default_partner_timeout(3) acceptor_process.start() time.sleep(SLEEP_TIME) connector = Waldo.tcp_connect(Ping, HOST, PORT, signal_func) return connector.testNetworkException()
def run_test(): ''' Tests Waldo's ability to detect a network failure between two endpoints mid-sequence, thrown a NetworkException, and catch that exception using a try-catch. Returns true if the exception is caught and handled, and false otherwise. ''' Waldo.set_default_heartbeat_period(1) Waldo.set_default_partner_timeout(3) acceptor_process.start() time.sleep(SLEEP_TIME) connector = Waldo.tcp_connect(Ping,HOST,PORT,signal_func) return connector.testNetworkException()
def run_test(): ''' Tests that Waldo can detect a network exception mid-sequence and propagate that exception back through an endpoint call. Returns true if the test passes and false otherwise. ''' Waldo.set_default_heartbeat_period(1) Waldo.set_default_partner_timeout(2) acceptor_process.start() time.sleep(SLEEP_TIME) endpt = Waldo.tcp_connect(Ping, HOST, PORT) endpt.addTerminationFunction(signal_func) catcher = Waldo.no_partner_create(Catcher) catcher.addEndpoint(endpt) return catcher.testPropagateNetworkExceptionOnEndpointCall()
def getMSG(endpoint, msg): global startTime global c global numClients global hit if msg == '0': hit = False print 'start' startTime = time.time() if msg == '999' and not hit: f.write(str(numClients) + ' ' + str(numClients * numMessages) + ' ' + str(time.time() - startTime) + '\n') print time.time() - startTime print 'finished' numClients += 1 client = Waldo.tcp_connect(Client, HOSTNAME, PORT, getMSG) c.append(client) hit = True
def run_test(): ''' Tests Waldo's ability to detect a network failure between two endpoints mid-sequence, thrown a NetworkException, and catch that exception using a try-catch. Returns true if the exception is caught and handled, and false otherwise. ''' acceptor_process = Process(target=spawn_acceptor,args=()) Waldo.set_default_heartbeat_period(1) Waldo.set_default_partner_timeout(3) acceptor_process.start() time.sleep(KILL_WAIT_TIME) connector = Waldo.tcp_connect(Ping,HOST,PORT) time.sleep(KILL_WAIT_TIME) acceptor_process.terminate() time.sleep(TIMEOUT_DETECT_TIME) return connector.testNetworkException()
def main(): print "Started" startTime = time.time() # Connecting + Starting client = Waldo.tcp_connect(Client, HOSTNAME, PORT) # Packaging time and sending it totalTime = time.time() - startTime print "Finished: " + str(totalTime) numClients = 1 if len(sys.argv) >= 2: # assume numClients is only one unless the number of clients is given numClients = int(sys.argv[1]) # Writing and closing client.stop() f = open("clientLog", "a") f.write(str(numClients) + " " + str(numClients * numMessages) + " " + str(totalTime) + "\n") f.close()
def run_test(): original_sidea_num = 13 original_sideb_num = 135.1 accept_stoppable = Waldo.tcp_accept( SideA, SIDEA_HOST, SIDEA_PORT,original_sidea_num, connected_callback=sidea_connected) sideb = Waldo.tcp_connect( SideB,SIDEA_HOST,SIDEA_PORT,original_sideb_num) sidea = sidea_wait_queue.get() # check if each initialized correctly if sidea.get_other_val() != original_sideb_num: print '\nErr: symmetric did not initialize correctly' return False if sideb.get_other_val() != original_sidea_num: print '\nErr: symmetric did not initialize correctly' return False sidea_num = 39 sideb_num = 41 # write endpoint number to each side sidea.set_other_val(sideb_num) sideb.set_other_val(sidea_num) if sidea.get_other_val() != sideb_num: print '\nErr: symmetric did not set other side correctly' return False if sideb.get_other_val() != sidea_num: print '\nErr: symmetric did not set other side correctly' return False accept_stoppable.stop() return True
def run_test(): accept_stoppable = Waldo.tcp_accept( Modifier, MODIFIER_HOST, MODIFIER_PORT, connected_callback=modifier_connected) data_reader = Waldo.tcp_connect( DataReader,MODIFIER_HOST,MODIFIER_PORT) modifier = modifier_wait_queue.get() # check peered value is initialized properly if modifier.read_peered_num() != 22: print '\nErr: incorrect modifier initial val of peered num' return False if data_reader.read_peered_num() != 22: print '\nErr: incorrect data reader initial val of peered num' return False # check modifier can increment if modifier.increment_peered_num() != 23: print '\nErr: incorrect modifier return from peered num increment' return False # check modifier sees increment if modifier.read_peered_num() != 23: print '\nErr: incorrect modifier return from peered num read' return False # check data reader sees increment if data_reader.read_peered_num() != 23: print '\nErr: incorrect data reader return from peered num read' return False accept_stoppable.stop() return True
def main(): #Connecting + Starting client = Waldo.tcp_connect(Client, HOSTNAME, PORT) print 'Started' #preparing the string lengths length = 0 if(len(sys.argv) >= 2): length = int(sys.argv[1]) if length == -1: mult = 0 else: mult = 2**length texts = [] for i in range(0,mult): texts.append('123') startTime = time.time() #Sending all messages try: for i in range(0,numMessages): client.send_msg(texts) except: print 'Sending message failed.' #Packaging time and sending it totalTime = time.time() - startTime client.send_msg(str(numMessages - 1)) #final message to signal to server print "Finished: " + str(totalTime) #Writing and closing client.stop() f = open('clientLog', 'a') f.write(str(length) + ' ' + str(numMessages) + ' ' + str(totalTime) + '\n') f.close()
def main(): #Connecting + Starting client = Waldo.tcp_connect(Client, HOSTNAME, PORT) print 'Started' #preparing the string lengths power = 0 if(len(sys.argv) >= 2): power = int(sys.argv[1]) mult = 2**power texts = [] toFill = '123' * mult for n in range(0,numMessages): texts.append(toFill) startTime = time.time() #Sending all messages try: for text in texts: client.send_msg(text) except: print 'Sending message failed.' #Packaging time and sending it totalTime = time.time() - startTime client.send_msg(str(numMessages - 1)) #final message to signal to server print "Finished: " + str(totalTime) #Writing and closing client.stop() f = open('clientLog', 'a') f.write(str(power) + ' ' + str(numMessages) + ' ' + str(totalTime) + '\n') f.close()
def run_chatter_client(): ''' Runs a connecting single chatter. Connects to the chat server. ''' client = Waldo.tcp_connect(Client, HOSTNAME, PORT, display_msg) listen_for_user_input(client)
def main(): client = Waldo.tcp_connect(Client, HOSTNAME, PORT) print 'Started' time.sleep(5) client.stop()
from emitted import Client import sys import time sys.path.append("../..") from waldo.lib import Waldo HOSTNAME = '127.0.0.1' PORT = 9028 numMessages = 1000 f = open('clientLog', 'w') client = [] for i in range(1,17): thing = Waldo.tcp_connect(Client, HOSTNAME, PORT) client.append(thing) print 'Started' f.write(str(i) + ' ' + str(i * numMessages) + ' ') startTime = time.time() for c in client: for n in range(0, numMessages): c.send_msg(str(n)) f.write(str(time.time() - startTime) + '\n') print "Finished: " + str(time.time() - startTime) + '\n' f.close()
import sys sys.path.append("../..") from waldo.lib import Waldo from emitted import Ping import time numMessages = 1000 f = open('clientLog', 'w') pingers = [] for i in range(1,17): ping = Waldo.tcp_connect(Ping, '127.0.0.1', 6767) pingers.append(ping) print 'Started' startTime = time.time() for p in pingers: for i in range(0, numMessages): p.ping_seq(i) print "Finished: " + str(time.time() - startTime) + '\n' f.write(str(i) + " " + str(i * numMessages) + " " + str(time.time() - startTime) + '\n')
def run_chatter_b(): chatter_b = Waldo.tcp_connect(ChatterB, HOSTNAME, PORT, display_msg) listen_for_user_input(chatter_b)
import sys, os sys.path.append(os.path.join('..', '..', 'Waldo')) from waldo.lib import Waldo from emitted import Ping import time ping = Waldo.tcp_connect(Ping, 'localhost', 6767) print ('\nThis is result of ping seq: ' + str(ping.ping_seq(0)))
root = Tk() root.geometry("500x220") scrollbar = Scrollbar(root) scrollbar.pack(side=RIGHT, fill=Y) listbox = Listbox(root, yscrollcommand=scrollbar.set) listbox.pack(side=TOP, fill=BOTH) scrollbar.config(command=listbox.yview) e = Entry(root,width=100) e.pack() e.focus_set() #client stuff client = Waldo.tcp_connect(Client, HOSTNAME, PORT, getMSG, name) def cb(event): callback() def callback(): myGame = int(client.getGame()) msg_to_send = e.get() ready = client.send_cmd(-3, False) #if ready: #print full[myGame] + " is ready to play!" if(msg_to_send != ''): e.delete(0,END) listbox.yview(END)
from emitted import Client import sys import time sys.path.append("../..") from waldo.lib import Waldo HOSTNAME = '127.0.0.1' PORT = 9028 f = open('clientLog', 'w') for i in range(0,16): client = Waldo.tcp_connect(Client, HOSTNAME, PORT) client2 = Waldo.tcp_connect(Client, HOSTNAME, PORT) print 'Started' f.write(str(i) + ' ') startTime = time.time() for n in range(0, 1000): client.send_msg(str(n)) client2.send_msg(str(n)) f.write(str(time.time() - startTime) + '\n') print "Finished: " + str(time.time() - startTime) + '\n' f.close()