Skip to content

Commit

Permalink
Update name to state (Azure#22991)
Browse files Browse the repository at this point in the history
* Update name to state

* async
  • Loading branch information
rakshith91 authored Feb 10, 2022
1 parent 3cdd31d commit 1e60360
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions sdk/servicebus/azure-servicebus/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Release History

## 7.6.0 (Unreleased)
## 7.6.0 (2022-02-10)

### Features Added

- Introduce `ServiceBusMessageState` enum that can assume the values of `active`, `scheduled` or `deferred`.
- Add `ServiceBusMessageState` property in `ServiceBusReceivedMessage`.
- Add `state` property in `ServiceBusReceivedMessage`.

### Breaking Changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -970,13 +970,13 @@ def dead_letter_source(self):
return None

@property
def message_state(self):
# type: () -> int
def state(self):
# type: () -> ServiceBusMessageState
"""
Defaults to Active. Represents the message state of the message. Can be Active, Deferred.
or Scheduled.
:rtype: int
:rtype: ~azure.servicebus.ServiceBusMessageState
"""
try:
message_state = self._raw_amqp_message.annotations.get(MESSAGE_STATE_NAME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2131,7 +2131,7 @@ async def test_queue_async_send_amqp_annotated_message(self, servicebus_namespac
@CachedResourceGroupPreparer(name_prefix='servicebustest')
@CachedServiceBusNamespacePreparer(name_prefix='servicebustest')
@ServiceBusQueuePreparer(name_prefix='servicebustest', dead_lettering_on_message_expiration=True)
async def test_message_state_scheduled_async(self, servicebus_namespace_connection_string, servicebus_queue, **kwargs):
async def test_state_scheduled_async(self, servicebus_namespace_connection_string, servicebus_queue, **kwargs):
async with ServiceBusClient.from_connection_string(
servicebus_namespace_connection_string) as sb_client:

Expand All @@ -2146,15 +2146,15 @@ async def test_message_state_scheduled_async(self, servicebus_namespace_connecti
async with receiver:
messages = await receiver.peek_messages()
for msg in messages:
assert msg.message_state == ServiceBusMessageState.SCHEDULED
assert msg.state == ServiceBusMessageState.SCHEDULED


@pytest.mark.liveTest
@pytest.mark.live_test_only
@CachedResourceGroupPreparer(name_prefix='servicebustest')
@CachedServiceBusNamespacePreparer(name_prefix='servicebustest')
@ServiceBusQueuePreparer(name_prefix='servicebustest', dead_lettering_on_message_expiration=True)
async def test_message_state_deferred_async(self, servicebus_namespace_connection_string, servicebus_queue, **kwargs):
async def test_state_deferred_async(self, servicebus_namespace_connection_string, servicebus_queue, **kwargs):
async with ServiceBusClient.from_connection_string(
servicebus_namespace_connection_string) as sb_client:

Expand All @@ -2169,12 +2169,12 @@ async def test_message_state_deferred_async(self, servicebus_namespace_connectio
async with receiver:
received_msgs = await receiver.receive_messages()
for message in received_msgs:
assert message.message_state == ServiceBusMessageState.ACTIVE
assert message.state == ServiceBusMessageState.ACTIVE
deferred_messages.append(message.sequence_number)
await receiver.defer_message(message)
if deferred_messages:
received_deferred_msg = await receiver.receive_deferred_messages(
sequence_numbers=deferred_messages
)
for message in received_deferred_msg:
assert message.message_state == ServiceBusMessageState.DEFERRED
assert message.state == ServiceBusMessageState.DEFERRED
12 changes: 6 additions & 6 deletions sdk/servicebus/azure-servicebus/tests/test_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_servicebus_received_message_repr():
assert "content_type=None, correlation_id=None, to=None, reply_to=None, reply_to_session_id=None, subject=None,"
assert "partition_key=r_key, scheduled_enqueue_time_utc" in repr_str

def test_servicebus_received_message_state():
def test_servicebus_received_state():
uamqp_received_message = uamqp.message.Message(
body=b'data',
annotations={
Expand All @@ -65,7 +65,7 @@ def test_servicebus_received_message_state():
properties=uamqp.message.MessageProperties()
)
received_message = ServiceBusReceivedMessage(uamqp_received_message, receiver=None)
assert received_message.message_state == 3
assert received_message.state == 3

uamqp_received_message = uamqp.message.Message(
body=b'data',
Expand All @@ -75,7 +75,7 @@ def test_servicebus_received_message_state():
properties=uamqp.message.MessageProperties()
)
received_message = ServiceBusReceivedMessage(uamqp_received_message, receiver=None)
assert received_message.message_state == ServiceBusMessageState.DEFERRED
assert received_message.state == ServiceBusMessageState.DEFERRED

uamqp_received_message = uamqp.message.Message(
body=b'data',
Expand All @@ -84,14 +84,14 @@ def test_servicebus_received_message_state():
properties=uamqp.message.MessageProperties()
)
received_message = ServiceBusReceivedMessage(uamqp_received_message, receiver=None)
assert received_message.message_state == ServiceBusMessageState.ACTIVE
assert received_message.state == ServiceBusMessageState.ACTIVE

uamqp_received_message = uamqp.message.Message(
body=b'data',
properties=uamqp.message.MessageProperties()
)
received_message = ServiceBusReceivedMessage(uamqp_received_message, receiver=None)
assert received_message.message_state == ServiceBusMessageState.ACTIVE
assert received_message.state == ServiceBusMessageState.ACTIVE

uamqp_received_message = uamqp.message.Message(
body=b'data',
Expand All @@ -101,7 +101,7 @@ def test_servicebus_received_message_state():
properties=uamqp.message.MessageProperties()
)
received_message = ServiceBusReceivedMessage(uamqp_received_message, receiver=None)
assert received_message.message_state == ServiceBusMessageState.ACTIVE
assert received_message.state == ServiceBusMessageState.ACTIVE

def test_servicebus_received_message_repr_with_props():
uamqp_received_message = uamqp.message.Message(
Expand Down
10 changes: 5 additions & 5 deletions sdk/servicebus/azure-servicebus/tests/test_queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -2590,7 +2590,7 @@ def test_queue_send_amqp_annotated_message(self, servicebus_namespace_connection
@CachedResourceGroupPreparer(name_prefix='servicebustest')
@CachedServiceBusNamespacePreparer(name_prefix='servicebustest')
@ServiceBusQueuePreparer(name_prefix='servicebustest', dead_lettering_on_message_expiration=True)
def test_message_state_scheduled(self, servicebus_namespace_connection_string, servicebus_queue, **kwargs):
def test_state_scheduled(self, servicebus_namespace_connection_string, servicebus_queue, **kwargs):
with ServiceBusClient.from_connection_string(
servicebus_namespace_connection_string) as sb_client:

Expand All @@ -2603,15 +2603,15 @@ def test_message_state_scheduled(self, servicebus_namespace_connection_string, s
receiver = sb_client.get_queue_receiver(servicebus_queue.name)
with receiver:
for msg in receiver.peek_messages():
assert msg.message_state == ServiceBusMessageState.SCHEDULED
assert msg.state == ServiceBusMessageState.SCHEDULED


@pytest.mark.liveTest
@pytest.mark.live_test_only
@CachedResourceGroupPreparer(name_prefix='servicebustest')
@CachedServiceBusNamespacePreparer(name_prefix='servicebustest')
@ServiceBusQueuePreparer(name_prefix='servicebustest', dead_lettering_on_message_expiration=True)
def test_message_state_deferred(self, servicebus_namespace_connection_string, servicebus_queue, **kwargs):
def test_state_deferred(self, servicebus_namespace_connection_string, servicebus_queue, **kwargs):
with ServiceBusClient.from_connection_string(
servicebus_namespace_connection_string) as sb_client:

Expand All @@ -2625,12 +2625,12 @@ def test_message_state_deferred(self, servicebus_namespace_connection_string, se
with receiver:
received_msgs = receiver.receive_messages()
for message in received_msgs:
assert message.message_state == ServiceBusMessageState.ACTIVE
assert message.state == ServiceBusMessageState.ACTIVE
deferred_messages.append(message.sequence_number)
receiver.defer_message(message)
if deferred_messages:
received_deferred_msg = receiver.receive_deferred_messages(
sequence_numbers=deferred_messages
)
for message in received_deferred_msg:
assert message.message_state == ServiceBusMessageState.DEFERRED
assert message.state == ServiceBusMessageState.DEFERRED

0 comments on commit 1e60360

Please sign in to comment.