Search in sources :

Example 11 with ExpectedTrace

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

the class SpringAmqpRabbit_1_4_2_to_1_7_0_IT method testPull.

@Test
public void testPull() throws Exception {
    final String remoteAddress = testRunner.getRemoteAddress();
    Class<?> rabbitTemplateClass = Class.forName("org.springframework.amqp.rabbit.core.RabbitTemplate");
    // verify queue-initiated traces
    Method rabbitTemplateConvertAndSend = rabbitTemplateClass.getDeclaredMethod("convertAndSend", String.class, String.class, Object.class);
    ExpectedTrace rabbitTemplateConvertAndSendTrace = Expectations.event(// serviceType
    RabbitMQTestConstants.RABBITMQ_CLIENT_INTERNAL, // method
    rabbitTemplateConvertAndSend);
    // automatic recovery deliberately disabled as Spring has it's own recovery mechanism
    Class<?> channelNClass = Class.forName("com.rabbitmq.client.impl.ChannelN");
    Method channelNBasicPublish = channelNClass.getDeclaredMethod("basicPublish", String.class, String.class, boolean.class, boolean.class, AMQP.BasicProperties.class, byte[].class);
    ExpectedTrace channelNBasicPublishTrace = Expectations.event(// serviceType
    RabbitMQTestConstants.RABBITMQ_CLIENT, // method
    channelNBasicPublish, // rpc
    null, // endPoint
    remoteAddress, // destinationId
    "exchange-" + RabbitMQTestConstants.EXCHANGE, Expectations.annotation("rabbitmq.exchange", RabbitMQTestConstants.EXCHANGE), Expectations.annotation("rabbitmq.routingkey", RabbitMQTestConstants.ROUTING_KEY_PULL));
    ExpectedTrace rabbitMqConsumerInvocationTrace = Expectations.root(// serviceType
    RabbitMQTestConstants.RABBITMQ_CLIENT, // method
    "RabbitMQ Consumer Invocation", // rpc
    "rabbitmq://exchange=" + RabbitMQTestConstants.EXCHANGE, // endPoint (collected but API to retrieve local address is not available in all versions, so skip)
    null, // remoteAddress
    remoteAddress, Expectations.annotation("rabbitmq.routingkey", RabbitMQTestConstants.ROUTING_KEY_PULL));
    Class<?> amqChannelClass = Class.forName("com.rabbitmq.client.impl.AMQChannel");
    Method amqChannelHandleCompleteInboundCommand = amqChannelClass.getDeclaredMethod("handleCompleteInboundCommand", AMQCommand.class);
    ExpectedTrace amqChannelHandleCompleteInboundCommandTrace = Expectations.event(// method
    RabbitMQTestConstants.RABBITMQ_CLIENT_INTERNAL, amqChannelHandleCompleteInboundCommand);
    ExpectedTrace[] producerTraces = { rabbitTemplateConvertAndSendTrace, channelNBasicPublishTrace };
    ExpectedTrace[] consumerTraces = { rabbitMqConsumerInvocationTrace, amqChannelHandleCompleteInboundCommandTrace };
    // verify client-initiated traces
    Method rabbitTemplateReceive = rabbitTemplateClass.getDeclaredMethod("receive", String.class);
    ExpectedTrace rabbitTemplateReceiveTrace = Expectations.event(// serviceType
    RabbitMQTestConstants.RABBITMQ_CLIENT_INTERNAL, // method
    rabbitTemplateReceive);
    Method channelNBasicGet = channelNClass.getDeclaredMethod("basicGet", String.class, boolean.class);
    ExpectedTrace channelNBasicGetTrace = Expectations.event(RabbitMQTestConstants.RABBITMQ_CLIENT_INTERNAL, channelNBasicGet);
    Class<?> propagationMarkerClass = PropagationMarker.class;
    Method propagationMarkerMark = propagationMarkerClass.getDeclaredMethod("mark");
    ExpectedTrace markTrace = Expectations.event(ServiceType.INTERNAL_METHOD.getName(), propagationMarkerMark);
    ExpectedTrace[] clientInitiatedTraces = { rabbitTemplateReceiveTrace, channelNBasicGetTrace, markTrace };
    final int expectedTraceCount = producerTraces.length + consumerTraces.length + clientInitiatedTraces.length;
    final PluginTestVerifier verifier = testRunner.runPull(expectedTraceCount);
    verifier.verifyDiscreteTrace(producerTraces);
    verifier.verifyDiscreteTrace(consumerTraces);
    verifier.verifyDiscreteTrace(clientInitiatedTraces);
    verifier.verifyTraceCount(0);
}
Also used : PropagationMarker(com.navercorp.test.pinpoint.plugin.rabbitmq.PropagationMarker) ExpectedTrace(com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedTrace) AMQP(com.rabbitmq.client.AMQP) Method(java.lang.reflect.Method) PluginTestVerifier(com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier) Test(org.junit.Test)

Example 12 with ExpectedTrace

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

the class SpringAmqpRabbit_1_4_2_to_1_7_0_IT method testPush.

@Test
public void testPush() throws Exception {
    final String remoteAddress = testRunner.getRemoteAddress();
    Class<?> rabbitTemplateClass = Class.forName("org.springframework.amqp.rabbit.core.RabbitTemplate");
    Method rabbitTemplateConvertAndSend = rabbitTemplateClass.getDeclaredMethod("convertAndSend", String.class, String.class, Object.class);
    ExpectedTrace rabbitTemplateConvertAndSendTrace = Expectations.event(// serviceType
    RabbitMQTestConstants.RABBITMQ_CLIENT_INTERNAL, // method
    rabbitTemplateConvertAndSend);
    // automatic recovery deliberately disabled as Spring has it's own recovery mechanism
    Class<?> channelNClass = Class.forName("com.rabbitmq.client.impl.ChannelN");
    Method channelNBasicPublish = channelNClass.getDeclaredMethod("basicPublish", String.class, String.class, boolean.class, boolean.class, AMQP.BasicProperties.class, byte[].class);
    ExpectedTrace channelNBasicPublishTrace = Expectations.event(// serviceType
    RabbitMQTestConstants.RABBITMQ_CLIENT, // method
    channelNBasicPublish, // rpc
    null, // endPoint
    remoteAddress, // destinationId
    "exchange-" + RabbitMQTestConstants.EXCHANGE, Expectations.annotation("rabbitmq.exchange", RabbitMQTestConstants.EXCHANGE), Expectations.annotation("rabbitmq.routingkey", RabbitMQTestConstants.ROUTING_KEY_PUSH));
    ExpectedTrace rabbitMqConsumerInvocationTrace = Expectations.root(// serviceType
    RabbitMQTestConstants.RABBITMQ_CLIENT, // method
    "RabbitMQ Consumer Invocation", // rpc
    "rabbitmq://exchange=" + RabbitMQTestConstants.EXCHANGE, // endPoint (collected but API to retrieve local address is not available in all versions, so skip)
    null, // remoteAddress
    remoteAddress, Expectations.annotation("rabbitmq.routingkey", RabbitMQTestConstants.ROUTING_KEY_PUSH));
    Class<?> consumerDispatcherClass = Class.forName("com.rabbitmq.client.impl.ConsumerDispatcher");
    Method consumerDispatcherHandleDelivery = consumerDispatcherClass.getDeclaredMethod("handleDelivery", Consumer.class, String.class, Envelope.class, AMQP.BasicProperties.class, byte[].class);
    ExpectedTrace consumerDispatcherHandleDeliveryTrace = Expectations.event(// serviceType
    RabbitMQTestConstants.RABBITMQ_CLIENT_INTERNAL, // method
    consumerDispatcherHandleDelivery);
    ExpectedTrace asynchronousInvocationTrace = Expectations.event(ServiceType.ASYNC.getName(), "Asynchronous Invocation");
    Class<?> blockingQueueConsumerInternalConsumerClass = Class.forName("org.springframework.amqp.rabbit.listener.BlockingQueueConsumer$InternalConsumer");
    Method blockingQueueConsumerInternalConsumerHandleDelivery = blockingQueueConsumerInternalConsumerClass.getDeclaredMethod("handleDelivery", String.class, Envelope.class, AMQP.BasicProperties.class, byte[].class);
    ExpectedTrace blockingQueueConsumerInternalConsumerHandleDeliveryTrace = Expectations.event(// serviceType
    RabbitMQTestConstants.RABBITMQ_CLIENT_INTERNAL, blockingQueueConsumerInternalConsumerHandleDelivery);
    Class<?> deliveryClass = Class.forName("org.springframework.amqp.rabbit.listener.BlockingQueueConsumer$Delivery");
    Constructor<?> deliveryConstructor = deliveryClass.getDeclaredConstructor(String.class, Envelope.class, AMQP.BasicProperties.class, byte[].class);
    ExpectedTrace deliveryConstructorTrace = Expectations.event(// serviceType
    RabbitMQTestConstants.RABBITMQ_CLIENT_INTERNAL, deliveryConstructor);
    Class<?> abstractMessageListenerContainerClass = Class.forName("org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer");
    Method abstractMessageListenerContainerExecuteListener = abstractMessageListenerContainerClass.getDeclaredMethod("executeListener", Channel.class, Message.class);
    ExpectedTrace abstractMessageListenerContainerExecuteListenerTrace = Expectations.event(ServiceType.INTERNAL_METHOD.getName(), abstractMessageListenerContainerExecuteListener);
    Class<?> propagationMarkerClass = PropagationMarker.class;
    Method propagationMarkerMark = propagationMarkerClass.getDeclaredMethod("mark");
    ExpectedTrace markTrace = Expectations.event(ServiceType.INTERNAL_METHOD.getName(), propagationMarkerMark);
    ExpectedTrace[] producerTraces = { rabbitTemplateConvertAndSendTrace, channelNBasicPublishTrace };
    ExpectedTrace[] consumerTraces = { rabbitMqConsumerInvocationTrace, consumerDispatcherHandleDeliveryTrace, asynchronousInvocationTrace, blockingQueueConsumerInternalConsumerHandleDeliveryTrace, deliveryConstructorTrace, asynchronousInvocationTrace, abstractMessageListenerContainerExecuteListenerTrace, markTrace };
    final int expectedTraceCount = producerTraces.length + consumerTraces.length;
    final PluginTestVerifier verifier = testRunner.runPush(expectedTraceCount);
    verifier.verifyDiscreteTrace(producerTraces);
    verifier.verifyDiscreteTrace(consumerTraces);
    verifier.verifyTraceCount(0);
}
Also used : PropagationMarker(com.navercorp.test.pinpoint.plugin.rabbitmq.PropagationMarker) ExpectedTrace(com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedTrace) AMQP(com.rabbitmq.client.AMQP) Method(java.lang.reflect.Method) PluginTestVerifier(com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier) Test(org.junit.Test)

Example 13 with ExpectedTrace

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

the class KafkaClientITBase method verifyProducerSend.

protected void verifyProducerSend(int messageCount) throws NoSuchMethodException {
    int consumerInvocationCount = messageCount * 2;
    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    verifier.awaitTraceCount(messageCount + consumerInvocationCount, 100, MAX_TRACE_WAIT_TIME);
    verifier.printCache();
    Method sendMethod = KafkaProducer.class.getDeclaredMethod("send", ProducerRecord.class, Callback.class);
    ExpectedTrace.Builder eventBuilder = ExpectedTrace.createEventBuilder(KAFKA_CLIENT_SERVICE_TYPE);
    eventBuilder.setMethod(sendMethod);
    eventBuilder.setEndPoint(BROKER_URL);
    eventBuilder.setDestinationId(BROKER_URL);
    eventBuilder.setAnnotations(annotation("kafka.topic", TOPIC));
    ExpectedTrace producerSendExpected = eventBuilder.build();
    for (int i = 0; i < messageCount; i++) {
        verifier.verifyDiscreteTrace(producerSendExpected);
    }
    verifier.verifyTraceCount(consumerInvocationCount);
}
Also used : ExpectedTrace(com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedTrace) Method(java.lang.reflect.Method) PluginTestVerifier(com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier)

Example 14 with ExpectedTrace

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

the class PluginVerifierExternalAdaptor method verifyTrace.

@Override
public void verifyTrace(ExpectedTrace... expectations) {
    if (ArrayUtils.isEmpty(expectations)) {
        throw new IllegalArgumentException("No expectations");
    }
    for (ExpectedTrace expected : expectations) {
        ResolvedExpectedTrace resolved = resolveExpectedTrace(expected, null);
        final Item<SpanType> actualItem = popItem();
        if (actualItem == null) {
            AssertionErrorBuilder builder = new AssertionErrorBuilder("actualItem is null", resolved, "null");
            builder.throwAssertionError();
        }
        final SpanType actual = actualItem.getValue();
        ActualTrace wrapped = ActualTraceFactory.wrap(actual);
        verifySpan(resolved, wrapped);
        verifyAsyncTraces(expected, wrapped);
    }
}
Also used : ExpectedTrace(com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedTrace) SpanType(com.navercorp.pinpoint.profiler.context.SpanType) AssertionErrorBuilder(com.navercorp.pinpoint.test.util.AssertionErrorBuilder) ActualTrace(com.navercorp.pinpoint.test.wrapper.ActualTrace)

Example 15 with ExpectedTrace

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

the class PluginVerifierExternalAdaptor method verifyAsyncTraces.

private void verifyAsyncTraces(ExpectedTrace expected, ActualTrace actual) throws AssertionError {
    final ExpectedTrace[] expectedAsyncTraces = expected.getAsyncTraces();
    if (expectedAsyncTraces != null && expectedAsyncTraces.length > 0) {
        Integer actualAsyncId = actual.getNextAsyncId();
        if (actualAsyncId == null) {
            AssertionErrorBuilder builder = new AssertionErrorBuilder("async traces triggered but nextAsyncId is null", Arrays.toString(expectedAsyncTraces), actualAsyncId);
            builder.setComparison(expected, actual);
            builder.throwAssertionError();
        }
        verifyDiscreteTraceBlock(expectedAsyncTraces, actualAsyncId);
    }
}
Also used : ExpectedTrace(com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedTrace) AssertionErrorBuilder(com.navercorp.pinpoint.test.util.AssertionErrorBuilder)

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