1616import io .opentelemetry .api .common .AttributeKey ;
1717import io .opentelemetry .api .trace .SpanKind ;
1818import io .opentelemetry .sdk .testing .assertj .SpanDataAssert ;
19+ import io .opentelemetry .sdk .trace .data .SpanData ;
1920import io .opentelemetry .semconv .ClientAttributes ;
2021import io .opentelemetry .semconv .NetworkAttributes ;
2122import io .opentelemetry .semconv .UrlAttributes ;
2627import io .opentelemetry .testing .internal .armeria .common .HttpMethod ;
2728import io .opentelemetry .testing .internal .armeria .common .RequestHeaders ;
2829import java .util .List ;
30+ import java .util .Optional ;
31+ import java .util .function .Consumer ;
32+
2933import org .junit .jupiter .api .AfterAll ;
3034import org .junit .jupiter .api .BeforeEach ;
3135import org .junit .jupiter .api .Test ;
@@ -152,14 +156,7 @@ void testStaticFileNotFound() {
152156
153157 assertThat (response .status ().code ()).isEqualTo (404 );
154158
155- testing ()
156- .waitAndAssertTraces (
157- trace ->
158- trace .hasSpansSatisfyingExactly (
159- span -> assertServerSpan (span , path ),
160- span ->
161- span .hasName ("HttpServletResponseWrapper.sendError" )
162- .hasKind (SpanKind .INTERNAL )));
159+ getAndAssertServerSpan (span -> assertServerSpan (span , path ));
163160 }
164161
165162 @ Test
@@ -169,9 +166,7 @@ void testRequestForWebInfWebXml() {
169166
170167 assertThat (response .status ().code ()).isEqualTo (404 );
171168
172- testing ()
173- .waitAndAssertTraces (
174- trace -> trace .hasSpansSatisfyingExactly (span -> assertServerSpan (span , path )));
169+ getAndAssertServerSpan (span -> assertServerSpan (span , path ));
175170 }
176171
177172 @ Test
@@ -203,9 +198,7 @@ void testRequestOutsideDeployedApplication() {
203198 var response = testing ().client ().get (path ).aggregate ().join ();
204199 assertThat (response .status ().code ()).isEqualTo (404 );
205200
206- testing ()
207- .waitAndAssertTraces (
208- trace -> trace .hasSpansSatisfyingExactly (span -> assertServerSpan (span , path )));
201+ getAndAssertServerSpan (span -> assertServerSpan (span , path ));
209202 }
210203
211204 @ Test
@@ -227,12 +220,7 @@ void jspSmokeTestForSnippetInjection() {
227220 .contains ("<script>console.log(hi)</script>" );
228221
229222 if (expectServerSpan ()) {
230- testing ()
231- .waitAndAssertTraces (
232- trace ->
233- trace .hasSpansSatisfyingExactly (
234- span -> span .hasName ("GET /app/jsp" ).hasKind (SpanKind .SERVER ),
235- span -> span .hasName ("Compile /test.jsp" ).hasKind (SpanKind .INTERNAL )));
223+ getAndAssertServerSpan (span -> span .hasName ("GET /app/jsp" ));
236224 }
237225 }
238226
@@ -272,4 +260,11 @@ private SpanDataAssert assertServerSpan(SpanDataAssert span, String path) {
272260 .hasKind (SpanKind .SERVER )
273261 .hasAttribute (UrlAttributes .URL_PATH , path );
274262 }
263+
264+ private void getAndAssertServerSpan (Consumer <SpanDataAssert > assertion ) {
265+ Optional <SpanData > serverSpan =
266+ testing ().spans ().stream ().filter (span -> span .getKind () == SpanKind .SERVER ).findFirst ();
267+
268+ assertThat (serverSpan ).hasValueSatisfying (span -> assertion .accept (assertThat (span )));
269+ }
275270}
0 commit comments