use of com.microsoft.applicationinsights.smoketest.schemav2.Envelope 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.Envelope 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.Envelope 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");
}
use of com.microsoft.applicationinsights.smoketest.schemav2.Envelope in project ApplicationInsights-Java by microsoft.
the class CoreAndFilterTests method validateSlowTest.
private void validateSlowTest(int expectedDurationSeconds, String operationName) throws Exception {
List<Envelope> rdList = mockedIngestion.waitForItems("RequestData", 1);
Envelope rdEnvelope = rdList.get(0);
RequestData rd = (RequestData) ((Data<?>) rdEnvelope.getData()).getBaseData();
long actual = rd.getDuration().getTotalMilliseconds();
long expected = (new Duration(0, 0, 0, expectedDurationSeconds, 0).getTotalMilliseconds());
// 2 seconds
long tolerance = 2 * 1000;
long min = expected - tolerance;
long max = expected + tolerance;
System.out.printf("Slow response time: expected=%d, actual=%d%n", expected, actual);
assertThat(actual, both(greaterThanOrEqualTo(min)).and(lessThan(max)));
assertEquals(operationName, rdEnvelope.getTags().get("ai.operation.name"));
}
use of com.microsoft.applicationinsights.smoketest.schemav2.Envelope in project ApplicationInsights-Java by microsoft.
the class MockedAppInsightsIngestionServer method getTelemetryDataByType.
private <T extends Domain> List<T> getTelemetryDataByType(String type, boolean inRequestOnly) {
Objects.requireNonNull(type, "type");
List<Envelope> items = getItemsEnvelopeDataType(type);
List<T> dataItems = new ArrayList<>();
for (Envelope e : items) {
if (!inRequestOnly || e.getTags().containsKey("ai.operation.id")) {
Data<T> dt = (Data<T>) e.getData();
dataItems.add(dt.getBaseData());
}
}
return dataItems;
}
Aggregations