1616
1717package org .springframework .boot .actuate .autoconfigure .metrics .web .jetty ;
1818
19- import java .time .Duration ;
20-
2119import io .micrometer .core .instrument .MeterRegistry ;
2220import io .micrometer .core .instrument .Tags ;
2321import io .micrometer .core .instrument .simple .SimpleMeterRegistry ;
3735import org .springframework .boot .web .embedded .jetty .JettyServletWebServerFactory ;
3836import org .springframework .boot .web .reactive .context .AnnotationConfigReactiveWebServerApplicationContext ;
3937import org .springframework .boot .web .servlet .context .AnnotationConfigServletWebServerApplicationContext ;
38+ import org .springframework .context .ConfigurableApplicationContext ;
4039import org .springframework .context .annotation .Bean ;
4140import org .springframework .context .annotation .Configuration ;
4241import org .springframework .http .server .reactive .HttpHandler ;
@@ -59,8 +58,7 @@ void autoConfiguresThreadPoolMetricsWithEmbeddedServletJetty() {
5958 ServletWebServerFactoryAutoConfiguration .class ))
6059 .withUserConfiguration (ServletWebServerConfiguration .class , MeterRegistryConfiguration .class )
6160 .run ((context ) -> {
62- context .publishEvent (new ApplicationStartedEvent (new SpringApplication (), null ,
63- context .getSourceApplicationContext (), Duration .ZERO ));
61+ context .publishEvent (createApplicationStartedEvent (context .getSourceApplicationContext ()));
6462 assertThat (context ).hasSingleBean (JettyServerThreadPoolMetricsBinder .class );
6563 SimpleMeterRegistry registry = context .getBean (SimpleMeterRegistry .class );
6664 assertThat (registry .find ("jetty.threads.config.min" ).meter ()).isNotNull ();
@@ -74,8 +72,7 @@ void autoConfiguresThreadPoolMetricsWithEmbeddedReactiveJetty() {
7472 ReactiveWebServerFactoryAutoConfiguration .class ))
7573 .withUserConfiguration (ReactiveWebServerConfiguration .class , MeterRegistryConfiguration .class )
7674 .run ((context ) -> {
77- context .publishEvent (new ApplicationStartedEvent (new SpringApplication (), null ,
78- context .getSourceApplicationContext (), Duration .ZERO ));
75+ context .publishEvent (createApplicationStartedEvent (context .getSourceApplicationContext ()));
7976 SimpleMeterRegistry registry = context .getBean (SimpleMeterRegistry .class );
8077 assertThat (registry .find ("jetty.threads.config.min" ).meter ()).isNotNull ();
8178 });
@@ -96,8 +93,7 @@ void autoConfiguresConnectionMetricsWithEmbeddedServletJetty() {
9693 ServletWebServerFactoryAutoConfiguration .class ))
9794 .withUserConfiguration (ServletWebServerConfiguration .class , MeterRegistryConfiguration .class )
9895 .run ((context ) -> {
99- context .publishEvent (new ApplicationStartedEvent (new SpringApplication (), null ,
100- context .getSourceApplicationContext (), Duration .ZERO ));
96+ context .publishEvent (createApplicationStartedEvent (context .getSourceApplicationContext ()));
10197 assertThat (context ).hasSingleBean (JettyConnectionMetricsBinder .class );
10298 SimpleMeterRegistry registry = context .getBean (SimpleMeterRegistry .class );
10399 assertThat (registry .find ("jetty.connections.messages.in" ).meter ()).isNotNull ();
@@ -111,8 +107,7 @@ void autoConfiguresConnectionMetricsWithEmbeddedReactiveJetty() {
111107 ReactiveWebServerFactoryAutoConfiguration .class ))
112108 .withUserConfiguration (ReactiveWebServerConfiguration .class , MeterRegistryConfiguration .class )
113109 .run ((context ) -> {
114- context .publishEvent (new ApplicationStartedEvent (new SpringApplication (), null ,
115- context .getSourceApplicationContext (), Duration .ZERO ));
110+ context .publishEvent (createApplicationStartedEvent (context .getSourceApplicationContext ()));
116111 SimpleMeterRegistry registry = context .getBean (SimpleMeterRegistry .class );
117112 assertThat (registry .find ("jetty.connections.messages.in" ).meter ()).isNotNull ();
118113 });
@@ -126,8 +121,7 @@ void allowsCustomJettyConnectionMetricsBinderToBeUsed() {
126121 .withUserConfiguration (ServletWebServerConfiguration .class , CustomJettyConnectionMetricsBinder .class ,
127122 MeterRegistryConfiguration .class )
128123 .run ((context ) -> {
129- context .publishEvent (new ApplicationStartedEvent (new SpringApplication (), null ,
130- context .getSourceApplicationContext (), Duration .ZERO ));
124+ context .publishEvent (createApplicationStartedEvent (context .getSourceApplicationContext ()));
131125 assertThat (context ).hasSingleBean (JettyConnectionMetricsBinder .class )
132126 .hasBean ("customJettyConnectionMetricsBinder" );
133127 SimpleMeterRegistry registry = context .getBean (SimpleMeterRegistry .class );
@@ -145,8 +139,7 @@ void autoConfiguresSslHandshakeMetricsWithEmbeddedServletJetty() {
145139 .withPropertyValues ("server.ssl.enabled: true" , "server.ssl.key-store: src/test/resources/test.jks" ,
146140 "server.ssl.key-store-password: secret" , "server.ssl.key-password: password" )
147141 .run ((context ) -> {
148- context .publishEvent (new ApplicationStartedEvent (new SpringApplication (), null ,
149- context .getSourceApplicationContext (), Duration .ZERO ));
142+ context .publishEvent (createApplicationStartedEvent (context .getSourceApplicationContext ()));
150143 assertThat (context ).hasSingleBean (JettySslHandshakeMetricsBinder .class );
151144 SimpleMeterRegistry registry = context .getBean (SimpleMeterRegistry .class );
152145 assertThat (registry .find ("jetty.ssl.handshakes" ).meter ()).isNotNull ();
@@ -162,8 +155,7 @@ void autoConfiguresSslHandshakeMetricsWithEmbeddedReactiveJetty() {
162155 .withPropertyValues ("server.ssl.enabled: true" , "server.ssl.key-store: src/test/resources/test.jks" ,
163156 "server.ssl.key-store-password: secret" , "server.ssl.key-password: password" )
164157 .run ((context ) -> {
165- context .publishEvent (new ApplicationStartedEvent (new SpringApplication (), null ,
166- context .getSourceApplicationContext (), Duration .ZERO ));
158+ context .publishEvent (createApplicationStartedEvent (context .getSourceApplicationContext ()));
167159 SimpleMeterRegistry registry = context .getBean (SimpleMeterRegistry .class );
168160 assertThat (registry .find ("jetty.ssl.handshakes" ).meter ()).isNotNull ();
169161 });
@@ -179,8 +171,7 @@ void allowsCustomJettySslHandshakeMetricsBinderToBeUsed() {
179171 .withPropertyValues ("server.ssl.enabled: true" , "server.ssl.key-store: src/test/resources/test.jks" ,
180172 "server.ssl.key-store-password: secret" , "server.ssl.key-password: password" )
181173 .run ((context ) -> {
182- context .publishEvent (new ApplicationStartedEvent (new SpringApplication (), null ,
183- context .getSourceApplicationContext (), Duration .ZERO ));
174+ context .publishEvent (createApplicationStartedEvent (context .getSourceApplicationContext ()));
184175 assertThat (context ).hasSingleBean (JettySslHandshakeMetricsBinder .class )
185176 .hasBean ("customJettySslHandshakeMetricsBinder" );
186177 SimpleMeterRegistry registry = context .getBean (SimpleMeterRegistry .class );
@@ -215,6 +206,10 @@ void doesNotAutoConfigureSslHandshakeMetricsWhenSslEnabledPropertySetToFalse() {
215206 .run ((context ) -> assertThat (context ).doesNotHaveBean (JettySslHandshakeMetricsBinder .class ));
216207 }
217208
209+ private ApplicationStartedEvent createApplicationStartedEvent (ConfigurableApplicationContext context ) {
210+ return new ApplicationStartedEvent (new SpringApplication (), null , context , null );
211+ }
212+
218213 @ Configuration (proxyBeanMethods = false )
219214 static class MeterRegistryConfiguration {
220215
0 commit comments