async def test_send_multiple_partition_with_app_prop_async(connstr_receivers):
    connection_str, receivers = connstr_receivers
    app_prop_key = "raw_prop"
    app_prop_value = "raw_value"
    app_prop = {app_prop_key: app_prop_value}
    client = EventHubProducerClient.from_connection_string(connection_str)
    async with client:
        ed0 = EventData(b"Message 0")
        ed0.application_properties = app_prop
        await client.send(ed0, partition_id="0")
        ed1 = EventData(b"Message 1")
        ed1.application_properties = app_prop
        await client.send(ed1, partition_id="1")

    partition_0 = [
        EventData._from_message(x)
        for x in receivers[0].receive_message_batch(timeout=5000)
    ]
    assert len(partition_0) == 1
    assert partition_0[0].application_properties[b"raw_prop"] == b"raw_value"
    partition_1 = [
        EventData._from_message(x)
        for x in receivers[1].receive_message_batch(timeout=5000)
    ]
    assert len(partition_1) == 1
    assert partition_1[0].application_properties[b"raw_prop"] == b"raw_value"
 def batched():
     for i in range(10):
         ed = EventData("Event Data {}".format(i))
         ed.application_properties = app_prop
         yield ed
     for i in range(10, 20):
         ed = EventData("Event Data {}".format(i))
         ed.application_properties = app_prop
         yield ed
Exemplo n.º 3
0
def test_receive_over_websocket_sync(connstr_senders):
    app_prop = {"raw_prop": "raw_value"}

    def on_event(partition_context, event):
        on_event.received.append(event)
        on_event.app_prop = event.application_properties

    on_event.received = []
    on_event.app_prop = None
    connection_str, senders = connstr_senders
    client = EventHubConsumerClient.from_connection_string(
        connection_str, transport_type=TransportType.AmqpOverWebsocket)

    event_list = []
    for i in range(5):
        ed = EventData("Event Number {}".format(i))
        ed.application_properties = app_prop
        event_list.append(ed)
    senders[0].send(event_list)

    with client:
        thread = threading.Thread(target=client.receive,
                                  args=(on_event, "$default"),
                                  kwargs={
                                      "partition_id": "0",
                                      "initial_event_position": "-1"
                                  })
        thread.start()
        time.sleep(10)
    assert len(on_event.received) == 5
    for ed in on_event.received:
        assert ed.application_properties[b"raw_prop"] == b"raw_value"
Exemplo n.º 4
0
async def test_receive_over_websocket_async(connstr_senders):
    app_prop = {"raw_prop": "raw_value"}

    async def on_event(partition_context, event):
        on_event.received.append(event)
        on_event.app_prop = event.application_properties

    on_event.received = []
    on_event.app_prop = None
    connection_str, senders = connstr_senders
    client = EventHubConsumerClient.from_connection_string(
        connection_str, transport_type=TransportType.AmqpOverWebsocket)

    event_list = []
    for i in range(5):
        ed = EventData("Event Number {}".format(i))
        ed.application_properties = app_prop
        event_list.append(ed)
    senders[0].send(event_list)

    async with client:
        task = asyncio.ensure_future(
            client.receive(on_event,
                           "$default",
                           partition_id="0",
                           initial_event_position="-1"))
        await asyncio.sleep(10)
    task.cancel()
    assert len(on_event.received) == 5
    for ed in on_event.received:
        assert ed.application_properties[b"raw_prop"] == b"raw_value"
Exemplo n.º 5
0
async def test_receive_batch_with_app_prop_async(connstr_senders):
    pytest.skip("Waiting on uAMQP release")
    connection_str, senders = connstr_senders

    def batched():
        for i in range(10):
            yield "Event Data {}".format(i)
        for i in range(10, 20):
            yield EventData("Event Data {}".format(i))

    client = EventHubClientAsync.from_connection_string(connection_str,
                                                        debug=False)
    receiver = client.add_async_receiver("$default",
                                         "0",
                                         prefetch=500,
                                         offset=Offset('@latest'))
    try:
        await client.run_async()

        received = await receiver.receive(timeout=5)
        assert len(received) == 0

        app_prop_key = "raw_prop"
        app_prop_value = "raw_value"
        batch_app_prop = {app_prop_key: app_prop_value}
        batch_event = EventData(batch=batched())
        batch_event.application_properties = batch_app_prop

        senders[0].send(batch_event)

        await asyncio.sleep(1)

        received = await receiver.receive(max_batch_size=15, timeout=5)
        assert len(received) == 15

        for index, message in enumerate(received):
            assert list(message.body)[0] == "Event Data {}".format(
                index).encode('utf-8')
            assert (app_prop_key.encode('utf-8') in message.application_properties) \
                and (dict(message.application_properties)[app_prop_key.encode('utf-8')] == app_prop_value.encode('utf-8'))
    except:
        raise
    finally:
        await client.stop_async()
Exemplo n.º 6
0
def test_send_with_create_event_batch_with_app_prop_sync(connstr_receivers):
    connection_str, receivers = connstr_receivers
    app_prop_key = "raw_prop"
    app_prop_value = "raw_value"
    app_prop = {app_prop_key: app_prop_value}
    client = EventHubProducerClient.from_connection_string(connection_str, transport_type=TransportType.AmqpOverWebsocket)
    with client:
        event_data_batch = client.create_batch(max_size=100000)
        while True:
            try:
                ed = EventData('A single event data')
                ed.application_properties = app_prop
                event_data_batch.try_add(ed)
            except ValueError:
                break
        client.send(event_data_batch)
        received = []
        for r in receivers:
            received.extend(r.receive_message_batch(timeout=5000))
        assert len(received) > 1
        assert EventData._from_message(received[0]).application_properties[b"raw_prop"] == b"raw_value"
Exemplo n.º 7
0
async def test_send_batch_with_app_prop_async(connstr_receivers):
    pytest.skip("Waiting on uAMQP release")
    connection_str, receivers = connstr_receivers

    def batched():
        for i in range(10):
            yield "Event number {}".format(i)
        for i in range(10, 20):
            yield EventData("Event number {}".format(i))

    client = EventHubClientAsync.from_connection_string(connection_str,
                                                        debug=False)
    sender = client.add_async_sender()
    try:
        await client.run_async()

        app_prop_key = "raw_prop"
        app_prop_value = "raw_value"
        batch_app_prop = {app_prop_key: app_prop_value}
        batch_event = EventData(batch=batched())
        batch_event.application_properties = batch_app_prop

        await sender.send(batch_event)
    except:
        raise
    finally:
        await client.stop_async()

    time.sleep(1)

    received = []
    for r in receivers:
        received.extend(r.receive(timeout=3))

    assert len(received) == 20
    for index, message in enumerate(received):
        assert list(
            message.body)[0] == "Event number {}".format(index).encode('utf-8')
        assert (app_prop_key.encode('utf-8') in message.application_properties) \
            and (dict(message.application_properties)[app_prop_key.encode('utf-8')] == app_prop_value.encode('utf-8'))
Exemplo n.º 8
0
async def test_send_batch_with_app_prop_async(connstr_receivers):
    pytest.skip("Waiting on uAMQP release")
    connection_str, receivers = connstr_receivers

    def batched():
        for i in range(10):
            yield "Event number {}".format(i)
        for i in range(10, 20):
            yield EventData("Event number {}".format(i))

    client = EventHubClientAsync.from_connection_string(connection_str, debug=False)
    sender = client.add_async_sender()
    try:
        await client.run_async()

        app_prop_key = "raw_prop"
        app_prop_value = "raw_value"
        batch_app_prop = {app_prop_key:app_prop_value}
        batch_event = EventData(batch=batched())
        batch_event.application_properties = batch_app_prop

        await sender.send(batch_event)
    except:
        raise
    finally:
        await client.stop_async()

    time.sleep(1)

    received = []
    for r in receivers:
        received.extend(r.receive(timeout=3))

    assert len(received) == 20
    for index, message in enumerate(received):
        assert list(message.body)[0] == "Event number {}".format(index).encode('utf-8')
        assert (app_prop_key.encode('utf-8') in message.application_properties) \
            and (dict(message.application_properties)[app_prop_key.encode('utf-8')] == app_prop_value.encode('utf-8'))
Exemplo n.º 9
0
def test_app_properties():
    app_props = {"a": "b"}
    event_data = EventData("")
    event_data.application_properties = app_props
    assert event_data.application_properties["a"] == "b"