Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use max number of bytes and not max number of messages in Pub/Sub message size check #27017

Merged
merged 1 commit into from
Jun 6, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -1410,7 +1410,7 @@ public void startBundle(StartBundleContext c) throws IOException {
public void processElement(@Element PubsubMessage message, @Timestamp Instant timestamp)
throws IOException, SizeLimitExceededException {
// Validate again here just as a sanity check.
PreparePubsubWriteDoFn.validatePubsubMessageSize(message, maxPublishBatchSize);
PreparePubsubWriteDoFn.validatePubsubMessageSize(message, maxPublishBatchByteSize);
byte[] payload = message.getPayload();
int messageSize = payload.length;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import org.apache.avro.Schema;
import org.apache.avro.generic.GenericRecord;
import org.apache.avro.reflect.AvroSchema;
Expand Down Expand Up @@ -742,4 +743,39 @@ public void testDynamicTopics(boolean isBounded) throws IOException {
pipeline.run();
}
}

@Test
public void testBigMessageBounded() throws IOException {
String bigMsg =
IntStream.range(0, 100_000).mapToObj(_unused -> "x").collect(Collectors.joining(""));

OutgoingMessage msg =
OutgoingMessage.of(
com.google.pubsub.v1.PubsubMessage.newBuilder()
.setData(ByteString.copyFromUtf8(bigMsg))
.build(),
0,
null,
"projects/project/topics/topic1");

try (PubsubTestClientFactory factory =
PubsubTestClient.createFactoryForPublish(null, ImmutableList.of(msg), ImmutableList.of())) {
TimestampedValue<PubsubMessage> pubsubMsg =
TimestampedValue.of(
new PubsubMessage(
msg.getMessage().getData().toByteArray(),
Collections.emptyMap(),
msg.recordId())
.withTopic(msg.topic()),
Instant.ofEpochMilli(msg.getTimestampMsSinceEpoch()));

PCollection<PubsubMessage> messages =
pipeline.apply(
Create.timestamped(ImmutableList.of(pubsubMsg))
.withCoder(new PubsubMessageWithTopicCoder()));
messages.setIsBoundedInternal(PCollection.IsBounded.BOUNDED);
messages.apply(PubsubIO.writeMessagesDynamic().withClientFactory(factory));
pipeline.run();
}
}
}