Search in sources :

Example 31 with RequestData

use of com.microsoft.applicationinsights.smoketest.schemav2.RequestData in project ApplicationInsights-Java by microsoft.

the class CoreAndFilterTests method testTrackPageViewJsp.

@Test
@TargetUri("/doPageView.jsp")
public void testTrackPageViewJsp() throws Exception {
    List<Envelope> rdList = mockedIngestion.waitForItems("RequestData", 1);
    Envelope rdEnvelope = rdList.get(0);
    String operationId = rdEnvelope.getTags().get("ai.operation.id");
    List<Envelope> pvdList = mockedIngestion.waitForItemsInOperation("PageViewData", 1, operationId);
    assertEquals(0, mockedIngestion.getCountForType("EventData"));
    Envelope pvdEnvelope = pvdList.get(0);
    RequestData rd = (RequestData) ((Data<?>) rdEnvelope.getData()).getBaseData();
    PageViewData pv = (PageViewData) ((Data<?>) pvdEnvelope.getData()).getBaseData();
    assertEquals("doPageView", pv.getName());
    assertEquals(new Duration(0), pv.getDuration());
    assertParentChild(rd, rdEnvelope, pvdEnvelope, "GET /CoreAndFilter/doPageView.jsp");
}
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) PageViewData(com.microsoft.applicationinsights.smoketest.schemav2.PageViewData) Test(org.junit.Test)

Example 32 with RequestData

use of com.microsoft.applicationinsights.smoketest.schemav2.RequestData in project ApplicationInsights-Java by microsoft.

the class CoreAndFilterTests method testAutoExceptionWithFailedRequest.

@Test
@TargetUri("/autoExceptionWithFailedRequest")
public void testAutoExceptionWithFailedRequest() 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.waitForItems(new Predicate<Envelope>() {

        @Override
        public boolean test(Envelope input) {
            if (!"ExceptionData".equals(input.getData().getBaseType())) {
                return false;
            }
            if (!operationId.equals(input.getTags().get("ai.operation.id"))) {
                return false;
            }
            // lastly, filter out ExceptionData captured from tomcat logger
            ExceptionData data = (ExceptionData) ((Data<?>) input.getData()).getBaseData();
            return !data.getProperties().containsKey("LoggerName");
        }
    }, 1, 10, TimeUnit.SECONDS);
    Envelope edEnvelope = edList.get(0);
    RequestData rd = (RequestData) ((Data<?>) rdEnvelope.getData()).getBaseData();
    ExceptionData ed = (ExceptionData) ((Data<?>) edEnvelope.getData()).getBaseData();
    assertFalse(rd.getSuccess());
    ExceptionDetails details = getExceptionDetails(ed);
    assertEquals("This is a auto thrown exception !", details.getMessage());
}
Also used : RequestData(com.microsoft.applicationinsights.smoketest.schemav2.RequestData) ExceptionData(com.microsoft.applicationinsights.smoketest.schemav2.ExceptionData) RequestData(com.microsoft.applicationinsights.smoketest.schemav2.RequestData) MessageData(com.microsoft.applicationinsights.smoketest.schemav2.MessageData) PageViewData(com.microsoft.applicationinsights.smoketest.schemav2.PageViewData) ExceptionData(com.microsoft.applicationinsights.smoketest.schemav2.ExceptionData) MetricData(com.microsoft.applicationinsights.smoketest.schemav2.MetricData) EventData(com.microsoft.applicationinsights.smoketest.schemav2.EventData) Data(com.microsoft.applicationinsights.smoketest.schemav2.Data) ExceptionDetails(com.microsoft.applicationinsights.smoketest.schemav2.ExceptionDetails) Envelope(com.microsoft.applicationinsights.smoketest.schemav2.Envelope) Test(org.junit.Test)

Example 33 with RequestData

use of com.microsoft.applicationinsights.smoketest.schemav2.RequestData in project ApplicationInsights-Java by microsoft.

the class CoreAndFilterTests method testAutoFailedRequestWithResultCode.

@Test
@TargetUri("/autoFailedRequestWithResultCode")
public void testAutoFailedRequestWithResultCode() throws Exception {
    List<Envelope> rdList = mockedIngestion.waitForItems("RequestData", 1);
    Envelope rdEnvelope = rdList.get(0);
    RequestData rd = (RequestData) ((Data<?>) rdEnvelope.getData()).getBaseData();
    assertEquals(false, rd.getSuccess());
    assertEquals("404", rd.getResponseCode());
    assertEquals("GET /CoreAndFilter/*", rdEnvelope.getTags().get("ai.operation.name"));
}
Also used : RequestData(com.microsoft.applicationinsights.smoketest.schemav2.RequestData) Envelope(com.microsoft.applicationinsights.smoketest.schemav2.Envelope) Test(org.junit.Test)

Example 34 with RequestData

use of com.microsoft.applicationinsights.smoketest.schemav2.RequestData in project ApplicationInsights-Java by microsoft.

the class CoreAndFilterTests method testTrackException.

@Test
@TargetUri("/trackException")
public void testTrackException() 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("ExceptionData", 3, operationId);
    assertEquals(0, mockedIngestion.getCountForType("EventData"));
    Envelope edEnvelope1 = edList.get(0);
    Envelope edEnvelope2 = edList.get(1);
    Envelope edEnvelope3 = edList.get(2);
    RequestData rd = (RequestData) ((Data<?>) rdEnvelope.getData()).getBaseData();
    final String expectedName = "This is track exception.";
    final String expectedProperties = "value";
    final Double expectedMetrice = 1d;
    List<ExceptionData> exceptions = mockedIngestion.getTelemetryDataByTypeInRequest("ExceptionData");
    assertThat(exceptions, hasItem(hasException(withMessage(expectedName))));
    assertThat(exceptions, hasItem(allOf(hasException(withMessage(expectedName)), ExceptionDataMatchers.hasProperty("key", expectedProperties), hasMeasurement("key", expectedMetrice))));
    assertThat(exceptions, hasItem(allOf(hasException(withMessage(expectedName)), hasSeverityLevel(SeverityLevel.Error))));
    assertParentChild(rd, rdEnvelope, edEnvelope1, "GET /CoreAndFilter/trackException");
    assertParentChild(rd, rdEnvelope, edEnvelope2, "GET /CoreAndFilter/trackException");
    assertParentChild(rd, rdEnvelope, edEnvelope3, "GET /CoreAndFilter/trackException");
}
Also used : RequestData(com.microsoft.applicationinsights.smoketest.schemav2.RequestData) ExceptionData(com.microsoft.applicationinsights.smoketest.schemav2.ExceptionData) Envelope(com.microsoft.applicationinsights.smoketest.schemav2.Envelope) Test(org.junit.Test)

Example 35 with RequestData

use of com.microsoft.applicationinsights.smoketest.schemav2.RequestData in project ApplicationInsights-Java by microsoft.

the class CoreAndFilterTests method testTrackPageView.

@Test
@TargetUri("/trackPageView")
public void testTrackPageView() throws Exception {
    List<Envelope> rdList = mockedIngestion.waitForItems("RequestData", 1);
    Envelope rdEnvelope = rdList.get(0);
    List<Envelope> pvdList = mockedIngestion.waitForItems("PageViewData", 3);
    assertEquals(0, mockedIngestion.getCountForType("EventData"));
    RequestData rd = (RequestData) ((Data<?>) rdEnvelope.getData()).getBaseData();
    Envelope pvdEnvelope1 = null;
    Envelope pvdEnvelope2 = null;
    Envelope pvdEnvelope3 = null;
    for (Envelope pvdEnvelope : pvdList) {
        PageViewData pv = (PageViewData) ((Data<?>) pvdEnvelope.getData()).getBaseData();
        if (pv.getName().equals("test-page")) {
            pvdEnvelope1 = pvdEnvelope;
        } else if (pv.getName().equals("test-page-2")) {
            pvdEnvelope2 = pvdEnvelope;
        } else if (pv.getName().equals("test-page-3")) {
            pvdEnvelope3 = pvdEnvelope;
        } else {
            throw new AssertionError("Unexpected page view: " + pv.getName());
        }
    }
    PageViewData pv1 = (PageViewData) ((Data<?>) pvdEnvelope1.getData()).getBaseData();
    PageViewData pv2 = (PageViewData) ((Data<?>) pvdEnvelope2.getData()).getBaseData();
    PageViewData pv3 = (PageViewData) ((Data<?>) pvdEnvelope3.getData()).getBaseData();
    assertNotNull(pv1);
    assertEquals(new Duration(0), pv1.getDuration());
    // checking that instrumentation key, cloud role name, cloud role instance, and sdk version are
    // from the agent
    assertEquals("00000000-0000-0000-0000-0FEEDDADBEEF", pvdEnvelope1.getIKey());
    assertEquals("testrolename", pvdEnvelope1.getTags().get("ai.cloud.role"));
    assertEquals("testroleinstance", pvdEnvelope1.getTags().get("ai.cloud.roleInstance"));
    assertTrue(pvdEnvelope1.getTags().get("ai.internal.sdkVersion").startsWith("java:3."));
    assertNotNull(pv2);
    assertEquals(new Duration(123456), pv2.getDuration());
    assertEquals("2010-10-10T00:00:00Z", pvdEnvelope2.getTime());
    assertEquals("value", pv2.getProperties().get("key"));
    assertEquals("a-value", pv2.getProperties().get("a-prop"));
    assertEquals("another-value", pv2.getProperties().get("another-prop"));
    // operation name is verified below in assertParentChild()
    assertEquals("user-id-goes-here", pvdEnvelope2.getTags().get("ai.user.id"));
    assertEquals("account-id-goes-here", pvdEnvelope2.getTags().get("ai.user.accountId"));
    assertEquals("user-agent-goes-here", pvdEnvelope2.getTags().get("ai.user.userAgent"));
    assertEquals("os-goes-here", pvdEnvelope2.getTags().get("ai.device.os"));
    assertEquals("session-id-goes-here", pvdEnvelope2.getTags().get("ai.session.id"));
    assertEquals("1.2.3.4", pvdEnvelope2.getTags().get("ai.location.ip"));
    // checking that instrumentation key, cloud role name and cloud role instance are overridden
    assertEquals("12341234-1234-1234-1234-123412341234", pvdEnvelope2.getIKey());
    assertEquals("role-goes-here", pvdEnvelope2.getTags().get("ai.cloud.role"));
    assertEquals("role-instance-goes-here", pvdEnvelope2.getTags().get("ai.cloud.roleInstance"));
    // checking that sdk version is from the agent
    assertTrue(pvdEnvelope2.getTags().get("ai.internal.sdkVersion").startsWith("java:3."));
    assertNotNull(pv3);
    assertEquals(new Duration(123456), pv3.getDuration());
    assertEquals("2010-10-10T00:00:00Z", pvdEnvelope3.getTime());
    assertEquals("value", pv3.getProperties().get("key"));
    assertEquals("a-value", pv3.getProperties().get("a-prop"));
    assertEquals("another-value", pv3.getProperties().get("another-prop"));
    // operation name is verified below in assertParentChild()
    assertEquals("user-id-goes-here", pvdEnvelope3.getTags().get("ai.user.id"));
    assertEquals("account-id-goes-here", pvdEnvelope3.getTags().get("ai.user.accountId"));
    assertEquals("user-agent-goes-here", pvdEnvelope3.getTags().get("ai.user.userAgent"));
    assertEquals("os-goes-here", pvdEnvelope3.getTags().get("ai.device.os"));
    assertEquals("session-id-goes-here", pvdEnvelope3.getTags().get("ai.session.id"));
    assertEquals("1.2.3.4", pvdEnvelope3.getTags().get("ai.location.ip"));
    // checking that instrumentation key, cloud role name and cloud role instance are from the agent
    assertEquals("00000000-0000-0000-0000-0FEEDDADBEEF", pvdEnvelope3.getIKey());
    assertEquals("testrolename", pvdEnvelope3.getTags().get("ai.cloud.role"));
    assertEquals("testroleinstance", pvdEnvelope3.getTags().get("ai.cloud.roleInstance"));
    // checking that sdk version is from the agent
    assertTrue(pvdEnvelope3.getTags().get("ai.internal.sdkVersion").startsWith("java:3."));
    assertParentChild(rd, rdEnvelope, pvdEnvelope1, "GET /CoreAndFilter/trackPageView");
    assertEquals("operation-id-goes-here", pvdEnvelope2.getTags().get("ai.operation.id"));
    assertEquals("operation-parent-id-goes-here", pvdEnvelope2.getTags().get("ai.operation.parentId"));
    assertEquals("operation-name-goes-here", pvdEnvelope2.getTags().get("ai.operation.name"));
    assertEquals("operation-id-goes-here", pvdEnvelope3.getTags().get("ai.operation.id"));
    assertEquals("operation-parent-id-goes-here", pvdEnvelope3.getTags().get("ai.operation.parentId"));
    assertEquals("operation-name-goes-here", pvdEnvelope3.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) PageViewData(com.microsoft.applicationinsights.smoketest.schemav2.PageViewData) 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