Search in sources :

Example 76 with Context

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));
}
Also used : Context(com.megaease.easeagent.plugin.api.Context) Message(org.springframework.amqp.core.Message) MethodInfo(com.megaease.easeagent.plugin.interceptor.MethodInfo) Test(org.junit.Test)

Example 77 with Context

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());
}
Also used : Context(com.megaease.easeagent.plugin.api.Context) ReportSpan(com.megaease.easeagent.plugin.report.tracing.ReportSpan) Message(org.springframework.amqp.core.Message) ArrayList(java.util.ArrayList) MethodInfo(com.megaease.easeagent.plugin.interceptor.MethodInfo) Test(org.junit.Test)

Example 78 with Context

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());
}
Also used : Context(com.megaease.easeagent.plugin.api.Context) Message(org.springframework.amqp.core.Message) ArrayList(java.util.ArrayList) ReportSpan(com.megaease.easeagent.plugin.report.tracing.ReportSpan) Span(com.megaease.easeagent.plugin.api.trace.Span) ReportSpan(com.megaease.easeagent.plugin.report.tracing.ReportSpan) MethodInfo(com.megaease.easeagent.plugin.interceptor.MethodInfo) Test(org.junit.Test)

Example 79 with Context

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));
}
Also used : Context(com.megaease.easeagent.plugin.api.Context) ReportSpan(com.megaease.easeagent.plugin.report.tracing.ReportSpan) Message(org.springframework.amqp.core.Message) ReportSpan(com.megaease.easeagent.plugin.report.tracing.ReportSpan) Span(com.megaease.easeagent.plugin.api.trace.Span) Test(org.junit.Test)

Example 80 with Context

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());
}
Also used : Context(com.megaease.easeagent.plugin.api.Context) ReportSpan(com.megaease.easeagent.plugin.report.tracing.ReportSpan) Message(org.springframework.amqp.core.Message) ArrayList(java.util.ArrayList) MethodInfo(com.megaease.easeagent.plugin.interceptor.MethodInfo) Test(org.junit.Test)

Aggregations

Context (com.megaease.easeagent.plugin.api.Context)122 Test (org.junit.Test)101 MethodInfo (com.megaease.easeagent.plugin.interceptor.MethodInfo)87 ReportSpan (com.megaease.easeagent.plugin.report.tracing.ReportSpan)39 Span (com.megaease.easeagent.plugin.api.trace.Span)32 RequestContext (com.megaease.easeagent.plugin.api.context.RequestContext)13 Scope (com.megaease.easeagent.plugin.api.trace.Scope)13 Message (org.springframework.amqp.core.Message)10 URI (java.net.URI)9 LastJsonReporter (com.megaease.easeagent.mock.report.impl.LastJsonReporter)8 TagVerifier (com.megaease.easeagent.mock.plugin.api.utils.TagVerifier)7 BsonDocument (org.bson.BsonDocument)7 MockServerWebExchange (org.springframework.mock.web.server.MockServerWebExchange)7 HttpRequest (com.megaease.easeagent.plugin.tools.trace.HttpRequest)6 CommandSucceededEvent (com.mongodb.event.CommandSucceededEvent)6 ArrayList (java.util.ArrayList)6 BsonString (org.bson.BsonString)6 Call (okhttp3.Call)5 ClientRequest (org.springframework.web.reactive.function.client.ClientRequest)4 MockClientRequest (org.springframework.web.reactive.function.client.MockClientRequest)4