Search in sources :

Example 36 with ExpectedTrace

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

the class SpringAmqpRabbit_1_7_7_to_2_0_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<?> blockingQueueConsumerConsumerDecoratorClass = Class.forName("org.springframework.amqp.rabbit.listener.BlockingQueueConsumer$ConsumerDecorator");
    Method blockingQueueConsumerConsumerDecoratorHandleDelivery = blockingQueueConsumerConsumerDecoratorClass.getDeclaredMethod("handleDelivery", String.class, Envelope.class, AMQP.BasicProperties.class, byte[].class);
    ExpectedTrace blockingQueueConsumerConsumerDecoratorHandleDeliveryTrace = Expectations.event(// serviceType
    RabbitMQTestConstants.RABBITMQ_CLIENT_INTERNAL, blockingQueueConsumerConsumerDecoratorHandleDelivery);
    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, blockingQueueConsumerConsumerDecoratorHandleDeliveryTrace, 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 37 with ExpectedTrace

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

the class SpringAmqpRabbit_2_0_3_to_2_1_0_IT method testPullWithTimeout.

@Test
public void testPullWithTimeout() 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<?> 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");
    // RabbitTemplate internal consumer implementation - may change in future versions which will cause tests to
    // fail, in which case the integration test needs to be updated to match code changes
    Class<?> rabbitTemplateInternalConsumerClass = Class.forName("org.springframework.amqp.rabbit.core.RabbitTemplate$2");
    Method rabbitTemplateInternalConsumerHandleDelivery = rabbitTemplateInternalConsumerClass.getDeclaredMethod("handleDelivery", String.class, Envelope.class, AMQP.BasicProperties.class, byte[].class);
    ExpectedTrace rabbitTemplateInternalConsumerHandleDeliveryTrace = Expectations.event(// serviceType
    RabbitMQTestConstants.RABBITMQ_CLIENT_INTERNAL, // method
    rabbitTemplateInternalConsumerHandleDelivery);
    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);
    ExpectedTrace[] producerTraces = { rabbitTemplateConvertAndSendTrace, channelNBasicPublishTrace };
    ExpectedTrace[] consumerTraces = { rabbitMqConsumerInvocationTrace, consumerDispatcherHandleDeliveryTrace, asynchronousInvocationTrace, rabbitTemplateInternalConsumerHandleDeliveryTrace, deliveryConstructorTrace };
    // verify client-initiated traces
    Method rabbitTemplateReceive = rabbitTemplateClass.getDeclaredMethod("receive", String.class, long.class);
    ExpectedTrace rabbitTemplateReceiveTrace = Expectations.event(// serviceType
    RabbitMQTestConstants.RABBITMQ_CLIENT_INTERNAL, // method
    rabbitTemplateReceive);
    Class<?> propagationMarkerClass = PropagationMarker.class;
    Method propagationMarkerMark = propagationMarkerClass.getDeclaredMethod("mark");
    ExpectedTrace markTrace = Expectations.event(ServiceType.INTERNAL_METHOD.getName(), propagationMarkerMark);
    ExpectedTrace[] clientInitiatedTraces = { rabbitTemplateReceiveTrace, markTrace };
    final int expectedTraceCount = producerTraces.length + consumerTraces.length + clientInitiatedTraces.length;
    final PluginTestVerifier verifier = testRunner.runPull(expectedTraceCount, 5000L);
    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 38 with ExpectedTrace

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

the class SpringAmqpRabbit_2_0_3_to_2_1_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<?> blockingQueueConsumerConsumerDecoratorClass = Class.forName("org.springframework.amqp.rabbit.listener.BlockingQueueConsumer$ConsumerDecorator");
    Method blockingQueueConsumerConsumerDecoratorHandleDelivery = blockingQueueConsumerConsumerDecoratorClass.getDeclaredMethod("handleDelivery", String.class, Envelope.class, AMQP.BasicProperties.class, byte[].class);
    ExpectedTrace blockingQueueConsumerConsumerDecoratorHandleDeliveryTrace = Expectations.event(// serviceType
    RabbitMQTestConstants.RABBITMQ_CLIENT_INTERNAL, blockingQueueConsumerConsumerDecoratorHandleDelivery);
    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, blockingQueueConsumerConsumerDecoratorHandleDeliveryTrace, 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 39 with ExpectedTrace

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

the class SpringAmqpRabbit_2_1_x_to_2_x_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 40 with ExpectedTrace

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

the class SpringAmqpRabbit_2_1_x_to_2_x_IT method testPullWithTimeout.

@Test
public void testPullWithTimeout() 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<?> 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");
    // RabbitTemplate internal consumer implementation - may change in future versions which will cause tests to
    // fail, in which case the integration test needs to be updated to match code changes
    Class<?> rabbitTemplateInternalConsumerClass = getRabbitTemplateClazz();
    Method rabbitTemplateInternalConsumerHandleDelivery = rabbitTemplateInternalConsumerClass.getDeclaredMethod("handleDelivery", String.class, Envelope.class, AMQP.BasicProperties.class, byte[].class);
    ExpectedTrace rabbitTemplateInternalConsumerHandleDeliveryTrace = Expectations.event(// serviceType
    RabbitMQTestConstants.RABBITMQ_CLIENT_INTERNAL, // method
    rabbitTemplateInternalConsumerHandleDelivery);
    Class<?> deliveryClass = Class.forName("org.springframework.amqp.rabbit.support.Delivery");
    Constructor<?> deliveryConstructor = deliveryClass.getDeclaredConstructor(String.class, Envelope.class, AMQP.BasicProperties.class, byte[].class, String.class);
    ExpectedTrace deliveryConstructorTrace = Expectations.event(// serviceType
    RabbitMQTestConstants.RABBITMQ_CLIENT_INTERNAL, deliveryConstructor);
    ExpectedTrace[] producerTraces = { rabbitTemplateConvertAndSendTrace, channelNBasicPublishTrace };
    ExpectedTrace[] consumerTraces = { rabbitMqConsumerInvocationTrace, consumerDispatcherHandleDeliveryTrace, asynchronousInvocationTrace, rabbitTemplateInternalConsumerHandleDeliveryTrace, deliveryConstructorTrace };
    // verify client-initiated traces
    Method rabbitTemplateReceive = rabbitTemplateClass.getDeclaredMethod("receive", String.class, long.class);
    ExpectedTrace rabbitTemplateReceiveTrace = Expectations.event(// serviceType
    RabbitMQTestConstants.RABBITMQ_CLIENT_INTERNAL, // method
    rabbitTemplateReceive);
    Class<?> propagationMarkerClass = PropagationMarker.class;
    Method propagationMarkerMark = propagationMarkerClass.getDeclaredMethod("mark");
    ExpectedTrace markTrace = Expectations.event(ServiceType.INTERNAL_METHOD.getName(), propagationMarkerMark);
    ExpectedTrace[] clientInitiatedTraces = { rabbitTemplateReceiveTrace, markTrace };
    final int expectedTraceCount = producerTraces.length + consumerTraces.length + clientInitiatedTraces.length;
    final PluginTestVerifier verifier = testRunner.runPull(expectedTraceCount, 5000L);
    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)

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