use of com.megaease.easeagent.plugin.api.context.AsyncContext in project easeagent by megaease.
the class ElasticsearchPerformRequestAsync4TraceInterceptor method before.
@Override
public void before(MethodInfo methodInfo, Context context) {
ElasticsearchCtxUtils.initSpan(methodInfo, context);
AsyncContext asyncContext = context.exportAsync();
ResponseListener listener = (ResponseListener) methodInfo.getArgs()[1];
ResponseListener asyncResponseListener = new AsyncResponse4TraceListener(listener, asyncContext);
methodInfo.changeArg(1, asyncResponseListener);
}
use of com.megaease.easeagent.plugin.api.context.AsyncContext in project easeagent by megaease.
the class AgentMonoTest method testImportToCurrent.
@Test
public void testImportToCurrent() throws InterruptedException {
Context context = EaseAgent.getContext();
Span span = context.nextSpan();
Thread thread;
try (Scope ignored4 = span.maybeScope()) {
AsyncContext asyncContext1 = context.exportAsync();
AsyncContext asyncContext2 = context.exportAsync();
AsyncContext asyncContext3 = context.exportAsync();
thread = new Thread(() -> {
Context asyncContext = EaseAgent.getContext();
assertFalse(asyncContext.currentTracing().hasCurrentSpan());
try (Cleaner ignored = asyncContext1.importToCurrent()) {
assertTrue(asyncContext.currentTracing().hasCurrentSpan());
try (Cleaner ignored1 = asyncContext2.importToCurrent()) {
assertTrue(asyncContext.currentTracing().hasCurrentSpan());
try (Cleaner ignored2 = asyncContext3.importToCurrent()) {
assertTrue(asyncContext.currentTracing().hasCurrentSpan());
}
assertTrue(asyncContext.currentTracing().hasCurrentSpan());
}
assertTrue(asyncContext.currentTracing().hasCurrentSpan());
}
assertFalse(asyncContext.currentTracing().hasCurrentSpan());
});
}
thread.start();
thread.join();
}
use of com.megaease.easeagent.plugin.api.context.AsyncContext in project easeagent by megaease.
the class AgentCoreSubscriberTest method onError.
@Test
public void onError() {
MockCoreSubscriber mockCoreSubscriber = new MockCoreSubscriber();
MethodInfo errorMethodInfo = MethodInfo.builder().build();
AsyncContext errorAsyncContext = EaseAgent.getContext().exportAsync();
RuntimeException runtimeException = new RuntimeException();
AgentCoreSubscriber agentCoreSubscriber = new AgentCoreSubscriber(mockCoreSubscriber, errorMethodInfo, errorAsyncContext, (methodInfo, asyncContext) -> {
assertNotNull(methodInfo);
assertNotNull(asyncContext);
assertSame(errorMethodInfo, methodInfo);
assertSame(errorAsyncContext, asyncContext);
assertFalse(methodInfo.isSuccess());
assertSame(runtimeException, methodInfo.getThrowable());
});
agentCoreSubscriber.onError(runtimeException);
assertTrue(mockCoreSubscriber.onError.get());
}
use of com.megaease.easeagent.plugin.api.context.AsyncContext in project easeagent by megaease.
the class SessionContextTest method exportAsync.
@Test
public void exportAsync() {
SessionContext sessionContext = new SessionContext();
sessionContext.setSupplier(EaseAgent.initializeContextSupplier);
MockITracing iTracing = new MockITracing();
sessionContext.setCurrentTracing(iTracing);
String name = "test_name";
String value = "test_value";
assertNull(sessionContext.get(name));
sessionContext.put(name, value);
assertEquals(value, sessionContext.get(name));
AsyncContext asyncContext = sessionContext.exportAsync();
assertTrue(asyncContext.getSpanContext().isNoop());
assertEquals(1, iTracing.exportAsyncCount.get());
assertEquals(value, asyncContext.get(name));
assertFalse(asyncContext.isNoop());
SessionContext sessionContext2 = new SessionContext();
sessionContext2.setCurrentTracing(iTracing);
assertNull(sessionContext2.get(name));
try (Cleaner ignored = sessionContext2.importAsync(asyncContext)) {
assertEquals(value, sessionContext2.get(name));
assertEquals(1, iTracing.importAsyncCount.get());
try (Cleaner ignored1 = sessionContext2.importAsync(asyncContext)) {
assertEquals(2, iTracing.importAsyncCount.get());
}
assertEquals(value, sessionContext2.get(name));
}
}
use of com.megaease.easeagent.plugin.api.context.AsyncContext in project easeagent by megaease.
the class AgentCoreSubscriberTest method onComplete.
@Test
public void onComplete() {
MockCoreSubscriber mockCoreSubscriber = new MockCoreSubscriber();
MethodInfo completeMethodInfo = MethodInfo.builder().build();
AsyncContext completeAsyncContext = EaseAgent.getContext().exportAsync();
AgentCoreSubscriber agentCoreSubscriber = new AgentCoreSubscriber(mockCoreSubscriber, completeMethodInfo, completeAsyncContext, (methodInfo, asyncContext) -> {
assertNotNull(methodInfo);
assertNotNull(asyncContext);
assertSame(completeMethodInfo, methodInfo);
assertSame(completeAsyncContext, asyncContext);
assertTrue(methodInfo.isSuccess());
});
agentCoreSubscriber.onComplete();
assertTrue(mockCoreSubscriber.onComplete.get());
}
Aggregations