use of com.navercorp.test.pinpoint.plugin.activemq.MessagePrinter 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 MessagePrinter messagePrinter = new MessagePrinter();
final CountDownLatch consumerLatch = new CountDownLatch(2);
final AtomicReference<Exception> exception = new AtomicReference<>();
// create producer
final ActiveMQSession producerSession = ActiveMQClientITHelper.createSession(getProducerBrokerName(), getProducerBrokerUrl());
final MessageProducer producer = new MessageProducerBuilder(producerSession, testTopic).waitTillStarted().build();
final TextMessage expectedTextMessage = producerSession.createTextMessage(testMessage);
// create 2 consumers
final MessageListener messageListener = new MessageListener() {
@Override
public void onMessage(Message message) {
try {
messagePrinter.printMessage(message);
} catch (Exception e) {
exception.set(e);
} finally {
consumerLatch.countDown();
}
}
};
final ActiveMQSession consumer1Session = ActiveMQClientITHelper.createSession(getConsumerBrokerName(), getConsumerBrokerUrl());
new MessageConsumerBuilder(consumer1Session, testTopic).withMessageListener(messageListener).waitTillStarted().build();
ActiveMQSession consumer2Session = ActiveMQClientITHelper.createSession(getConsumerBrokerName(), getConsumerBrokerUrl());
new MessageConsumerBuilder(consumer2Session, testTopic).withMessageListener(messageListener).waitTillStarted().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(7, 100, 5000);
verifier.verifyTraceCount(7);
verifyProducerSendEvent(verifier, testTopic, producerSession);
verifyConsumerConsumeEvent(verifier, testTopic, consumer1Session);
verifyConsumerConsumeEvent(verifier, testTopic, consumer2Session);
Method printMessageMethod = MessagePrinter.class.getDeclaredMethod("printMessage", Message.class);
for (int i = 0; i < 2; ++i) {
verifier.verifyTrace(event(ServiceType.INTERNAL_METHOD.getName(), printMessageMethod));
}
verifier.verifyTraceCount(0);
}
use of com.navercorp.test.pinpoint.plugin.activemq.MessagePrinter 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);
}
Aggregations