use of com.megaease.easeagent.plugin.api.Context in project easeagent by megaease.
the class RabbitMqOnMessageTracingInterceptorTest method before4Single.
@Test
public void before4Single() {
RabbitMqOnMessageTracingInterceptor interceptor = new RabbitMqOnMessageTracingInterceptor();
Context context = EaseAgent.getContext();
Message message = buildMessage(context);
MethodInfo methodInfo = MethodInfo.builder().args(new Object[] { message }).build();
interceptor.before4Single(methodInfo, context);
assertNotNull(context.get(RabbitMqOnMessageTracingInterceptor.SPAN_CONTEXT_KEY + 0));
context.<Span>get(RabbitMqOnMessageTracingInterceptor.SPAN_CONTEXT_KEY + 0).finish();
assertNull(context.get(RabbitMqOnMessageTracingInterceptor.SPAN_CONTEXT_KEY + 1));
}
use of com.megaease.easeagent.plugin.api.Context in project easeagent by megaease.
the class RabbitMqOnMessageTracingInterceptorTest method after4List.
@Test
public void after4List() {
RabbitMqOnMessageTracingInterceptor interceptor = new RabbitMqOnMessageTracingInterceptor();
Context context = EaseAgent.getContext();
int count = 5;
List<Message> messages = new ArrayList<>();
for (int i = 0; i < count; i++) {
messages.add(buildMessage(context));
}
MethodInfo methodInfo = MethodInfo.builder().args(new Object[] { messages }).build();
interceptor.before4List(methodInfo, context);
List<ReportSpan> reportSpans = new ArrayList<>();
MockEaseAgent.setMockSpanReport(reportSpans::add);
interceptor.after4List(methodInfo, context);
assertEquals(count, reportSpans.size());
}
use of com.megaease.easeagent.plugin.api.Context in project easeagent by megaease.
the class RabbitMqOnMessageTracingInterceptorTest method after.
@Test
public void after() {
RabbitMqOnMessageTracingInterceptor interceptor = new RabbitMqOnMessageTracingInterceptor();
Context context = EaseAgent.getContext();
Message message = buildMessage(context);
MethodInfo methodInfo = MethodInfo.builder().args(new Object[] { message }).build();
interceptor.before(methodInfo, context);
Span span = context.get(RabbitMqOnMessageTracingInterceptor.SPAN_CONTEXT_KEY + 0);
interceptor.after(methodInfo, context);
ReportSpan reportSpan = MockEaseAgent.getLastSpan();
SpanTestUtils.sameId(span, reportSpan);
int count = 5;
List<Message> messages = new ArrayList<>();
for (int i = 0; i < count; i++) {
messages.add(buildMessage(context));
}
methodInfo = MethodInfo.builder().args(new Object[] { messages }).build();
interceptor.before(methodInfo, context);
List<Span> spans = new ArrayList<>();
for (int i = 0; i < count; i++) {
spans.add(context.get(RabbitMqOnMessageTracingInterceptor.SPAN_CONTEXT_KEY + i));
}
span = context.get(RabbitMqOnMessageTracingInterceptor.SCOPE_CONTEXT_KEY);
List<ReportSpan> reportSpans = new ArrayList<>();
MockEaseAgent.setMockSpanReport(reportSpans::add);
interceptor.after(methodInfo, context);
assertEquals(spans.size() + 1, reportSpans.size());
for (int i = 0; i < spans.size(); i++) {
ReportSpan child = reportSpans.get(i);
SpanTestUtils.sameId(spans.get(i), child);
assertEquals(span.traceIdString(), child.traceId());
assertEquals(span.spanIdString(), child.parentId());
}
reportSpan = reportSpans.get(reportSpans.size() - 1);
assertEquals("on-message-list", reportSpan.name());
}
use of com.megaease.easeagent.plugin.api.Context in project easeagent by megaease.
the class RabbitMqOnMessageTracingInterceptorTest method processMessageBefore.
@Test
public void processMessageBefore() {
RabbitMqOnMessageTracingInterceptor interceptor = new RabbitMqOnMessageTracingInterceptor();
Context context = EaseAgent.getContext();
Message message = buildMessage(context);
interceptor.processMessageBefore(message, context, 0);
Span span = context.get(RabbitMqOnMessageTracingInterceptor.SPAN_CONTEXT_KEY + 0);
assertNotNull(span);
span.finish();
ReportSpan reportSpan = MockEaseAgent.getLastSpan();
assertEquals(Span.Kind.CONSUMER.name(), reportSpan.kind());
assertEquals(exchange, reportSpan.tag("rabbit.exchange"));
assertEquals(routingKey, reportSpan.tag("rabbit.routing_key"));
assertEquals(queue, reportSpan.tag("rabbit.queue"));
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));
TestUtils.setRedirect();
RedirectProcessor.redirected(Redirect.RABBITMQ, TestUtils.getRedirectUri());
interceptor.processMessageBefore(message, context, 0);
span = context.get(RabbitMqOnMessageTracingInterceptor.SPAN_CONTEXT_KEY + 0);
span.finish();
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 RabbitMqOnMessageTracingInterceptorTest method before.
@Test
public void before() {
RabbitMqOnMessageTracingInterceptor interceptor = new RabbitMqOnMessageTracingInterceptor();
Context context = EaseAgent.getContext();
Message message = buildMessage(context);
MethodInfo methodInfo = MethodInfo.builder().args(new Object[] { message }).build();
interceptor.before(methodInfo, context);
assertNotNull(context.get(RabbitMqOnMessageTracingInterceptor.SPAN_CONTEXT_KEY + 0));
context.<Span>remove(RabbitMqOnMessageTracingInterceptor.SPAN_CONTEXT_KEY + 0).finish();
assertNull(context.get(RabbitMqOnMessageTracingInterceptor.SPAN_CONTEXT_KEY + 1));
int count = 5;
List<Message> messages = new ArrayList<>();
for (int i = 0; i < count; i++) {
messages.add(buildMessage(context));
}
methodInfo = MethodInfo.builder().args(new Object[] { messages }).build();
interceptor.before(methodInfo, context);
for (int i = 0; i < count; i++) {
assertNotNull(context.get(RabbitMqOnMessageTracingInterceptor.SPAN_CONTEXT_KEY + i));
context.<Span>remove(RabbitMqOnMessageTracingInterceptor.SPAN_CONTEXT_KEY + i).finish();
}
assertNull(context.get(RabbitMqOnMessageTracingInterceptor.SPAN_CONTEXT_KEY + (count + 1)));
assertNotNull(context.get(RabbitMqOnMessageTracingInterceptor.SCOPE_CONTEXT_KEY));
context.<Span>remove(RabbitMqOnMessageTracingInterceptor.SCOPE_CONTEXT_KEY).finish();
ReportSpan reportSpan = MockEaseAgent.getLastSpan();
assertEquals("on-message-list", reportSpan.name());
}
Aggregations