From 5706f8667af285f4c269aeee670d4479ebcbe737 Mon Sep 17 00:00:00 2001 From: feynmanlin <315157973@qq.com> Date: Sun, 4 Feb 2024 09:33:39 +0800 Subject: [PATCH] [fix] [test] fix flaky test testPerTopicExpiredStat --- .../pulsar/broker/stats/PrometheusMetricsTest.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/stats/PrometheusMetricsTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/stats/PrometheusMetricsTest.java index c2cacac56ca40..d3891931496c5 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/stats/PrometheusMetricsTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/stats/PrometheusMetricsTest.java @@ -32,9 +32,9 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.lang.reflect.Field; +import java.math.BigDecimal; import java.math.RoundingMode; import java.nio.charset.StandardCharsets; -import java.text.NumberFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -727,14 +727,13 @@ public void testPerTopicExpiredStat() throws Exception { //check value field = PersistentSubscription.class.getDeclaredField("expiryMonitor"); field.setAccessible(true); - NumberFormat nf = NumberFormat.getNumberInstance(); - nf.setMaximumFractionDigits(3); - nf.setRoundingMode(RoundingMode.DOWN); for (int i = 0; i < topicList.size(); i++) { PersistentSubscription subscription = (PersistentSubscription) pulsar.getBrokerService() .getTopicIfExists(topicList.get(i)).get().get().getSubscription(subName); PersistentMessageExpiryMonitor monitor = (PersistentMessageExpiryMonitor) field.get(subscription); - assertEquals(Double.valueOf(nf.format(monitor.getMessageExpiryRate())).doubleValue(), cm.get(i).value); + BigDecimal bigDecimal = BigDecimal.valueOf(monitor.getMessageExpiryRate()); + bigDecimal = bigDecimal.setScale(3, RoundingMode.DOWN); + assertEquals(bigDecimal.doubleValue(), cm.get(i).value); } cm = (List) metrics.get("pulsar_subscription_total_msg_expired");