Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .chronus/changes/eventhub-receiver-link-max-message-size.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: internal
packages:
- azure-eventhub
---

The pyAMQP receiver link now sends a max message size of 0 (no limit) on its attach frame by default, matching the sender link. ([#42814](https://github.com/Azure/azure-sdk-for-python/issues/42814))
7 changes: 7 additions & 0 deletions .chronus/changes/servicebus-receiver-link-max-message-size.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: internal
packages:
- azure-servicebus
---

The pyAMQP receiver link now sends a max message size of 0 (no limit) on its attach frame by default, matching the sender link. ([#42814](https://github.com/Azure/azure-sdk-for-python/issues/42814))
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ def __init__(self, hostname, source, **kwargs):
self._message_received_callback = kwargs.pop("message_received_callback", None)

# Sender and Link settings
self._max_message_size = kwargs.pop("max_message_size", MAX_FRAME_SIZE_BYTES)
self._max_message_size = kwargs.pop("max_message_size", LINK_MAX_MESSAGE_SIZE)
self._link_properties = kwargs.pop("link_properties", None)
self._link_credit = kwargs.pop("link_credit", 300)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
from unittest.mock import AsyncMock, Mock

import pytest

from azure.eventhub._pyamqp.aio import SendClientAsync, ReceiveClientAsync
from azure.eventhub._pyamqp.aio._session_async import Session
from azure.eventhub._pyamqp.constants import LINK_MAX_MESSAGE_SIZE
from azure.eventhub._pyamqp.performatives import AttachFrame


# shadows conftest's autouse amqpproxy, which skips without a live Event Hub
@pytest.fixture(autouse=True)
def amqpproxy():
yield


@pytest.mark.asyncio
@pytest.mark.parametrize(
"kwargs, expected",
[({}, LINK_MAX_MESSAGE_SIZE), ({"max_message_size": 5 * 1024 * 1024}, 5 * 1024 * 1024)],
)
@pytest.mark.parametrize(
"cls, factory",
[(SendClientAsync, "create_sender_link"), (ReceiveClientAsync, "create_receiver_link")],
)
async def test_link_max_message_size_async(cls, factory, kwargs, expected):
client = cls("fake.host.com", "fake_eh", auth="my_fake_auth", **kwargs)
client._session = Mock()
getattr(client._session, factory).return_value = AsyncMock()

assert await client._client_ready_async() is False
assert getattr(client._session, factory).call_args.kwargs["max_message_size"] == expected


@pytest.mark.asyncio
@pytest.mark.parametrize(
"kwargs, expected",
[({}, 0), ({"max_message_size": 5 * 1024 * 1024}, 5 * 1024 * 1024)],
)
async def test_receiver_attach_frame_max_message_size_async(kwargs, expected):
client = ReceiveClientAsync("fake.host.com", "fake_eh", auth="my_fake_auth", **kwargs)
connection = AsyncMock()
client._session = Session(connection, 0, network_trace=False, network_trace_params={})

assert await client._client_ready_async() is False
frame = connection._process_outgoing_frame.call_args.args[1]
assert isinstance(frame, AttachFrame)
assert frame.max_message_size == expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
from unittest.mock import Mock

import pytest

from azure.eventhub._pyamqp import SendClient, ReceiveClient
from azure.eventhub._pyamqp.constants import LINK_MAX_MESSAGE_SIZE
from azure.eventhub._pyamqp.performatives import AttachFrame
from azure.eventhub._pyamqp.session import Session


# shadows conftest's autouse amqpproxy, which skips without a live Event Hub
@pytest.fixture(autouse=True)
def amqpproxy():
yield


@pytest.mark.parametrize(
"kwargs, expected",
[({}, LINK_MAX_MESSAGE_SIZE), ({"max_message_size": 5 * 1024 * 1024}, 5 * 1024 * 1024)],
)
@pytest.mark.parametrize(
"cls, factory",
[(SendClient, "create_sender_link"), (ReceiveClient, "create_receiver_link")],
)
def test_link_max_message_size(cls, factory, kwargs, expected):
client = cls("fake.host.com", "fake_eh", auth="my_fake_auth", **kwargs)
client._session = Mock()

assert client._client_ready() is False
assert getattr(client._session, factory).call_args.kwargs["max_message_size"] == expected


@pytest.mark.parametrize(
"kwargs, expected",
[({}, 0), ({"max_message_size": 5 * 1024 * 1024}, 5 * 1024 * 1024)],
)
def test_receiver_attach_frame_max_message_size(kwargs, expected):
client = ReceiveClient("fake.host.com", "fake_eh", auth="my_fake_auth", **kwargs)
connection = Mock()
client._session = Session(connection, 0, network_trace=False, network_trace_params={})

assert client._client_ready() is False
frame = connection._process_outgoing_frame.call_args.args[1]
assert isinstance(frame, AttachFrame)
assert frame.max_message_size == expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
from unittest.mock import AsyncMock, Mock

import pytest

from azure.eventhub import EventData
from azure.eventhub.aio import EventHubProducerClient
from azure.eventhub._constants import ALL_PARTITIONS, MAX_MESSAGE_LENGTH_BYTES

MB = 1024 * 1024


# shadows conftest's autouse amqpproxy, which skips without a live Event Hub
@pytest.fixture(autouse=True)
def amqpproxy():
yield


def _client_with_remote_max_message_size(remote):
client = EventHubProducerClient("fake.host.com", "fake_eh", None)
inner = client._producers[ALL_PARTITIONS]
inner._open_with_retry = AsyncMock()
inner._handler = Mock()
inner._handler._link.remote_max_message_size = remote
return client


@pytest.mark.asyncio
async def test_create_batch_uses_remote_max_message_size_async():
client = _client_with_remote_max_message_size(20 * MB)

batch = await client.create_batch()
assert batch.max_size_in_bytes == 20 * MB
batch.add(EventData(b"a" * (2 * MB)))
assert batch.size_in_bytes > MB

assert (await client.create_batch(max_size_in_bytes=5 * MB)).max_size_in_bytes == 5 * MB
await client.create_batch(max_size_in_bytes=20 * MB)
with pytest.raises(ValueError):
await client.create_batch(max_size_in_bytes=20 * MB + 1)


@pytest.mark.asyncio
@pytest.mark.parametrize("remote", [None, 0])
async def test_create_batch_falls_back_to_1mb_async(remote):
client = _client_with_remote_max_message_size(remote)

assert (await client.create_batch()).max_size_in_bytes == MAX_MESSAGE_LENGTH_BYTES
with pytest.raises(ValueError):
await client.create_batch(max_size_in_bytes=MB + 1)
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
from unittest.mock import Mock

import pytest

from azure.eventhub import EventData, EventHubProducerClient
from azure.eventhub._constants import ALL_PARTITIONS, MAX_MESSAGE_LENGTH_BYTES

MB = 1024 * 1024


# shadows conftest's autouse amqpproxy, which skips without a live Event Hub
@pytest.fixture(autouse=True)
def amqpproxy():
yield


def _client_with_remote_max_message_size(remote):
client = EventHubProducerClient("fake.host.com", "fake_eh", None)
inner = client._producers[ALL_PARTITIONS]
inner._open_with_retry = Mock()
inner._handler = Mock()
inner._handler._link.remote_max_message_size = remote
return client


def test_create_batch_uses_remote_max_message_size():
client = _client_with_remote_max_message_size(20 * MB)

batch = client.create_batch()
assert batch.max_size_in_bytes == 20 * MB
batch.add(EventData(b"a" * (2 * MB)))
assert batch.size_in_bytes > MB

assert client.create_batch(max_size_in_bytes=5 * MB).max_size_in_bytes == 5 * MB
client.create_batch(max_size_in_bytes=20 * MB)
with pytest.raises(ValueError):
client.create_batch(max_size_in_bytes=20 * MB + 1)


@pytest.mark.parametrize("remote", [None, 0])
def test_create_batch_falls_back_to_1mb(remote):
client = _client_with_remote_max_message_size(remote)

assert client.create_batch().max_size_in_bytes == MAX_MESSAGE_LENGTH_BYTES
with pytest.raises(ValueError):
client.create_batch(max_size_in_bytes=MB + 1)
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ def __init__(self, hostname, source, **kwargs):
self._message_received_callback = kwargs.pop("message_received_callback", None)

# Sender and Link settings
self._max_message_size = kwargs.pop("max_message_size", MAX_FRAME_SIZE_BYTES)
self._max_message_size = kwargs.pop("max_message_size", LINK_MAX_MESSAGE_SIZE)
self._link_properties = kwargs.pop("link_properties", None)
self._link_credit = kwargs.pop("link_credit", 300)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
from unittest.mock import AsyncMock, Mock

import pytest

from azure.servicebus._pyamqp import SendClient, ReceiveClient
from azure.servicebus._pyamqp.aio import SendClientAsync, ReceiveClientAsync
from azure.servicebus._pyamqp.aio._session_async import Session as SessionAsync
from azure.servicebus._pyamqp.constants import LINK_MAX_MESSAGE_SIZE
from azure.servicebus._pyamqp.performatives import AttachFrame
from azure.servicebus._pyamqp.session import Session

SIZE_CASES = [({}, LINK_MAX_MESSAGE_SIZE), ({"max_message_size": 5 * 1024 * 1024}, 5 * 1024 * 1024)]
ATTACH_SIZE_CASES = [({}, 0), ({"max_message_size": 5 * 1024 * 1024}, 5 * 1024 * 1024)]


@pytest.mark.parametrize("kwargs, expected", SIZE_CASES)
@pytest.mark.parametrize(
"cls, factory",
[(SendClient, "create_sender_link"), (ReceiveClient, "create_receiver_link")],
)
def test_link_max_message_size(cls, factory, kwargs, expected):
client = cls("fake.host.com", "fake_sb", auth="my_fake_auth", **kwargs)
client._session = Mock()

assert client._client_ready() is False
assert getattr(client._session, factory).call_args.kwargs["max_message_size"] == expected


@pytest.mark.asyncio
@pytest.mark.parametrize("kwargs, expected", SIZE_CASES)
@pytest.mark.parametrize(
"cls, factory",
[(SendClientAsync, "create_sender_link"), (ReceiveClientAsync, "create_receiver_link")],
)
async def test_link_max_message_size_async(cls, factory, kwargs, expected):
client = cls("fake.host.com", "fake_sb", auth="my_fake_auth", **kwargs)
client._session = Mock()
getattr(client._session, factory).return_value = AsyncMock()

assert await client._client_ready_async() is False
assert getattr(client._session, factory).call_args.kwargs["max_message_size"] == expected


@pytest.mark.parametrize("kwargs, expected", ATTACH_SIZE_CASES)
def test_receiver_attach_frame_max_message_size(kwargs, expected):
client = ReceiveClient("fake.host.com", "fake_sb", auth="my_fake_auth", **kwargs)
connection = Mock()
client._session = Session(connection, 0, network_trace=False, network_trace_params={})

assert client._client_ready() is False
frame = connection._process_outgoing_frame.call_args.args[1]
assert isinstance(frame, AttachFrame)
assert frame.max_message_size == expected


@pytest.mark.asyncio
@pytest.mark.parametrize("kwargs, expected", ATTACH_SIZE_CASES)
async def test_receiver_attach_frame_max_message_size_async(kwargs, expected):
client = ReceiveClientAsync("fake.host.com", "fake_sb", auth="my_fake_auth", **kwargs)
connection = AsyncMock()
client._session = SessionAsync(connection, 0, network_trace=False, network_trace_params={})

assert await client._client_ready_async() is False
frame = connection._process_outgoing_frame.call_args.args[1]
assert isinstance(frame, AttachFrame)
assert frame.max_message_size == expected
Loading