def test_send_with_partition_key(connection_str, receivers): client = EventHubClient.from_connection_string(connection_str, debug=False) sender = client.add_sender() try: client.run() data_val = 0 for partition in [b"a", b"b", b"c", b"d", b"e", b"f"]: partition_key = b"test_partition_" + partition for i in range(50): data = EventData(str(data_val)) data.partition_key = partition_key data_val += 1 sender.send(data) except: raise finally: client.stop() found_partition_keys = {} for index, partition in enumerate(receivers): received = partition.receive(timeout=5) for message in received: try: existing = found_partition_keys[message.partition_key] assert existing == index except KeyError: found_partition_keys[message.partition_key] = index
async def test_send_with_partition_key_async(connstr_receivers): connection_str, receivers = connstr_receivers client = EventHubClientAsync.from_connection_string(connection_str, debug=False) sender = client.add_async_sender() await client.run_async() data_val = 0 for partition in [b"a", b"b", b"c", b"d", b"e", b"f"]: partition_key = b"test_partition_" + partition for i in range(50): data = EventData(str(data_val)) data.partition_key = partition_key data_val += 1 await sender.send(data) await client.stop_async() found_partition_keys = {} for index, partition in enumerate(receivers): received = partition.receive(timeout=5) for message in received: try: existing = found_partition_keys[message.partition_key] assert existing == index except KeyError: found_partition_keys[message.partition_key] = index
async def test_send_partition_key_with_partition_async(connection_str): client = EventHubClientAsync.from_connection_string(connection_str, debug=True) sender = client.add_async_sender(partition="1") try: await client.run_async() data = EventData(b"Data") data.partition_key = b"PKey" with pytest.raises(ValueError): await sender.send(data) finally: await client.stop_async()
def test_send_partition_key_with_partition_sync(connection_str): pytest.skip("Skipped tentatively. Confirm whether to throw ValueError or just warn users") client = EventHubClient.from_connection_string(connection_str, network_tracing=False) sender = client.create_producer(partition_id="1") try: data = EventData(b"Data") data.partition_key = b"PKey" with pytest.raises(ValueError): sender.send(data) finally: sender.close()
async def test_send_partition_key_with_partition_async(connection_str): client = EventHubClientAsync.from_connection_string(connection_str, debug=True) sender = client.add_async_sender(partition="1") try: await client.run_async() data = EventData(b"Data") data.partition_key = b"PKey" with pytest.raises(ValueError): await sender.send(data) finally: await client.stop_async()
def test_send_partition_key_with_partition(connection_str): client = EventHubClient.from_connection_string(connection_str, debug=False) sender = client.add_sender(partition="1") try: client.run() data = EventData(b"Data") data.partition_key = b"PKey" with pytest.raises(ValueError): sender.send(data) except: raise finally: client.stop()
async def send(snd, count): for i in range(count): logger.info("Sending message: {}".format(i)) data = EventData(str(i)) data.partition_key = b'SamplePartitionKey' await snd.send(data)
async def send(snd, count): for i in range(count): logger.info("Sending message: {}".format(i)) data = EventData(str(i)) data.partition_key = b'SamplePartitionKey' await snd.send(data)