Search in sources :

Example 46 with RequestData

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

the class SpringBootTest method testAsyncDependencyCall.

@Test
@TargetUri("/asyncDependencyCall")
public void testAsyncDependencyCall() throws Exception {
    List<Envelope> rdList = mockedIngestion.waitForItems("RequestData", 1);
    Envelope rdEnvelope = rdList.get(0);
    String operationId = rdEnvelope.getTags().get("ai.operation.id");
    List<Envelope> rddList = mockedIngestion.waitForItemsInOperation("RemoteDependencyData", 1, operationId);
    assertEquals(0, mockedIngestion.getCountForType("EventData"));
    Envelope rddEnvelope1 = rddList.get(0);
    RequestData rd = (RequestData) ((Data<?>) rdEnvelope.getData()).getBaseData();
    RemoteDependencyData rdd1 = (RemoteDependencyData) ((Data<?>) rddEnvelope1.getData()).getBaseData();
    assertEquals("GET /SpringBootTest/asyncDependencyCall", rd.getName());
    assertEquals("200", rd.getResponseCode());
    assertTrue(rd.getProperties().isEmpty());
    assertTrue(rd.getSuccess());
    assertEquals("GET /", rdd1.getName());
    assertEquals("https://www.bing.com", rdd1.getData());
    assertEquals("www.bing.com", rdd1.getTarget());
    assertTrue(rdd1.getProperties().isEmpty());
    assertTrue(rdd1.getSuccess());
    assertParentChild(rd, rdEnvelope, rddEnvelope1, "GET /SpringBootTest/asyncDependencyCall");
}
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 47 with RequestData

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

the class TraceLog4j2Test method testTraceLog4j2WithException.

@Test
@TargetUri("/traceLog4j2WithException")
public void testTraceLog4j2WithException() 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", 1, operationId);
    assertEquals(0, mockedIngestion.getCountForType("EventData"));
    Envelope edEnvelope = edList.get(0);
    RequestData rd = (RequestData) ((Data<?>) rdEnvelope.getData()).getBaseData();
    ExceptionData ed = (ExceptionData) ((Data<?>) edEnvelope.getData()).getBaseData();
    List<ExceptionDetails> details = ed.getExceptions();
    ExceptionDetails ex = details.get(0);
    assertEquals("Fake Exception", ex.getMessage());
    assertEquals(SeverityLevel.Error, ed.getSeverityLevel());
    assertEquals("This is an exception!", ed.getProperties().get("Logger Message"));
    assertEquals("Logger", ed.getProperties().get("SourceType"));
    assertEquals("ERROR", ed.getProperties().get("LoggingLevel"));
    assertEquals("smoketestapp", ed.getProperties().get("LoggerName"));
    assertNotNull(ed.getProperties().get("ThreadName"));
    assertEquals("MDC value", ed.getProperties().get("MDC key"));
    assertEquals(6, ed.getProperties().size());
    assertParentChild(rd, rdEnvelope, edEnvelope, "GET /TraceLog4j2UsingAgent/traceLog4j2WithException");
}
Also used : RequestData(com.microsoft.applicationinsights.smoketest.schemav2.RequestData) ExceptionData(com.microsoft.applicationinsights.smoketest.schemav2.ExceptionData) ExceptionDetails(com.microsoft.applicationinsights.smoketest.schemav2.ExceptionDetails) Envelope(com.microsoft.applicationinsights.smoketest.schemav2.Envelope) Test(org.junit.Test)

Example 48 with RequestData

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

the class SpringCloudStreamTest method doMostBasicTest.

@Test
@TargetUri("/sendMessage")
public void doMostBasicTest() throws Exception {
    List<Envelope> rdList = mockedIngestion.waitForItems("RequestData", 2);
    Envelope rdEnvelope1 = rdList.get(0);
    String operationId = rdEnvelope1.getTags().get("ai.operation.id");
    List<Envelope> rddList = mockedIngestion.waitForItemsInOperation("RemoteDependencyData", 1, operationId);
    assertEquals(0, mockedIngestion.getCountForType("EventData"));
    Envelope rdEnvelope2 = rdList.get(1);
    Envelope rddEnvelope1 = rddList.get(0);
    RequestData rd1 = (RequestData) ((Data<?>) rdEnvelope1.getData()).getBaseData();
    RequestData rd2 = (RequestData) ((Data<?>) rdEnvelope2.getData()).getBaseData();
    RemoteDependencyData rdd1 = (RemoteDependencyData) ((Data<?>) rddEnvelope1.getData()).getBaseData();
    assertEquals("GET /sendMessage", rd1.getName());
    assertTrue(rd1.getProperties().isEmpty());
    assertTrue(rd1.getSuccess());
    assertEquals("greetings send", rdd1.getName());
    assertNull(rdd1.getData());
    assertEquals("Queue Message | kafka", rdd1.getType());
    assertEquals("greetings", rdd1.getTarget());
    assertTrue(rdd1.getProperties().isEmpty());
    assertTrue(rdd1.getSuccess());
    assertEquals("greetings process", rd2.getName());
    assertEquals("greetings", rd2.getSource());
    assertTrue(rd2.getProperties().isEmpty());
    assertTrue(rd2.getSuccess());
    assertParentChild(rd1, rdEnvelope1, rddEnvelope1, "GET /sendMessage");
    assertParentChild(rdd1.getId(), rddEnvelope1, rdEnvelope2, "GET /sendMessage", "greetings 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 49 with RequestData

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

the class SpringBootAutoTest method spawnAnotherJavaProcess.

@Test
@TargetUri("/spawn-another-java-process")
public void spawnAnotherJavaProcess() throws Exception {
    List<Envelope> rdList = mockedIngestion.waitForItems("RequestData", 1);
    List<Envelope> rddList = mockedIngestion.waitForItems("RemoteDependencyData", 1);
    Envelope rdEnvelope = rdList.get(0);
    Envelope rddEnvelope = rddList.get(0);
    RequestData rd = (RequestData) ((Data<?>) rdEnvelope.getData()).getBaseData();
    RemoteDependencyData rdd = (RemoteDependencyData) ((Data<?>) rddEnvelope.getData()).getBaseData();
    assertTrue(rd.getProperties().isEmpty());
    assertTrue(rd.getSuccess());
    assertEquals("GET /search", rdd.getName());
    assertEquals("Http", rdd.getType());
    assertEquals("www.bing.com", rdd.getTarget());
    assertEquals("https://www.bing.com/search?q=test", rdd.getData());
    assertTrue(rdd.getProperties().isEmpty());
    assertTrue(rdd.getSuccess());
}
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 50 with RequestData

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

the class SamplingTest method testSampling.

@Test
@TargetUri(value = "/sampling", callCount = 100)
public void testSampling() throws Exception {
    // super super low chance that number of sampled requests is less than 25
    long start = System.nanoTime();
    while (mockedIngestion.getCountForType("RequestData") < 25 && NANOSECONDS.toSeconds(System.nanoTime() - start) < 10) {
    }
    // wait ten more seconds before checking that we didn't receive too many
    Thread.sleep(SECONDS.toMillis(10));
    List<Envelope> requestEnvelopes = mockedIngestion.getItemsEnvelopeDataType("RequestData");
    List<Envelope> eventEnvelopes = mockedIngestion.getItemsEnvelopeDataType("EventData");
    // super super low chance that number of sampled requests/dependencies/events
    // is less than 25 or greater than 75
    assertThat(requestEnvelopes.size(), greaterThanOrEqualTo(25));
    assertThat(requestEnvelopes.size(), lessThanOrEqualTo(75));
    assertThat(eventEnvelopes.size(), greaterThanOrEqualTo(25));
    assertThat(eventEnvelopes.size(), lessThanOrEqualTo(75));
    for (Envelope requestEnvelope : requestEnvelopes) {
        assertEquals(50, requestEnvelope.getSampleRate(), 0);
    }
    for (Envelope eventEnvelope : eventEnvelopes) {
        assertEquals(50, eventEnvelope.getSampleRate(), 0);
    }
    for (Envelope requestEnvelope : requestEnvelopes) {
        String operationId = requestEnvelope.getTags().get("ai.operation.id");
        mockedIngestion.waitForItemsInOperation("EventData", 1, operationId);
    }
}
Also used : Envelope(com.microsoft.applicationinsights.smoketest.schemav2.Envelope) 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