use of org.apache.skywalking.apm.agent.core.context.util.KeyValuePair in project incubator-skywalking by apache.
the class HttpClientExecuteInterceptorTest method testStatusCodeNotEquals200.
@Test
public void testStatusCodeNotEquals200() throws Throwable {
when(statusLine.getStatusCode()).thenReturn(500);
httpClientExecuteInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentsType, null);
httpClientExecuteInterceptor.afterMethod(enhancedInstance, null, allArguments, argumentsType, httpResponse);
Assert.assertThat(segmentStorage.getTraceSegments().size(), is(1));
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
assertThat(spans.size(), is(1));
List<KeyValuePair> tags = SpanHelper.getTags(spans.get(0));
assertThat(tags.size(), is(3));
assertThat(tags.get(2).getValue(), is("500"));
assertHttpSpan(spans.get(0));
assertThat(SpanHelper.getErrorOccurred(spans.get(0)), is(true));
verify(request, times(1)).setHeader(anyString(), anyString());
}
use of org.apache.skywalking.apm.agent.core.context.util.KeyValuePair in project incubator-skywalking by apache.
the class SyncHttpRequestSendInterceptorTest method testMethodsAroundError.
@Test
public void testMethodsAroundError() throws Throwable {
interceptor.beforeMethod(enhancedInstance, null, allArguments, argumentTypes, null);
interceptor.handleMethodException(enhancedInstance, null, allArguments, argumentTypes, new RuntimeException());
interceptor.afterMethod(enhancedInstance, null, allArguments, argumentTypes, null);
assertThat(segmentStorage.getTraceSegments().size(), is(1));
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
Assert.assertEquals(1, SegmentHelper.getSpans(traceSegment).size());
AbstractTracingSpan finishedSpan = SegmentHelper.getSpans(traceSegment).get(0);
List<KeyValuePair> tags = SpanHelper.getTags(finishedSpan);
assertThat(tags.size(), is(2));
assertThat(tags.get(0).getValue(), is("GET"));
assertThat(tags.get(1).getValue(), is(uri.toString()));
Assert.assertEquals(true, SpanHelper.getErrorOccurred(finishedSpan));
SpanAssert.assertException(SpanHelper.getLogs(finishedSpan).get(0), RuntimeException.class);
}
use of org.apache.skywalking.apm.agent.core.context.util.KeyValuePair in project incubator-skywalking by apache.
the class DefaultHttpClientInterceptorTest method testException.
@Test
public void testException() throws Throwable {
defaultHttpClientInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentTypes, result);
defaultHttpClientInterceptor.handleMethodException(enhancedInstance, null, allArguments, argumentTypes, new NullPointerException("testException"));
Response response = mock(Response.class);
when(response.status()).thenReturn(200);
defaultHttpClientInterceptor.afterMethod(enhancedInstance, null, allArguments, argumentTypes, response);
assertThat(segmentStorage.getTraceSegments().size(), is(1));
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
Assert.assertEquals(1, SegmentHelper.getSpans(traceSegment).size());
AbstractTracingSpan finishedSpan = SegmentHelper.getSpans(traceSegment).get(0);
assertSpan(finishedSpan);
List<KeyValuePair> tags = SpanHelper.getTags(finishedSpan);
assertThat(tags.size(), is(2));
assertThat(tags.get(0).getValue(), is("GET"));
assertThat(tags.get(1).getValue(), is("http://skywalking.org/"));
Assert.assertEquals(true, SpanHelper.getErrorOccurred(finishedSpan));
Assert.assertEquals(1, SpanHelper.getLogs(finishedSpan).size());
LogDataEntity logDataEntity = SpanHelper.getLogs(finishedSpan).get(0);
assertThat(logDataEntity.getLogs().size(), is(4));
assertThat(logDataEntity.getLogs().get(0).getValue(), CoreMatchers.<Object>is("error"));
assertThat(logDataEntity.getLogs().get(1).getValue(), CoreMatchers.<Object>is(NullPointerException.class.getName()));
assertThat(logDataEntity.getLogs().get(2).getValue(), is("testException"));
assertNotNull(logDataEntity.getLogs().get(3).getValue());
}
use of org.apache.skywalking.apm.agent.core.context.util.KeyValuePair in project incubator-skywalking by apache.
the class DefaultHttpClientInterceptorTest method testMethodsAroundError.
@Test
public void testMethodsAroundError() throws Throwable {
defaultHttpClientInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentTypes, result);
Response response = mock(Response.class);
when(response.status()).thenReturn(404);
defaultHttpClientInterceptor.afterMethod(enhancedInstance, null, allArguments, argumentTypes, response);
assertThat(segmentStorage.getTraceSegments().size(), is(1));
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
Assert.assertEquals(1, SegmentHelper.getSpans(traceSegment).size());
AbstractTracingSpan finishedSpan = SegmentHelper.getSpans(traceSegment).get(0);
assertSpan(finishedSpan);
List<KeyValuePair> tags = SpanHelper.getTags(finishedSpan);
assertThat(tags.size(), is(3));
assertThat(tags.get(0).getValue(), is("GET"));
assertThat(tags.get(1).getValue(), is("http://skywalking.org/"));
assertThat(tags.get(2).getValue(), is("404"));
Assert.assertEquals(true, SpanHelper.getErrorOccurred(finishedSpan));
}
use of org.apache.skywalking.apm.agent.core.context.util.KeyValuePair in project incubator-skywalking by apache.
the class SyncHttpRequestSendInterceptorTest method testMethodsAround.
@Test
public void testMethodsAround() throws Throwable {
interceptor.beforeMethod(enhancedInstance, null, allArguments, argumentTypes, null);
interceptor.afterMethod(enhancedInstance, null, allArguments, argumentTypes, null);
assertThat(segmentStorage.getTraceSegments().size(), is(1));
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
Assert.assertEquals(1, SegmentHelper.getSpans(traceSegment).size());
AbstractTracingSpan finishedSpan = SegmentHelper.getSpans(traceSegment).get(0);
List<KeyValuePair> tags = SpanHelper.getTags(finishedSpan);
assertThat(tags.size(), is(2));
assertThat(tags.get(0).getValue(), is("GET"));
assertThat(tags.get(1).getValue(), is(uri.toString()));
Assert.assertEquals(false, SpanHelper.getErrorOccurred(finishedSpan));
}
Aggregations