Search in sources :

Example 36 with MockSpan

use of io.opentracing.mock.MockSpan in project java-spring-web by opentracing-contrib.

the class MVCJettyITest method testControllerMappedException.

@Test
public void testControllerMappedException() throws Exception {
    {
        getRestTemplate().getForEntity("/mappedException", String.class);
        Awaitility.await().until(reportedSpansSize(), IsEqual.equalTo(1));
    }
    List<MockSpan> mockSpans = TracingBeansConfiguration.mockTracer.finishedSpans();
    Assert.assertEquals(1, mockSpans.size());
    assertOnErrors(mockSpans);
    MockSpan span = mockSpans.get(0);
    Assert.assertEquals("mappedException", span.operationName());
    Assert.assertEquals(5, span.tags().size());
    Assert.assertEquals(Tags.SPAN_KIND_SERVER, span.tags().get(Tags.SPAN_KIND.getKey()));
    Assert.assertEquals("GET", span.tags().get(Tags.HTTP_METHOD.getKey()));
    Assert.assertEquals(getUrl("/mappedException"), span.tags().get(Tags.HTTP_URL.getKey()));
    Assert.assertEquals(409, span.tags().get(Tags.HTTP_STATUS.getKey()));
    Assert.assertNotNull(span.tags().get(Tags.COMPONENT.getKey()));
    assertLogEvents(span.logEntries(), Arrays.asList("preHandle", "afterCompletion"));
}
Also used : MockSpan(io.opentracing.mock.MockSpan) Test(org.junit.Test)

Example 37 with MockSpan

use of io.opentracing.mock.MockSpan in project java-spring-web by opentracing-contrib.

the class MVCJettyITest method testNoURLMapping.

@Test
public void testNoURLMapping() {
    {
        getRestTemplate().getForEntity("/nouUrlMapping", String.class);
        Awaitility.await().until(reportedSpansSize(), IsEqual.equalTo(1));
    }
    List<MockSpan> mockSpans = TracingBeansConfiguration.mockTracer.finishedSpans();
    Assert.assertEquals(1, mockSpans.size());
    assertOnErrors(mockSpans);
    MockSpan span = mockSpans.get(0);
    Assert.assertEquals("GET", span.operationName());
    Assert.assertEquals(404, span.tags().get(Tags.HTTP_STATUS.getKey()));
    assertLogEvents(span.logEntries(), Collections.<String>emptyList());
}
Also used : MockSpan(io.opentracing.mock.MockSpan) Test(org.junit.Test)

Example 38 with MockSpan

use of io.opentracing.mock.MockSpan in project java-spring-web by opentracing-contrib.

the class MVCJettyITest method testControllerException.

@Test
public void testControllerException() throws Exception {
    {
        getRestTemplate().getForEntity("/exception", String.class);
        Awaitility.await().until(reportedSpansSize(), IsEqual.equalTo(1));
    }
    List<MockSpan> mockSpans = TracingBeansConfiguration.mockTracer.finishedSpans();
    Assert.assertEquals(1, mockSpans.size());
    assertOnErrors(mockSpans);
    MockSpan span = mockSpans.get(0);
    Assert.assertEquals("exception", span.operationName());
    Assert.assertEquals(6, span.tags().size());
    Assert.assertEquals(Tags.SPAN_KIND_SERVER, span.tags().get(Tags.SPAN_KIND.getKey()));
    Assert.assertEquals("GET", span.tags().get(Tags.HTTP_METHOD.getKey()));
    Assert.assertEquals(getUrl("/exception"), span.tags().get(Tags.HTTP_URL.getKey()));
    Assert.assertEquals(500, span.tags().get(Tags.HTTP_STATUS.getKey()));
    Assert.assertNotNull(span.tags().get(Tags.COMPONENT.getKey()));
    Assert.assertEquals(Boolean.TRUE, span.tags().get(Tags.ERROR.getKey()));
    assertLogEvents(span.logEntries(), Arrays.asList("preHandle", "afterCompletion", "error"));
    // error log
    Assert.assertEquals(3, span.logEntries().get(2).fields().size());
    Assert.assertEquals(Tags.ERROR.getKey(), span.logEntries().get(2).fields().get("event"));
    Assert.assertEquals(TestController.EXCEPTION_MESSAGE, span.logEntries().get(2).fields().get("message"));
    Assert.assertNotNull(span.logEntries().get(2).fields().get("stack"));
}
Also used : MockSpan(io.opentracing.mock.MockSpan) Test(org.junit.Test)

Example 39 with MockSpan

use of io.opentracing.mock.MockSpan in project java-spring-web by opentracing-contrib.

the class MVCJettyITest method testSecuredURLUnAuthorized.

@Test
public void testSecuredURLUnAuthorized() throws Exception {
    {
        getRestTemplate().getForEntity("/secured", String.class);
        Awaitility.await().until(reportedSpansSize(), IsEqual.equalTo(1));
    }
    List<MockSpan> mockSpans = TracingBeansConfiguration.mockTracer.finishedSpans();
    Assert.assertEquals(1, mockSpans.size());
    assertOnErrors(mockSpans);
    MockSpan span = mockSpans.get(0);
    Assert.assertEquals("GET", span.operationName());
    Assert.assertEquals(5, span.tags().size());
    Assert.assertEquals(Tags.SPAN_KIND_SERVER, span.tags().get(Tags.SPAN_KIND.getKey()));
    Assert.assertEquals("GET", span.tags().get(Tags.HTTP_METHOD.getKey()));
    Assert.assertEquals(getUrl("/secured"), span.tags().get(Tags.HTTP_URL.getKey()));
    Assert.assertEquals(401, span.tags().get(Tags.HTTP_STATUS.getKey()));
    Assert.assertNotNull(span.tags().get(Tags.COMPONENT.getKey()));
    // request does not hit any controller
    assertLogEvents(span.logEntries(), Collections.<String>emptyList());
}
Also used : MockSpan(io.opentracing.mock.MockSpan) Test(org.junit.Test)

Example 40 with MockSpan

use of io.opentracing.mock.MockSpan in project java-spring-web by opentracing-contrib.

the class MVCJettyITest method testFilterException.

@Test
public void testFilterException() throws Exception {
    {
        getRestTemplate().getForEntity(ExceptionFilter.EXCEPTION_URL, String.class);
        Awaitility.await().until(reportedSpansSize(), IsEqual.equalTo(1));
    }
    List<MockSpan> mockSpans = TracingBeansConfiguration.mockTracer.finishedSpans();
    Assert.assertEquals(1, mockSpans.size());
    assertOnErrors(mockSpans);
    MockSpan span = mockSpans.get(0);
    Assert.assertEquals("GET", span.operationName());
    Assert.assertEquals(6, span.tags().size());
    Assert.assertEquals(Tags.SPAN_KIND_SERVER, span.tags().get(Tags.SPAN_KIND.getKey()));
    Assert.assertEquals("GET", span.tags().get(Tags.HTTP_METHOD.getKey()));
    Assert.assertEquals(getUrl(ExceptionFilter.EXCEPTION_URL), span.tags().get(Tags.HTTP_URL.getKey()));
    Assert.assertEquals(500, span.tags().get(Tags.HTTP_STATUS.getKey()));
    Assert.assertNotNull(span.tags().get(Tags.COMPONENT.getKey()));
    Assert.assertEquals(Boolean.TRUE, span.tags().get(Tags.ERROR.getKey()));
    // request is not hitting controller
    assertLogEvents(span.logEntries(), Arrays.asList("error"));
    // error logs
    Assert.assertEquals(3, span.logEntries().get(0).fields().size());
    Assert.assertEquals(Tags.ERROR.getKey(), span.logEntries().get(0).fields().get("event"));
    Assert.assertNotNull(span.logEntries().get(0).fields().get("stack"));
    Assert.assertEquals(ExceptionFilter.EXCEPTION_MESSAGE, span.logEntries().get(0).fields().get("message"));
}
Also used : MockSpan(io.opentracing.mock.MockSpan) Test(org.junit.Test)

Aggregations

MockSpan (io.opentracing.mock.MockSpan)51 Test (org.junit.Test)50 MockTracer (io.opentracing.mock.MockTracer)17 Matchers.anyString (org.mockito.Matchers.anyString)14 SpanDecorator (org.apache.camel.opentracing.SpanDecorator)13 Endpoint (org.apache.camel.Endpoint)11 Scope (io.opentracing.Scope)10 Exchange (org.apache.camel.Exchange)10 Message (org.apache.camel.Message)8 Span (io.opentracing.Span)2 DefaultResponse (com.weibo.api.motan.rpc.DefaultResponse)1 Response (com.weibo.api.motan.rpc.Response)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Client (javax.ws.rs.client.Client)1 WebTarget (javax.ws.rs.client.WebTarget)1