sijie commented on a change in pull request #6051: Expose lastConsumedTimestamp 
and lastAckedTimestamp to consumer stats
URL: https://github.com/apache/pulsar/pull/6051#discussion_r368249383
 
 

 ##########
 File path: 
pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiTest2.java
 ##########
 @@ -948,4 +952,98 @@ public void testCreateNamespaceWithNoClusters() throws 
PulsarAdminException {
         
assertEquals(admin.namespaces().getNamespaceReplicationClusters(namespace),
                 Collections.singletonList(localCluster));
     }
+
+    @Test(timeOut = 30000)
+    public void testConsumerStatsLastTimestamp() throws PulsarClientException, 
PulsarAdminException, InterruptedException {
+        long timestamp = System.currentTimeMillis();
+        final String topicName = "consumer-stats-" + timestamp;
+        final String subscribeName = topicName + "-test-stats-sub";
+        final String topic = "persistent://prop-xyz/ns1/" + topicName;
+        final String producerName = "producer-" + topicName;
+
+        @Cleanup
+        PulsarClient client = 
PulsarClient.builder().serviceUrl(pulsar.getWebServiceAddress()).build();
+        Producer<byte[]> producer = client.newProducer().topic(topic)
+            .enableBatching(false)
+            .producerName(producerName)
+            .create();
+
+        // a. Send a message to the topic.
+        producer.send("message-1".getBytes(StandardCharsets.UTF_8));
+
+        // b. Create a consumer, because there was a message in the topic, the 
consumer will receive the message pushed
+        // by the broker, the lastConsumedTimestamp will as the consume 
subscribe time.
+        Consumer<byte[]> consumer = client.newConsumer().topic(topic)
+            .subscriptionName(subscribeName)
+            .subscriptionInitialPosition(SubscriptionInitialPosition.Earliest)
+            .subscribe();
+
+        // Get the consumer stats.
+        TopicStats topicStats = admin.topics().getStats(topic);
 
 Review comment:
   don't you need to call `#receive` to ensure the message is dispatched to the 
consumer? Otherwise this can easily become a flaky test.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to