Search in sources :

Example 11 with KeyValuePair

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));
}
Also used : KeyValuePair(org.apache.skywalking.apm.agent.core.context.util.KeyValuePair) AbstractTracingSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan) TraceSegment(org.apache.skywalking.apm.agent.core.context.trace.TraceSegment) Test(org.junit.Test)

Example 12 with KeyValuePair

use of org.apache.skywalking.apm.agent.core.context.util.KeyValuePair in project incubator-skywalking by apache.

the class DefaultHttpClientInterceptorTest method testMethodsAround.

@Test
public void testMethodsAround() throws Throwable {
    Response response = mock(Response.class);
    when(response.status()).thenReturn(200);
    defaultHttpClientInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentTypes, result);
    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(false, SpanHelper.getErrorOccurred(finishedSpan));
}
Also used : Response(feign.Response) KeyValuePair(org.apache.skywalking.apm.agent.core.context.util.KeyValuePair) AbstractTracingSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan) TraceSegment(org.apache.skywalking.apm.agent.core.context.trace.TraceSegment) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 13 with KeyValuePair

use of org.apache.skywalking.apm.agent.core.context.util.KeyValuePair in project incubator-skywalking by apache.

the class StateInterceptorTest method testStatusCodeNotEquals200.

@Test
public void testStatusCodeNotEquals200() throws Throwable {
    when(statusLine.getStatusCode()).thenReturn(500);
    AbstractSpan span = ContextManager.createLocalSpan("httpasyncclient/HttpAsyncRequestExecutor:");
    stateInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentsType, null);
    stateInterceptor.afterMethod(enhancedInstance, null, allArguments, argumentsType, httpResponse);
    allArguments = new Object[] { httpResponse };
    setResponseInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentsType, null);
    setResponseInterceptor.afterMethod(enhancedInstance, null, allArguments, argumentsType, httpResponse);
    processResponseInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentsType, null);
    processResponseInterceptor.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(3));
    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());
}
Also used : KeyValuePair(org.apache.skywalking.apm.agent.core.context.util.KeyValuePair) AbstractTracingSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan) TraceSegment(org.apache.skywalking.apm.agent.core.context.trace.TraceSegment) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

KeyValuePair (org.apache.skywalking.apm.agent.core.context.util.KeyValuePair)13 AbstractTracingSpan (org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan)10 TraceSegment (org.apache.skywalking.apm.agent.core.context.trace.TraceSegment)10 Test (org.junit.Test)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 Response (feign.Response)3 Method (java.lang.reflect.Method)1 Map (java.util.Map)1 AbstractSpan (org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)1 LogDataEntity (org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity)1 LogMessage (org.apache.skywalking.apm.network.proto.LogMessage)1 SpanObject (org.apache.skywalking.apm.network.proto.SpanObject)1