Search in sources :

Example 11 with Envelope

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");
}
Also used : RequestData(com.microsoft.applicationinsights.smoketest.schemav2.RequestData) Envelope(com.microsoft.applicationinsights.smoketest.schemav2.Envelope) EventData(com.microsoft.applicationinsights.smoketest.schemav2.EventData) Test(org.junit.Test)

Example 12 with Envelope

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");
}
Also used : RequestData(com.microsoft.applicationinsights.smoketest.schemav2.RequestData) MessageData(com.microsoft.applicationinsights.smoketest.schemav2.MessageData) Envelope(com.microsoft.applicationinsights.smoketest.schemav2.Envelope) Test(org.junit.Test)

Example 13 with Envelope

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");
}
Also used : DataPoint(com.microsoft.applicationinsights.smoketest.schemav2.DataPoint) RequestData(com.microsoft.applicationinsights.smoketest.schemav2.RequestData) Envelope(com.microsoft.applicationinsights.smoketest.schemav2.Envelope) MetricData(com.microsoft.applicationinsights.smoketest.schemav2.MetricData) Test(org.junit.Test)

Example 14 with Envelope

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"));
}
Also used : RequestData(com.microsoft.applicationinsights.smoketest.schemav2.RequestData) RequestDataMatchers.hasDuration(com.microsoft.applicationinsights.smoketest.matchers.RequestDataMatchers.hasDuration) Duration(com.microsoft.applicationinsights.smoketest.telemetry.Duration) Envelope(com.microsoft.applicationinsights.smoketest.schemav2.Envelope)

Example 15 with Envelope

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;
}
Also used : ArrayList(java.util.ArrayList) MessageData(com.microsoft.applicationinsights.smoketest.schemav2.MessageData) Data(com.microsoft.applicationinsights.smoketest.schemav2.Data) Envelope(com.microsoft.applicationinsights.smoketest.schemav2.Envelope)

Aggregations

Envelope (com.microsoft.applicationinsights.smoketest.schemav2.Envelope)57 Test (org.junit.Test)52 RequestData (com.microsoft.applicationinsights.smoketest.schemav2.RequestData)45 RemoteDependencyData (com.microsoft.applicationinsights.smoketest.schemav2.RemoteDependencyData)28 Envelope (org.opensaml.soap.soap11.Envelope)16 Body (org.opensaml.soap.soap11.Body)11 Header (org.opensaml.soap.soap11.Header)11 AiSmokeTest (com.microsoft.applicationinsights.smoketest.AiSmokeTest)10 TargetUri (com.microsoft.applicationinsights.smoketest.TargetUri)10 ExceptionData (com.microsoft.applicationinsights.smoketest.schemav2.ExceptionData)9 MessageData (com.microsoft.applicationinsights.smoketest.schemav2.MessageData)9 Data (com.microsoft.applicationinsights.smoketest.schemav2.Data)8 EventData (com.microsoft.applicationinsights.smoketest.schemav2.EventData)6 MetricData (com.microsoft.applicationinsights.smoketest.schemav2.MetricData)6 RequestDataMatchers.hasDuration (com.microsoft.applicationinsights.smoketest.matchers.RequestDataMatchers.hasDuration)4 DataPoint (com.microsoft.applicationinsights.smoketest.schemav2.DataPoint)4 ExceptionDetails (com.microsoft.applicationinsights.smoketest.schemav2.ExceptionDetails)4 Duration (com.microsoft.applicationinsights.smoketest.telemetry.Duration)4 PageViewData (com.microsoft.applicationinsights.smoketest.schemav2.PageViewData)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3