2020import java .io .PrintStream ;
2121
2222import io .helidon .metrics .api .Metrics ;
23+ import io .helidon .metrics .api .MetricsConfig ;
2324import io .helidon .metrics .api .MetricsFactory ;
2425
2526import org .junit .jupiter .api .AfterAll ;
3334import static org .hamcrest .Matchers .isEmptyString ;
3435
3536import static org .hamcrest .MatcherAssert .assertThat ;
37+ import static org .hamcrest .Matchers .not ;
3638
3739class TestMultipleRegistryLogging {
3840
@@ -65,15 +67,15 @@ static void afterAll() {
6567 }
6668
6769 @ Test
68- void testSingleRegistration () throws IOException {
70+ void testSingleRegistry () throws IOException {
6971 Metrics .globalRegistry ();
7072 testPrintStream .flush ();
7173 String output = baos .toString ();
7274 assertThat ("Single meter registry" , output , isEmptyString ());
7375 }
7476
7577 @ Test
76- void testTwoRegistrations () throws IOException {
78+ void testTwoRegistries () throws IOException {
7779 Metrics .globalRegistry ();
7880 Metrics .createMeterRegistry ();
7981 testPrintStream .flush ();
@@ -86,7 +88,7 @@ void testTwoRegistrations() throws IOException {
8688 }
8789
8890 @ Test
89- void testThreeRegistrations () throws IOException {
91+ void testThreeRegistries () throws IOException {
9092 Metrics .globalRegistry ();
9193 Metrics .createMeterRegistry ();
9294 Metrics .createMeterRegistry ();
@@ -100,4 +102,20 @@ void testThreeRegistrations() throws IOException {
100102 containsString ("Unexpected additional instantiation" )));
101103 }
102104
105+ @ Test
106+ void testTwoRegistriesWithWarningDisabled () {
107+ MetricsConfig configWithWarningsSuppressed = MetricsConfig .builder ().warnOnMultipleRegistries (false ).build ();
108+ Metrics .createMeterRegistry (configWithWarningsSuppressed );
109+ Metrics .createMeterRegistry (configWithWarningsSuppressed );
110+ testPrintStream .flush ();
111+
112+ String output = baos .toString ();
113+ assertThat ("Two meter registrations with warnings suppressed" , output , allOf (
114+ not (containsString ("Unexpected duplicate" )),
115+ not (containsString ("Original instantiation" )),
116+ not (containsString ("Additional instantiation" )),
117+ not (containsString ("Unexpected additional instantiation" ))));
118+
119+ }
120+
103121}
0 commit comments