activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
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 GMT
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 <activemq/exceptions/ActiveMQException.h>
+
+#include <decaf/lang/Thread.h>
+
+#include <cms/Session.h>
+#include <cms/MessageListener.h>
+
+#include <memory>
+
+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> session( connection->createSession( Session::CLIENT_ACKNOWLEDGE
) );
+    std::auto_ptr<Destination> queue( session->createTemporaryQueue() );
+    std::auto_ptr<MessageProducer> producer( session->createProducer( queue.get()
) );
+
+    std::auto_ptr<TextMessage> msg1( session->createTextMessage( "Hello" ) );
+    producer->send( msg1.get() );
+
+    // Consume the message...
+    std::auto_ptr<MessageConsumer> consumer( session->createConsumer( queue.get()
) );
+    std::auto_ptr<Message> 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> session( connection->createSession( Session::CLIENT_ACKNOWLEDGE
) );
+    std::auto_ptr<Destination> queue( session->createTemporaryQueue() );
+    std::auto_ptr<MessageProducer> producer( session->createProducer( queue.get()
) );
+
+    std::auto_ptr<TextMessage> msg1( session->createTextMessage( "Hello1" ) );
+    std::auto_ptr<TextMessage> msg2( session->createTextMessage( "Hello2" ) );
+    std::auto_ptr<TextMessage> msg3( session->createTextMessage( "Hello3" ) );
+    producer->send( msg1.get() );
+    producer->send( msg2.get() );
+    producer->send( msg3.get() );
+
+    // Consume the message...
+    std::auto_ptr<MessageConsumer> consumer( session->createConsumer( queue.get()
) );
+    std::auto_ptr<Message> 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> session( connection->createSession( Session::CLIENT_ACKNOWLEDGE
) );
+    std::auto_ptr<Destination> queue( session->createTemporaryQueue() );
+    std::auto_ptr<MessageProducer> producer( session->createProducer( queue.get()
) );
+
+    std::auto_ptr<TextMessage> msg1( session->createTextMessage( "Hello" ) );
+    producer->send( msg1.get() );
+
+    // Consume the message...
+    std::auto_ptr<MessageConsumer> consumer( session->createConsumer( queue.get()
) );
+    std::auto_ptr<Message> 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> session( connection->createSession( Session::CLIENT_ACKNOWLEDGE
) );
+    std::auto_ptr<Destination> queue( session->createTemporaryQueue() );
+    std::auto_ptr<MessageProducer> producer( session->createProducer( queue.get()
) );
+
+    std::auto_ptr<TextMessage> msg1( session->createTextMessage( "Hello" ) );
+    producer->send( msg1.get() );
+
+    // Consume the message...
+    std::auto_ptr<MessageConsumer> 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<Message> 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> session( connection->createSession( Session::CLIENT_ACKNOWLEDGE
) );
+    std::auto_ptr<Destination> queue( session->createTemporaryQueue() );
+    std::auto_ptr<MessageProducer> producer( session->createProducer( queue.get()
) );
+
+    std::auto_ptr<TextMessage> msg1( session->createTextMessage( "Hello" ) );
+    producer->send( msg1.get() );
+
+    // Consume the message...
+    std::auto_ptr<MessageConsumer> 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<Message> 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 <activemq/test/CMSTestFixture.h>
+#include <activemq/util/IntegrationCommon.h>
+
+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



Mime
View raw message