Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from 2 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
26 changes: 0 additions & 26 deletions 26 google/cloud/pubsub_v1/publisher/_batch/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,32 +109,6 @@ def status(self):
"""
raise NotImplementedError

def will_accept(self, message):
"""Return True if the batch is able to accept the message.

In concurrent implementations, the attributes on the current batch
may be modified by other workers. With this in mind, the caller will
likely want to hold a lock that will make sure the state remains
the same after the "will accept?" question is answered.

Args:
message (~.pubsub_v1.types.PubsubMessage): The Pub/Sub message.

Returns:
bool: Whether this batch can accept the message.
"""
# If this batch is not accepting messages generally, return False.
if self.status != BatchStatus.ACCEPTING_MESSAGES:
return False
IlyaFaer marked this conversation as resolved.
Show resolved Hide resolved

# If this message will make the batch exceed the ``max_messages``
# setting, return False.
if len(self.messages) >= self.settings.max_messages:
return False

# Okay, everything is good.
return True

def cancel(self, cancellation_reason):
"""Complete pending futures with an exception.

Expand Down
4 changes: 2 additions & 2 deletions 4 google/cloud/pubsub_v1/publisher/_batch/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,8 @@ def publish(self, message):
self._status != base.BatchStatus.ERROR
), "Publish after stop() or publish error."

if not self.will_accept(message):
return future
if self.status != base.BatchStatus.ACCEPTING_MESSAGES:
return

size_increase = types.PublishRequest(messages=[message]).ByteSize()

Expand Down
30 changes: 0 additions & 30 deletions 30 tests/unit/pubsub_v1/publisher/batch/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,33 +46,3 @@ def test_len():
assert len(batch) == 0
batch.publish(types.PubsubMessage(data=b"foo"))
assert len(batch) == 1


def test_will_accept():
IlyaFaer marked this conversation as resolved.
Show resolved Hide resolved
batch = create_batch(status=BatchStatus.ACCEPTING_MESSAGES)
message = types.PubsubMessage()
assert batch.will_accept(message) is True


def test_will_accept_oversize():
batch = create_batch(
settings=types.BatchSettings(max_bytes=10),
status=BatchStatus.ACCEPTING_MESSAGES,
)
message = types.PubsubMessage(data=b"abcdefghijklmnopqrstuvwxyz")
assert batch.will_accept(message) is True


def test_will_not_accept_status():
batch = create_batch(status="talk to the hand")
message = types.PubsubMessage()
assert batch.will_accept(message) is False


def test_will_not_accept_number():
batch = create_batch(
settings=types.BatchSettings(max_messages=-1),
status=BatchStatus.ACCEPTING_MESSAGES,
)
message = types.PubsubMessage(data=b"abc")
assert batch.will_accept(message) is False
14 changes: 0 additions & 14 deletions 14 tests/unit/pubsub_v1/publisher/batch/test_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,20 +287,6 @@ def test_publish_updating_batch_size():
assert batch.size > 0 # I do not always trust protobuf.


def test_publish_not_will_accept():
IlyaFaer marked this conversation as resolved.
Show resolved Hide resolved
batch = create_batch(topic="topic_foo", max_messages=0)
base_request_size = types.PublishRequest(topic="topic_foo").ByteSize()

# Publish the message.
message = types.PubsubMessage(data=b"foobarbaz")
future = batch.publish(message)

assert future is None
assert batch.size == base_request_size
assert batch.messages == []
assert batch._futures == []


def test_publish_exceed_max_messages():
max_messages = 4
batch = create_batch(max_messages=max_messages)
Expand Down
3 changes: 0 additions & 3 deletions 3 tests/unit/pubsub_v1/publisher/test_publisher_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ def test_publish():
# Use a mock in lieu of the actual batch class.
batch = mock.Mock(spec=client._batch_class)
# Set the mock up to claim indiscriminately that it accepts all messages.
batch.will_accept.return_value = True
batch.publish.side_effect = (mock.sentinel.future1, mock.sentinel.future2)

topic = "topic/path"
Expand Down Expand Up @@ -185,7 +184,6 @@ def test_publish_attrs_bytestring():
# Use a mock in lieu of the actual batch class.
batch = mock.Mock(spec=client._batch_class)
# Set the mock up to claim indiscriminately that it accepts all messages.
batch.will_accept.return_value = True

topic = "topic/path"
client._set_batch(topic, batch)
Expand Down Expand Up @@ -391,7 +389,6 @@ def test_publish_with_ordering_key():
# Use a mock in lieu of the actual batch class.
batch = mock.Mock(spec=client._batch_class)
# Set the mock up to claim indiscriminately that it accepts all messages.
batch.will_accept.return_value = True
batch.publish.side_effect = (mock.sentinel.future1, mock.sentinel.future2)

topic = "topic/path"
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.