You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by xi...@apache.org on 2022/12/14 03:54:20 UTC

[pulsar] branch branch-2.10 updated: [fix][flaky-test]ManagedCursorMetricsTest.testManagedCursorMetrics (#16878)

This is an automated email from the ASF dual-hosted git repository.

xiangying pushed a commit to branch branch-2.10
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/branch-2.10 by this push:
     new 3a7834772a6 [fix][flaky-test]ManagedCursorMetricsTest.testManagedCursorMetrics (#16878)
3a7834772a6 is described below

commit 3a7834772a6f784ed4b706be499c4a1106c12150
Author: fengyubiao <yu...@streamnative.io>
AuthorDate: Wed Aug 3 12:08:44 2022 +0800

    [fix][flaky-test]ManagedCursorMetricsTest.testManagedCursorMetrics (#16878)
    
    (cherry picked from commit a8231a4f821b360d7469685c77268d9591fb072d)
---
 .../broker/stats/ManagedCursorMetricsTest.java      | 21 ++-------------------
 1 file changed, 2 insertions(+), 19 deletions(-)

diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/stats/ManagedCursorMetricsTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/stats/ManagedCursorMetricsTest.java
index dbd40dc3d7c..c51ec263e17 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/stats/ManagedCursorMetricsTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/stats/ManagedCursorMetricsTest.java
@@ -21,7 +21,6 @@ package org.apache.pulsar.broker.stats;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.UUID;
-import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
 import lombok.Cleanup;
 import org.apache.bookkeeper.client.LedgerHandle;
@@ -144,7 +143,7 @@ public class ManagedCursorMetricsTest extends MockedPulsarServiceBaseTest {
         // Assert.
         metricsList = metrics.generate();
         Assert.assertFalse(metricsList.isEmpty());
-        Assert.assertNotEquals(metricsList.get(0).getMetrics().get("brk_ml_cursor_persistLedgerSucceed"), 1L);
+        Assert.assertNotEquals(metricsList.get(0).getMetrics().get("brk_ml_cursor_persistLedgerSucceed"), 0L);
         Assert.assertEquals(metricsList.get(0).getMetrics().get("brk_ml_cursor_persistLedgerErrors"), 0L);
         Assert.assertEquals(metricsList.get(0).getMetrics().get("brk_ml_cursor_persistZookeeperSucceed"), 0L);
         Assert.assertEquals(metricsList.get(0).getMetrics().get("brk_ml_cursor_persistZookeeperErrors"), 0L);
@@ -160,7 +159,7 @@ public class ManagedCursorMetricsTest extends MockedPulsarServiceBaseTest {
         // Assert.
         metricsList = metrics.generate();
         Assert.assertFalse(metricsList.isEmpty());
-        Assert.assertNotEquals(metricsList.get(0).getMetrics().get("brk_ml_cursor_persistLedgerSucceed"), 1L);
+        Assert.assertNotEquals(metricsList.get(0).getMetrics().get("brk_ml_cursor_persistLedgerSucceed"), 0L);
         Assert.assertEquals(metricsList.get(0).getMetrics().get("brk_ml_cursor_persistLedgerErrors"), 0L);
         Assert.assertEquals(metricsList.get(0).getMetrics().get("brk_ml_cursor_persistZookeeperSucceed"), 0L);
         Assert.assertEquals(metricsList.get(0).getMetrics().get("brk_ml_cursor_persistZookeeperErrors"), 0L);
@@ -203,15 +202,6 @@ public class ManagedCursorMetricsTest extends MockedPulsarServiceBaseTest {
         admin.topics().delete(topicName, true);
     }
 
-    private ManagedCursorMXBean getManagedCursorMXBean(String topicName, String subscriptionName)
-            throws ExecutionException, InterruptedException {
-        final PersistentSubscription persistentSubscription =
-                (PersistentSubscription) pulsar.getBrokerService()
-                        .getTopic(topicName, false).get().get().getSubscription(subscriptionName);
-        final ManagedCursorImpl managedCursor = (ManagedCursorImpl) persistentSubscription.getCursor();
-        return managedCursor.getStats();
-    }
-
     @Test
     public void testCursorReadWriteMetrics() throws Exception {
         final String subName1 = "read-write-sub-1";
@@ -257,13 +247,6 @@ public class ManagedCursorMetricsTest extends MockedPulsarServiceBaseTest {
                 consumer2.acknowledge(consumer.receive().getMessageId());
             }
         }
-
-        // Wait for persistent cursor meta.
-        ManagedCursorMXBean cursorMXBean1 = getManagedCursorMXBean(topicName, subName1);
-        ManagedCursorMXBean cursorMXBean2 = getManagedCursorMXBean(topicName, subName2);
-        Awaitility.await().until(() -> cursorMXBean1.getWriteCursorLedgerLogicalSize() > 0);
-        Awaitility.await().until(() -> cursorMXBean2.getWriteCursorLedgerLogicalSize() > 0);
-
         metricsList = metrics.generate();
         Assert.assertEquals(metricsList.size(), 2);
         Assert.assertNotEquals(metricsList.get(0).getMetrics().get("brk_ml_cursor_writeLedgerSize"), 0L);