use of com.megaease.easeagent.plugin.api.Context in project easeagent by megaease.
the class AgentCoreSubscriberTest method onComplete.
@Test
public void onComplete() throws URISyntaxException {
MockCoreSubscriber mockCoreSubscriber = new MockCoreSubscriber();
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);
RequestContext requestContext = context.get(interceptor.getProgressKey());
AgentCoreSubscriber agentCoreSubscriber = new AgentCoreSubscriber(mockCoreSubscriber, methodInfo, requestContext);
agentCoreSubscriber.onComplete();
assertTrue(mockCoreSubscriber.onComplete.get());
ReportSpan mockSpan = MockEaseAgent.getLastSpan();
assertFalse(mockSpan.hasError());
MockEaseAgent.cleanLastSpan();
methodInfo = MethodInfo.builder().args(new Object[] { clientRequest }).retValue(new MockMono()).build();
interceptor.doBefore(methodInfo, context);
requestContext = context.get(interceptor.getProgressKey());
agentCoreSubscriber = new AgentCoreSubscriber(mockCoreSubscriber, methodInfo, requestContext);
ClientResponse clientResponse = MockDefaultClientResponse.builder(203).build();
agentCoreSubscriber.onNext(clientResponse);
agentCoreSubscriber.onComplete();
assertTrue(mockCoreSubscriber.onComplete.get());
mockSpan = MockEaseAgent.getLastSpan();
assertFalse(mockSpan.hasError());
}
use of com.megaease.easeagent.plugin.api.Context in project easeagent by megaease.
the class InterceptorTest method testBeforeAfter.
@Test
public void testBeforeAfter() {
assertNull(MockEaseAgent.getLastSpan());
final Object key = new Object();
Interceptor interceptor = new Interceptor() {
@Override
public void before(MethodInfo methodInfo, Context context) {
Span span = context.nextSpan();
span.start();
context.put(key, span);
}
@Override
public void after(MethodInfo methodInfo, Context context) {
Span span = context.remove(key);
span.finish();
}
};
Context context = EaseAgent.getContext();
interceptor.before(null, context);
Span span = context.get(key);
assertNotNull(span);
assertNull(MockEaseAgent.getLastSpan());
interceptor.after(null, context);
ReportSpan reportSpan = MockEaseAgent.getLastSpan();
SpanTestUtils.sameId(span, reportSpan);
}
use of com.megaease.easeagent.plugin.api.Context in project easeagent by megaease.
the class MockEaseAgentTest method resetAll.
@Test
public void resetAll() {
Context context = EaseAgent.getContext();
String key = "testKey";
context.put(key, "value");
assertNotNull(context.get(key));
MockEaseAgent.resetAll();
assertNull(context.get(key));
}
use of com.megaease.easeagent.plugin.api.Context in project easeagent by megaease.
the class RabbitMqChannelPublishTracingInterceptorTest method before.
@Test
public void before() {
RabbitMqChannelPublishTracingInterceptor interceptor = new RabbitMqChannelPublishTracingInterceptor();
Context context = EaseAgent.getContext();
String uri = "192.168.0.13:2222";
context.put(ContextCons.MQ_URI, uri);
String exchange = "testExchange";
String routingKey = "testRoutingKey";
AMQP.BasicProperties basicProperties = new AMQP.BasicProperties();
MethodInfo methodInfo = MethodInfo.builder().args(new Object[] { exchange, routingKey, null, null, basicProperties }).build();
interceptor.before(methodInfo, context);
interceptor.after(methodInfo, context);
ReportSpan reportSpan = MockEaseAgent.getLastSpan();
assertNotNull(reportSpan);
assertEquals(Span.Kind.PRODUCER.name(), reportSpan.kind());
assertEquals(exchange, reportSpan.tag("rabbit.exchange"));
assertEquals(routingKey, reportSpan.tag("rabbit.routing_key"));
assertEquals(uri, reportSpan.tag("rabbit.broker"));
assertEquals("rabbitmq", reportSpan.remoteServiceName());
assertEquals(Type.RABBITMQ.getRemoteType(), reportSpan.tag(MiddlewareConstants.TYPE_TAG_NAME));
assertNull(reportSpan.tag(MiddlewareConstants.REDIRECTED_LABEL_REMOTE_TAG_NAME));
assertFalse(reportSpan.hasError());
String errorInfo = "testError";
methodInfo = MethodInfo.builder().args(new Object[] { exchange, routingKey, null, null, basicProperties }).throwable(new RuntimeException(errorInfo)).build();
interceptor.before(methodInfo, context);
interceptor.after(methodInfo, context);
reportSpan = MockEaseAgent.getLastSpan();
assertTrue(reportSpan.hasError());
assertEquals(errorInfo, reportSpan.errorInfo());
Span span = context.nextSpan();
span.cacheScope();
methodInfo = MethodInfo.builder().args(new Object[] { exchange, routingKey, null, null, basicProperties }).build();
interceptor.before(methodInfo, context);
interceptor.after(methodInfo, context);
reportSpan = MockEaseAgent.getLastSpan();
assertEquals(span.traceIdString(), reportSpan.traceId());
assertEquals(span.spanIdString(), reportSpan.parentId());
span.finish();
TestUtils.setRedirect();
RedirectProcessor.redirected(Redirect.RABBITMQ, TestUtils.getRedirectUri());
methodInfo = MethodInfo.builder().args(new Object[] { exchange, routingKey, null, null, basicProperties }).build();
interceptor.before(methodInfo, context);
interceptor.after(methodInfo, context);
reportSpan = MockEaseAgent.getLastSpan();
assertEquals(TestUtils.getRedirectUri(), reportSpan.tag(MiddlewareConstants.REDIRECTED_LABEL_REMOTE_TAG_NAME));
}
use of com.megaease.easeagent.plugin.api.Context in project easeagent by megaease.
the class RabbitMqMessageListenerOnMessageInterceptorTest method before.
@Test
public void before() {
RabbitMqMessageListenerOnMessageInterceptor interceptor = new RabbitMqMessageListenerOnMessageInterceptor();
MessageProperties messageProperties = new MessageProperties();
String testMqUri = "testMqUri";
messageProperties.setHeader(ContextCons.MQ_URI, testMqUri);
Message message = new Message("testBody".getBytes(), messageProperties);
MethodInfo methodInfo = MethodInfo.builder().args(new Object[] { message }).build();
Context context = EaseAgent.getContext();
interceptor.before(methodInfo, context);
assertEquals(testMqUri, context.get(ContextCons.MQ_URI));
context.remove(ContextCons.MQ_URI);
methodInfo = MethodInfo.builder().args(new Object[] { Collections.singletonList(message) }).build();
interceptor.before(methodInfo, context);
assertEquals(testMqUri, context.get(ContextCons.MQ_URI));
}
Aggregations