From commits-return-10413-apmail-activemq-commits-archive=activemq.apache.org@activemq.apache.org Fri Mar 13 19:19:25 2009 Return-Path: Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: (qmail 61412 invoked from network); 13 Mar 2009 19:19:25 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 13 Mar 2009 19:19:25 -0000 Received: (qmail 63062 invoked by uid 500); 13 Mar 2009 19:19:25 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 63006 invoked by uid 500); 13 Mar 2009 19:19:25 -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 62997 invoked by uid 99); 13 Mar 2009 19:19:25 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Mar 2009 12:19:25 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.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; Fri, 13 Mar 2009 19:19:22 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 34ABB23888CA; Fri, 13 Mar 2009 19:19:01 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r753355 - in /activemq/activemq-cpp/trunk: activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/ src/main/activemq/commands/ src/main/activemq/transport/failover/ src/test/activemq/transport/failover/ Date: Fri, 13 Mar 2009 19:18:57 -0000 To: commits@activemq.apache.org From: tabish@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090313191901.34ABB23888CA@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: tabish Date: Fri Mar 13 19:18:53 2009 New Revision: 753355 URL: http://svn.apache.org/viewvc?rev=753355&view=rev Log: http://issues.apache.org/activemq/browse/AMQCPP-100 Add a test to check that all messages are sent when a transport fails during a send. Fix source code generator to add in missing isMessage method in Message.h. Make the FailoverTransport pass on a call to Narrow to a connected Transport if there is one. Modified: activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/CommandCodeGeneratorsFactory.java activemq/activemq-cpp/trunk/src/main/activemq/commands/Message.h activemq/activemq-cpp/trunk/src/main/activemq/transport/failover/FailoverTransport.h activemq/activemq-cpp/trunk/src/test/activemq/transport/failover/FailoverTransportTest.cpp activemq/activemq-cpp/trunk/src/test/activemq/transport/failover/FailoverTransportTest.h Modified: activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/CommandCodeGeneratorsFactory.java URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/CommandCodeGeneratorsFactory.java?rev=753355&r1=753354&r2=753355&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/CommandCodeGeneratorsFactory.java (original) +++ activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/CommandCodeGeneratorsFactory.java Fri Mar 13 19:18:53 2009 @@ -43,6 +43,7 @@ commandsWithShortcuts.add( "BrokerInfo" ); commandsWithShortcuts.add( "KeepAliveInfo" ); commandsWithShortcuts.add( "WireFormatInfo" ); + commandsWithShortcuts.add( "Message" ); commandsWithShortcuts.add( "MessageAck" ); commandsWithShortcuts.add( "ProducerAck" ); commandsWithShortcuts.add( "MessageDispatchNotification" ); Modified: activemq/activemq-cpp/trunk/src/main/activemq/commands/Message.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/commands/Message.h?rev=753355&r1=753354&r2=753355&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/src/main/activemq/commands/Message.h (original) +++ activemq/activemq-cpp/trunk/src/main/activemq/commands/Message.h Fri Mar 13 19:18:53 2009 @@ -373,6 +373,13 @@ virtual void setBrokerOutTime( long long brokerOutTime ); /** + * @return an answer of true to the isMessage() query. + */ + virtual bool isMessage() const { + return true; + } + + /** * Allows a Visitor to visit this command and return a response to the * command based on the command type being visited. The command will call * the proper processXXX method in the visitor. Modified: activemq/activemq-cpp/trunk/src/main/activemq/transport/failover/FailoverTransport.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/transport/failover/FailoverTransport.h?rev=753355&r1=753354&r2=753355&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/src/main/activemq/transport/failover/FailoverTransport.h (original) +++ activemq/activemq-cpp/trunk/src/main/activemq/transport/failover/FailoverTransport.h Fri Mar 13 19:18:53 2009 @@ -266,6 +266,10 @@ return this; } + if( this->connectedTransport != NULL ) { + return this->connectedTransport->narrow( typeId ); + } + return NULL; } Modified: activemq/activemq-cpp/trunk/src/test/activemq/transport/failover/FailoverTransportTest.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/activemq/transport/failover/FailoverTransportTest.cpp?rev=753355&r1=753354&r2=753355&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/src/test/activemq/transport/failover/FailoverTransportTest.cpp (original) +++ activemq/activemq-cpp/trunk/src/test/activemq/transport/failover/FailoverTransportTest.cpp Fri Mar 13 19:18:53 2009 @@ -19,13 +19,17 @@ #include #include +#include #include +#include #include #include using namespace activemq; +using namespace activemq::commands; using namespace activemq::transport; using namespace activemq::transport::failover; +using namespace activemq::transport::mock; using namespace activemq::exceptions; using namespace decaf::lang; using namespace decaf::util; @@ -152,3 +156,98 @@ transport->start(); transport->close(); } + +//////////////////////////////////////////////////////////////////////////////// +class MessageCountingListener : public DefaultTransportListener { +public: + + int numMessages; + + MessageCountingListener() : numMessages( 0 ) {} + + virtual void onCommand( const Pointer& command AMQCPP_UNUSED ) { + numMessages++; + } +}; + +//////////////////////////////////////////////////////////////////////////////// +void FailoverTransportTest::testSendOnewayMessage() { + + std::string uri = "failover://(mock://localhost:61616)?randomize=false"; + + Pointer message( new ActiveMQMessage() ); + + MessageCountingListener messageCounter; + DefaultTransportListener listener; + FailoverTransportFactory factory; + + Pointer transport( factory.create( uri ) ); + CPPUNIT_ASSERT( transport != NULL ); + transport->setTransportListener( &listener ); + + FailoverTransport* failover = dynamic_cast( + transport->narrow( typeid( FailoverTransport ) ) ); + + CPPUNIT_ASSERT( failover != NULL ); + CPPUNIT_ASSERT( failover->isRandomize() == false ); + + transport->start(); + + MockTransport* mock = NULL; + while( mock == NULL ) { + mock = dynamic_cast( transport->narrow( typeid( MockTransport ) ) ); + } + mock->setOutgoingListener( &messageCounter ); + + transport->oneway( message ); + transport->oneway( message ); + transport->oneway( message ); + transport->oneway( message ); + Thread::sleep( 1000 ); + + CPPUNIT_ASSERT( messageCounter.numMessages = 4 ); + + transport->close(); +} + +//////////////////////////////////////////////////////////////////////////////// +void FailoverTransportTest::testSendOnewayMessageFail() { + + std::string uri = + "failover://(mock://localhost:61616?failOnSendMessage=true," + "mock://localhost:61618)?randomize=false"; + + Pointer message( new ActiveMQMessage() ); + + MessageCountingListener messageCounter; + DefaultTransportListener listener; + FailoverTransportFactory factory; + + Pointer transport( factory.create( uri ) ); + CPPUNIT_ASSERT( transport != NULL ); + transport->setTransportListener( &listener ); + + FailoverTransport* failover = dynamic_cast( + transport->narrow( typeid( FailoverTransport ) ) ); + + CPPUNIT_ASSERT( failover != NULL ); + CPPUNIT_ASSERT( failover->isRandomize() == false ); + + transport->start(); + + MockTransport* mock = NULL; + while( mock == NULL ) { + mock = dynamic_cast( transport->narrow( typeid( MockTransport ) ) ); + } + mock->setOutgoingListener( &messageCounter ); + + transport->oneway( message ); + transport->oneway( message ); + transport->oneway( message ); + transport->oneway( message ); + Thread::sleep( 1000 ); + + CPPUNIT_ASSERT( messageCounter.numMessages = 4 ); + + transport->close(); +} Modified: activemq/activemq-cpp/trunk/src/test/activemq/transport/failover/FailoverTransportTest.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/activemq/transport/failover/FailoverTransportTest.h?rev=753355&r1=753354&r2=753355&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/src/test/activemq/transport/failover/FailoverTransportTest.h (original) +++ activemq/activemq-cpp/trunk/src/test/activemq/transport/failover/FailoverTransportTest.h Fri Mar 13 19:18:53 2009 @@ -33,6 +33,8 @@ CPPUNIT_TEST( testTransportCreateWithBackups ); CPPUNIT_TEST( testTransportCreateFailOnCreate ); CPPUNIT_TEST( testFailingBackupCreation ); + CPPUNIT_TEST( testSendOnewayMessage ); + CPPUNIT_TEST( testSendOnewayMessageFail ); CPPUNIT_TEST_SUITE_END(); public: @@ -56,6 +58,13 @@ // transports won't segfault and can be started, and stopped without error. void testFailingBackupCreation(); + // Test that messages sent via the Oneway method are received. + void testSendOnewayMessage(); + + // Test that messages sent via the Oneway method are received after the first + // transport faults on the send and transport 2 is created. + void testSendOnewayMessageFail(); + }; }}}