use of com.microsoft.applicationinsights.smoketest.schemav2.RequestData in project ApplicationInsights-Java by microsoft.
the class AiSmokeTest method waitForHealthCheckTelemetryIfNeeded.
private static void waitForHealthCheckTelemetryIfNeeded(String contextRootUrl) throws InterruptedException, ExecutionException {
if (!requestCaptureEnabled) {
return;
}
Stopwatch receivedTelemetryTimer = Stopwatch.createStarted();
int requestTelemetryFromHealthCheckTimeout;
if (currentImageName.startsWith("javase_")) {
requestTelemetryFromHealthCheckTimeout = APPLICATION_READY_TIMEOUT_SECONDS;
} else {
requestTelemetryFromHealthCheckTimeout = TELEMETRY_RECEIVE_TIMEOUT_SECONDS;
}
try {
mockedIngestion.waitForItem(new Predicate<Envelope>() {
@Override
public boolean test(Envelope input) {
if (!"RequestData".equals(input.getData().getBaseType())) {
return false;
}
RequestData data = (RequestData) ((Data<?>) input.getData()).getBaseData();
return contextRootUrl.equals(data.getUrl()) && "200".equals(data.getResponseCode());
}
}, requestTelemetryFromHealthCheckTimeout, TimeUnit.SECONDS);
System.out.printf("Received request telemetry after %.3f seconds...%n", receivedTelemetryTimer.elapsed(TimeUnit.MILLISECONDS) / 1000.0);
System.out.println("Clearing any RequestData from health check.");
} catch (java.util.concurrent.TimeoutException e) {
throw new TimeoutException("request telemetry from application health check", requestTelemetryFromHealthCheckTimeout, TimeUnit.SECONDS, e);
}
}
use of com.microsoft.applicationinsights.smoketest.schemav2.RequestData in project ApplicationInsights-Java by microsoft.
the class CoreAndFilterTests method testHttpRequest.
@Test
@TargetUri("/trackHttpRequest")
public void testHttpRequest() throws Exception {
mockedIngestion.waitForItems("RequestData", 5);
int totalItems = mockedIngestion.getItemCount();
int expectedItems = 5;
assertEquals(String.format("There were %d extra telemetry items received.", totalItems - expectedItems), expectedItems, totalItems);
// TODO get HttpRequest data envelope and verify value
List<Domain> requests = mockedIngestion.getTelemetryDataByType("RequestData");
// true
assertThat(requests, hasItem(allOf(hasName("HttpRequestDataTest"), hasResponseCode("200"), hasDuration(new Duration(4711)), hasSuccess(true))));
assertThat(requests, hasItem(allOf(hasName("PingTest"), hasResponseCode("200"), hasDuration(new Duration(1)), hasSuccess(true), hasUrl("http://tempuri.org/ping"))));
// false
assertThat(requests, hasItem(allOf(hasName("FailedHttpRequest"), hasResponseCode("404"), hasDuration(new Duration(6666)), hasSuccess(false))));
assertThat(requests, hasItem(allOf(hasName("FailedHttpRequest2"), hasResponseCode("505"), hasDuration(new Duration(8888)), hasSuccess(false), hasUrl("https://www.bingasdasdasdasda.com/"))));
}
use of com.microsoft.applicationinsights.smoketest.schemav2.RequestData in project ApplicationInsights-Java by microsoft.
the class CoreAndFilterTests method testTrackEvent.
@Test
@TargetUri("/trackEvent")
public void testTrackEvent() throws Exception {
List<Envelope> rdList = mockedIngestion.waitForItems("RequestData", 1);
Envelope rdEnvelope = rdList.get(0);
String operationId = rdEnvelope.getTags().get("ai.operation.id");
List<Envelope> edList = mockedIngestion.waitForItemsInOperation("EventData", 2, operationId);
Envelope edEnvelope1 = edList.get(0);
Envelope edEnvelope2 = edList.get(1);
RequestData rd = (RequestData) ((Data<?>) rdEnvelope.getData()).getBaseData();
List<EventData> events = mockedIngestion.getTelemetryDataByTypeInRequest("EventData");
events.sort(Comparator.comparing(EventData::getName));
EventData ed1 = events.get(0);
EventData ed2 = events.get(1);
assertEquals("EventDataPropertyTest", ed1.getName());
assertEquals("value", ed1.getProperties().get("key"));
assertEquals((Double) 1.0, ed1.getMeasurements().get("key"));
assertEquals("EventDataTest", ed2.getName());
assertParentChild(rd, rdEnvelope, edEnvelope1, "GET /CoreAndFilter/trackEvent");
assertParentChild(rd, rdEnvelope, edEnvelope2, "GET /CoreAndFilter/trackEvent");
}
use of com.microsoft.applicationinsights.smoketest.schemav2.RequestData in project ApplicationInsights-Java by microsoft.
the class CoreAndFilterTests method testTrackTrace.
@Test
@TargetUri("/trackTrace")
public void testTrackTrace() throws Exception {
List<Envelope> rdList = mockedIngestion.waitForItems("RequestData", 1);
List<Envelope> mdList = mockedIngestion.waitForMessageItemsInRequest(3);
Envelope rdEnvelope = rdList.get(0);
Envelope mdEnvelope1 = mdList.get(0);
Envelope mdEnvelope2 = mdList.get(1);
Envelope mdEnvelope3 = mdList.get(2);
RequestData rd = (RequestData) ((Data<?>) rdEnvelope.getData()).getBaseData();
List<MessageData> messages = mockedIngestion.getMessageDataInRequest();
assertThat(messages, hasItem(TraceDataMatchers.hasMessage("This is first trace message.")));
assertThat(messages, hasItem(allOf(TraceDataMatchers.hasMessage("This is second trace message."), TraceDataMatchers.hasSeverityLevel(SeverityLevel.Error))));
assertThat(messages, hasItem(allOf(TraceDataMatchers.hasMessage("This is third trace message."), TraceDataMatchers.hasSeverityLevel(SeverityLevel.Information), TraceDataMatchers.hasProperty("key", "value"))));
assertParentChild(rd, rdEnvelope, mdEnvelope1, "GET /CoreAndFilter/trackTrace");
assertParentChild(rd, rdEnvelope, mdEnvelope2, "GET /CoreAndFilter/trackTrace");
assertParentChild(rd, rdEnvelope, mdEnvelope3, "GET /CoreAndFilter/trackTrace");
}
use of com.microsoft.applicationinsights.smoketest.schemav2.RequestData in project ApplicationInsights-Java by microsoft.
the class CoreAndFilterTests method trackMetric.
@Test
@TargetUri("/trackMetric")
public void trackMetric() throws Exception {
List<Envelope> rdList = mockedIngestion.waitForItems("RequestData", 1);
List<Envelope> mdList = mockedIngestion.waitForItems("MetricData", 1);
Envelope rdEnvelope = rdList.get(0);
Envelope mdEnvelope = mdList.get(0);
RequestData rd = (RequestData) ((Data<?>) rdEnvelope.getData()).getBaseData();
MetricData md = (MetricData) ((Data<?>) mdEnvelope.getData()).getBaseData();
List<DataPoint> metrics = md.getMetrics();
assertEquals(1, metrics.size());
DataPoint dp = metrics.get(0);
final double expectedValue = 111222333.0;
double epsilon = Math.ulp(expectedValue);
assertEquals(DataPointType.Measurement, dp.getKind());
assertEquals(expectedValue, dp.getValue(), epsilon);
assertEquals("TimeToRespond", dp.getName());
assertNull("getCount was non-null", dp.getCount());
assertNull("getMin was non-null", dp.getMin());
assertNull("getMax was non-null", dp.getMax());
assertNull("getStdDev was non-null", dp.getStdDev());
assertParentChild(rd, rdEnvelope, mdEnvelope, "GET /CoreAndFilter/trackMetric");
}
Aggregations