BewareMyPower commented on code in PR #21091:
URL: https://github.com/apache/pulsar/pull/21091#discussion_r1312797218
##########
pulsar-broker/src/test/java/org/apache/pulsar/compaction/StrategicCompactionTest.java:
##########
@@ -148,24 +159,56 @@ public void testNumericOrderCompaction() throws Exception
{
Assert.assertEquals(tableView.entrySet(), expectedCopy.entrySet());
}
- @Override
- public void testCompactCompressedBatching() throws Exception {
- compactor = new StrategicTwoPhaseCompactor(conf, pulsarClient, bk,
compactionScheduler, 10);
- super.testCompactCompressedBatching();
- compactor = new StrategicTwoPhaseCompactor(conf, pulsarClient, bk,
compactionScheduler, 1);
- }
+ @Test(timeOut = 20000)
+ public void testSameBatchCompactToSameBatch() throws Exception {
+ final String topic =
+
"persistent://my-property/use/my-ns/testSameBatchCompactToSameBatch" +
UUID.randomUUID();
- @Override
- public void testCompactEncryptedAndCompressedBatching() throws Exception {
- compactor = new StrategicTwoPhaseCompactor(conf, pulsarClient, bk,
compactionScheduler, 10);
- super.testCompactEncryptedAndCompressedBatching();
- compactor = new StrategicTwoPhaseCompactor(conf, pulsarClient, bk,
compactionScheduler, 1);
- }
+ final int messages = 10;
+
+ // 1.create producer and publish message to the topic.
+ ProducerBuilder<Integer> builder =
pulsarClient.newProducer(Schema.INT32)
+ .compressionType(MSG_COMPRESSION_TYPE).topic(topic);
+ builder.batchingMaxMessages(2)
+ .batchingMaxPublishDelay(10, TimeUnit.MILLISECONDS);
+
+ Producer<Integer> producer = builder.create();
+
+ List<CompletableFuture<MessageId>> futures = new ArrayList<>(messages);
+ for (int i = 0; i < messages; i++) {
+ futures.add(producer.newMessage().key(String.valueOf(i))
+ .value(i)
+ .sendAsync());
+ }
+
+ FutureUtil.waitForAll(futures).get();
+
+ // 2.compact the topic.
+ StrategicTwoPhaseCompactor compactor
+ = new StrategicTwoPhaseCompactor(conf, pulsarClient, bk,
compactionScheduler);
+ compactor.compact(topic, strategy).get();
+
+ // consumer with readCompacted enabled only get compacted entries
+ try (Consumer<Integer> consumer = pulsarClient
+ .newConsumer(Schema.INT32)
+ .topic(topic)
+ .subscriptionName("sub1")
+ .readCompacted(true)
+
.subscriptionInitialPosition(SubscriptionInitialPosition.Earliest).subscribe())
{
+ int received = 0;
+ while(true) {
+ Message<Integer> m = consumer.receive(2, TimeUnit.SECONDS);
+ if (m == null) {
+ break;
+ }
+ MessageIdImpl messageId = (MessageIdImpl) m.getMessageId();
Review Comment:
Use `MessageIdAdv` here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]