Search in sources :

Example 1 with ExpectedTrace

use of com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedTrace in project pinpoint by naver.

the class PluginTestAgent method verifyTrace.

@Override
public void verifyTrace(ExpectedTrace... expectations) {
    if (expectations == null || expectations.length == 0) {
        throw new IllegalArgumentException("No expectations");
    }
    for (ExpectedTrace expected : expectations) {
        ResolvedExpectedTrace resolved = resolveExpectedTrace(expected, null);
        final Object actual = popSpan();
        if (actual == null) {
            throw new AssertionError("Expected a " + resolved.toString() + " but there is no trace");
        }
        ActualTrace wrapped = wrap(actual);
        verifySpan(resolved, wrapped);
        verifyAsyncTraces(expected, wrapped);
    }
}
Also used : ExpectedTrace(com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedTrace)

Example 2 with ExpectedTrace

use of com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedTrace in project pinpoint by naver.

the class PluginTestAgent method verifyDiscreteTraceBlock.

public void verifyDiscreteTraceBlock(ExpectedTrace[] expectations, Integer asyncId) {
    if (expectations == null || expectations.length == 0) {
        throw new IllegalArgumentException("No expectations");
    }
    ExpectedTrace expected = expectations[0];
    ResolvedExpectedTrace resolved = resolveExpectedTrace(expected, asyncId);
    int i = 0;
    Iterator<?> iterator = getRecorder().iterator();
    while (iterator.hasNext()) {
        ActualTrace actual = wrap(iterator.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);
}
Also used : ExpectedTrace(com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedTrace)

Example 3 with ExpectedTrace

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 testExecutionExceptionWithFallback.

@Test
public void testExecutionExceptionWithFallback() throws Exception {
    Exception expectedException = new RuntimeException("expected");
    String fallbackMessage = "Fallback";
    executeThrowExceptionWithFallbackCommand(expectedException, fallbackMessage);
    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", ThrowExceptionCommandWithFallback.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);
}
Also used : ExpectedTrace(com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedTrace) Method(java.lang.reflect.Method) PluginTestVerifier(com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier) Test(org.junit.Test)

Example 4 with ExpectedTrace

use of com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedTrace in project pinpoint by naver.

the class ActiveMQClientITBase method verifyConsumerConsumeEvent.

/**
 * Verifies traces for when {@link ActiveMQMessageConsumer} consumes the message and dispatches for
 * further processing (for example, calling {@link MessageListener} attached to the consumer directly, or adding
 * the message to {@link org.apache.activemq.MessageDispatchChannel MessageDispatchChannel}.
 *
 * @param verifier verifier used to verify traces
 * @param destination the destination from which the consumer is receiving the message
 * @param session the session established by the consumer
 * @throws Exception
 */
private void verifyConsumerConsumeEvent(PluginTestVerifier verifier, ActiveMQDestination destination, ActiveMQSession session) throws Exception {
    String expectedEndPoint = session.getConnection().getTransport().getRemoteAddress();
    ExpectedTrace activeMQConsumerInvocationTrace = root(// serviceType
    ACTIVEMQ_CLIENT, // method
    "ActiveMQ Consumer Invocation", // rpc
    destination.getQualifiedName(), // endPoint (collected but there's no easy way to retrieve local address)
    null, expectedEndPoint);
    Method dispatchMethod = ActiveMQMessageConsumer.class.getDeclaredMethod("dispatch", MessageDispatch.class);
    ExpectedTrace dispatchTrace = event(ACTIVEMQ_CLIENT_INTERNAL, dispatchMethod);
    verifier.verifyDiscreteTrace(activeMQConsumerInvocationTrace, dispatchTrace);
}
Also used : ExpectedTrace(com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedTrace) Method(java.lang.reflect.Method)

Example 5 with ExpectedTrace

use of com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedTrace in project pinpoint by naver.

the class ActiveMQClientITBase method testTopicPoll.

@Test
public void testTopicPoll() throws Exception {
    // Given
    final String testTopicName = "TestPollTopic";
    final ActiveMQTopic testTopic = new ActiveMQTopic(testTopicName);
    final String testMessage = "Hello World for Topic!";
    // create producer
    final ActiveMQSession producerSession = ActiveMQClientITHelper.createSession(getProducerBrokerName(), getProducerBrokerUrl());
    final MessageProducer producer = new MessageProducerBuilder(producerSession, testTopic).waitTillStarted().build();
    final TextMessage expectedTextMessage = producerSession.createTextMessage(testMessage);
    // create 2 consumers
    final ActiveMQSession consumer1Session = ActiveMQClientITHelper.createSession(getConsumerBrokerName(), getConsumerBrokerUrl());
    final MessageConsumer consumer1 = new MessageConsumerBuilder(consumer1Session, testTopic).waitTillStarted().build();
    final MessageReceiveHandler messageReceiveHandler1 = new MessageReceiveHandler();
    final PollingMessageReceiver pollingMessageReceiver1 = new PollingMessageReceiver(consumer1, messageReceiveHandler1);
    final ActiveMQSession consumer2Session = ActiveMQClientITHelper.createSession(getConsumerBrokerName(), getConsumerBrokerUrl());
    final MessageConsumer consumer2 = new MessageConsumerBuilder(consumer2Session, testTopic).waitTillStarted().build();
    final MessageReceiveHandler messageReceiveHandler2 = new MessageReceiveHandler();
    final PollingMessageReceiver pollingMessageReceiver2 = new PollingMessageReceiver(consumer2, messageReceiveHandler2);
    // When
    pollingMessageReceiver1.start();
    pollingMessageReceiver2.start();
    producer.send(expectedTextMessage);
    messageReceiveHandler1.await(5000L);
    messageReceiveHandler2.await(5000L);
    pollingMessageReceiver1.stop();
    pollingMessageReceiver2.stop();
    // Then
    assertNoConsumerError(pollingMessageReceiver1.getException());
    assertNoConsumerError(pollingMessageReceiver2.getException());
    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    verifier.printCache();
    // Wait till all traces are recorded (consumer traces are recorded from another thread)
    verifier.awaitTraceCount(11, 100, 5000);
    verifier.verifyTraceCount(11);
    verifyProducerSendEvent(verifier, testTopic, producerSession);
    verifyConsumerConsumeEvent(verifier, testTopic, consumer1Session);
    verifyConsumerConsumeEvent(verifier, testTopic, consumer2Session);
    ExpectedTrace asyncTrace = event(ServiceType.ASYNC.getName(), "Asynchronous Invocation");
    Method handleMessageMethod = MessageReceiveHandler.class.getDeclaredMethod("handleMessage", Message.class);
    ExpectedTrace handleMessageTrace = event(ServiceType.INTERNAL_METHOD.getName(), handleMessageMethod);
    Method printMessageMethod = MessagePrinter.class.getDeclaredMethod("printMessage", Message.class);
    ExpectedTrace printMessageTrace = event(ServiceType.INTERNAL_METHOD.getName(), printMessageMethod);
    for (int i = 0; i < 2; ++i) {
        verifier.verifyDiscreteTrace(asyncTrace, handleMessageTrace, printMessageTrace);
    }
    verifier.verifyTraceCount(0);
}
Also used : ExpectedTrace(com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedTrace) ActiveMQMessageConsumer(org.apache.activemq.ActiveMQMessageConsumer) MessageConsumer(javax.jms.MessageConsumer) ActiveMQTopic(org.apache.activemq.command.ActiveMQTopic) MessageConsumerBuilder(com.navercorp.pinpoint.plugin.activemq.client.util.MessageConsumerBuilder) Method(java.lang.reflect.Method) PluginTestVerifier(com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier) MessageProducerBuilder(com.navercorp.pinpoint.plugin.activemq.client.util.MessageProducerBuilder) ActiveMQSession(org.apache.activemq.ActiveMQSession) MessageReceiveHandler(com.navercorp.test.pinpoint.plugin.activemq.MessageReceiveHandler) PollingMessageReceiver(com.navercorp.test.pinpoint.plugin.activemq.PollingMessageReceiver) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Aggregations

ExpectedTrace (com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedTrace)40 Method (java.lang.reflect.Method)33 PluginTestVerifier (com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier)28 Test (org.junit.Test)24 PropagationMarker (com.navercorp.test.pinpoint.plugin.rabbitmq.PropagationMarker)21 AMQP (com.rabbitmq.client.AMQP)21 ExpectedAnnotation (com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedAnnotation)3 SpanType (com.navercorp.pinpoint.profiler.context.SpanType)2 AssertionErrorBuilder (com.navercorp.pinpoint.test.util.AssertionErrorBuilder)2 ActualTrace (com.navercorp.pinpoint.test.wrapper.ActualTrace)2 Channel (com.rabbitmq.client.Channel)2 Connection (com.rabbitmq.client.Connection)2 Constructor (java.lang.reflect.Constructor)2 MessageConsumerBuilder (com.navercorp.pinpoint.plugin.activemq.client.util.MessageConsumerBuilder)1 MessageProducerBuilder (com.navercorp.pinpoint.plugin.activemq.client.util.MessageProducerBuilder)1 MessageReceiveHandler (com.navercorp.test.pinpoint.plugin.activemq.MessageReceiveHandler)1 PollingMessageReceiver (com.navercorp.test.pinpoint.plugin.activemq.PollingMessageReceiver)1 TestConsumer (com.navercorp.test.pinpoint.plugin.rabbitmq.TestConsumer)1 TestMessagePuller (com.navercorp.test.pinpoint.plugin.rabbitmq.TestMessagePuller)1 InetSocketAddress (java.net.InetSocketAddress)1