Return-Path: Delivered-To: apmail-geronimo-activemq-commits-archive@www.apache.org Received: (qmail 73751 invoked from network); 5 Dec 2006 00:36:48 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 5 Dec 2006 00:36:48 -0000 Received: (qmail 31261 invoked by uid 500); 5 Dec 2006 00:36:57 -0000 Delivered-To: apmail-geronimo-activemq-commits-archive@geronimo.apache.org Received: (qmail 31214 invoked by uid 500); 5 Dec 2006 00:36:57 -0000 Mailing-List: contact activemq-commits-help@geronimo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: activemq-dev@geronimo.apache.org Delivered-To: mailing list activemq-commits@geronimo.apache.org Received: (qmail 31204 invoked by uid 99); 5 Dec 2006 00:36:57 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 04 Dec 2006 16:36:57 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 04 Dec 2006 16:36:48 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id 5B4B71A9846; Mon, 4 Dec 2006 16:36:07 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r482431 - /incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQSessionTest.h Date: Tue, 05 Dec 2006 00:36:07 -0000 To: activemq-commits@geronimo.apache.org From: tabish@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20061205003607.5B4B71A9846@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: tabish Date: Mon Dec 4 16:36:05 2006 New Revision: 482431 URL: http://svn.apache.org/viewvc?view=rev&rev=482431 Log: https://issues.apache.org/activemq/browse/AMQCPP-14 added unit testing for expiration in core api Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQSessionTest.h Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQSessionTest.h URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQSessionTest.h?view=diff&rev=482431&r1=482430&r2=482431 ============================================================================== --- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQSessionTest.h (original) +++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQSessionTest.h Mon Dec 4 16:36:05 2006 @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -59,6 +60,7 @@ CPPUNIT_TEST( testAutoAcking ); CPPUNIT_TEST( testClientAck ); CPPUNIT_TEST( testTransactional ); + CPPUNIT_TEST( testExpiration ); CPPUNIT_TEST_SUITE_END(); private: @@ -188,7 +190,9 @@ } void injectTextMessage( const std::string message, - const cms::Destination& destination ) + const cms::Destination& destination, + const long long timeStamp = -1, + const long long timeToLive = -1 ) { connector::stomp::StompFrame* frame = new connector::stomp::StompFrame(); @@ -205,6 +209,18 @@ msg->setText( message.c_str() ); msg->setCMSDestination( &destination ); msg->setCMSMessageId( "Id: 123456" ); + + long long expiration = 0LL; + + if( timeStamp != 0 ) { + msg->setCMSTimeStamp( timeStamp ); + + if( timeToLive > 0LL ) { + expiration = timeToLive + timeStamp; + } + } + + msg->setCMSExpiration( expiration ); // Send the Message CPPUNIT_ASSERT( dTransport != NULL ); @@ -577,6 +593,83 @@ delete session; } + void testExpiration() + { + MyCMSMessageListener msgListener1; + MyCMSMessageListener msgListener2; + + CPPUNIT_ASSERT( connection != NULL ); + + // Create an Auto Ack Session + cms::Session* session = connection->createSession(); + + // Create a Topic + cms::Topic* topic1 = session->createTopic( "TestTopic1"); + cms::Topic* topic2 = session->createTopic( "TestTopic2"); + + CPPUNIT_ASSERT( topic1 != NULL ); + CPPUNIT_ASSERT( topic2 != NULL ); + + // Create a consumer + cms::MessageConsumer* consumer1 = + session->createConsumer( topic1 ); + cms::MessageConsumer* consumer2 = + session->createConsumer( topic2 ); + + CPPUNIT_ASSERT( consumer1 != NULL ); + CPPUNIT_ASSERT( consumer2 != NULL ); + + consumer1->setMessageListener( &msgListener1 ); + consumer2->setMessageListener( &msgListener2 ); + + injectTextMessage( "This is a Test 1" , + *topic1, + activemq::util::Date::getCurrentTimeMilliseconds(), + 50 ); + + synchronized( &msgListener1.mutex ) + { + if( msgListener1.messages.size() == 0 ) + { + msgListener1.mutex.wait( 3000 ); + } + } + + CPPUNIT_ASSERT( msgListener1.messages.size() == 1 ); + + injectTextMessage( "This is a Test 2" , + *topic2, + activemq::util::Date::getCurrentTimeMilliseconds() - 100, + 1 ); + + synchronized( &msgListener2.mutex ) + { + if( msgListener2.messages.size() == 0 ) + { + msgListener2.mutex.wait( 100 ); + } + } + + CPPUNIT_ASSERT( msgListener2.messages.size() == 0 ); + + cms::TextMessage* msg1 = + dynamic_cast< cms::TextMessage* >( + msgListener1.messages[0] ); + + CPPUNIT_ASSERT( msg1 != NULL ); + + std::string text1 = msg1->getText(); + + CPPUNIT_ASSERT( text1 == "This is a Test 1" ); + + delete topic1; + delete topic2; + + delete consumer1; + delete consumer2; + + delete session; + } }; }}