Best Python code snippet using molotov_python
test_routing_manager.py
Source:test_routing_manager.py
...25 self.routing_m.on_timeout(tc.SERVER_NODE)26 # main: CLIENT_NODE, replacement: empty27 eq_(self.routing_m.get_closest_rnodes(tc.SERVER_ID),28 [tc.CLIENT_NODE])29 self.routing_m.on_response_received(tc.SERVER_NODE)30 # main: client_node, server_node, replacement: empty31 # this should reset refresh task32 self.routing_m.on_response_received(tc.SERVER_NODE)33 eq_(self.routing_m.get_closest_rnodes(tc.SERVER_ID),34 [tc.SERVER_NODE, tc.CLIENT_NODE])35 self.routing_m.on_timeout(tc.SERVER_NODE)36 # main: client_node, replacement: server_node37 eq_(self.routing_m.get_closest_rnodes(tc.SERVER_ID),38 [tc.CLIENT_NODE])39 self.routing_m.on_response_received(tc.SERVER2_NODE)40 # main: client_node, server_node, replacement: server2_node(q)41 eq_(self.routing_m.get_closest_rnodes(tc.SERVER_ID),42 [tc.SERVER2_NODE, tc.CLIENT_NODE])43 self.routing_m.on_response_received(tc.SERVER_NODE)44 # main: client_node, server_node, replacement: server2_node(q)45 eq_(self.routing_m.get_closest_rnodes(tc.SERVER_ID),46 [tc.SERVER_NODE, tc.SERVER2_NODE, tc.CLIENT_NODE])47 eq_(self.routing_m.get_closest_rnodes(tc.SERVER2_ID),48 [tc.SERVER2_NODE, tc.CLIENT_NODE])49 eq_(self.routing_m.get_closest_rnodes(tc.CLIENT_ID),50 [tc.CLIENT_NODE])51 for n in tc.NODES:52 self.routing_m.on_response_received(n)53 """54 Main Routing Table55 # -156 client57 # 15458 server259 # 15960 server nodes[0:7]61 """62 eq_(self.routing_m.get_closest_rnodes(tc.CLIENT_ID),63 [tc.CLIENT_NODE])64 for n in tc.NODES:65 eq_(self.routing_m.get_closest_rnodes(n.id),66 [tc.SERVER_NODE] + tc.NODES[:7])67 # bucket full (NODES[7] in replacement68 69 self.routing_m.on_query_received(tc.NODES[7])70 eq_(self.routing_m.get_closest_rnodes(n.id),71 [tc.SERVER_NODE] + tc.NODES[:7])72 73 # nodes[0] is kicked out from main74 # all nodes in replacement are refreshed (pinged)75 self.routing_m.on_timeout(tc.NODES[0])76 eq_(self.routing_m.get_closest_rnodes(tc.NODES[0].id),77 [tc.SERVER_NODE] + tc.NODES[1:7] + [tc.SERVER2_NODE])78 # nodes[7] is refreshed79 self.routing_m.on_query_received(tc.NODES[7])80 # nodes[7] still in replacement (queries don't cause movements)81 eq_(self.routing_m.get_closest_rnodes(tc.NODES[0].id),82 [tc.SERVER_NODE] + tc.NODES[1:7] + [tc.SERVER2_NODE])83 # nodes[7] is moved to the main table (response to refresh ping)84 self.routing_m.on_response_received(tc.NODES[7])85 eq_(self.routing_m.get_closest_rnodes(tc.NODES[0].id),86 [tc.SERVER_NODE] + tc.NODES[1:8])87 # nodes[7] is refreshed (no change to the tables)88 self.routing_m.on_query_received(tc.NODES[7])89 eq_(self.routing_m.get_closest_rnodes(tc.NODES[0].id),90 [tc.SERVER_NODE] + tc.NODES[1:8])91 # nodes[7] is in main and get response92 self.routing_m.on_response_received(tc.NODES[7])93 94 # nodes[0] gets strike 2, 3 and 4 (timeouts)95 self.routing_m.on_timeout(tc.NODES[0])96 self.routing_m.on_timeout(tc.NODES[0])97 self.routing_m.on_timeout(tc.NODES[0])98 # and can be expelled from the replacement table99 # nodes2[:] send responses100 #TODO2: rnode(nodes[0] report 5 timeouts101 eq_(self.routing_m.replacement.get_rnode(102 tc.NODES[0]).timeouts_in_a_row(), 5)103 104 if mode is message.QUERY:105 for n in tc.NODES2:106 self.routing_m.on_query_received(n)107 elif mode is message.RESPONSE:108 for n in tc.NODES2:109 self.routing_m.on_response_received(n)110 # nodes[0] comes back but the repl bucket is full111 self.routing_m.on_response_received(tc.NODES[0])112 # nodes[0] sends error (routing manager ignores it)113 self.routing_m.on_error_received(tc.NODES[0])114 # timeout from node without id (ignored)115 # nodes[0] comes back but the repl bucket is full116 self.routing_m.on_timeout(tc.EXTERNAL_NODE)117 # nodes found (but no room in main118 self.routing_m.on_nodes_found(tc.NODES)119 120 # nodes[1] (in main) timeout and repl bucket is full121 # find worst node in repl (nodes[7]) and replace it122 # all nodes in repl bucket get refreshed (not nodes[1]123 self.routing_m.on_timeout(tc.NODES[1])124 eq_(self.routing_m.get_closest_rnodes(tc.NODES[0].id),125 [tc.SERVER_NODE] + tc.NODES[2:8] +[tc.SERVER2_NODE])126 # nodes found (there is room now)127 # nodes2[0:1] get refreshed (pinged128 self.routing_m.on_nodes_found(tc.NODES2)129 # nodes2[0] replies (and is added to main)130 self.routing_m.on_response_received(tc.NODES2[0])131 eq_(self.routing_m.get_closest_rnodes(tc.NODES2[0].id),132 [tc.SERVER_NODE] + tc.NODES[2:8] +tc.NODES2[0:1])133 if mode == message.QUERY:134 expected_main = [tc.SERVER2_NODE] + \135 [tc.SERVER_NODE] + tc.NODES[2:8] + tc.NODES2[0:1] + \136 [tc.CLIENT_NODE]137 138 expected_replacement = tc.NODES[0:2]139 140 elif mode == message.RESPONSE:141 expected_main = [tc.SERVER2_NODE] + \142 [tc.SERVER_NODE] + tc.NODES[2:8] + tc.NODES2[0:1] + \143 [tc.CLIENT_NODE]144 145 expected_replacement = tc.NODES2[1:7] + tc.NODES[1:2]146 147 all_main, all_replacement = self.routing_m.get_all_rnodes()148 for n, expected in zip(all_main, expected_main):149 eq_(n, expected)150 for n, expected in zip(all_replacement, expected_replacement):151 eq_(n, expected)152 eq_(len(all_main), len(expected_main))153 eq_(len(all_replacement), len(expected_replacement))154 155 def test_query(self):156 self.exercise_mock(message.QUERY)157 def test_response(self):158 self.exercise_mock(message.RESPONSE)159 160 161 162 def test_bootstrap(self):163 self.routing_m.do_bootstrap()164 fn_r = message.OutgoingFindNodeResponse(tc.NODES[0].id,165 tc.NODES2[0:1])166 fn_r = message.IncomingMsg(fn_r.encode('\0\0'))167 self.querier.on_response_received(fn_r, tc.NODES[0].addr)168 def test_routing_m_mock(self):169 # Just testing interface170 rm = RoutingManagerMock()171 eq_(rm.get_closest_rnodes(tc.TARGET_ID), tc.NODES)172 def test_complete_coverage(self):173 self.routing_m._do_nothing()...
test_node.py
Source:test_node.py
...71 assert self.rnode1.timeouts_in_a_row(False) == 372 self.rnode1.on_query_received()73 assert self.rnode1.timeouts_in_a_row() == 074 eq_(self.rnode1.timeouts_in_a_row(False), 3)75 self.rnode1.on_response_received(1)76 assert self.rnode1.timeouts_in_a_row() == 077 assert self.rnode1.timeouts_in_a_row(False) == 078 assert self.rnode1._num_queries == 179 assert self.rnode1._num_responses == 180 assert self.rnode1._num_timeouts == 3 81 self.rnode1.on_response_received(RTT1)82 self.rnode1.on_response_received(RTT1)83 self.rnode1.on_response_received(RTT1)84 self.rnode1.on_response_received(RTT1)85 self.rnode1.on_response_received(RTT1)86 self.rnode1.on_response_received(RTT1)87 self.rnode1.on_response_received(RTT1)88 self.rnode1.on_response_received(RTT2)89 eq_(self.rnode1._rtt_avg,90 RTT1 * (1 - LAST_RTT_W) + RTT2 * LAST_RTT_W)91 self.rnode1.on_timeout()92 self.rnode1.on_timeout()93 94 def _test_rank(self):95 eq_(self.rnode1.rank(), 0)96 self.rnode1.on_query_received()97 eq_(self.rnode1.rank(), 0)98 self.rnode1.on_response_received()99 eq_(self.rnode1.rank(), 1)100 def test_repr(self):101 _ = repr(RoutingNode(tc.CLIENT_NODE))102 def test_get_rnode(self):103 eq_(self.rnode1.get_rnode(),...
client.py
Source:client.py
1import pika2from pika.exchange_type import ExchangeType3import uuid4def on_response_received(ch,mehod, properties, body):5 print("Waiting for response...")6 print("Client received the response: %r" %body)7connection_parameters = pika.ConnectionParameters("localhost")8 9connection = pika.BlockingConnection(connection_parameters)10channel = connection.channel()11request = "Face Detection"12coreId = str(uuid.uuid4)13channel.queue_declare(queue="reply_queue", exclusive=True)14channel.basic_publish(exchange="",routing_key="request_queue",properties=pika.BasicProperties(15 reply_to="reply_queue",16 correlation_id= coreId17), body=request)18channel.basic_consume(queue="reply_queue",auto_ack=True,on_message_callback=on_response_received)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!