Search in sources :

Example 1 with MessageReceiveHandler

use of com.navercorp.test.pinpoint.plugin.activemq.MessageReceiveHandler in project pinpoint by naver.

the class ActiveMQClientITBase method testTopicPoll.

@Test
public void testTopicPoll() throws Exception {
    // Given
    final String testTopicName = "TestPollTopic";
    final ActiveMQTopic testTopic = new ActiveMQTopic(testTopicName);
    final String testMessage = "Hello World for Topic!";
    // 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 ActiveMQSession consumer1Session = ActiveMQClientITHelper.createSession(getConsumerBrokerName(), getConsumerBrokerUrl());
    final MessageConsumer consumer1 = new MessageConsumerBuilder(consumer1Session, testTopic).waitTillStarted().build();
    final MessageReceiveHandler messageReceiveHandler1 = new MessageReceiveHandler();
    final PollingMessageReceiver pollingMessageReceiver1 = new PollingMessageReceiver(consumer1, messageReceiveHandler1);
    final ActiveMQSession consumer2Session = ActiveMQClientITHelper.createSession(getConsumerBrokerName(), getConsumerBrokerUrl());
    final MessageConsumer consumer2 = new MessageConsumerBuilder(consumer2Session, testTopic).waitTillStarted().build();
    final MessageReceiveHandler messageReceiveHandler2 = new MessageReceiveHandler();
    final PollingMessageReceiver pollingMessageReceiver2 = new PollingMessageReceiver(consumer2, messageReceiveHandler2);
    // When
    pollingMessageReceiver1.start();
    pollingMessageReceiver2.start();
    producer.send(expectedTextMessage);
    messageReceiveHandler1.await(5000L);
    messageReceiveHandler2.await(5000L);
    pollingMessageReceiver1.stop();
    pollingMessageReceiver2.stop();
    // Then
    assertNoConsumerError(pollingMessageReceiver1.getException());
    assertNoConsumerError(pollingMessageReceiver2.getException());
    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    verifier.printCache();
    // Wait till all traces are recorded (consumer traces are recorded from another thread)
    verifier.awaitTraceCount(11, 100, 5000);
    verifier.verifyTraceCount(11);
    verifyProducerSendEvent(verifier, testTopic, producerSession);
    verifyConsumerConsumeEvent(verifier, testTopic, consumer1Session);
    verifyConsumerConsumeEvent(verifier, testTopic, consumer2Session);
    ExpectedTrace asyncTrace = event(ServiceType.ASYNC.getName(), "Asynchronous Invocation");
    Method handleMessageMethod = MessageReceiveHandler.class.getDeclaredMethod("handleMessage", Message.class);
    ExpectedTrace handleMessageTrace = event(ServiceType.INTERNAL_METHOD.getName(), handleMessageMethod);
    Method printMessageMethod = MessagePrinter.class.getDeclaredMethod("printMessage", Message.class);
    ExpectedTrace printMessageTrace = event(ServiceType.INTERNAL_METHOD.getName(), printMessageMethod);
    for (int i = 0; i < 2; ++i) {
        verifier.verifyDiscreteTrace(asyncTrace, handleMessageTrace, printMessageTrace);
    }
    verifier.verifyTraceCount(0);
}
Also used : ExpectedTrace(com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedTrace) ActiveMQMessageConsumer(org.apache.activemq.ActiveMQMessageConsumer) MessageConsumer(javax.jms.MessageConsumer) ActiveMQTopic(org.apache.activemq.command.ActiveMQTopic) MessageConsumerBuilder(com.navercorp.pinpoint.plugin.activemq.client.util.MessageConsumerBuilder) Method(java.lang.reflect.Method) PluginTestVerifier(com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier) MessageProducerBuilder(com.navercorp.pinpoint.plugin.activemq.client.util.MessageProducerBuilder) ActiveMQSession(org.apache.activemq.ActiveMQSession) MessageReceiveHandler(com.navercorp.test.pinpoint.plugin.activemq.MessageReceiveHandler) PollingMessageReceiver(com.navercorp.test.pinpoint.plugin.activemq.PollingMessageReceiver) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 2 with MessageReceiveHandler

use of com.navercorp.test.pinpoint.plugin.activemq.MessageReceiveHandler in project pinpoint by naver.

the class ActiveMQClientITBase method testQueuePoll.

@Test
public void testQueuePoll() throws Exception {
    // Given
    final String testQueueName = "TestPollQueue";
    final ActiveMQQueue testQueue = new ActiveMQQueue(testQueueName);
    final String testMessage = "Hello World for Queue!";
    // 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());
    final MessageConsumer consumer = new MessageConsumerBuilder(consumerSession, testQueue).waitTillStarted().build();
    final MessageReceiveHandler messageReceiveHandler = new MessageReceiveHandler();
    final PollingMessageReceiver pollingMessageReceiver = new PollingMessageReceiver(consumer, messageReceiveHandler);
    // When
    pollingMessageReceiver.start();
    producer.send(expectedTextMessage);
    messageReceiveHandler.await(5000L);
    pollingMessageReceiver.stop();
    // Then
    assertNoConsumerError(pollingMessageReceiver.getException());
    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    verifier.printCache();
    // Wait till all traces are recorded (consumer traces are recorded from another thread)
    verifier.awaitTraceCount(6, 100, 5000);
    verifier.verifyTraceCount(6);
    verifyProducerSendEvent(verifier, testQueue, producerSession);
    verifyConsumerConsumeEvent(verifier, testQueue, consumerSession);
    verifier.verifyTrace(event(ServiceType.ASYNC.getName(), "Asynchronous Invocation"));
    Method handleMessageMethod = MessageReceiveHandler.class.getDeclaredMethod("handleMessage", Message.class);
    verifier.verifyTrace(event(ServiceType.INTERNAL_METHOD.getName(), handleMessageMethod));
    Method printMessageMethod = MessagePrinter.class.getDeclaredMethod("printMessage", Message.class);
    verifier.verifyTrace(event(ServiceType.INTERNAL_METHOD.getName(), printMessageMethod));
    verifier.verifyTraceCount(0);
}
Also used : MessageProducerBuilder(com.navercorp.pinpoint.plugin.activemq.client.util.MessageProducerBuilder) ActiveMQMessageConsumer(org.apache.activemq.ActiveMQMessageConsumer) MessageConsumer(javax.jms.MessageConsumer) ActiveMQSession(org.apache.activemq.ActiveMQSession) MessageReceiveHandler(com.navercorp.test.pinpoint.plugin.activemq.MessageReceiveHandler) MessageConsumerBuilder(com.navercorp.pinpoint.plugin.activemq.client.util.MessageConsumerBuilder) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) PollingMessageReceiver(com.navercorp.test.pinpoint.plugin.activemq.PollingMessageReceiver) MessageProducer(javax.jms.MessageProducer) Method(java.lang.reflect.Method) PluginTestVerifier(com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Aggregations

PluginTestVerifier (com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier)2 MessageConsumerBuilder (com.navercorp.pinpoint.plugin.activemq.client.util.MessageConsumerBuilder)2 MessageProducerBuilder (com.navercorp.pinpoint.plugin.activemq.client.util.MessageProducerBuilder)2 MessageReceiveHandler (com.navercorp.test.pinpoint.plugin.activemq.MessageReceiveHandler)2 PollingMessageReceiver (com.navercorp.test.pinpoint.plugin.activemq.PollingMessageReceiver)2 Method (java.lang.reflect.Method)2 MessageConsumer (javax.jms.MessageConsumer)2 MessageProducer (javax.jms.MessageProducer)2 TextMessage (javax.jms.TextMessage)2 ActiveMQMessageConsumer (org.apache.activemq.ActiveMQMessageConsumer)2 ActiveMQSession (org.apache.activemq.ActiveMQSession)2 Test (org.junit.Test)2 ExpectedTrace (com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedTrace)1 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)1 ActiveMQTopic (org.apache.activemq.command.ActiveMQTopic)1