Skip to content
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 @@ -237,7 +237,7 @@ public void testRetentionPolicyByProducingMessages() throws Exception {

@Test
public void testProducerCompressionMinMsgBodySize() throws PulsarClientException {
byte[] msg1022 = new byte[1022];
byte[] msg1024 = new byte[1024];
byte[] msg1025 = new byte[1025];
final String topicName = BrokerTestUtil.newUniqueName("persistent://my-property/my-ns/tp_");
@Cleanup
Expand All @@ -256,7 +256,7 @@ public void testProducerCompressionMinMsgBodySize() throws PulsarClientException
producer.conf.setCompressionType(CompressionType.LZ4);
// disable batch
producer.conf.setBatchingEnabled(false);
producer.newMessage().value(msg1022).send();
producer.newMessage().value(msg1024).send();
MessageImpl<byte[]> message = (MessageImpl<byte[]>) consumer.receive();
CompressionType compressionType = message.getCompressionType();
assertEquals(compressionType, CompressionType.NONE);
Expand All @@ -267,13 +267,28 @@ public void testProducerCompressionMinMsgBodySize() throws PulsarClientException

// enable batch
producer.conf.setBatchingEnabled(true);
producer.newMessage().value(msg1022).send();
producer.newMessage().value(msg1024).send();
message = (MessageImpl<byte[]>) consumer.receive();
compressionType = message.getCompressionType();
assertEquals(compressionType, CompressionType.NONE);
producer.newMessage().value(msg1025).send();
message = (MessageImpl<byte[]>) consumer.receive();
compressionType = message.getCompressionType();
assertEquals(compressionType, CompressionType.LZ4);

// Verify data integrity
String data = "compression test message";
producer.conf.setBatchingEnabled(true);
producer.getConfiguration().setCompressMinMsgBodySize(1);
producer.newMessage().value(data.getBytes()).send();
message = (MessageImpl<byte[]>) consumer.receive();
assertEquals(new String(message.getData()), data);

producer.conf.setBatchingEnabled(false);
producer.getConfiguration().setCompressMinMsgBodySize(1);
producer.newMessage().value(data.getBytes()).send();
message = (MessageImpl<byte[]>) consumer.receive();
assertEquals(new String(message.getData()), data);
Comment thread
liangyepianzhou marked this conversation as resolved.

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -542,10 +542,8 @@ public void sendAsync(Message<?> message, SendCallback callback) {
boolean compressed = false;
// Batch will be compressed when closed
// If a message has a delayed delivery time, we'll always send it individually
if (((!isBatchMessagingEnabled() || msgMetadata.hasDeliverAtTime()))) {
if (payload.readableBytes() < conf.getCompressMinMsgBodySize()) {

} else {
if (!isBatchMessagingEnabled() || msgMetadata.hasDeliverAtTime()) {
if (payload.readableBytes() > conf.getCompressMinMsgBodySize()) {
compressedPayload = applyCompression(payload);
compressed = true;

Expand Down