1717import static com .microsoft .applicationinsights .smoketest .EnvironmentValue .WILDFLY_13_JAVA_8 ;
1818import static com .microsoft .applicationinsights .smoketest .EnvironmentValue .WILDFLY_13_JAVA_8_OPENJ9 ;
1919import static org .assertj .core .api .Assertions .assertThat ;
20+ import static org .junit .jupiter .api .Assertions .assertTrue ;
2021
2122import com .azure .json .JsonProviders ;
2223import com .azure .json .JsonReader ;
2829import com .azure .monitor .opentelemetry .autoconfigure .implementation .quickpulse .swagger .models .Trace ;
2930import java .io .IOException ;
3031import java .time .Duration ;
31- import java .util .ArrayList ;
3232import java .util .List ;
3333import org .awaitility .Awaitility ;
3434import org .junit .jupiter .api .Test ;
@@ -52,36 +52,35 @@ void testTelemetryDataFlow() {
5252 // Need to wait because some but not all the telemetry may be available in the first post body
5353 Awaitility .await ()
5454 .atMost (Duration .ofSeconds (30 ))
55- .until (
56- () -> {
57- List < String > postBodies = testing . mockedIngestion . getPostBodies ();
58- if ( postBodies . isEmpty ()) {
59- return false ;
60- }
61-
62- PostBodyVerifier tempVerifier = new PostBodyVerifier ();
63- for ( String postBody : postBodies ) {
64- tempVerifier . searchPostBody ( postBody );
65- }
66-
67- return tempVerifier .hasExceptionDoc ()
68- && tempVerifier .hasTraceDoc ()
69- && tempVerifier .hasDependency ()
70- && tempVerifier . hasRequest () ;
71- });
55+ .until (() -> {
56+ List < String > postBodies = testing . mockedIngestion . getPostBodies ();
57+ if ( postBodies . isEmpty ()) {
58+ return false ;
59+ }
60+
61+ PostBodyVerifier tempVerifier = new PostBodyVerifier ();
62+ for ( String postBody : postBodies ) {
63+ tempVerifier . searchPostBody ( postBody );
64+ }
65+
66+ assertTrue ( tempVerifier . hasExceptionDoc ());
67+ assertTrue ( tempVerifier .hasTraceDoc ());
68+ assertTrue ( tempVerifier .hasDependency ());
69+ assertTrue ( tempVerifier .hasRequest ());
70+ return true ;
71+ });
7272 }
7373
74- class PostBodyVerifier {
74+ static class PostBodyVerifier {
7575 boolean foundExceptionDoc = false ;
7676 boolean foundTraceDoc = false ;
7777 boolean foundDependency = false ;
7878 boolean foundRequest = false ;
7979
8080 public void searchPostBody (String postBody ) {
8181 // Each post body is a list with a singular MonitoringDataPoint
82- List <MonitoringDataPoint > dataPoints = new ArrayList <>();
83- try {
84- JsonReader reader = JsonProviders .createReader (postBody );
82+ List <MonitoringDataPoint > dataPoints ;
83+ try (JsonReader reader = JsonProviders .createReader (postBody )) {
8584 dataPoints = reader .readArray (MonitoringDataPoint ::fromJson );
8685 } catch (IOException e ) {
8786 throw new IllegalStateException ("Failed to parse post request body" , e );
0 commit comments