Search in sources :

Example 21 with Context

use of com.megaease.easeagent.plugin.api.Context in project easeagent by megaease.

the class HttpClient5AsyncForwardedInterceptorTest method before.

@Test
public void before() {
    SimpleHttpRequest simpleHttpRequest = SimpleHttpRequest.create("GET", "http://127.0.0.1:8080");
    SimpleRequestProducer simpleRequestProducer = SimpleRequestProducer.create(simpleHttpRequest);
    MethodInfo methodInfo = MethodInfo.builder().args(new Object[] { simpleRequestProducer }).build();
    HttpClient5AsyncForwardedInterceptor httpClientDoExecuteForwardedInterceptor = new HttpClient5AsyncForwardedInterceptor();
    Context context = EaseAgent.getContext();
    httpClientDoExecuteForwardedInterceptor.before(methodInfo, context);
    assertNull(simpleHttpRequest.getFirstHeader(TestConst.FORWARDED_NAME));
    context.put(TestConst.FORWARDED_NAME, TestConst.FORWARDED_VALUE);
    try {
        httpClientDoExecuteForwardedInterceptor.before(methodInfo, context);
        assertNotNull(simpleHttpRequest.getFirstHeader(TestConst.FORWARDED_NAME));
        assertEquals(TestConst.FORWARDED_VALUE, simpleHttpRequest.getFirstHeader(TestConst.FORWARDED_NAME).getValue());
    } finally {
        context.remove(TestConst.FORWARDED_NAME);
    }
}
Also used : Context(com.megaease.easeagent.plugin.api.Context) SimpleRequestProducer(org.apache.hc.client5.http.async.methods.SimpleRequestProducer) SimpleHttpRequest(org.apache.hc.client5.http.async.methods.SimpleHttpRequest) MethodInfo(com.megaease.easeagent.plugin.interceptor.MethodInfo) Test(org.junit.Test)

Example 22 with Context

use of com.megaease.easeagent.plugin.api.Context in project easeagent by megaease.

the class ElasticsearchBaseTest method before.

@Before
public void before() {
    Context context = EaseAgent.getContext();
    ContextUtils.setBeginTime(context);
    request = new Request("GET", "/" + index + "/_search");
    body = "mock body";
    HttpEntity httpEntity = new ByteArrayEntity(body.getBytes(StandardCharsets.UTF_8), ContentType.APPLICATION_JSON);
    request.setEntity(httpEntity);
    errMsg = "mock exception";
    {
        successResponse = mock(Response.class);
        StatusLine statusLine = mock(StatusLine.class);
        when(statusLine.getStatusCode()).thenReturn(200);
        when(successResponse.getStatusLine()).thenReturn(statusLine);
    }
    {
        failResponse = mock(Response.class);
        StatusLine statusLine = mock(StatusLine.class);
        when(statusLine.getStatusCode()).thenReturn(500);
        when(failResponse.getStatusLine()).thenReturn(statusLine);
    }
    config = mock(IPluginConfig.class);
    when(config.namespace()).thenReturn("es");
    responseListener = mock(ResponseListener.class);
}
Also used : Context(com.megaease.easeagent.plugin.api.Context) StatusLine(org.apache.http.StatusLine) HttpEntity(org.apache.http.HttpEntity) ByteArrayEntity(org.apache.http.entity.ByteArrayEntity) Request(org.elasticsearch.client.Request) ResponseListener(org.elasticsearch.client.ResponseListener) IPluginConfig(com.megaease.easeagent.plugin.api.config.IPluginConfig) Before(org.junit.Before)

Example 23 with Context

use of com.megaease.easeagent.plugin.api.Context in project easeagent by megaease.

the class ElasticsearchPerformRequestAsyncMetricsInterceptorTest method performFailThrowable.

@Test
public void performFailThrowable() {
    MethodInfo methodInfo = MethodInfo.builder().invoker(this).method("perform").args(new Object[] { request, responseListener }).build();
    Context context = EaseAgent.getContext();
    interceptor.init(config, "", "", "");
    interceptor.before(methodInfo, context);
    AsyncResponse4MetricsListener traceListener = (AsyncResponse4MetricsListener) methodInfo.getArgs()[1];
    traceListener.onFailure(new RuntimeException(this.errMsg));
    this.assertMetric(interceptor.getElasticsearchMetric().getNameFactory(), interceptor.getElasticsearchMetric().getMetricRegistry(), false);
}
Also used : Context(com.megaease.easeagent.plugin.api.Context) MethodInfo(com.megaease.easeagent.plugin.interceptor.MethodInfo) Test(org.junit.Test)

Example 24 with Context

use of com.megaease.easeagent.plugin.api.Context in project easeagent by megaease.

the class ElasticsearchPerformRequestAsyncMetricsInterceptorTest method performFail.

@Test
public void performFail() {
    MethodInfo methodInfo = MethodInfo.builder().invoker(this).method("perform").args(new Object[] { request, responseListener }).build();
    Context context = EaseAgent.getContext();
    interceptor.init(config, "", "", "");
    interceptor.before(methodInfo, context);
    AsyncResponse4MetricsListener traceListener = (AsyncResponse4MetricsListener) methodInfo.getArgs()[1];
    traceListener.onSuccess(this.failResponse);
    this.assertMetric(interceptor.getElasticsearchMetric().getNameFactory(), interceptor.getElasticsearchMetric().getMetricRegistry(), false);
}
Also used : Context(com.megaease.easeagent.plugin.api.Context) MethodInfo(com.megaease.easeagent.plugin.interceptor.MethodInfo) Test(org.junit.Test)

Example 25 with Context

use of com.megaease.easeagent.plugin.api.Context in project easeagent by megaease.

the class ElasticsearchPerformRequestAsyncTraceInterceptorTest method performSuccess.

@Test
public void performSuccess() {
    Context context = EaseAgent.getContext();
    MethodInfo methodInfo = MethodInfo.builder().invoker(this).method("perform").args(new Object[] { request, responseListener }).build();
    interceptor.before(methodInfo, context);
    AsyncResponse4TraceListener traceListener = (AsyncResponse4TraceListener) methodInfo.getArgs()[1];
    traceListener.onSuccess(this.successResponse);
    this.assertTrace(true, null);
}
Also used : Context(com.megaease.easeagent.plugin.api.Context) 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