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));
        }

        Assertions.assertEquals(numMessages, actualMessages.size());
        for (String actualMessage : actualMessages) {
            Assertions.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(
                RabbitMQTestConstants.RABBITMQ_CLIENT, // serviceType
                channelBasicPublish, // method
                null, // rpc
                remoteAddress, // endPoint
                "exchange-" + RabbitMQTestConstants.EXCHANGE, // destinationId
                Expectations.annotation("rabbitmq.exchange", RabbitMQTestConstants.EXCHANGE),
                Expectations.annotation("rabbitmq.routingkey", RabbitMQTestConstants.ROUTING_KEY_PUSH));
        ExpectedTrace rabbitMqConsumerInvocationTrace = Expectations.root(
                RabbitMQTestConstants.RABBITMQ_CLIENT, // serviceType
                "RabbitMQ Consumer Invocation", // method
                "rabbitmq://exchange=" + RabbitMQTestConstants.EXCHANGE, // rpc
                null, // endPoint (collected but API to retrieve local address is not available in all versions, so skip)
                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,
                consumerDispatchHandleDelivery); // method
        ExpectedTrace asynchronousInvocationTrace = Expectations.event(
                ASYNC,
                "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(
                INTERNAL_METHOD,
                propagationMarkerMark);

        for (int i = 0; i < numMessages; i++) {
            verifier.verifyDiscreteTrace(channelBasicPublishTrace);
            verifier.verifyDiscreteTrace(
                    rabbitMqConsumerInvocationTrace,
                    Expectations.async(
                            consumerDispatcherHandleDeliveryTrace,
                            asynchronousInvocationTrace,
                            consumerHandleDeliveryTrace,
                            markTrace));
        }
        verifier.verifyTraceCount(0);
    }
@author Jiaqi Feng
@author HyunGil Jeong
agent-module/plugins-it/rabbitmq-it/src/test/java/com/navercorp/pinpoint/it/plugin/rabbitmq/RabbitMQTestRunner.java