Search in sources :

Example 6 with MessageProducerBuilder

use of com.navercorp.pinpoint.plugin.activemq.client.util.MessageProducerBuilder in project pinpoint by naver.

the class ActiveMQClientITBase method testQueuePush.

@Test
public void testQueuePush() throws Exception {
    // Given
    final String testQueueName = "TestPushQueue";
    final ActiveMQQueue testQueue = new ActiveMQQueue(testQueueName);
    final String testMessage = "Hello World for Queue!";
    final MessagePrinter messagePrinter = new MessagePrinter();
    final CountDownLatch consumerLatch = new CountDownLatch(1);
    final AtomicReference<Exception> exception = new AtomicReference<>();
    // create producer
    final ActiveMQSession producerSession = ActiveMQClientITHelper.createSession(getProducerBrokerName(), getProducerBrokerUrl());
    final MessageProducer producer = new MessageProducerBuilder(producerSession, testQueue).waitTillStarted().build();
    final TextMessage expectedTextMessage = producerSession.createTextMessage(testMessage);
    // create consumer
    final ActiveMQSession consumerSession = ActiveMQClientITHelper.createSession(getConsumerBrokerName(), getConsumerBrokerUrl());
    new MessageConsumerBuilder(consumerSession, testQueue).waitTillStarted().withMessageListener(new MessageListener() {

        @Override
        public void onMessage(Message message) {
            try {
                messagePrinter.printMessage(message);
            } catch (Exception e) {
                exception.set(e);
            } finally {
                consumerLatch.countDown();
            }
        }
    }).build();
    // When
    producer.send(expectedTextMessage);
    consumerLatch.await(1L, TimeUnit.SECONDS);
    // Then
    assertNoConsumerError(exception.get());
    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    verifier.printCache();
    // Wait till all traces are recorded (consumer traces are recorded from another thread)
    verifier.awaitTraceCount(4, 100, 5000);
    verifier.verifyTraceCount(4);
    verifyProducerSendEvent(verifier, testQueue, producerSession);
    verifyConsumerConsumeEvent(verifier, testQueue, consumerSession);
    Method printMessageMethod = MessagePrinter.class.getDeclaredMethod("printMessage", Message.class);
    verifier.verifyTrace(event(ServiceType.INTERNAL_METHOD.getName(), printMessageMethod));
    verifier.verifyTraceCount(0);
}
Also used : Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) MessageConsumerBuilder(com.navercorp.pinpoint.plugin.activemq.client.util.MessageConsumerBuilder) MessageListener(javax.jms.MessageListener) MessagePrinter(com.navercorp.test.pinpoint.plugin.activemq.MessagePrinter) AtomicReference(java.util.concurrent.atomic.AtomicReference) Method(java.lang.reflect.Method) CountDownLatch(java.util.concurrent.CountDownLatch) PluginTestVerifier(com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier) JMSException(javax.jms.JMSException) MessageProducerBuilder(com.navercorp.pinpoint.plugin.activemq.client.util.MessageProducerBuilder) ActiveMQSession(org.apache.activemq.ActiveMQSession) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Aggregations

PluginTestVerifier (com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier)6 MessageConsumerBuilder (com.navercorp.pinpoint.plugin.activemq.client.util.MessageConsumerBuilder)6 MessageProducerBuilder (com.navercorp.pinpoint.plugin.activemq.client.util.MessageProducerBuilder)6 Method (java.lang.reflect.Method)6 MessageProducer (javax.jms.MessageProducer)6 TextMessage (javax.jms.TextMessage)6 ActiveMQSession (org.apache.activemq.ActiveMQSession)6 Test (org.junit.Test)6 PollingMessageReceiver (com.navercorp.test.pinpoint.plugin.activemq.PollingMessageReceiver)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 JMSException (javax.jms.JMSException)4 MessageConsumer (javax.jms.MessageConsumer)4 ActiveMQMessageConsumer (org.apache.activemq.ActiveMQMessageConsumer)4 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)3 ActiveMQTopic (org.apache.activemq.command.ActiveMQTopic)3 MessagePrinter (com.navercorp.test.pinpoint.plugin.activemq.MessagePrinter)2 MessageReceiveHandler (com.navercorp.test.pinpoint.plugin.activemq.MessageReceiveHandler)2 MessageReceiver (com.navercorp.test.pinpoint.plugin.activemq.MessageReceiver)2 Message (javax.jms.Message)2