Search in sources :

Example 26 with ExpectedTrace

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

the class RabbitMQTestRunner method runPushTest.

void runPushTest(int numMessages) throws Exception {
    final String message = "hello rabbit mq";
    // producer side
    final Connection producerConnection = connectionFactory.newConnection();
    final Channel producerChannel = producerConnection.createChannel();
    producerChannel.exchangeDeclare(RabbitMQTestConstants.EXCHANGE, "direct", false);
    producerChannel.queueDeclare(RabbitMQTestConstants.QUEUE_PUSH, false, false, false, null);
    producerChannel.queueBind(RabbitMQTestConstants.QUEUE_PUSH, RabbitMQTestConstants.EXCHANGE, RabbitMQTestConstants.ROUTING_KEY_PUSH);
    for (int i = 0; i < numMessages; i++) {
        AMQP.BasicProperties.Builder builder = new AMQP.BasicProperties.Builder();
        producerChannel.basicPublish(RabbitMQTestConstants.EXCHANGE, RabbitMQTestConstants.ROUTING_KEY_PUSH, false, false, builder.appId("test").build(), message.getBytes());
    }
    producerChannel.close();
    producerConnection.close();
    // consumer side
    final Connection consumerConnection = connectionFactory.newConnection();
    final Channel consumerChannel = consumerConnection.createChannel();
    final String remoteAddress = consumerConnection.getAddress().getHostAddress() + ":" + consumerConnection.getPort();
    consumerChannel.queueDeclare(RabbitMQTestConstants.QUEUE_PUSH, false, false, false, null);
    TestConsumer<String> consumer = new TestConsumer<>(consumerChannel, MessageConverter.FOR_TEST);
    consumerChannel.basicConsume(RabbitMQTestConstants.QUEUE_PUSH, true, consumer);
    List<String> actualMessages = new ArrayList<>(numMessages);
    for (int i = 0; i < numMessages; i++) {
        actualMessages.add(consumer.getMessage(10, TimeUnit.SECONDS));
    }
    Assert.assertEquals(numMessages, actualMessages.size());
    for (String actualMessage : actualMessages) {
        Assert.assertEquals(message, actualMessage);
    }
    consumerChannel.close();
    consumerConnection.close();
    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    // Wait till all traces are recorded (consumer traces are recorded from another thread)
    int expectedTraceCountPerMessage = 6;
    awaitAndVerifyTraceCount(verifier, expectedTraceCountPerMessage * numMessages, 5000L);
    verifier.printCache();
    Class<?> producerChannelClass = producerChannel.getClass();
    Method channelBasicPublish = producerChannelClass.getDeclaredMethod("basicPublish", String.class, String.class, boolean.class, boolean.class, AMQP.BasicProperties.class, byte[].class);
    ExpectedTrace channelBasicPublishTrace = Expectations.event(// serviceType
    RabbitMQTestConstants.RABBITMQ_CLIENT, // method
    channelBasicPublish, // 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<?> consumerDispatchClass = Class.forName("com.rabbitmq.client.impl.ConsumerDispatcher");
    Method consumerDispatchHandleDelivery = consumerDispatchClass.getDeclaredMethod("handleDelivery", Consumer.class, String.class, Envelope.class, AMQP.BasicProperties.class, byte[].class);
    ExpectedTrace consumerDispatcherHandleDeliveryTrace = Expectations.event(RabbitMQTestConstants.RABBITMQ_CLIENT_INTERNAL, // method
    consumerDispatchHandleDelivery);
    ExpectedTrace asynchronousInvocationTrace = Expectations.event(ServiceType.ASYNC.getName(), "Asynchronous Invocation");
    Class<?> consumerClass = consumer.getClass();
    Method consumerHandleDelivery = consumerClass.getDeclaredMethod("handleDelivery", String.class, Envelope.class, AMQP.BasicProperties.class, byte[].class);
    ExpectedTrace consumerHandleDeliveryTrace = Expectations.event(RabbitMQTestConstants.RABBITMQ_CLIENT_INTERNAL, consumerHandleDelivery);
    Class<?> propagationMarkerClass = PropagationMarker.class;
    Method propagationMarkerMark = propagationMarkerClass.getDeclaredMethod("mark");
    ExpectedTrace markTrace = Expectations.event(ServiceType.INTERNAL_METHOD.getName(), propagationMarkerMark);
    for (int i = 0; i < numMessages; i++) {
        verifier.verifyDiscreteTrace(channelBasicPublishTrace);
        verifier.verifyDiscreteTrace(rabbitMqConsumerInvocationTrace, Expectations.async(consumerDispatcherHandleDeliveryTrace, asynchronousInvocationTrace, consumerHandleDeliveryTrace, markTrace));
    }
    verifier.verifyTraceCount(0);
}
Also used : ExpectedTrace(com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedTrace) Channel(com.rabbitmq.client.Channel) Connection(com.rabbitmq.client.Connection) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) PluginTestVerifier(com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier) TestConsumer(com.navercorp.test.pinpoint.plugin.rabbitmq.TestConsumer) PropagationMarker(com.navercorp.test.pinpoint.plugin.rabbitmq.PropagationMarker) AMQP(com.rabbitmq.client.AMQP)

Example 27 with ExpectedTrace

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

the class RabbitMQTestRunner method runPullTest.

void runPullTest() throws Exception {
    final String message = "hello rabbit mq";
    // producer side
    final Connection producerConnection = connectionFactory.newConnection();
    final Channel producerChannel = producerConnection.createChannel();
    producerChannel.exchangeDeclare(RabbitMQTestConstants.EXCHANGE, "direct", false);
    producerChannel.queueDeclare(RabbitMQTestConstants.QUEUE_PULL, false, false, false, null);
    producerChannel.queueBind(RabbitMQTestConstants.QUEUE_PULL, RabbitMQTestConstants.EXCHANGE, RabbitMQTestConstants.ROUTING_KEY_PULL);
    AMQP.BasicProperties.Builder builder = new AMQP.BasicProperties.Builder();
    producerChannel.basicPublish(RabbitMQTestConstants.EXCHANGE, RabbitMQTestConstants.ROUTING_KEY_PULL, false, false, builder.appId("test").build(), message.getBytes());
    producerChannel.close();
    producerConnection.close();
    // comsumer side
    final Connection consumerConnection = connectionFactory.newConnection();
    final Channel consumerChannel = consumerConnection.createChannel();
    final String remoteAddress = consumerConnection.getAddress().getHostAddress() + ":" + consumerConnection.getPort();
    TestMessagePuller messagePuller = new TestMessagePuller(consumerChannel);
    Assert.assertEquals(message, messagePuller.pullMessage(MessageConverter.FOR_TEST, RabbitMQTestConstants.QUEUE_PULL, true));
    consumerChannel.close();
    consumerConnection.close();
    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    // Wait till all traces are recorded (consumer traces are recorded from another thread)
    awaitAndVerifyTraceCount(verifier, 5, 5000L);
    verifier.printCache();
    // verify producer traces
    Class<?> producerChannelClass = producerChannel.getClass();
    Method channelBasicPublish = producerChannelClass.getDeclaredMethod("basicPublish", String.class, String.class, boolean.class, boolean.class, AMQP.BasicProperties.class, byte[].class);
    ExpectedTrace channelBasicPublishTrace = Expectations.event(// serviceType
    RabbitMQTestConstants.RABBITMQ_CLIENT, // method
    channelBasicPublish, // 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 handleCompleteInboundCommand = amqChannelClass.getDeclaredMethod("handleCompleteInboundCommand", AMQCommand.class);
    ExpectedTrace handleCompleteInboundCommandTrace = Expectations.event(// serviceType
    RabbitMQTestConstants.RABBITMQ_CLIENT_INTERNAL, // method
    handleCompleteInboundCommand);
    ExpectedTrace[] producerTraces = { channelBasicPublishTrace };
    ExpectedTrace[] consumerTraces = { rabbitMqConsumerInvocationTrace, handleCompleteInboundCommandTrace };
    verifier.verifyDiscreteTrace(producerTraces);
    verifier.verifyDiscreteTrace(consumerTraces);
    // verify consumer traces
    Class<?> consumerChannelClass = consumerChannel.getClass();
    Method channelBasicGet = consumerChannelClass.getDeclaredMethod("basicGet", String.class, boolean.class);
    ExpectedTrace channelBasicGetTrace = Expectations.event(RabbitMQTestConstants.RABBITMQ_CLIENT_INTERNAL, channelBasicGet);
    Class<?> propagationMarkerClass = PropagationMarker.class;
    Method propagationMarkerMark = propagationMarkerClass.getDeclaredMethod("mark");
    ExpectedTrace markTrace = Expectations.event(ServiceType.INTERNAL_METHOD.getName(), propagationMarkerMark);
    verifier.verifyDiscreteTrace(channelBasicGetTrace, markTrace);
    verifier.verifyTraceCount(0);
}
Also used : ExpectedTrace(com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedTrace) Channel(com.rabbitmq.client.Channel) Connection(com.rabbitmq.client.Connection) Method(java.lang.reflect.Method) PluginTestVerifier(com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier) PropagationMarker(com.navercorp.test.pinpoint.plugin.rabbitmq.PropagationMarker) TestMessagePuller(com.navercorp.test.pinpoint.plugin.rabbitmq.TestMessagePuller) AMQP(com.rabbitmq.client.AMQP)

Example 28 with ExpectedTrace

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

the class SpringAmqpRabbit_1_3_3_to_1_4_2_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(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 29 with ExpectedTrace

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

the class SpringAmqpRabbit_1_7_0_to_1_7_7_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 30 with ExpectedTrace

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

the class SpringAmqpRabbit_1_7_0_to_1_7_7_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.support.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)

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