Skip to content

Commit 5fd3c90

Browse files
committed
better failures
1 parent 3757c50 commit 5fd3c90

File tree

1 file changed

+21
-22
lines changed
  • smoke-tests/apps/LiveMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest

1 file changed

+21
-22
lines changed

smoke-tests/apps/LiveMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/LiveMetricsTest.java

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.WILDFLY_13_JAVA_8;
1818
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.WILDFLY_13_JAVA_8_OPENJ9;
1919
import static org.assertj.core.api.Assertions.assertThat;
20+
import static org.junit.jupiter.api.Assertions.assertTrue;
2021

2122
import com.azure.json.JsonProviders;
2223
import com.azure.json.JsonReader;
@@ -28,7 +29,6 @@
2829
import com.azure.monitor.opentelemetry.autoconfigure.implementation.quickpulse.swagger.models.Trace;
2930
import java.io.IOException;
3031
import java.time.Duration;
31-
import java.util.ArrayList;
3232
import java.util.List;
3333
import org.awaitility.Awaitility;
3434
import 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

Comments
 (0)