Search in sources :

Example 36 with Data

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

the class SpringBootTest method trackEvent.

@Test
@TargetUri("/basic/trackEvent")
public void trackEvent() throws Exception {
    List<Envelope> rdList = mockedIngestion.waitForItems("RequestData", 1);
    Envelope rdEnvelope = rdList.get(0);
    String operationId = rdEnvelope.getTags().get("ai.operation.id");
    mockedIngestion.waitForItemsInOperation("EventData", 2, operationId);
    // TODO get event data envelope and verify value
    List<EventData> data = mockedIngestion.getTelemetryDataByTypeInRequest("EventData");
    assertThat(data, hasItem(new TypeSafeMatcher<EventData>() {

        final String name = "EventDataTest";

        final Matcher<String> nameMatcher = Matchers.equalTo(name);

        @Override
        protected boolean matchesSafely(EventData item) {
            return nameMatcher.matches(item.getName());
        }

        @Override
        public void describeTo(Description description) {
            description.appendDescriptionOf(nameMatcher);
        }
    }));
    assertThat(data, hasItem(new TypeSafeMatcher<EventData>() {

        final String expectedKey = "key";

        final String expectedName = "EventDataPropertyTest";

        final String expectedPropertyValue = "value";

        final Double expectedMetricValue = 1d;

        final Matcher<Map<? extends String, ? extends Double>> metricMatcher = Matchers.hasEntry(expectedKey, expectedMetricValue);

        final Matcher<Map<? extends String, ? extends String>> propertyMatcher = Matchers.hasEntry(expectedKey, expectedPropertyValue);

        final Matcher<String> nameMatcher = Matchers.equalTo(expectedName);

        @Override
        public void describeTo(Description description) {
            description.appendDescriptionOf(nameMatcher);
            description.appendDescriptionOf(propertyMatcher);
            description.appendDescriptionOf(metricMatcher);
        }

        @Override
        protected boolean matchesSafely(EventData item) {
            return nameMatcher.matches(item.getName()) && propertyMatcher.matches(item.getProperties()) && metricMatcher.matches(item.getMeasurements());
        }
    }));
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Matcher(org.hamcrest.Matcher) Envelope(com.microsoft.applicationinsights.smoketest.schemav2.Envelope) EventData(com.microsoft.applicationinsights.smoketest.schemav2.EventData) Test(org.junit.Test)

Example 37 with Data

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

the class SpringBootTest method testResultCodeWhenRestControllerThrows.

@Test
@TargetUri("/throwsException")
public void testResultCodeWhenRestControllerThrows() 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);
    assertEquals(0, mockedIngestion.getCountForType("EventData"));
    Envelope edEnvelope1 = edList.get(0);
    RequestData rd = getTelemetryDataForType(0, "RequestData");
    assertEquals("GET /SpringBootTest/throwsException", rd.getName());
    assertEquals("500", rd.getResponseCode());
    assertTrue(rd.getProperties().isEmpty());
    assertFalse(rd.getSuccess());
    assertParentChild(rd, rdEnvelope, edEnvelope1, "GET /SpringBootTest/throwsException");
}
Also used : RequestData(com.microsoft.applicationinsights.smoketest.schemav2.RequestData) ExceptionData(com.microsoft.applicationinsights.smoketest.schemav2.ExceptionData) RemoteDependencyData(com.microsoft.applicationinsights.smoketest.schemav2.RemoteDependencyData) RequestData(com.microsoft.applicationinsights.smoketest.schemav2.RequestData) EventData(com.microsoft.applicationinsights.smoketest.schemav2.EventData) ExceptionData(com.microsoft.applicationinsights.smoketest.schemav2.ExceptionData) Data(com.microsoft.applicationinsights.smoketest.schemav2.Data) Envelope(com.microsoft.applicationinsights.smoketest.schemav2.Envelope) Test(org.junit.Test)

Example 38 with Data

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

the class MicrometerTest method doMostBasicTest.

@Test
@TargetUri("/test")
public void doMostBasicTest() throws Exception {
    Telemetry telemetry = getTelemetry(0);
    assertEquals("GET /test", telemetry.rd.getName());
    assertTrue(telemetry.rd.getUrl().matches("http://localhost:[0-9]+/test"));
    assertEquals("200", telemetry.rd.getResponseCode());
    assertTrue(telemetry.rd.getSuccess());
    assertNull(telemetry.rd.getSource());
    assertTrue(telemetry.rd.getProperties().isEmpty());
    assertTrue(telemetry.rd.getMeasurements().isEmpty());
    // sleep a bit and make sure that the excluded metric is not reported
    Thread.sleep(10000);
    List<Envelope> metricItems = mockedIngestion.getItemsEnvelopeDataType("MetricData").stream().filter(e -> {
        MetricData data = (MetricData) ((Data<?>) e.getData()).getBaseData();
        List<DataPoint> points = data.getMetrics();
        DataPoint point = points.get(0);
        return point.getValue() == 1;
    }).collect(Collectors.toList());
    MetricData data = (MetricData) ((Data<?>) metricItems.get(0).getData()).getBaseData();
    List<DataPoint> points = data.getMetrics();
    assertEquals(1, points.size());
    DataPoint point = points.get(0);
    assertEquals(DataPointType.Measurement, point.getKind());
    // (this was verified above in Predicate also)
    assertEquals(1, point.getValue(), 0);
    assertEquals("test_counter", point.getName());
    assertNull("getCount was non-null", point.getCount());
    assertNull("getMin was non-null", point.getMin());
    assertNull("getMax was non-null", point.getMax());
    assertNull("getStdDev was non-null", point.getStdDev());
    assertEquals(1, data.getProperties().size());
    assertEquals("value1", data.getProperties().get("tag1"));
}
Also used : List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) MetricData(com.microsoft.applicationinsights.smoketest.schemav2.MetricData) Assert.assertTrue(org.junit.Assert.assertTrue) Envelope(com.microsoft.applicationinsights.smoketest.schemav2.Envelope) Test(org.junit.Test) Data(com.microsoft.applicationinsights.smoketest.schemav2.Data) DataPoint(com.microsoft.applicationinsights.smoketest.schemav2.DataPoint) Collectors(java.util.stream.Collectors) Assert.assertEquals(org.junit.Assert.assertEquals) DataPointType(com.microsoft.applicationinsights.smoketest.schemav2.DataPointType) DataPoint(com.microsoft.applicationinsights.smoketest.schemav2.DataPoint) MetricData(com.microsoft.applicationinsights.smoketest.schemav2.MetricData) Data(com.microsoft.applicationinsights.smoketest.schemav2.Data) List(java.util.List) Envelope(com.microsoft.applicationinsights.smoketest.schemav2.Envelope) MetricData(com.microsoft.applicationinsights.smoketest.schemav2.MetricData) Test(org.junit.Test)

Example 39 with Data

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

the class KafkaControllerSpansEnabledTest method doMostBasicTest.

@Test
@TargetUri("/sendMessage")
public void doMostBasicTest() throws Exception {
    List<Envelope> rdList = mockedIngestion.waitForItems("RequestData", 2);
    Envelope rdEnvelope1 = getRequestEnvelope(rdList, "GET /sendMessage");
    String operationId = rdEnvelope1.getTags().get("ai.operation.id");
    List<Envelope> rddList = mockedIngestion.waitForItemsInOperation("RemoteDependencyData", 3, operationId);
    assertEquals(0, mockedIngestion.getCountForType("EventData"));
    Envelope rdEnvelope2 = getRequestEnvelope(rdList, "mytopic process");
    Envelope rddEnvelope1 = getDependencyEnvelope(rddList, "HelloController.sendMessage");
    Envelope rddEnvelope2 = getDependencyEnvelope(rddList, "mytopic send");
    Envelope rddEnvelope3 = getDependencyEnvelope(rddList, "GET /");
    RequestData rd1 = (RequestData) ((Data<?>) rdEnvelope1.getData()).getBaseData();
    RequestData rd2 = (RequestData) ((Data<?>) rdEnvelope2.getData()).getBaseData();
    RemoteDependencyData rdd1 = (RemoteDependencyData) ((Data<?>) rddEnvelope1.getData()).getBaseData();
    RemoteDependencyData rdd2 = (RemoteDependencyData) ((Data<?>) rddEnvelope2.getData()).getBaseData();
    RemoteDependencyData rdd3 = (RemoteDependencyData) ((Data<?>) rddEnvelope3.getData()).getBaseData();
    assertEquals("GET /sendMessage", rd1.getName());
    assertTrue(rd1.getProperties().isEmpty());
    assertTrue(rd1.getSuccess());
    assertEquals("HelloController.sendMessage", rdd1.getName());
    assertNull(rdd1.getData());
    assertEquals("InProc", rdd1.getType());
    assertNull(rdd1.getTarget());
    assertTrue(rdd1.getProperties().isEmpty());
    assertTrue(rdd1.getSuccess());
    assertEquals("mytopic send", rdd2.getName());
    assertNull(rdd2.getData());
    assertEquals("Queue Message | kafka", rdd2.getType());
    assertEquals("mytopic", rdd2.getTarget());
    assertTrue(rdd2.getProperties().isEmpty());
    assertTrue(rdd2.getSuccess());
    assertEquals("mytopic process", rd2.getName());
    assertEquals("mytopic", rd2.getSource());
    assertTrue(rd2.getProperties().isEmpty());
    assertTrue(rd2.getSuccess());
    assertTrue(rd2.getMeasurements().containsKey("timeSinceEnqueued"));
    assertEquals("GET /", rdd3.getName());
    assertEquals("https://www.bing.com", rdd3.getData());
    assertEquals("Http", rdd3.getType());
    assertEquals("www.bing.com", rdd3.getTarget());
    assertTrue(rdd3.getProperties().isEmpty());
    assertTrue(rdd3.getSuccess());
    assertParentChild(rd1, rdEnvelope1, rddEnvelope1, "GET /sendMessage");
    assertParentChild(rdd1, rddEnvelope1, rddEnvelope2, "GET /sendMessage");
    assertParentChild(rdd2.getId(), rddEnvelope2, rdEnvelope2, "GET /sendMessage", "mytopic process", false);
    assertParentChild(rd2.getId(), rdEnvelope2, rddEnvelope3, "mytopic process", "mytopic process", false);
}
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)

Example 40 with Data

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

the class JmsControllerSpansEnabledTest method doMostBasicTest.

@Test
@TargetUri("/sendMessage")
public void doMostBasicTest() throws Exception {
    List<Envelope> rdList = mockedIngestion.waitForItems("RequestData", 2);
    Envelope rdEnvelope1 = getRequestEnvelope(rdList, "GET /sendMessage");
    String operationId = rdEnvelope1.getTags().get("ai.operation.id");
    List<Envelope> rddList = mockedIngestion.waitForItemsInOperation("RemoteDependencyData", 3, operationId);
    assertEquals(0, mockedIngestion.getCountForType("EventData"));
    Envelope rdEnvelope2 = getRequestEnvelope(rdList, "message process");
    Envelope rddEnvelope1 = getDependencyEnvelope(rddList, "HelloController.sendMessage");
    Envelope rddEnvelope2 = getDependencyEnvelope(rddList, "message send");
    Envelope rddEnvelope3 = getDependencyEnvelope(rddList, "GET /");
    RequestData rd1 = (RequestData) ((Data<?>) rdEnvelope1.getData()).getBaseData();
    RequestData rd2 = (RequestData) ((Data<?>) rdEnvelope2.getData()).getBaseData();
    RemoteDependencyData rdd1 = (RemoteDependencyData) ((Data<?>) rddEnvelope1.getData()).getBaseData();
    RemoteDependencyData rdd2 = (RemoteDependencyData) ((Data<?>) rddEnvelope2.getData()).getBaseData();
    RemoteDependencyData rdd3 = (RemoteDependencyData) ((Data<?>) rddEnvelope3.getData()).getBaseData();
    assertEquals("GET /sendMessage", rd1.getName());
    assertTrue(rd1.getProperties().isEmpty());
    assertTrue(rd1.getSuccess());
    assertEquals("HelloController.sendMessage", rdd1.getName());
    assertNull(rdd1.getData());
    assertEquals("InProc", rdd1.getType());
    assertNull(rdd1.getTarget());
    assertTrue(rdd1.getProperties().isEmpty());
    assertTrue(rdd1.getSuccess());
    assertEquals("message send", rdd2.getName());
    assertNull(rdd2.getData());
    assertEquals("Queue Message | jms", rdd2.getType());
    assertEquals("message", rdd2.getTarget());
    assertTrue(rdd2.getProperties().isEmpty());
    assertTrue(rdd2.getSuccess());
    assertEquals("message process", rd2.getName());
    assertEquals("message", rd2.getSource());
    assertTrue(rd2.getProperties().isEmpty());
    assertTrue(rd2.getSuccess());
    assertEquals("GET /", rdd3.getName());
    assertEquals("https://www.bing.com", rdd3.getData());
    assertEquals("Http", rdd3.getType());
    assertEquals("www.bing.com", rdd3.getTarget());
    assertTrue(rdd3.getProperties().isEmpty());
    assertTrue(rdd3.getSuccess());
    assertParentChild(rd1, rdEnvelope1, rddEnvelope1, "GET /sendMessage");
    assertParentChild(rdd1, rddEnvelope1, rddEnvelope2, "GET /sendMessage");
    assertParentChild(rdd2.getId(), rddEnvelope2, rdEnvelope2, "GET /sendMessage", "message process", false);
    assertParentChild(rd2.getId(), rdEnvelope2, rddEnvelope3, "message process", "message process", false);
}
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

Test (org.junit.Test)65 Envelope (com.microsoft.applicationinsights.smoketest.schemav2.Envelope)53 RequestData (com.microsoft.applicationinsights.smoketest.schemav2.RequestData)45 Data (org.geotoolkit.wps.xml.v200.Data)42 RemoteDependencyData (com.microsoft.applicationinsights.smoketest.schemav2.RemoteDependencyData)26 UnconvertibleObjectException (org.apache.sis.util.UnconvertibleObjectException)20 IOException (java.io.IOException)16 DataInput (org.geotoolkit.wps.xml.v200.DataInput)15 Format (org.geotoolkit.wps.xml.v200.Format)12 AiSmokeTest (com.microsoft.applicationinsights.smoketest.AiSmokeTest)10 TargetUri (com.microsoft.applicationinsights.smoketest.TargetUri)10 MessageData (com.microsoft.applicationinsights.smoketest.schemav2.MessageData)10 ComplexData (org.geotoolkit.wps.xml.v200.ComplexData)10 ExceptionData (com.microsoft.applicationinsights.smoketest.schemav2.ExceptionData)9 ReferenceProxy (org.geotoolkit.wps.xml.ReferenceProxy)9 Data (com.microsoft.applicationinsights.smoketest.schemav2.Data)8 DataStoreException (org.apache.sis.storage.DataStoreException)8 LiteralValue (org.geotoolkit.wps.xml.v200.LiteralValue)7 EventData (com.microsoft.applicationinsights.smoketest.schemav2.EventData)6 MetricData (com.microsoft.applicationinsights.smoketest.schemav2.MetricData)6