Return-Path: Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: (qmail 62169 invoked from network); 13 Nov 2009 13:48:22 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 13 Nov 2009 13:48:22 -0000 Received: (qmail 59123 invoked by uid 500); 13 Nov 2009 13:48:22 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 59075 invoked by uid 500); 13 Nov 2009 13:48:22 -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 59066 invoked by uid 99); 13 Nov 2009 13:48:22 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Nov 2009 13:48:22 +0000 X-ASF-Spam-Status: No, hits=-2.6 required=5.0 tests=AWL,BAYES_00 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; Fri, 13 Nov 2009 13:48:19 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id B4DF7238889D; Fri, 13 Nov 2009 13:47:59 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r835848 - in /activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration: Makefile.am TestRegistry.cpp activemq/test/openwire/OpenwireClientAckTest.cpp activemq/test/openwire/OpenwireClientAckTest.h Date: Fri, 13 Nov 2009 13:47:59 -0000 To: commits@activemq.apache.org From: tabish@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20091113134759.B4DF7238889D@eris.apache.org> Author: tabish Date: Fri Nov 13 13:47:59 2009 New Revision: 835848 URL: http://svn.apache.org/viewvc?rev=835848&view=rev Log: https://issues.apache.org/activemq/browse/AMQCPP-266 Add additional integration tests for Client Ack Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/activemq/test/openwire/OpenwireClientAckTest.cpp (with props) activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/activemq/test/openwire/OpenwireClientAckTest.h (with props) Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/Makefile.am activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/TestRegistry.cpp Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/Makefile.am URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/Makefile.am?rev=835848&r1=835847&r2=835848&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/Makefile.am (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/Makefile.am Fri Nov 13 13:47:59 2009 @@ -28,6 +28,7 @@ activemq/test/TransactionTest.cpp \ activemq/test/VirtualTopicTest.cpp \ activemq/test/openwire/OpenwireAsyncSenderTest.cpp \ + activemq/test/openwire/OpenwireClientAckTest.cpp \ activemq/test/openwire/OpenwireCmsTemplateTest.cpp \ activemq/test/openwire/OpenwireDurableTest.cpp \ activemq/test/openwire/OpenwireExpirationTest.cpp \ @@ -68,6 +69,7 @@ activemq/test/TransactionTest.h \ activemq/test/VirtualTopicTest.h \ activemq/test/openwire/OpenwireAsyncSenderTest.h \ + activemq/test/openwire/OpenwireClientAckTest.h \ activemq/test/openwire/OpenwireCmsTemplateTest.h \ activemq/test/openwire/OpenwireDurableTest.h \ activemq/test/openwire/OpenwireExpirationTest.h \ Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/TestRegistry.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/TestRegistry.cpp?rev=835848&r1=835847&r2=835848&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/TestRegistry.cpp (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/TestRegistry.cpp Fri Nov 13 13:47:59 2009 @@ -16,6 +16,7 @@ */ #include "activemq/test/openwire/OpenwireAsyncSenderTest.h" +#include "activemq/test/openwire/OpenwireClientAckTest.h" #include "activemq/test/openwire/OpenwireCmsTemplateTest.h" #include "activemq/test/openwire/OpenwireDurableTest.h" #include "activemq/test/openwire/OpenwireExpirationTest.h" @@ -40,6 +41,7 @@ // Openwire Tests CPPUNIT_TEST_SUITE_REGISTRATION( activemq::test::openwire::OpenwireAsyncSenderTest ); +CPPUNIT_TEST_SUITE_REGISTRATION( activemq::test::openwire::OpenwireClientAckTest ); CPPUNIT_TEST_SUITE_REGISTRATION( activemq::test::openwire::OpenwireCmsTemplateTest ); CPPUNIT_TEST_SUITE_REGISTRATION( activemq::test::openwire::OpenwireDurableTest ); CPPUNIT_TEST_SUITE_REGISTRATION( activemq::test::openwire::OpenwireExpirationTest ); Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/activemq/test/openwire/OpenwireClientAckTest.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/activemq/test/openwire/OpenwireClientAckTest.cpp?rev=835848&view=auto ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/activemq/test/openwire/OpenwireClientAckTest.cpp (added) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/activemq/test/openwire/OpenwireClientAckTest.cpp Fri Nov 13 13:47:59 2009 @@ -0,0 +1,247 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "OpenwireClientAckTest.h" + +#include + +#include + +#include +#include + +#include + +using namespace cms; +using namespace std; +using namespace decaf; +using namespace decaf::lang; +using namespace activemq; +using namespace activemq::test; +using namespace activemq::test::openwire; + +//////////////////////////////////////////////////////////////////////////////// +namespace { + + class MyMesageListener: public cms::MessageListener { + private: + + bool dontAck; + + public: + + MyMesageListener( bool dontAck = false ) { + this->dontAck = dontAck; + } + + virtual void onMessage( const Message* message ) { + + CPPUNIT_ASSERT( message != NULL ); + + if( !dontAck ) { + + try { + message->acknowledge(); + } catch( Exception& e ) { + e.printStackTrace(); + } + } + } + + }; +} + +//////////////////////////////////////////////////////////////////////////////// +OpenwireClientAckTest::OpenwireClientAckTest() { +} + +//////////////////////////////////////////////////////////////////////////////// +OpenwireClientAckTest::~OpenwireClientAckTest() { +} + +//////////////////////////////////////////////////////////////////////////////// +void OpenwireClientAckTest::testAckedMessageAreConsumed() { + + Connection* connection = this->cmsProvider->getConnection(); + connection->start(); + + std::auto_ptr session( connection->createSession( Session::CLIENT_ACKNOWLEDGE ) ); + std::auto_ptr queue( session->createTemporaryQueue() ); + std::auto_ptr producer( session->createProducer( queue.get() ) ); + + std::auto_ptr msg1( session->createTextMessage( "Hello" ) ); + producer->send( msg1.get() ); + + // Consume the message... + std::auto_ptr consumer( session->createConsumer( queue.get() ) ); + std::auto_ptr msg( consumer->receive( 1000 ) ); + CPPUNIT_ASSERT( msg.get() != NULL ); + msg->acknowledge(); + + // Reset the session-> + session->close(); + session.reset( connection->createSession( Session::CLIENT_ACKNOWLEDGE ) ); + + // Attempt to Consume the message... + consumer.reset( session->createConsumer( queue.get() ) ); + msg.reset( consumer->receive( 1000 ) ); + CPPUNIT_ASSERT( msg.get() == NULL ); + + session->close(); +} + +//////////////////////////////////////////////////////////////////////////////// +void OpenwireClientAckTest::testLastMessageAcked() { + + Connection* connection = this->cmsProvider->getConnection(); + connection->start(); + + std::auto_ptr session( connection->createSession( Session::CLIENT_ACKNOWLEDGE ) ); + std::auto_ptr queue( session->createTemporaryQueue() ); + std::auto_ptr producer( session->createProducer( queue.get() ) ); + + std::auto_ptr msg1( session->createTextMessage( "Hello1" ) ); + std::auto_ptr msg2( session->createTextMessage( "Hello2" ) ); + std::auto_ptr msg3( session->createTextMessage( "Hello3" ) ); + producer->send( msg1.get() ); + producer->send( msg2.get() ); + producer->send( msg3.get() ); + + // Consume the message... + std::auto_ptr consumer( session->createConsumer( queue.get() ) ); + std::auto_ptr msg( consumer->receive( 1000 ) ); + CPPUNIT_ASSERT( msg.get() != NULL ); + msg.reset( consumer->receive( 1000 ) ); + CPPUNIT_ASSERT( msg.get() != NULL ); + msg.reset( consumer->receive( 1000 ) ); + CPPUNIT_ASSERT( msg.get() != NULL ); + msg->acknowledge(); + + // Reset the session-> + session->close(); + session.reset( connection->createSession( Session::CLIENT_ACKNOWLEDGE ) ); + + // Attempt to Consume the message... + consumer.reset( session->createConsumer( queue.get() ) ); + msg.reset( consumer->receive( 1000 ) ); + CPPUNIT_ASSERT( msg.get() == NULL ); + + session->close(); +} + +//////////////////////////////////////////////////////////////////////////////// +void OpenwireClientAckTest::testUnAckedMessageAreNotConsumedOnSessionClose() { + + Connection* connection = this->cmsProvider->getConnection(); + connection->start(); + + std::auto_ptr session( connection->createSession( Session::CLIENT_ACKNOWLEDGE ) ); + std::auto_ptr queue( session->createTemporaryQueue() ); + std::auto_ptr producer( session->createProducer( queue.get() ) ); + + std::auto_ptr msg1( session->createTextMessage( "Hello" ) ); + producer->send( msg1.get() ); + + // Consume the message... + std::auto_ptr consumer( session->createConsumer( queue.get() ) ); + std::auto_ptr msg( consumer->receive( 1000 ) ); + CPPUNIT_ASSERT( msg.get() != NULL ); + // Don't ack the message. + + // Reset the session-> This should cause the unacknowledged message to be re-delivered. + session->close(); + session.reset( connection->createSession( Session::CLIENT_ACKNOWLEDGE ) ); + + // Attempt to Consume the message... + consumer.reset( session->createConsumer( queue.get() ) ); + msg.reset( consumer->receive( 1000 ) ); + CPPUNIT_ASSERT( msg.get() != NULL ); + msg->acknowledge(); + + session->close(); +} + +//////////////////////////////////////////////////////////////////////////////// +void OpenwireClientAckTest::testAckedMessageAreConsumedAsync() { + + Connection* connection = this->cmsProvider->getConnection(); + connection->start(); + + MyMesageListener listener( false ); + + std::auto_ptr session( connection->createSession( Session::CLIENT_ACKNOWLEDGE ) ); + std::auto_ptr queue( session->createTemporaryQueue() ); + std::auto_ptr producer( session->createProducer( queue.get() ) ); + + std::auto_ptr msg1( session->createTextMessage( "Hello" ) ); + producer->send( msg1.get() ); + + // Consume the message... + std::auto_ptr consumer( session->createConsumer( queue.get() ) ); + consumer->setMessageListener( &listener ); + + Thread::sleep( 5000 ); + + // Reset the session-> + session->close(); + + session.reset( connection->createSession( Session::CLIENT_ACKNOWLEDGE ) ); + + // Attempt to Consume the message... + consumer.reset( session->createConsumer( queue.get() ) ); + std::auto_ptr msg( consumer->receive( 1000 ) ); + CPPUNIT_ASSERT( msg.get() == NULL ); + + session->close(); +} + +//////////////////////////////////////////////////////////////////////////////// +void OpenwireClientAckTest::testUnAckedMessageAreNotConsumedOnSessionCloseAsync() { + + Connection* connection = this->cmsProvider->getConnection(); + connection->start(); + + // Don't send an ack + MyMesageListener listener( true ); + + std::auto_ptr session( connection->createSession( Session::CLIENT_ACKNOWLEDGE ) ); + std::auto_ptr queue( session->createTemporaryQueue() ); + std::auto_ptr producer( session->createProducer( queue.get() ) ); + + std::auto_ptr msg1( session->createTextMessage( "Hello" ) ); + producer->send( msg1.get() ); + + // Consume the message... + std::auto_ptr consumer( session->createConsumer( queue.get() ) ); + consumer->setMessageListener( &listener ); + // Don't ack the message. + + // Reset the session-> This should cause the Unacked message to be redelivered. + session->close(); + + Thread::sleep( 5000 ); + session.reset( connection->createSession( Session::CLIENT_ACKNOWLEDGE ) ); + + // Attempt to Consume the message... + consumer.reset( session->createConsumer( queue.get() ) ); + std::auto_ptr msg( consumer->receive( 2000 ) ); + CPPUNIT_ASSERT( msg.get() != NULL ); + msg->acknowledge(); + + session->close(); +} + Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/activemq/test/openwire/OpenwireClientAckTest.cpp ------------------------------------------------------------------------------ svn:eol-style = native Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/activemq/test/openwire/OpenwireClientAckTest.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/activemq/test/openwire/OpenwireClientAckTest.h?rev=835848&view=auto ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/activemq/test/openwire/OpenwireClientAckTest.h (added) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/activemq/test/openwire/OpenwireClientAckTest.h Fri Nov 13 13:47:59 2009 @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _ACTIVEMQ_TEST_OPENWIRE_OPENWIRECLIENTACKTEST_H_ +#define _ACTIVEMQ_TEST_OPENWIRE_OPENWIRECLIENTACKTEST_H_ + +#include +#include + +namespace activemq { +namespace test { +namespace openwire { + + class OpenwireClientAckTest : public CMSTestFixture { + + CPPUNIT_TEST_SUITE( OpenwireClientAckTest ); + CPPUNIT_TEST( testAckedMessageAreConsumed ); + CPPUNIT_TEST( testLastMessageAcked ); + CPPUNIT_TEST( testUnAckedMessageAreNotConsumedOnSessionClose ); + CPPUNIT_TEST( testUnAckedMessageAreNotConsumedOnSessionCloseAsync ); + CPPUNIT_TEST( testAckedMessageAreConsumedAsync ); + CPPUNIT_TEST_SUITE_END(); + + public: + + OpenwireClientAckTest(); + virtual ~OpenwireClientAckTest(); + + virtual std::string getBrokerURL() const { + return activemq::util::IntegrationCommon::getInstance().getOpenwireURL(); + } + + void testAckedMessageAreConsumed(); + void testLastMessageAcked(); + void testUnAckedMessageAreNotConsumedOnSessionClose(); + void testAckedMessageAreConsumedAsync(); + void testUnAckedMessageAreNotConsumedOnSessionCloseAsync(); + }; + +}}} + +#endif /* _ACTIVEMQ_TEST_OPENWIRE_OPENWIRECLIENTACKTEST_H_ */ Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/activemq/test/openwire/OpenwireClientAckTest.h ------------------------------------------------------------------------------ svn:eol-style = native