Search in sources :

Example 11 with EventData

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

the class AiSmokeTest method getTelemetry.

protected static Telemetry getTelemetry(int rddCount, Predicate<RemoteDependencyData> condition) throws Exception {
    if (rddCount > 3) {
        throw new IllegalArgumentException("this method currently only supports rddCount up to 3");
    }
    Telemetry telemetry = new Telemetry();
    List<Envelope> rdList = mockedIngestion.waitForItems("RequestData", 1);
    telemetry.rdEnvelope = rdList.get(0);
    telemetry.rd = (RequestData) ((Data<?>) telemetry.rdEnvelope.getData()).getBaseData();
    assertEquals(0, mockedIngestion.getCountForType("EventData"));
    if (rddCount == 0) {
        return telemetry;
    }
    String operationId = telemetry.rdEnvelope.getTags().get("ai.operation.id");
    List<Envelope> rddList = mockedIngestion.waitForItemsInOperation("RemoteDependencyData", rddCount, operationId, envelope -> {
        RemoteDependencyData rdd = (RemoteDependencyData) ((Data<?>) envelope.getData()).getBaseData();
        return condition.test(rdd);
    });
    telemetry.rddEnvelope1 = rddList.get(0);
    telemetry.rdd1 = (RemoteDependencyData) ((Data<?>) telemetry.rddEnvelope1.getData()).getBaseData();
    if (rddCount == 1) {
        return telemetry;
    }
    telemetry.rddEnvelope2 = rddList.get(1);
    telemetry.rdd2 = (RemoteDependencyData) ((Data<?>) telemetry.rddEnvelope2.getData()).getBaseData();
    if (rddCount == 2) {
        return telemetry;
    }
    telemetry.rddEnvelope3 = rddList.get(2);
    telemetry.rdd3 = (RemoteDependencyData) ((Data<?>) telemetry.rddEnvelope3.getData()).getBaseData();
    return telemetry;
}
Also used : RemoteDependencyData(com.microsoft.applicationinsights.smoketest.schemav2.RemoteDependencyData) 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)

Example 12 with EventData

use of com.microsoft.applicationinsights.smoketest.schemav2.EventData 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 13 with EventData

use of com.microsoft.applicationinsights.smoketest.schemav2.EventData 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 14 with EventData

use of com.microsoft.applicationinsights.smoketest.schemav2.EventData 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)

Example 15 with EventData

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

the class JmsDisabledTest method doMostBasicTest.

@Test
@TargetUri("/sendMessage")
public void doMostBasicTest() throws Exception {
    List<Envelope> rdList = mockedIngestion.waitForItems("RequestData", 1);
    Envelope rdEnvelope = rdList.get(0);
    RequestData rd = (RequestData) ((Data<?>) rdEnvelope.getData()).getBaseData();
    assertEquals(0, mockedIngestion.getCountForType("EventData"));
    assertEquals("GET /sendMessage", rd.getName());
    assertEquals("200", rd.getResponseCode());
    assertTrue(rd.getProperties().isEmpty());
    assertTrue(rd.getSuccess());
    // verify the downstream http dependency that is no longer part of the same trace
    List<Envelope> rddList = mockedIngestion.waitForItems("RemoteDependencyData", 1);
    Envelope rddEnvelope = rddList.get(0);
    RemoteDependencyData rdd = (RemoteDependencyData) ((Data<?>) rddEnvelope.getData()).getBaseData();
    assertEquals("GET /", rdd.getName());
    assertEquals("https://www.bing.com", rdd.getData());
    assertTrue(rdd.getProperties().isEmpty());
    assertTrue(rdd.getSuccess());
    // sleep a bit and make sure no kafka "requests" or dependencies are reported
    Thread.sleep(5000);
    assertEquals(1, mockedIngestion.getCountForType("RequestData"));
    assertEquals(1, mockedIngestion.getCountForType("RemoteDependencyData"));
}
Also used : RequestData(com.microsoft.applicationinsights.smoketest.schemav2.RequestData) RemoteDependencyData(com.microsoft.applicationinsights.smoketest.schemav2.RemoteDependencyData) Envelope(com.microsoft.applicationinsights.smoketest.schemav2.Envelope) Test(org.junit.Test)

Aggregations

Envelope (com.microsoft.applicationinsights.smoketest.schemav2.Envelope)25 Test (org.junit.Test)24 RequestData (com.microsoft.applicationinsights.smoketest.schemav2.RequestData)22 RemoteDependencyData (com.microsoft.applicationinsights.smoketest.schemav2.RemoteDependencyData)14 ExceptionData (com.microsoft.applicationinsights.smoketest.schemav2.ExceptionData)7 EventData (com.microsoft.applicationinsights.smoketest.schemav2.EventData)5 Data (com.microsoft.applicationinsights.smoketest.schemav2.Data)3 RequestDataMatchers.hasDuration (com.microsoft.applicationinsights.smoketest.matchers.RequestDataMatchers.hasDuration)2 ExceptionDetails (com.microsoft.applicationinsights.smoketest.schemav2.ExceptionDetails)2 PageViewData (com.microsoft.applicationinsights.smoketest.schemav2.PageViewData)2 Duration (com.microsoft.applicationinsights.smoketest.telemetry.Duration)2 Description (org.hamcrest.Description)2 Matcher (org.hamcrest.Matcher)2 TypeSafeMatcher (org.hamcrest.TypeSafeMatcher)2 AiSmokeTest (com.microsoft.applicationinsights.smoketest.AiSmokeTest)1 TargetUri (com.microsoft.applicationinsights.smoketest.TargetUri)1