eolivelli commented on a change in pull request #11739:
URL: https://github.com/apache/pulsar/pull/11739#discussion_r695532911



##########
File path: 
pulsar-broker/src/test/java/org/apache/pulsar/broker/stats/CompactionMetricsTest.java
##########
@@ -0,0 +1,96 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.broker.stats;
+
+import lombok.Cleanup;
+import org.apache.pulsar.broker.service.BrokerTestBase;
+import org.apache.pulsar.broker.stats.metrics.CompactionMetrics;
+import org.apache.pulsar.client.api.MessageRoutingMode;
+import org.apache.pulsar.client.api.Producer;
+import org.apache.pulsar.common.stats.Metrics;
+import org.junit.Assert;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import java.util.List;
+import java.util.Random;
+
+@Test(groups = "broker")
+public class CompactionMetricsTest extends BrokerTestBase {
+
+    @BeforeClass
+    @Override
+    protected void setup() throws Exception {
+        super.baseSetup();
+    }
+
+    @AfterClass(alwaysRun = true)
+    @Override
+    protected void cleanup() throws Exception {
+        super.internalCleanup();
+    }
+
+    @Test
+    public void testCompactionMetrics() throws Exception {
+        pulsar.getCompactor(true);
+        CompactionMetrics metrics = new CompactionMetrics(pulsar);
+
+        final String compactionRemovedEventCountKey = 
"brk_compaction_removedEventCount";
+        final String compactionSucceedCountKey = "brk_compaction_succeedCount";
+        final String compactionFailedCountKey = "brk_compaction_failedCount";
+        final String compactionDurationTimeInMillsKey = 
"brk_compaction_durationTimeInMills";
+        final String compactionReadThroughputKey = 
"brk_compaction_readThroughput";
+        final String compactionWriteThroughputKey = 
"brk_compaction_writeThroughput";
+        List<Metrics> list1 = metrics.generate();
+        Assert.assertTrue(list1.isEmpty());
+
+        String topic = "persistent://my-property/use/my-ns/my-topic1";
+        final int numMessages = 1000;
+        final int maxKeys = 10;
+
+        @Cleanup
+        Producer<byte[]> producer = pulsarClient.newProducer().topic(topic)
+                .enableBatching(false)
+                .messageRoutingMode(MessageRoutingMode.SinglePartition)
+                .create();
+
+        Random r = new Random(0);
+
+        for (int j = 0; j < numMessages; j++) {
+            int keyIndex = r.nextInt(maxKeys);
+            String key = "key" + keyIndex;
+            byte[] data = ("my-message-" + key + "-" + j).getBytes();
+            producer.newMessage()
+                    .key(key)
+                    .value(data)
+                    .send();
+        }
+
+        pulsar.getCompactor(true).compact(topic).get();
+        List<Metrics> list2 = metrics.generate();
+        System.out.println(list2);

Review comment:
       nit: please remove System.out or use logger

##########
File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentTopic.java
##########
@@ -2120,6 +2115,15 @@ public TopicStatsImpl getStats(boolean 
getPreciseBacklog, boolean subscriptionBa
         return statFuture;
     }
 
+    public Optional<CompactedTopicImpl.CompactedTopicContext> 
getCompactedTopicContext() {

Review comment:
       exposing something named *Impl is a code smell.
   
   can we create an interface for `CompactedTopicContext` ?




-- 
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: commits-unsubscr...@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to