Search in sources :

Example 1 with RequestData

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);
    }
}
Also used : RequestData(com.microsoft.applicationinsights.smoketest.schemav2.RequestData) Stopwatch(com.google.common.base.Stopwatch) Data(com.microsoft.applicationinsights.smoketest.schemav2.Data) RequestData(com.microsoft.applicationinsights.smoketest.schemav2.RequestData) RemoteDependencyData(com.microsoft.applicationinsights.smoketest.schemav2.RemoteDependencyData) Envelope(com.microsoft.applicationinsights.smoketest.schemav2.Envelope) TimeoutException(com.microsoft.applicationinsights.smoketest.exceptions.TimeoutException)

Example 2 with RequestData

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/"))));
}
Also used : RequestDataMatchers.hasDuration(com.microsoft.applicationinsights.smoketest.matchers.RequestDataMatchers.hasDuration) Duration(com.microsoft.applicationinsights.smoketest.telemetry.Duration) Domain(com.microsoft.applicationinsights.smoketest.schemav2.Domain) DataPoint(com.microsoft.applicationinsights.smoketest.schemav2.DataPoint) Test(org.junit.Test)

Example 3 with RequestData

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");
}
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 4 with RequestData

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");
}
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 5 with RequestData

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");
}
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)

Aggregations

Envelope (com.microsoft.applicationinsights.smoketest.schemav2.Envelope)48 Test (org.junit.Test)47 RequestData (com.microsoft.applicationinsights.smoketest.schemav2.RequestData)45 RemoteDependencyData (com.microsoft.applicationinsights.smoketest.schemav2.RemoteDependencyData)26 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)8 EventData (com.microsoft.applicationinsights.smoketest.schemav2.EventData)6 Data (com.microsoft.applicationinsights.smoketest.schemav2.Data)5 RequestDataMatchers.hasDuration (com.microsoft.applicationinsights.smoketest.matchers.RequestDataMatchers.hasDuration)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 DataPoint (com.microsoft.applicationinsights.smoketest.schemav2.DataPoint)2 MetricData (com.microsoft.applicationinsights.smoketest.schemav2.MetricData)2 Description (org.hamcrest.Description)2 Matcher (org.hamcrest.Matcher)2 TypeSafeMatcher (org.hamcrest.TypeSafeMatcher)2 Stopwatch (com.google.common.base.Stopwatch)1