use of com.megaease.easeagent.plugin.api.Context in project easeagent by megaease.
the class WebClientFilterTracingInterceptorTest method doAfter.
@Test
public void doAfter() throws URISyntaxException {
WebClientFilterTracingInterceptor interceptor = new WebClientFilterTracingInterceptor();
Context context = EaseAgent.getContext();
URI uri = new URI(url);
ClientRequest clientRequest = MockClientRequest.build(uri);
MethodInfo methodInfo = MethodInfo.builder().args(new Object[] { clientRequest }).retValue(new MockMono()).build();
interceptor.doBefore(methodInfo, context);
assertTrue(context.currentTracing().hasCurrentSpan());
MockEaseAgent.cleanLastSpan();
interceptor.doAfter(methodInfo, context);
assertFalse(context.currentTracing().hasCurrentSpan());
assertNull(MockEaseAgent.getLastSpan());
assertTrue(methodInfo.getRetValue() instanceof AgentMono);
String errorInfo = "test error";
clientRequest = MockClientRequest.build(uri);
methodInfo = MethodInfo.builder().args(new Object[] { clientRequest }).retValue(new MockMono()).throwable(new RuntimeException(errorInfo)).build();
interceptor.doBefore(methodInfo, context);
assertTrue(context.currentTracing().hasCurrentSpan());
interceptor.doAfter(methodInfo, context);
assertFalse(context.currentTracing().hasCurrentSpan());
assertTrue(methodInfo.getRetValue() instanceof AgentMono);
ReportSpan mockSpan = MockEaseAgent.getLastSpan();
assertNotNull(mockSpan);
assertTrue(mockSpan.hasError());
assertEquals(errorInfo, mockSpan.errorInfo());
}
use of com.megaease.easeagent.plugin.api.Context in project easeagent by megaease.
the class GatewayMetricsInterceptorTest method before.
@Test
public void before() {
GatewayMetricsInterceptor interceptor = new GatewayMetricsInterceptor();
Context context = EaseAgent.getContext();
interceptor.before(null, context);
assertNotNull(context.get(startTime));
}
use of com.megaease.easeagent.plugin.api.Context in project easeagent by megaease.
the class GatewayServerTracingInterceptorTest method finishCallback.
@Test
public void finishCallback() throws InterruptedException {
GatewayServerTracingInterceptor interceptor = new GatewayServerTracingInterceptor();
Context context = EaseAgent.getContext();
MockServerWebExchange mockServerWebExchange = TestServerWebExchangeUtils.mockServerWebExchange();
MethodInfo methodInfo = MethodInfo.builder().args(new Object[] { mockServerWebExchange }).build();
interceptor.before(methodInfo, context);
RequestContext requestContext = context.get(GatewayServerTracingInterceptor.SPAN_CONTEXT_KEY);
interceptor.after(methodInfo, context);
assertNotNull(methodInfo.getRetValue());
assertTrue(methodInfo.getRetValue() instanceof AgentMono);
assertNull(MockEaseAgent.getLastSpan());
AtomicBoolean atomicBoolean = new AtomicBoolean(false);
BiConsumer<ServerWebExchange, MethodInfo> consumer = (methodInfo1, exchange) -> atomicBoolean.set(true);
mockServerWebExchange.getAttributes().put(GatewayCons.CLIENT_RECEIVE_CALLBACK_KEY, consumer);
AgentMono agentMono = (AgentMono) methodInfo.getRetValue();
Thread thread = new Thread(() -> agentMono.getFinish().accept(agentMono.getMethodInfo(), agentMono.getAsyncContext()));
thread.start();
thread.join();
assertTrue(atomicBoolean.get());
ReportSpan reportSpan = MockEaseAgent.getLastSpan();
assertTrue(reportSpan.name().contains("/test"));
SpanTestUtils.sameId(requestContext.span(), reportSpan);
}
use of com.megaease.easeagent.plugin.api.Context in project easeagent by megaease.
the class GatewayServerForwardedInterceptorTest method doBefore.
@Test
public void doBefore() {
GatewayServerForwardedInterceptor interceptor = new GatewayServerForwardedInterceptor();
MockServerWebExchange mockServerWebExchange = TestServerWebExchangeUtils.build(builder().header(TestConst.FORWARDED_NAME, TestConst.FORWARDED_VALUE));
Context context = EaseAgent.getContext();
MethodInfo methodInfo = MethodInfo.builder().args(new Object[] { mockServerWebExchange }).build();
interceptor.doBefore(methodInfo, context);
assertEquals(TestConst.FORWARDED_VALUE, context.get(TestConst.FORWARDED_NAME));
interceptor.doAfter(methodInfo, context);
assertNull(context.get(TestConst.FORWARDED_NAME));
}
use of com.megaease.easeagent.plugin.api.Context in project easeagent by megaease.
the class DoFilterTraceInterceptorTest method testHasPassHeader.
@Test
public void testHasPassHeader() {
MockHttpServletRequest httpServletRequest = TestServletUtils.buildMockRequest();
Context context = EaseAgent.getContext();
RequestContext requestContext = context.clientRequest(new MockClientRequest(httpServletRequest::addHeader));
requestContext.scope().close();
assertFalse(context.currentTracing().hasCurrentSpan());
HttpServletResponse response = TestServletUtils.buildMockResponse();
MethodInfo methodInfo = MethodInfo.builder().args(new Object[] { httpServletRequest, response }).build();
DoFilterTraceInterceptor doFilterTraceInterceptor = new DoFilterTraceInterceptor();
doFilterTraceInterceptor.doBefore(methodInfo, EaseAgent.getContext());
doFilterTraceInterceptor.doAfter(methodInfo, EaseAgent.getContext());
ReportSpan mockSpan = MockEaseAgent.getLastSpan();
assertNotNull(mockSpan);
assertEquals(requestContext.span().traceIdString(), mockSpan.traceId());
assertEquals(requestContext.span().spanIdString(), mockSpan.id());
assertEquals(requestContext.span().parentIdString(), mockSpan.parentId());
checkServerSpan(mockSpan);
}
Aggregations