Return-Path: X-Original-To: apmail-activemq-commits-archive@www.apache.org Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2663810A9D for ; Wed, 19 Jun 2013 18:04:50 +0000 (UTC) Received: (qmail 72899 invoked by uid 500); 19 Jun 2013 18:04:50 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 72821 invoked by uid 500); 19 Jun 2013 18:04:46 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 72802 invoked by uid 99); 19 Jun 2013 18:04:45 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 19 Jun 2013 18:04:45 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 19 Jun 2013 18:04:44 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id A632923888FE; Wed, 19 Jun 2013 18:04:24 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1494715 - in /activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core: ActiveMQSessionTest.cpp ActiveMQSessionTest.h Date: Wed, 19 Jun 2013 18:04:24 -0000 To: commits@activemq.apache.org From: tabish@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130619180424.A632923888FE@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: tabish Date: Wed Jun 19 18:04:24 2013 New Revision: 1494715 URL: http://svn.apache.org/r1494715 Log: New test case Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQSessionTest.cpp activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQSessionTest.h Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQSessionTest.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQSessionTest.cpp?rev=1494715&r1=1494714&r2=1494715&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQSessionTest.cpp (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQSessionTest.cpp Wed Jun 19 18:04:24 2013 @@ -42,8 +42,8 @@ using namespace decaf; using namespace decaf::lang; //////////////////////////////////////////////////////////////////////////////// -namespace activemq{ -namespace core{ +namespace activemq { +namespace core { class MyCMSMessageListener : public cms::MessageListener { public: @@ -104,6 +104,14 @@ namespace core{ }} //////////////////////////////////////////////////////////////////////////////// +ActiveMQSessionTest::ActiveMQSessionTest() : connection(), dTransport(), exListener() { +} + +//////////////////////////////////////////////////////////////////////////////// +ActiveMQSessionTest::~ActiveMQSessionTest() { +} + +//////////////////////////////////////////////////////////////////////////////// void ActiveMQSessionTest::testCreateManyConsumersAndSetListeners() { MyCMSMessageListener msgListener1; @@ -541,7 +549,7 @@ void ActiveMQSessionTest::testTransactio CPPUNIT_ASSERT_EQUAL(MSG_COUNT, (int)msgListener1.messages.size()); // This is what we are testing, since there was no commit, the session - // will rollback the transaction when this are closed. + // will rollback the transaction when this is closed. // session->commit(); consumer1->close(); @@ -606,77 +614,117 @@ void ActiveMQSessionTest::testExpiration } //////////////////////////////////////////////////////////////////////////////// -void ActiveMQSessionTest::setUp() -{ - try - { +void ActiveMQSessionTest::testTransactionCommitAfterConsumerClosed() { + + static const int MSG_COUNT = 50; + MyCMSMessageListener msgListener1; + + CPPUNIT_ASSERT(connection.get() != NULL); + + // Create an Transacted Session + std::auto_ptr session(connection->createSession(cms::Session::SESSION_TRANSACTED)); + + // Create a Topic + std::auto_ptr topic1(session->createTopic("TestTopic1")); + + CPPUNIT_ASSERT(topic1.get() != NULL); + + // Create a consumer + std::auto_ptr consumer1( + dynamic_cast( session->createConsumer( topic1.get() ) ) ); + + CPPUNIT_ASSERT(consumer1.get() != NULL); + CPPUNIT_ASSERT(consumer1->getMessageSelector() == ""); + CPPUNIT_ASSERT(consumer1->receiveNoWait() == NULL); + CPPUNIT_ASSERT(consumer1->receive(5) == NULL); + + consumer1->setMessageListener(&msgListener1); + + for (int i = 0; i < MSG_COUNT; ++i) { + injectTextMessage("This is a Test 1", *topic1, *(consumer1->getConsumerId())); + } + + msgListener1.asyncWaitForMessages(MSG_COUNT); + CPPUNIT_ASSERT_EQUAL(MSG_COUNT, (int )msgListener1.messages.size()); + + consumer1->close(); + session->commit(); + + Pointer msg1 = msgListener1.messages[0].dynamicCast(); + std::string text1 = msg1->getText(); + + CPPUNIT_ASSERT(text1 == "This is a Test 1"); + msgListener1.clear(); +} + +//////////////////////////////////////////////////////////////////////////////// +void ActiveMQSessionTest::setUp() { + + try { ActiveMQConnectionFactory factory("mock://127.0.0.1:12345?wireFormat=openwire"); - connection.reset( dynamic_cast< ActiveMQConnection*>( factory.createConnection() ) ); + connection.reset(dynamic_cast(factory.createConnection())); // Get a pointer to the Mock Transport for Message injection. dTransport = dynamic_cast( - connection->getTransport().narrow( typeid( transport::mock::MockTransport ) ) ); - CPPUNIT_ASSERT( dTransport != NULL ); + connection->getTransport().narrow(typeid(transport::mock::MockTransport))); + CPPUNIT_ASSERT(dTransport != NULL); - connection->setExceptionListener( &exListener ); + connection->setExceptionListener(&exListener); connection->start(); - } - catch(...) - { + } catch (...) { bool exceptionThrown = false; - - CPPUNIT_ASSERT( exceptionThrown ); + CPPUNIT_ASSERT(exceptionThrown); } } //////////////////////////////////////////////////////////////////////////////// void ActiveMQSessionTest::tearDown() { - connection.reset( NULL ); + connection.reset(NULL); } //////////////////////////////////////////////////////////////////////////////// -void ActiveMQSessionTest::injectTextMessage( const std::string message, - const cms::Destination& destination, - const commands::ConsumerId& id, - const long long timeStamp, - const long long timeToLive ) -{ - Pointer msg( new ActiveMQTextMessage() ); - - Pointer producerId( new ProducerId() ); - producerId->setConnectionId( id.getConnectionId() ); - producerId->setSessionId( id.getSessionId() ); - producerId->setValue( 1 ); - - Pointer messageId( new MessageId() ); - messageId->setProducerId( producerId ); - messageId->setProducerSequenceId( 2 ); +void ActiveMQSessionTest::injectTextMessage(const std::string message, + const cms::Destination& destination, + const commands::ConsumerId& id, + const long long timeStamp, + const long long timeToLive) { + + Pointer msg(new ActiveMQTextMessage()); + + Pointer producerId(new ProducerId()); + producerId->setConnectionId(id.getConnectionId()); + producerId->setSessionId(id.getSessionId()); + producerId->setValue(1); + + Pointer messageId(new MessageId()); + messageId->setProducerId(producerId); + messageId->setProducerSequenceId(2); // Init Message - msg->setText( message.c_str() ); - msg->setCMSDestination( &destination ); - msg->setCMSMessageID( "Id: 123456" ); - msg->setMessageId( messageId ); + msg->setText(message.c_str()); + msg->setCMSDestination(&destination); + msg->setCMSMessageID("Id: 123456"); + msg->setMessageId(messageId); long long expiration = 0LL; - if( timeStamp != 0 ) { - msg->setCMSTimestamp( timeStamp ); + if (timeStamp != 0) { + msg->setCMSTimestamp(timeStamp); - if( timeToLive > 0LL ) { + if (timeToLive > 0LL) { expiration = timeToLive + timeStamp; } } - msg->setCMSExpiration( expiration ); + msg->setCMSExpiration(expiration); // Send the Message - CPPUNIT_ASSERT( dTransport != NULL ); + CPPUNIT_ASSERT(dTransport != NULL); - Pointer dispatch( new MessageDispatch() ); - dispatch->setMessage( msg ); - dispatch->setConsumerId( Pointer( id.cloneDataStructure() ) ); + Pointer dispatch(new MessageDispatch()); + dispatch->setMessage(msg); + dispatch->setConsumerId(Pointer(id.cloneDataStructure())); - dTransport->fireCommand( dispatch ); + dTransport->fireCommand(dispatch); } Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQSessionTest.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQSessionTest.h?rev=1494715&r1=1494714&r2=1494715&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQSessionTest.h (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQSessionTest.h Wed Jun 19 18:04:24 2013 @@ -43,6 +43,7 @@ namespace core{ CPPUNIT_TEST( testClientAck ); CPPUNIT_TEST( testTransactionCommitOneConsumer ); CPPUNIT_TEST( testTransactionCommitTwoConsumer ); + CPPUNIT_TEST( testTransactionCommitAfterConsumerClosed ); CPPUNIT_TEST( testTransactionRollbackOneConsumer ); CPPUNIT_TEST( testTransactionRollbackTwoConsumer ); CPPUNIT_TEST( testTransactionCloseWithoutCommit ); @@ -76,20 +77,21 @@ namespace core{ ActiveMQSessionTest(const ActiveMQSessionTest&); ActiveMQSessionTest& operator= (const ActiveMQSessionTest&); - public: // CPPUNIT Method Overrides. + public: + + virtual void setUp(); + virtual void tearDown(); - void setUp(); - void tearDown(); - void injectTextMessage( const std::string message, - const cms::Destination& destination, - const commands::ConsumerId& id, - const long long timeStamp = -1, - const long long timeToLive = -1 ); + void injectTextMessage(const std::string message, + const cms::Destination& destination, + const commands::ConsumerId& id, + const long long timeStamp = -1, + const long long timeToLive = -1); public: - ActiveMQSessionTest() : connection(), dTransport(), exListener() {} - virtual ~ActiveMQSessionTest() {} + ActiveMQSessionTest(); + virtual ~ActiveMQSessionTest(); void testAutoAcking(); void testClientAck(); @@ -99,6 +101,7 @@ namespace core{ void testTransactionRollbackOneConsumer(); void testTransactionRollbackTwoConsumer(); void testTransactionCloseWithoutCommit(); + void testTransactionCommitAfterConsumerClosed(); void testExpiration(); };