@@ -148,197 +148,52 @@ void smokeTest() {
148148 @ Test
149149 void testStaticFileFound () {
150150 var response = testing ().client ().get ("/app/hello.txt" ).aggregate ().join ();
151- List <SpanData > spans = testing ().spans ();
152- Set <String > traceIds = testing ().getSpanTraceIds ();
153- String responseBody = response .contentUtf8 ();
154-
155- // There is one trace
156- assertThat (traceIds ).hasSize (1 );
157-
158- // Response contains Hello
159- assertThat (responseBody ).contains ("Hello" );
160-
161- // There is one server span
162- long serverSpanCount =
163- spans .stream ()
164- .filter (span -> span .getKind () == io .opentelemetry .api .trace .SpanKind .SERVER )
165- .count ();
166- assertThat (serverSpanCount ).isOne ();
167-
168- // Expected span names
169- long spanNameCount =
170- spans .stream ().filter (span -> getSpanName ("/app/hello.txt" ).equals (span .getName ())).count ();
171- assertThat (spanNameCount ).isOne ();
172-
173- // The span for the initial web request
174- long urlPathCount =
175- spans .stream ()
176- .filter (
177- span -> "/app/hello.txt" .equals (span .getAttributes ().get (UrlAttributes .URL_PATH )))
178- .count ();
179- assertThat (urlPathCount ).isOne ();
151+ assertThat (response .contentUtf8 ()).contains ("Hello" );
180152
181- // Number of spans tagged with current otel library version
182- long versionCount =
183- spans .stream ()
184- .filter (
185- span ->
186- testing ()
187- .getAgentVersion ()
188- .equals (
189- span .getResource ()
190- .getAttributes ()
191- .get (
192- io .opentelemetry .api .common .AttributeKey .stringKey (
193- TELEMETRY_DISTRO_VERSION ))))
194- .count ();
195- assertThat (versionCount ).isOne ();
196-
197- // Number of spans tagged with expected OS type
198- String expectedOsType = isWindows ? WINDOWS : LINUX ;
199- long osTypeCount =
200- spans .stream ()
201- .filter (span -> expectedOsType .equals (span .getResource ().getAttributes ().get (OS_TYPE )))
202- .count ();
203- assertThat (osTypeCount ).isOne ();
153+ testing ()
154+ .waitAndAssertTraces (
155+ trace ->
156+ trace .hasSpansSatisfyingExactly (
157+ span -> span .hasName (getSpanName ("/app/hello.txt" )).hasKind (SpanKind .SERVER )));
204158 }
205159
206160 @ Test
207- void testStaticFileNotFound () throws Exception {
161+ void testStaticFileNotFound () {
208162 var response = testing ().client ().get ("/app/file-that-does-not-exist" ).aggregate ().join ();
209- List <SpanData > traces = testing ().spans ();
210- Set <String > traceIds = testing ().getSpanTraceIds ();
211163
212- // There is one trace
213- assertThat (traceIds ).hasSize (1 );
214-
215- // Response code is 404
216164 assertThat (response .status ().code ()).isEqualTo (404 );
217165
218- // There is one server span
219- long serverSpanCount =
220- traces .stream ()
221- .filter (span -> span .getKind () == io .opentelemetry .api .trace .SpanKind .SERVER )
222- .count ();
223- assertThat (serverSpanCount ).isOne ();
224-
225- // Expected span names
226- long spanNameCount =
227- traces .stream ()
228- .filter (span -> getSpanName ("/app/file-that-does-not-exist" ).equals (span .getName ()))
229- .count ();
230- assertThat (spanNameCount ).isOne ();
231-
232- // The span for the initial web request
233- long urlPathCount =
234- traces .stream ()
235- .filter (
236- span ->
237- "/app/file-that-does-not-exist"
238- .equals (span .getAttributes ().get (UrlAttributes .URL_PATH )))
239- .count ();
240- assertThat (urlPathCount ).isOne ();
241-
242- // Number of spans tagged with current otel library version
243- long versionCount =
244- traces .stream ()
245- .filter (
246- span ->
247- testing ()
248- .getAgentVersion ()
249- .equals (
250- span .getResource ()
251- .getAttributes ()
252- .get (
253- io .opentelemetry .api .common .AttributeKey .stringKey (
254- TELEMETRY_DISTRO_VERSION ))))
255- .count ();
256- assertThat (versionCount ).isEqualTo (traces .size ());
257-
258- // Number of spans tagged with expected OS type
259- String expectedOsType = isWindows ? WINDOWS : LINUX ;
260- long osTypeCount =
261- traces .stream ()
262- .filter (span -> expectedOsType .equals (span .getResource ().getAttributes ().get (OS_TYPE )))
263- .count ();
264- assertThat (osTypeCount ).isEqualTo (traces .size ());
166+ testing ()
167+ .waitAndAssertTraces (
168+ trace ->
169+ trace .hasSpansSatisfyingExactly (
170+ span ->
171+ span .hasName (getSpanName ("/app/file-that-does-not-exist" ))
172+ .hasKind (SpanKind .SERVER )
173+ .hasAttribute (
174+ UrlAttributes .URL_PATH , "/app/file-that-does-not-exist" )));
265175 }
266176
267177 @ Test
268- void testRequestForWebInfWebXml () throws Exception {
178+ void testRequestForWebInfWebXml () {
269179 assumeTrue (testRequestWebInfWebXml ());
270180
271181 var response = testing ().client ().get ("/app/WEB-INF/web.xml" ).aggregate ().join ();
272182 List <SpanData > traces = testing ().spans ();
273183 Set <String > traceIds = testing ().getSpanTraceIds ();
274184
275- // There is one trace
276- assertThat (traceIds ).hasSize (1 );
277-
278- // Response code is 404
279- assertThat (response .status ().code ()).isEqualTo (404 );
280-
281- // There is one server span
282- long serverSpanCount =
283- traces .stream ()
284- .filter (span -> span .getKind () == io .opentelemetry .api .trace .SpanKind .SERVER )
285- .count ();
286- assertThat (serverSpanCount ).isOne ();
287-
288- // Expected span names
289- long spanNameCount =
290- traces .stream ()
291- .filter (span -> getSpanName ("/app/WEB-INF/web.xml" ).equals (span .getName ()))
292- .count ();
293- assertThat (spanNameCount ).isOne ();
294-
295- // The span for the initial web request
296- long urlPathCount =
297- traces .stream ()
298- .filter (
299- span ->
300- "/app/WEB-INF/web.xml" .equals (span .getAttributes ().get (UrlAttributes .URL_PATH )))
301- .count ();
302- assertThat (urlPathCount ).isOne ();
303-
304- // Number of spans with http protocol version
305- long protocolVersionCount =
306- traces .stream ()
307- .filter (
308- span ->
309- "1.1"
310- .equals (
311- span .getAttributes ().get (NetworkAttributes .NETWORK_PROTOCOL_VERSION )))
312- .count ();
313- assertThat (protocolVersionCount ).isOne ();
314-
315- // Number of spans tagged with current otel library version
316- long versionCount =
317- traces .stream ()
318- .filter (
319- span ->
320- testing ()
321- .getAgentVersion ()
322- .equals (
323- span .getResource ()
324- .getAttributes ()
325- .get (
326- io .opentelemetry .api .common .AttributeKey .stringKey (
327- TELEMETRY_DISTRO_VERSION ))))
328- .count ();
329- assertThat (versionCount ).isEqualTo (traces .size ());
330-
331- // Number of spans tagged with expected OS type
332- String expectedOsType = isWindows ? WINDOWS : LINUX ;
333- long osTypeCount =
334- traces .stream ()
335- .filter (span -> expectedOsType .equals (span .getResource ().getAttributes ().get (OS_TYPE )))
336- .count ();
337- assertThat (osTypeCount ).isEqualTo (traces .size ());
185+ testing ()
186+ .waitAndAssertTraces (
187+ trace ->
188+ trace .hasSpansSatisfyingExactly (
189+ span ->
190+ span .hasName (getSpanName ("/app/WEB-INF/web.xml" ))
191+ .hasKind (SpanKind .SERVER )
192+ .hasAttribute (UrlAttributes .URL_PATH , "/app/WEB-INF/web.xml" )));
338193 }
339194
340195 @ Test
341- void testRequestWithError () throws Exception {
196+ void testRequestWithError () {
342197 assumeTrue (testException ());
343198
344199 var response = testing ().client ().get ("/app/exception" ).aggregate ().join ();
@@ -423,7 +278,7 @@ void testRequestWithError() throws Exception {
423278 }
424279
425280 @ Test
426- void testRequestOutsideDeployedApplication () throws Exception {
281+ void testRequestOutsideDeployedApplication () {
427282 assumeTrue (testRequestOutsideDeployedApp ());
428283
429284 var response =
0 commit comments