activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r753295 - in /activemq/activemq-cpp/trunk/src: main/activemq/transport/mock/MockTransportFactory.cpp test/activemq/transport/failover/FailoverTransportTest.cpp test/activemq/transport/failover/FailoverTransportTest.h
Date Fri, 13 Mar 2009 15:13:18 GMT
Author: tabish
Date: Fri Mar 13 15:13:18 2009
New Revision: 753295

URL: http://svn.apache.org/viewvc?rev=753295&view=rev
Log:
http://issues.apache.org/activemq/browse/AMQCPP-100

Add new test to validate that the maxReconnectionAttempts parameter works and an exception
if forwarded when the max attempts value is reached.

Modified:
    activemq/activemq-cpp/trunk/src/main/activemq/transport/mock/MockTransportFactory.cpp
    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/src/main/activemq/transport/mock/MockTransportFactory.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/transport/mock/MockTransportFactory.cpp?rev=753295&r1=753294&r2=753295&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/transport/mock/MockTransportFactory.cpp
(original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/transport/mock/MockTransportFactory.cpp
Fri Mar 13 15:13:18 2009
@@ -26,6 +26,7 @@
 #include <activemq/util/URISupport.h>
 
 #include <decaf/lang/Boolean.h>
+#include <decaf/lang/Integer.h>
 #include <decaf/io/IOException.h>
 
 using namespace activemq;
@@ -115,9 +116,16 @@
             builder.reset( new wireformat::openwire::OpenWireResponseBuilder() );
         }
 
-        Pointer<Transport> transport( new MockTransport( wireFormat, builder ) );
-
+        Pointer<MockTransport> transport( new MockTransport( wireFormat, builder )
);
 
+        transport->setFailOnSendMessage(
+            Boolean::parseBoolean( properties.getProperty( "failOnSendMessage", "false" )
) );
+        transport->setNumSentMessageBeforeFail(
+            Integer::parseInt( properties.getProperty( "numSentMessageBeforeFail", "0" )
) );
+        transport->setFailOnReceiveMessage(
+            Boolean::parseBoolean( properties.getProperty( "failOnReceiveMessage", "false"
) ) );
+        transport->setNumReceivedMessageBeforeFail(
+            Integer::parseInt( properties.getProperty( "numReceivedMessageBeforeFail", "0"
) ) );
 
         return transport;
     }

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=753295&r1=753294&r2=753295&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 15:13:18 2009
@@ -84,3 +84,44 @@
     transport->start();
     transport->close();
 }
+
+////////////////////////////////////////////////////////////////////////////////
+class FailToConnectListener : public DefaultTransportListener {
+public:
+
+    bool caughtException;
+
+    FailToConnectListener() : caughtException( false ) {}
+
+    virtual void onException( const decaf::lang::Exception& ex AMQCPP_UNUSED ) {
+        caughtException = true;
+    }
+};
+
+////////////////////////////////////////////////////////////////////////////////
+void FailoverTransportTest::testTransportCreateFailOnCreate() {
+
+    std::string uri =
+        "failover://(mock://localhost:61616?failOnCreate=true)?maxReconnectAttempts=2";
+
+    FailToConnectListener listener;
+    FailoverTransportFactory factory;
+
+    Pointer<Transport> transport( factory.create( uri ) );
+    CPPUNIT_ASSERT( transport != NULL );
+    transport->setTransportListener( &listener );
+
+    FailoverTransport* failover = dynamic_cast<FailoverTransport*>(
+        transport->narrow( typeid( FailoverTransport ) ) );
+
+    CPPUNIT_ASSERT( failover != NULL );
+    CPPUNIT_ASSERT( failover->getMaxReconnectAttempts() == 2 );
+
+    transport->start();
+
+    Thread::sleep( 2000 );
+
+    CPPUNIT_ASSERT( listener.caughtException == true );
+
+    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=753295&r1=753294&r2=753295&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 15:13:18 2009
@@ -31,6 +31,7 @@
         CPPUNIT_TEST_SUITE( FailoverTransportTest );
         CPPUNIT_TEST( testTransportCreate );
         CPPUNIT_TEST( testTransportCreateWithBackups );
+        CPPUNIT_TEST( testTransportCreateFailOnCreate );
         CPPUNIT_TEST_SUITE_END();
 
     public:
@@ -40,6 +41,7 @@
 
         void testTransportCreate();
         void testTransportCreateWithBackups();
+        void testTransportCreateFailOnCreate();
 
     };
 



Mime
View raw message