activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mick Knutson <mknut...@baselogic.com>
Subject issue with MDP and VirtualTopic Unit Test
Date Tue, 08 Sep 2009 00:20:50 GMT
I have the following unit test, that I can NOT get to operate as expected:

Issue 1: When I send a message to a VirtualTopic that I did NOT subscribe
to, I should NOT get 4 messages anyways.

Issue 2. When I change the destination to the proper VirtualTopic, I thought
I should only get one message, but i actually get 8.

Issue 3: When I change the destination to another VirtualTopic that I am NOT
sending messages to, then I should not get any messages. I still get XXX
messages

Overall assumption: There seems to be a strange random error with Mock's in
general. The numbers change randomly on some runs. Such as an assertion that
should get zero messages might work for several unit test runs, then all of
the sudden, get a message delivered.



Now this is all part of a blog I started so that I could test MDP's and
VirtualTopics located at
http://www.baselogic.com/blog/java/testing-activemq-virtualtopics-using-camel-and-junit

Here is the unit test itself that is nor cooperating (with comments for the
issues):


    @Test
    @DirtiesContext
    public void testChangeMessageDestination() throws Exception {
        log.info("Send a test message to Table Service");
        log.info("***** testChangeMessageDestination()
********************************");

        DefaultMessageListenerContainer container =
(DefaultMessageListenerContainer)context.getBean("jmsListener12");
        assertNotNull(container);
        assertTrue(container instanceof DefaultMessageListenerContainer);
        assertEquals("Consumer.12.VirtualTopic.Table.12",
container.getDestinationName());

       * // FIXME Why do I get 4 messages here? There should be ZERO (0)!*
        resultChangeMessageDestination.expectedMessageCount(0);

        // Send the test message to make Server Service create our Status
Message
        // Message to be sent to 'VirtualTopic.Table.1' , NOT
'VirtualTopic.Table.12'
        producerTemplate.sendBody("jms:queue:sendStatusUpdate",
                ExchangePattern.InOnly, 1);

        // now lets assert that the mock endpoint received messages
        resultChangeMessageDestination.assertIsSatisfied();
        resultChangeMessageDestination.reset();


        log.info("* valid message
received.---------------------------------");

        ActiveMQQueue newDestination = new
ActiveMQQueue("Consumer.12.VirtualTopic.Table.1");
        container.setDestination(newDestination);

        *// not sure why I get 8 message on a different run here... I
thought I should get only one (1)*
        resultChangeMessageDestination.expectedMinimumMessageCount(8);

        // Send the test message to make Server Service create our Status
Message
        // Message to be sent to 'VirtualTopic.Table.1' , NOT
'VirtualTopic.Table.12'
        producerTemplate.sendBody("jms:queue:sendStatusUpdate",
                ExchangePattern.InOnly, 1);

        // now lets assert that the mock endpoint received messages
        resultChangeMessageDestination.assertIsSatisfied();
        resultChangeMessageDestination.reset();


        log.info("* no message received
again.---------------------------------");

        newDestination = new
ActiveMQQueue("Consumer.12.VirtualTopic.BADTOPIC");
        container.setDestination(newDestination);

        *// Should get zero messages here.
        // one run resulted zero, then another was 5, then the next was one,
then the next was zero....????*
        resultChangeMessageDestination.expectedMessageCount(99);

        // Send the test message to make Server Service create our Status
Message
        producerTemplate.sendBody("jms:queue:sendStatusUpdate",
                ExchangePattern.InOnly, 1);

        // now lets assert that the mock endpoint received messages
        resultChangeMessageDestination.assertIsSatisfied();

    }








---
Thank You…

Mick Knutson, President

BASE Logic, Inc.
Enterprise Architecture, Design, Mentoring & Agile Consulting
p. (866) BLiNC-411: (254-6241-1)
f. (415) 685-4233

Website: http://baselogic.com
Linked IN: http://linkedin.com/in/mickknutson
Vacation Rental: http://tahoe.baselogic.com
---

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message