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