BewareMyPower commented on code in PR #21091:
URL: https://github.com/apache/pulsar/pull/21091#discussion_r1312811572


##########
pulsar-broker/src/test/java/org/apache/pulsar/compaction/StrategicCompactionTest.java:
##########
@@ -148,24 +160,65 @@ 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());
+        }
+        // Add additional message to make sure the last batch is not full and 
test flush this batch.
+        futures.add(producer.newMessage().key(String.valueOf(messages))
+                .value(messages)
+                .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) {

Review Comment:
   ```suggestion
               while (true) {
   ```



##########
pulsar-broker/src/test/java/org/apache/pulsar/compaction/StrategicCompactionTest.java:
##########
@@ -148,24 +160,65 @@ 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());
+        }
+        // Add additional message to make sure the last batch is not full and 
test flush this batch.

Review Comment:
   It seems to be equivalent with
   
   ```java
   for (int i = 0; i < messages + 1; i++) {
       /* ... */
   }
   ```
   
   So why not use use `messages + 1` as the `messages`?



-- 
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]

Reply via email to