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);
}
}
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);
}
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);
}
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);
}
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);
}
Aggregations