Search in sources :

Example 1 with Duration

use of com.microsoft.applicationinsights.smoketest.telemetry.Duration 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 2 with Duration

use of com.microsoft.applicationinsights.smoketest.telemetry.Duration 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 3 with Duration

use of com.microsoft.applicationinsights.smoketest.telemetry.Duration in project ApplicationInsights-Java by microsoft.

the class CoreAndFilterTests method trackDependency.

@Test
@TargetUri("/trackDependency")
public void trackDependency() throws Exception {
    Telemetry telemetry = getTelemetry(1);
    Duration expectedDuration = new Duration(0, 0, 1, 1, 1);
    assertEquals("DependencyTest", telemetry.rdd1.getName());
    assertEquals("commandName", telemetry.rdd1.getData());
    assertNull(telemetry.rdd1.getType());
    assertNull(telemetry.rdd1.getTarget());
    assertTrue(telemetry.rdd1.getProperties().isEmpty());
    assertTrue(telemetry.rdd1.getSuccess());
    assertEquals(expectedDuration, telemetry.rdd1.getDuration());
    assertParentChild(telemetry.rd, telemetry.rdEnvelope, telemetry.rddEnvelope1, "GET /CoreAndFilter/trackDependency");
}
Also used : RequestDataMatchers.hasDuration(com.microsoft.applicationinsights.smoketest.matchers.RequestDataMatchers.hasDuration) Duration(com.microsoft.applicationinsights.smoketest.telemetry.Duration) Test(org.junit.Test)

Example 4 with Duration

use of com.microsoft.applicationinsights.smoketest.telemetry.Duration in project ApplicationInsights-Java by microsoft.

the class JsonHelperTests method testHourDuration.

@Test
public void testHourDuration() {
    Duration expected = new Duration(0, 1, 0, 50, 0);
    String json = getJsonDurationInHolder(expected);
    System.out.println(json);
    DurationHolder actual = JsonHelper.GSON.fromJson(json, DurationHolder.class);
    assertThat(actual.getData()).isEqualTo(expected);
    json = getJsonDurationInHolder(new Duration(3600000L + 50000L));
    System.out.println(json);
    actual = JsonHelper.GSON.fromJson(json, DurationHolder.class);
    assertThat(actual.getData()).isEqualTo(expected);
}
Also used : Duration(com.microsoft.applicationinsights.smoketest.telemetry.Duration) Test(org.junit.jupiter.api.Test)

Example 5 with Duration

use of com.microsoft.applicationinsights.smoketest.telemetry.Duration in project ApplicationInsights-Java by microsoft.

the class JsonHelperTests method testSecondDuration.

@Test
public void testSecondDuration() {
    Duration expected = new Duration(0, 0, 0, 50, 0);
    String json = getJsonDurationInHolder(expected);
    System.out.println(json);
    DurationHolder actual = JsonHelper.GSON.fromJson(json, DurationHolder.class);
    assertThat(actual.getData()).isEqualTo(expected);
    json = getJsonDurationInHolder(new Duration(50000L));
    System.out.println(json);
    actual = JsonHelper.GSON.fromJson(json, DurationHolder.class);
    assertThat(actual.getData()).isEqualTo(expected);
}
Also used : Duration(com.microsoft.applicationinsights.smoketest.telemetry.Duration) Test(org.junit.jupiter.api.Test)

Aggregations

Duration (com.microsoft.applicationinsights.smoketest.telemetry.Duration)11 Test (org.junit.jupiter.api.Test)6 RequestDataMatchers.hasDuration (com.microsoft.applicationinsights.smoketest.matchers.RequestDataMatchers.hasDuration)5 Test (org.junit.Test)4 Envelope (com.microsoft.applicationinsights.smoketest.schemav2.Envelope)3 RequestData (com.microsoft.applicationinsights.smoketest.schemav2.RequestData)3 PageViewData (com.microsoft.applicationinsights.smoketest.schemav2.PageViewData)2 DataPoint (com.microsoft.applicationinsights.smoketest.schemav2.DataPoint)1 Domain (com.microsoft.applicationinsights.smoketest.schemav2.Domain)1