def test_long_running_receive_async(connection_str): parser = argparse.ArgumentParser() parser.add_argument("--duration", help="Duration in seconds of the test", type=int, default=30) parser.add_argument("--consumer", help="Consumer group name", default="$default") parser.add_argument("--partitions", help="Comma seperated partition IDs") parser.add_argument("--offset", help="Starting offset", default="-1") parser.add_argument("--conn-str", help="EventHub connection string", default=connection_str) parser.add_argument("--eventhub", help="Name of EventHub") parser.add_argument("--address", help="Address URI to the EventHub entity") parser.add_argument( "--sas-policy", help="Name of the shared access policy to authenticate with") parser.add_argument("--sas-key", help="Shared access key") loop = asyncio.get_event_loop() args, _ = parser.parse_known_args() if args.conn_str: client = EventHubClientAsync.from_connection_string( args.conn_str, eventhub=args.eventhub, auth_timeout=240, debug=False) elif args.address: client = EventHubClientAsync(args.address, auth_timeout=240, username=args.sas_policy, password=args.sas_key) else: try: import pytest pytest.skip("Must specify either '--conn-str' or '--address'") except ImportError: raise ValueError("Must specify either '--conn-str' or '--address'") try: if not args.partitions: partitions = loop.run_until_complete(get_partitions(client)) else: partitions = args.partitions.split(",") pumps = [] for pid in partitions: receiver = client.add_async_receiver(consumer_group=args.consumer, partition=pid, offset=Offset(args.offset), prefetch=50) pumps.append(pump(pid, receiver, args, args.duration)) loop.run_until_complete(client.run_async()) loop.run_until_complete(asyncio.gather(*pumps)) finally: loop.run_until_complete(client.stop_async())
def test_long_running_partition_send_async(connection_str): parser = argparse.ArgumentParser() parser.add_argument("--duration", help="Duration in seconds of the test", type=int, default=30) parser.add_argument("--payload", help="payload size", type=int, default=1024) parser.add_argument("--batch", help="Number of events to send and wait", type=int, default=200) parser.add_argument("--partitions", help="Comma seperated partition IDs") parser.add_argument("--conn-str", help="EventHub connection string", default=connection_str) parser.add_argument("--eventhub", help="Name of EventHub") parser.add_argument("--address", help="Address URI to the EventHub entity") parser.add_argument("--sas-policy", help="Name of the shared access policy to authenticate with") parser.add_argument("--sas-key", help="Shared access key") parser.add_argument("--logger-name", help="Unique log file ID") loop = asyncio.get_event_loop() args, _ = parser.parse_known_args() if args.conn_str: client = EventHubClientAsync.from_connection_string( args.conn_str, eventhub=args.eventhub, debug=True) elif args.address: client = EventHubClientAsync( args.address, username=args.sas_policy, password=args.sas_key, auth_timeout=500) else: try: import pytest pytest.skip("Must specify either '--conn-str' or '--address'") except ImportError: raise ValueError("Must specify either '--conn-str' or '--address'") try: if not args.partitions: partitions = loop.run_until_complete(get_partitions(client)) else: pid_range = args.partitions.split("-") if len(pid_range) > 1: partitions = [str(i) for i in range(int(pid_range[0]), int(pid_range[1]) + 1)] else: partitions = args.partitions.split(",") pumps = [] for pid in partitions: sender = client.add_async_sender(partition=pid, send_timeout=0, keep_alive=False) pumps.append(pump(pid, sender, args, args.duration)) loop.run_until_complete(client.run_async()) results = loop.run_until_complete(asyncio.gather(*pumps, return_exceptions=True)) assert not results except Exception as e: logger.error("Sender failed: {}".format(e)) finally: logger.info("Shutting down sender") loop.run_until_complete(client.stop_async())
def test_long_running_receive_async(connection_str): parser = argparse.ArgumentParser() parser.add_argument("--duration", help="Duration in seconds of the test", type=int, default=30) parser.add_argument("--consumer", help="Consumer group name", default="$default") parser.add_argument("--partitions", help="Comma seperated partition IDs") parser.add_argument("--offset", help="Starting offset", default="-1") parser.add_argument("--conn-str", help="EventHub connection string", default=connection_str) parser.add_argument("--eventhub", help="Name of EventHub") parser.add_argument("--address", help="Address URI to the EventHub entity") parser.add_argument("--sas-policy", help="Name of the shared access policy to authenticate with") parser.add_argument("--sas-key", help="Shared access key") loop = asyncio.get_event_loop() args, _ = parser.parse_known_args() if args.conn_str: client = EventHubClientAsync.from_connection_string( args.conn_str, eventhub=args.eventhub, auth_timeout=240, debug=False) elif args.address: client = EventHubClientAsync( args.address, auth_timeout=240, username=args.sas_policy, password=args.sas_key) else: try: import pytest pytest.skip("Must specify either '--conn-str' or '--address'") except ImportError: raise ValueError("Must specify either '--conn-str' or '--address'") try: if not args.partitions: partitions = loop.run_until_complete(get_partitions(client)) else: partitions = args.partitions.split(",") pumps = [] for pid in partitions: receiver = client.add_async_receiver( consumer_group=args.consumer, partition=pid, offset=Offset(args.offset), prefetch=50) pumps.append(pump(pid, receiver, args, args.duration)) loop.run_until_complete(client.run_async()) loop.run_until_complete(asyncio.gather(*pumps)) finally: loop.run_until_complete(client.stop_async())