diff --git a/common/src/test/java/org/astraea/common/metrics/collector/MetricSensorTest.java b/common/src/test/java/org/astraea/common/metrics/collector/MetricSensorTest.java index 12a926e073..123239caea 100644 --- a/common/src/test/java/org/astraea/common/metrics/collector/MetricSensorTest.java +++ b/common/src/test/java/org/astraea/common/metrics/collector/MetricSensorTest.java @@ -57,7 +57,15 @@ void testNoSwallowException() { (client, ignored) -> { throw new RuntimeException("xxx"); }; - var sensor = MetricSensor.of(List.of(badMetricSensor, goodMetricSensor)).get(); + var sensor = + MetricSensor.of( + List.of(badMetricSensor, goodMetricSensor), + e -> { + if (e instanceof RuntimeException) { + throw new RuntimeException(); + } + }) + .get(); Assertions.assertThrows( RuntimeException.class, () -> sensor.fetch(Mockito.mock(MBeanClient.class), ClusterBean.EMPTY)); @@ -82,11 +90,20 @@ void testSensorsWithExceptionHandler() { Assertions.assertEquals( 1, sensor.fetch(Mockito.mock(MBeanClient.class), ClusterBean.EMPTY).size()); - Assertions.assertThrows( - RuntimeException.class, + Assertions.assertDoesNotThrow( () -> MetricSensor.of(List.of(metricSensor0, metricSensor2)) .get() .fetch(Mockito.mock(MBeanClient.class), ClusterBean.EMPTY)); + Assertions.assertThrows( + NoSuchElementException.class, + () -> + MetricSensor.of( + List.of(metricSensor1, metricSensor2), + e -> { + if (e instanceof NoSuchElementException) throw new NoSuchElementException(); + }) + .get() + .fetch(Mockito.mock(MBeanClient.class), ClusterBean.EMPTY)); } }