use of com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedTrace in project pinpoint by naver.
the class PluginVerifierExternalAdaptor method verifyDiscreteTraceBlock.
public void verifyDiscreteTraceBlock(ExpectedTrace[] expectations, Integer asyncId) {
if (ArrayUtils.isEmpty(expectations)) {
throw new IllegalArgumentException("No expectations");
}
ExpectedTrace expected = expectations[0];
ResolvedExpectedTrace resolved = resolveExpectedTrace(expected, asyncId);
int i = 0;
Iterator<SpanType> iterator = this.handler.getOrderedSpanRecorder().iterator();
while (iterator.hasNext()) {
final SpanType next = iterator.next();
ActualTrace actual = ActualTraceFactory.wrap(next);
try {
verifySpan(resolved, actual);
} catch (AssertionError e) {
continue;
}
iterator.remove();
verifyAsyncTraces(expected, actual);
if (++i == expectations.length) {
return;
}
expected = expectations[i];
resolved = resolveExpectedTrace(expected, asyncId);
}
throw new AssertionError("Failed to match " + i + "th expectation: " + resolved);
}
use of com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedTrace in project pinpoint by naver.
the class HystrixCommand_1_4_3_to_1_5_2_IT method testExecutionException.
@Test
public void testExecutionException() throws Exception {
Exception expectedException = new RuntimeException("expected");
executeThrowExceptionCommand(expectedException);
PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
verifier.printCache();
Method queue = HystrixCommand.class.getMethod("queue");
Class<?> executionObservableClazz = Class.forName(EXECUTION_OBSERVABLE_INNER_CLASS);
Method executionObservableCallCmd = executionObservableClazz.getDeclaredMethod("call", Subscriber.class);
Class<?> fallbackObservableClazz = Class.forName(FALLBACK_OBSERVABLE_INNER_CLASS);
Method fallbackObservableCallCmd = fallbackObservableClazz.getDeclaredMethod("call", Subscriber.class);
ExpectedTrace expectedFallbackTrace;
try {
// We record the cause of the fallback by invoking AbstractCommand.getExecutionException() added in 1.4.22
HystrixCommand.class.getMethod("getExecutionException");
expectedFallbackTrace = Expectations.event("HYSTRIX_COMMAND_INTERNAL", fallbackObservableCallCmd, annotation("hystrix.command.execution", "fallback"), annotation("hystrix.command.fallback.cause", expectedException.toString()));
} catch (NoSuchMethodException e) {
// pre 1.4.22
expectedFallbackTrace = Expectations.event("HYSTRIX_COMMAND_INTERNAL", fallbackObservableCallCmd, annotation("hystrix.command.execution", "fallback"));
}
verifier.verifyTrace(Expectations.async(Expectations.event("HYSTRIX_COMMAND", queue, annotation("hystrix.command", ThrowExceptionCommand.class.getSimpleName())), Expectations.event("ASYNC", "Asynchronous Invocation"), Expectations.event("HYSTRIX_COMMAND_INTERNAL", executionObservableCallCmd, annotation("hystrix.command.execution", "run")), expectedFallbackTrace));
// no more traces
verifier.verifyTraceCount(0);
}
use of com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedTrace in project pinpoint by naver.
the class ActiveMQClientITBase method verifyConsumerPullEvent.
/**
* Verifies spans and span events for when {@link ActiveMQMessageConsumer} receives the message and enqueues it to
* the {@link org.apache.activemq.MessageDispatchChannel MessageDispatchChannel}. The client then invokes any of
* {@link ActiveMQMessageConsumer#receive() receive()}, {@link ActiveMQMessageConsumer#receive(long) receive(long)},
* or {@link ActiveMQMessageConsumer#receiveNoWait() receiveNotWait()} to retrieve the message. (trace count : 4)
*
* @param destination the destination from which the consumer is receiving the message
* @param expectedMessage the message the consumer is expected to receive
* @throws Exception
*/
private void verifyConsumerPullEvent(ActiveMQDestination destination, MessageConsumer consumer, Message expectedMessage) throws Exception {
PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
verifier.printCache();
Class<?> messageConsumerClass = Class.forName("org.apache.activemq.ActiveMQMessageConsumer");
Method receiveWithTimeout = messageConsumerClass.getDeclaredMethod("receive", long.class);
URI consumerBrokerUri = new URI(getConsumerBrokerUrl());
ExpectedTrace consumerDispatchTrace = root(// serviceType
ACTIVEMQ_CLIENT, // method
"ActiveMQ Consumer Invocation", // rpc
destination.getQualifiedName(), // endPoint (collected but there's no easy way to retrieve local address)
null, consumerBrokerUri.getHost() + ":" + consumerBrokerUri.getPort());
ExpectedTrace consumerReceiveTrace = event(// serviceType
ACTIVEMQ_CLIENT_INTERNAL, // method
receiveWithTimeout, annotation("activemq.message", getMessageAsString(expectedMessage)));
Class<?> messageDispatchChannel = getMessageDispatchChannelClass(consumer);
if (messageDispatchChannel != null) {
Method enqueue = messageDispatchChannel.getDeclaredMethod("enqueue", MessageDispatch.class);
Method dequeueWithTimeout = messageDispatchChannel.getDeclaredMethod("dequeue", long.class);
// Consumer dispatches and enqueues the message to dispatch channel automatically
verifier.verifyDiscreteTrace(consumerDispatchTrace, event(ACTIVEMQ_CLIENT_INTERNAL, enqueue));
// Client receives the message by dequeueing it from the dispatch channel
verifier.verifyDiscreteTrace(consumerReceiveTrace, event(ACTIVEMQ_CLIENT_INTERNAL, dequeueWithTimeout));
} else {
// Consumer dispatches and enqueues the message to dispatch channel automatically
verifier.verifyDiscreteTrace(consumerDispatchTrace);
// Client receives the message by dequeueing it from the dispatch channel
verifier.verifyDiscreteTrace(consumerReceiveTrace);
}
}
use of com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedTrace in project pinpoint by naver.
the class AsyncEchoTestClient method verifyTraces.
@Override
public void verifyTraces(PluginTestVerifier verifier, String expectedMessage) throws Exception {
final InetSocketAddress socketAddress = this.environment.getServerAddress();
final String hostName = SocketAddressUtils.getHostNameFirst(socketAddress);
// refer to com.navercorp.pinpoint.plugin.thrift.ThriftUtils#getHostPort
final String remoteAddress = HostAndPort.toHostAndPortString(hostName, socketAddress.getPort());
// ********** Asynchronous Traces
// SpanEvent - Asynchronous Invocation
ExpectedTrace asyncInvocationTrace = event("ASYNC", "Asynchronous Invocation");
// SpanEvent - TAsyncMethodCall.cleanUpAndFireCallback
Method cleanUpAndFireCallback = TAsyncMethodCall.class.getDeclaredMethod("cleanUpAndFireCallback", SelectionKey.class);
ExpectedTrace cleanUpAndFireCallbackTrace = event("THRIFT_CLIENT_INTERNAL", cleanUpAndFireCallback);
// SpanEvent - TServiceClient.receiveBase
Method receiveBase = TServiceClient.class.getDeclaredMethod("receiveBase", TBase.class, String.class);
ExpectedAnnotation thriftResult = Expectations.annotation("thrift.result", "echo_result(success:" + expectedMessage + ")");
ExpectedTrace receiveBaseTrace = event(// ServiceType
"THRIFT_CLIENT_INTERNAL", // Method
receiveBase, // Annotation("thrift.result")
thriftResult);
// ********** Root trace for Asynchronous traces
// SpanEvent - TAsyncClientManager.call
Method call = TAsyncClientManager.class.getDeclaredMethod("call", TAsyncMethodCall.class);
ExpectedAnnotation thriftUrl = Expectations.annotation("thrift.url", remoteAddress + "/com/navercorp/pinpoint/plugin/thrift/dto/EchoService/echo");
ExpectedTrace callTrace = event(// ServiceType
"THRIFT_CLIENT", // Method
call, // rpc
null, // endPoint
null, // destinationId
remoteAddress, // Annotation("thrift.url")
thriftUrl);
verifier.verifyTrace(async(callTrace, asyncInvocationTrace, cleanUpAndFireCallbackTrace, receiveBaseTrace));
}
use of com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedTrace in project pinpoint by naver.
the class HttpEchoTestServer method verifyTraces.
@Override
public void verifyTraces(PluginTestVerifier verifier) throws Exception {
// ignore Jetty traces
verifier.ignoreServiceType("JETTY", "JETTY_METHOD");
// RootSpan - Jetty Servlet Process (ignore)
// SpanEvent - (Jetty) Server.handle (ignore)
// SpanEvent - TBaseProcessor.process
// refer to TBaseProcessorProcessInterceptor.finalizeSpanEvent(...)
Method processMethod = TBaseProcessor.class.getDeclaredMethod("process", TProtocol.class, TProtocol.class);
ExpectedAnnotation thriftUrl = Expectations.annotation("thrift.url", "com/navercorp/pinpoint/plugin/thrift/dto/EchoService/echo");
ExpectedTrace tBaseProcessorProcessTrace = event("THRIFT_SERVER_INTERNAL", processMethod, thriftUrl);
verifier.verifyDiscreteTrace(tBaseProcessorProcessTrace);
}
Aggregations