Skip to content

Commit

Permalink
Fix MetricSensor test (#1583)
Browse files Browse the repository at this point in the history
  • Loading branch information
harryteng9527 authored Mar 19, 2023
1 parent b4dab31 commit 2f2b6cf
Showing 1 changed file with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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));
}
}

0 comments on commit 2f2b6cf

Please sign in to comment.