16
16
package io .micrometer .jetty12 .client ;
17
17
18
18
import com .github .tomakehurst .wiremock .junit5 .WireMockRuntimeInfo ;
19
+ import io .micrometer .core .instrument .LongTaskTimer ;
19
20
import io .micrometer .core .instrument .observation .DefaultMeterObservationHandler ;
20
21
import io .micrometer .observation .ObservationRegistry ;
21
22
import io .micrometer .observation .tck .TestObservationRegistry ;
22
23
import org .junit .jupiter .api .BeforeEach ;
23
24
import org .junit .jupiter .api .Test ;
24
25
26
+ import java .time .Duration ;
27
+
25
28
import static com .github .tomakehurst .wiremock .client .WireMock .*;
26
29
import static java .util .concurrent .TimeUnit .SECONDS ;
27
30
import static org .assertj .core .api .Assertions .assertThat ;
31
+ import static org .awaitility .Awaitility .await ;
28
32
29
33
class JettyClientMetricsWithObservationTest extends JettyClientMetricsTest {
30
34
@@ -47,13 +51,31 @@ protected void addInstrumentingListener() {
47
51
48
52
@ Test
49
53
void activeTimer (WireMockRuntimeInfo wmRuntimeInfo ) throws Exception {
50
- stubFor (get ("/ok" ).willReturn (ok ()));
54
+ stubFor (get ("/ok" ).willReturn (ok ().withFixedDelay (100 )));
55
+
56
+ Thread thread = new Thread (() -> {
57
+ try {
58
+ httpClient .GET ("http://localhost:" + wmRuntimeInfo .getHttpPort () + "/ok" );
59
+ }
60
+ catch (Exception ex ) {
61
+ throw new RuntimeException (ex );
62
+ }
63
+ });
64
+ thread .start ();
65
+
66
+ await ().atMost (Duration .ofMillis (100 ))
67
+ .pollDelay (Duration .ofMillis (10 ))
68
+ .pollInterval (Duration .ofMillis (10 ))
69
+ .untilAsserted (() -> {
70
+ LongTaskTimer longTaskTimer = registry .find ("jetty.client.requests.active" )
71
+ .tags ("uri" , "/ok" , "method" , "GET" )
72
+ .longTaskTimer ();
73
+ assertThat (longTaskTimer ).isNotNull ();
74
+ assertThat (longTaskTimer .activeTasks ()).isOne ();
75
+ });
76
+
77
+ thread .join ();
51
78
52
- httpClient .GET ("http://localhost:" + wmRuntimeInfo .getHttpPort () + "/ok" );
53
- assertThat (registry .get ("jetty.client.requests.active" )
54
- .tags ("uri" , "/ok" , "method" , "GET" )
55
- .longTaskTimer ()
56
- .activeTasks ()).isOne ();
57
79
httpClient .stop ();
58
80
59
81
assertThat (singleRequestLatch .await (10 , SECONDS )).isTrue ();
0 commit comments