Search in sources :

Example 1 with AssertTextMessageListener

use of com.navercorp.pinpoint.plugin.jdk7.activemq.client.util.AssertTextMessageListener 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 CountDownLatch consumerLatch = new CountDownLatch(1);
    final Collection<Throwable> consumerThrowables = new CopyOnWriteArrayList<Throwable>();
    // create producer
    ActiveMQSession producerSession = ActiveMQClientITHelper.createSession(getProducerBrokerName(), getProducerBrokerUrl());
    MessageProducer producer = producerSession.createProducer(testQueue);
    final TextMessage expectedTextMessage = producerSession.createTextMessage(testMessage);
    // create consumer
    ActiveMQSession consumerSession = ActiveMQClientITHelper.createSession(getConsumerBrokerName(), getConsumerBrokerUrl());
    MessageConsumer consumer = consumerSession.createConsumer(testQueue);
    consumer.setMessageListener(new AssertTextMessageListener(consumerLatch, consumerThrowables, expectedTextMessage));
    // When
    producer.send(expectedTextMessage);
    consumerLatch.await(1L, TimeUnit.SECONDS);
    // Then
    assertNoConsumerError(consumerThrowables);
    // Wait till all traces are recorded (consumer traces are recorded from another thread)
    awaitAndVerifyTraceCount(2, 5000L);
    // trace count : 1
    verifyProducerSendEvent(testQueue);
    // trace count : 1
    verifyConsumerPushEvent(testQueue);
}
Also used : ActiveMQMessageConsumer(org.apache.activemq.ActiveMQMessageConsumer) MessageConsumer(javax.jms.MessageConsumer) ActiveMQSession(org.apache.activemq.ActiveMQSession) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) MessageProducer(javax.jms.MessageProducer) CountDownLatch(java.util.concurrent.CountDownLatch) TextMessage(javax.jms.TextMessage) AssertTextMessageListener(com.navercorp.pinpoint.plugin.jdk7.activemq.client.util.AssertTextMessageListener) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Test(org.junit.Test)

Example 2 with AssertTextMessageListener

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

the class ActiveMQClientITBase method testTopicPush.

@Test
public void testTopicPush() throws Exception {
    // Given
    final String testTopicName = "TestPushTopic";
    final ActiveMQTopic testTopic = new ActiveMQTopic(testTopicName);
    final String testMessage = "Hello World for Topic!";
    final int numMessageConsumers = 2;
    final CountDownLatch consumerConsumeLatch = new CountDownLatch(numMessageConsumers);
    final Collection<Throwable> consumerThrowables = new CopyOnWriteArrayList<Throwable>();
    // create producer
    ActiveMQSession producerSession = ActiveMQClientITHelper.createSession(getProducerBrokerName(), getProducerBrokerUrl());
    MessageProducer producer = new MessageProducerBuilder(producerSession, testTopic).waitTillStarted().build();
    final TextMessage expectedTextMessage = producerSession.createTextMessage(testMessage);
    // create 2 consumers
    ActiveMQSession consumer1Session = ActiveMQClientITHelper.createSession(getConsumerBrokerName(), getConsumerBrokerUrl());
    new MessageConsumerBuilder(consumer1Session, testTopic).withMessageListener(new AssertTextMessageListener(consumerConsumeLatch, consumerThrowables, expectedTextMessage)).waitTillStarted().build();
    ActiveMQSession consumer2Session = ActiveMQClientITHelper.createSession(getConsumerBrokerName(), getConsumerBrokerUrl());
    new MessageConsumerBuilder(consumer2Session, testTopic).withMessageListener(new AssertTextMessageListener(consumerConsumeLatch, consumerThrowables, expectedTextMessage)).waitTillStarted().build();
    // When
    producer.send(expectedTextMessage);
    consumerConsumeLatch.await(1L, TimeUnit.SECONDS);
    // Then
    // Wait till all traces are recorded (consumer traces are recorded from another thread)
    awaitAndVerifyTraceCount(3, 1000L);
    // trace count : 1
    verifyProducerSendEvent(testTopic);
    // trace count : 1
    verifyConsumerPushEvent(testTopic);
    // trace count : 1
    verifyConsumerPushEvent(testTopic);
}
Also used : ActiveMQTopic(org.apache.activemq.command.ActiveMQTopic) MessageConsumerBuilder(com.navercorp.pinpoint.plugin.jdk7.activemq.client.util.MessageConsumerBuilder) CountDownLatch(java.util.concurrent.CountDownLatch) MessageProducerBuilder(com.navercorp.pinpoint.plugin.jdk7.activemq.client.util.MessageProducerBuilder) ActiveMQSession(org.apache.activemq.ActiveMQSession) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) AssertTextMessageListener(com.navercorp.pinpoint.plugin.jdk7.activemq.client.util.AssertTextMessageListener) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Test(org.junit.Test)

Aggregations

AssertTextMessageListener (com.navercorp.pinpoint.plugin.jdk7.activemq.client.util.AssertTextMessageListener)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 MessageProducer (javax.jms.MessageProducer)2 TextMessage (javax.jms.TextMessage)2 ActiveMQSession (org.apache.activemq.ActiveMQSession)2 Test (org.junit.Test)2 MessageConsumerBuilder (com.navercorp.pinpoint.plugin.jdk7.activemq.client.util.MessageConsumerBuilder)1 MessageProducerBuilder (com.navercorp.pinpoint.plugin.jdk7.activemq.client.util.MessageProducerBuilder)1 MessageConsumer (javax.jms.MessageConsumer)1 ActiveMQMessageConsumer (org.apache.activemq.ActiveMQMessageConsumer)1 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)1 ActiveMQTopic (org.apache.activemq.command.ActiveMQTopic)1