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