def test_single_connection_protocol_trace(self): qd_manager = QdManager(self, self.address) # Turn off trace logging on all connections. qd_manager.update("org.apache.qpid.dispatch.log", {"enable": "info+"}, name="log/DEFAULT") TEST_ADDR_1 = "EnableConnectionLevelProtocolTraceTest1" MSG_BODY = "EnableConnectionLevelProtocolTraceTestMessage1" CONTAINER_ID_1 = "CONTAINERID_1" container_1 = Container() container_1.container_id = CONTAINER_ID_1 conn_1 = BlockingConnection(self.address, container=container_1) TEST_ADDR_2 = "EnableConnectionLevelProtocolTraceTest1" CONTAINER_ID_2 = "CONTAINERID_2" container_2 = Container() container_2.container_id = CONTAINER_ID_2 conn_2 = BlockingConnection(self.address, container=container_2) results = qd_manager.query("org.apache.qpid.dispatch.connection") conn_id = None for result in results: if result[u'container'] == CONTAINER_ID_1: conn_id = result[u'identity'] # Turn on trace logging for connection with identity conn_id qd_manager.update("org.apache.qpid.dispatch.connection", {"enableProtocolTrace": "true"}, identity=conn_id) blocking_receiver_1 = conn_1.create_receiver(address=TEST_ADDR_1) blocking_sender_1 = conn_1.create_sender(address=TEST_ADDR_1, options=apply_options) blocking_receiver_2 = conn_2.create_receiver(address=TEST_ADDR_2) blocking_sender_2 = conn_2.create_sender(address=TEST_ADDR_2, options=apply_options) num_attaches_1 = 0 num_attaches_2 = 0 logs = qd_manager.get_log() for log in logs: if u'PROTOCOL' in log[0]: if "@attach" in log[2] and TEST_ADDR_1 in log[2]: num_attaches_1 += 1 elif "@attach" in log[2] and TEST_ADDR_2 in log[2]: num_attaches_2 += 1 # num_attaches_1 for address TEST_ADDR_1 must be 4, two attaches to/from sender and receiver self.assertTrue(num_attaches_1 == 4) # num_attaches_2 for address TEST_ADDR_2 must be 0 since trace was not # turned on for that connection self.assertTrue(num_attaches_2 == 0) # Now turn off the connection tracing on that connection qd_manager.update("org.apache.qpid.dispatch.connection", {"enableProtocolTrace": "off"}, identity=conn_id) blocking_receiver_1.close() blocking_sender_1.close() # Since tracing was turned off, there should be no detaches logs = qd_manager.get_log() num_detaches = 0 for log in logs: if u'PROTOCOL' in log[0]: if "@detach" in log[2]: num_detaches += 1 self.assertTrue(num_detaches == 0) blocking_receiver_2.close() blocking_sender_2.close() conn_1.close() conn_2.close()
def test_worker_threads(self): long_type = 'org.apache.qpid.dispatch.router' qd_manager = QdManager(self, address=self.address()) output = qd_manager.query('org.apache.qpid.dispatch.router') self.assertEqual(output[0]['workerThreads'], 4)
def check_connector_delete(self, client_addr, server_addr): # Run curl 127.0.0.1:port --http2-prior-knowledge # We are first making sure that the http request goes thru successfully. out = self.run_curl(address=client_addr) # Run a qdmanage query on connections to see how many qdr_connections are # there on the egress router qd_manager = QdManager(self, address=server_addr) connections = qd_manager.query('org.apache.qpid.dispatch.connection') self.assertGreaterEqual(len(connections), 2) server_conn_found = False for conn in connections: if os.environ['SERVER_LISTEN_PORT'] in conn['name']: server_conn_found = True break self.assertTrue(server_conn_found) # Run a qdmanage DELETE on the httpConnector http_connectors = qd_manager.query('org.apache.qpid.dispatch.httpConnector') self.assertEqual(len(http_connectors), 1) # Delete the httpConnector qd_manager.delete("org.apache.qpid.dispatch.httpConnector", name=self.connector_name) # Make sure the connector is gone http_connectors = qd_manager.query('org.apache.qpid.dispatch.httpConnector') self.assertEqual(len(http_connectors), 0) # Deleting the connector must have taken out the connection to the server. connections = qd_manager.query('org.apache.qpid.dispatch.connection') http_server_conn_found = False for conn in connections: if os.environ['SERVER_LISTEN_PORT'] in conn['name']: server_conn_found = True break self.assertFalse(http_server_conn_found) sleep(2) # Now, run a curl client GET request with a timeout request_timed_out = False try: out = self.run_curl(address=client_addr, timeout=5) print(out) except Exception as e: request_timed_out = True self.assertTrue(request_timed_out) # Add back the httpConnector # qdmanage CREATE type=httpConnector address=examples.com host=127.0.0.1 port=80 protocolVersion=HTTP2 create_result = qd_manager.create("org.apache.qpid.dispatch.httpConnector", self.connector_props) num_tries = 2 tries = 0 conn_present = False while tries < num_tries: connections = qd_manager.query('org.apache.qpid.dispatch.connection') tries += 1 if (len(connections) < 2): sleep(2) else: conn_present = True self.assertTrue(conn_present) out = self.run_curl(address=client_addr) ret_string = "" i = 0 while (i < 1000): ret_string += str(i) + "," i += 1 self.assertIn(ret_string, out)