From f4183e377655bdfc67a7eed48b936d67a5c62fc6 Mon Sep 17 00:00:00 2001 From: Chia-Ping Tsai Date: Fri, 5 Aug 2022 15:13:59 +0800 Subject: [PATCH] Fix NodeLatencyCostTest#testCost --- .../astraea/app/cost/NodeLatencyCostTest.java | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/app/src/test/java/org/astraea/app/cost/NodeLatencyCostTest.java b/app/src/test/java/org/astraea/app/cost/NodeLatencyCostTest.java index 187598abd9..bbb4ef899e 100644 --- a/app/src/test/java/org/astraea/app/cost/NodeLatencyCostTest.java +++ b/app/src/test/java/org/astraea/app/cost/NodeLatencyCostTest.java @@ -71,18 +71,22 @@ void testCost() { producer.sender().topic(Utils.randomString(10)).value(new byte[100]).run(); producer.flush(); - var beans = ProducerMetrics.nodes(MBeanClient.local()); - var clusterBean = - ClusterBean.of( - Map.of( - -1, - beans.stream() - .map(b -> (HasBeanObject) b) - .collect(Collectors.toUnmodifiableList()))); - var clusterInfo = Mockito.mock(ClusterInfo.class); var function = new NodeLatencyCost(); - var cost = function.brokerCost(clusterInfo, clusterBean); - Assertions.assertEquals(1, cost.value().size()); + + Utils.waitFor( + () -> + function + .brokerCost( + Mockito.mock(ClusterInfo.class), + ClusterBean.of( + Map.of( + -1, + ProducerMetrics.nodes(MBeanClient.local()).stream() + .map(b -> (HasBeanObject) b) + .collect(Collectors.toUnmodifiableList())))) + .value() + .size() + >= 1); } }