activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r755380 - in /activemq/activemq-cpp/trunk/src: main/activemq/state/ test/ test/activemq/state/ test/activemq/transport/failover/
Date Tue, 17 Mar 2009 20:10:32 GMT
Author: tabish
Date: Tue Mar 17 20:10:31 2009
New Revision: 755380

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

Adds new test code for the Failover Transport to simulate a realistic use case, which exposed
some errors in the state tracker code, fixes for those errors are attached as well. 

Modified:
    activemq/activemq-cpp/trunk/src/main/activemq/state/ConnectionStateTracker.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/state/ConnectionStateTracker.h
    activemq/activemq-cpp/trunk/src/test/activemq/state/ConnectionStateTrackerTest.cpp
    activemq/activemq-cpp/trunk/src/test/activemq/transport/failover/FailoverTransportTest.cpp
    activemq/activemq-cpp/trunk/src/test/activemq/transport/failover/FailoverTransportTest.h
    activemq/activemq-cpp/trunk/src/test/testRegistry.cpp

Modified: activemq/activemq-cpp/trunk/src/main/activemq/state/ConnectionStateTracker.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/state/ConnectionStateTracker.cpp?rev=755380&r1=755379&r2=755380&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/state/ConnectionStateTracker.cpp (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/state/ConnectionStateTracker.cpp Tue Mar
17 20:10:31 2009
@@ -269,7 +269,7 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-Pointer<Command> ConnectionStateTracker::processAddDestination( DestinationInfo* info
)
+Pointer<Command> ConnectionStateTracker::processDestinationInfo( DestinationInfo* info
)
     throw ( exceptions::ActiveMQException ) {
 
     try{
@@ -305,7 +305,7 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-Pointer<Command> ConnectionStateTracker::processAddProducer( ProducerInfo* info )
+Pointer<Command> ConnectionStateTracker::processProducerInfo( ProducerInfo* info )
     throw ( exceptions::ActiveMQException ) {
 
     try{
@@ -362,7 +362,7 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-Pointer<Command> ConnectionStateTracker::processAddConsumer( ConsumerInfo* info )
+Pointer<Command> ConnectionStateTracker::processConsumerInfo( ConsumerInfo* info )
     throw ( exceptions::ActiveMQException ) {
 
     try{
@@ -418,7 +418,7 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-Pointer<Command> ConnectionStateTracker::processAddSession( SessionInfo* info)
+Pointer<Command> ConnectionStateTracker::processSessionInfo( SessionInfo* info)
     throw ( exceptions::ActiveMQException ) {
 
     try{
@@ -462,7 +462,7 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-Pointer<Command> ConnectionStateTracker::processAddConnection( ConnectionInfo* info
)
+Pointer<Command> ConnectionStateTracker::processConnectionInfo( ConnectionInfo* info
)
     throw ( exceptions::ActiveMQException ) {
 
     try{

Modified: activemq/activemq-cpp/trunk/src/main/activemq/state/ConnectionStateTracker.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/state/ConnectionStateTracker.h?rev=755380&r1=755379&r2=755380&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/state/ConnectionStateTracker.h (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/state/ConnectionStateTracker.h Tue Mar 17
20:10:31 2009
@@ -81,31 +81,31 @@
         void restore( const Pointer<transport::Transport>& transport )
             throw( decaf::io::IOException );
 
-        virtual Pointer<Command> processAddDestination( DestinationInfo* info )
+        virtual Pointer<Command> processDestinationInfo( DestinationInfo* info )
             throw ( exceptions::ActiveMQException );
 
         virtual Pointer<Command> processRemoveDestination( DestinationInfo* info )
             throw ( exceptions::ActiveMQException );
 
-        virtual Pointer<Command> processAddProducer( ProducerInfo* info )
+        virtual Pointer<Command> processProducerInfo( ProducerInfo* info )
             throw ( exceptions::ActiveMQException );
 
         virtual Pointer<Command> processRemoveProducer( ProducerId* id )
             throw ( exceptions::ActiveMQException );
 
-        virtual Pointer<Command> processAddConsumer( ConsumerInfo* info )
+        virtual Pointer<Command> processConsumerInfo( ConsumerInfo* info )
             throw ( exceptions::ActiveMQException );
 
         virtual Pointer<Command> processRemoveConsumer( ConsumerId* id )
             throw ( exceptions::ActiveMQException );
 
-        virtual Pointer<Command> processAddSession( SessionInfo* info )
+        virtual Pointer<Command> processSessionInfo( SessionInfo* info )
             throw ( exceptions::ActiveMQException );
 
         virtual Pointer<Command> processRemoveSession( SessionId* id )
             throw ( exceptions::ActiveMQException );
 
-        virtual Pointer<Command> processAddConnection( ConnectionInfo* info)
+        virtual Pointer<Command> processConnectionInfo( ConnectionInfo* info)
             throw ( exceptions::ActiveMQException );
 
         virtual Pointer<Command> processRemoveConnection( ConnectionId* id )

Modified: activemq/activemq-cpp/trunk/src/test/activemq/state/ConnectionStateTrackerTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/activemq/state/ConnectionStateTrackerTest.cpp?rev=755380&r1=755379&r2=755380&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/activemq/state/ConnectionStateTrackerTest.cpp (original)
+++ activemq/activemq-cpp/trunk/src/test/activemq/state/ConnectionStateTrackerTest.cpp Tue
Mar 17 20:10:31 2009
@@ -59,10 +59,10 @@
     producer_info->setProducerId( producer_id );
 
     ConnectionStateTracker tracker;
-    tracker.processAddConnection( conn_info.get() );
-    tracker.processAddSession( session_info.get() );
-    tracker.processAddConsumer( consumer_info.get() );
-    tracker.processAddProducer( producer_info.get() );
+    tracker.processConnectionInfo( conn_info.get() );
+    tracker.processSessionInfo( session_info.get() );
+    tracker.processConsumerInfo( consumer_info.get() );
+    tracker.processProducerInfo( producer_info.get() );
 
     tracker.processRemoveProducer( producer_id.get() );
     tracker.processRemoveConsumer( consumer_id.get() );

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=755380&r1=755379&r2=755380&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
Tue Mar 17 20:10:31 2009
@@ -24,6 +24,7 @@
 #include <activemq/commands/ActiveMQMessage.h>
 #include <decaf/lang/Pointer.h>
 #include <decaf/lang/Thread.h>
+#include <decaf/util/UUID.h>
 
 using namespace activemq;
 using namespace activemq::commands;
@@ -368,3 +369,145 @@
 
     transport->close();
 }
+
+////////////////////////////////////////////////////////////////////////////////
+void FailoverTransportTest::testWithOpewireCommands() {
+
+    std::string uri = "failover://(mock://localhost:61616)?randomize=false";
+
+    DefaultTransportListener 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->isRandomize() == false );
+
+    transport->start();
+
+    Pointer<ConnectionInfo> connection = createConnection();
+    transport->request( connection );
+    Pointer<SessionInfo> session1 = createSession( connection );
+    transport->request( session1 );
+    Pointer<SessionInfo> session2 = createSession( connection );
+    transport->request( session2 );
+    Pointer<ConsumerInfo> consumer1 = createConsumer( session1 );
+    transport->request( consumer1 );
+    Pointer<ConsumerInfo> consumer2 = createConsumer( session1 );
+    transport->request( consumer2 );
+    Pointer<ConsumerInfo> consumer3 = createConsumer( session2 );
+    transport->request( consumer3 );
+
+    Pointer<ProducerInfo> producer1 = createProducer( session2 );
+    transport->request( producer1 );
+
+    // Remove the Producers
+    this->disposeOf( producer1, transport );
+
+    // Remove the Consumers
+    this->disposeOf( consumer1, transport );
+    this->disposeOf( consumer2, transport );
+    this->disposeOf( consumer3, transport );
+
+    // Remove the Session instances.
+    this->disposeOf( session1, transport );
+    this->disposeOf( session2, transport );
+
+    // Indicate that we are done.
+    Pointer<ShutdownInfo> shutdown( new ShutdownInfo() );
+    transport->oneway( shutdown );
+
+    transport->close();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Pointer<ConnectionInfo> FailoverTransportTest::createConnection() {
+
+    Pointer<ConnectionId> id( new ConnectionId() );
+    id->setValue( UUID::randomUUID().toString() );
+
+    Pointer<ConnectionInfo> info( new ConnectionInfo() );
+    info->setClientId( UUID::randomUUID().toString() );
+    info->setConnectionId( id );
+
+    return info;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Pointer<SessionInfo> FailoverTransportTest::createSession( const Pointer<ConnectionInfo>&
parent ) {
+
+    static int idx = 1;
+
+    Pointer<SessionId> id( new SessionId() );
+    id->setConnectionId( parent->getConnectionId()->getValue() );
+    id->setValue( idx++ );
+
+    Pointer<SessionInfo> info( new SessionInfo() );
+    info->setSessionId( id );
+
+    return info;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Pointer<ConsumerInfo> FailoverTransportTest::createConsumer( const Pointer<SessionInfo>&
parent ) {
+
+    static int idx = 1;
+
+    Pointer<ConsumerId> id( new ConsumerId() );
+    id->setConnectionId( parent->getSessionId()->getConnectionId() );
+    id->setSessionId( parent->getSessionId()->getValue() );
+    id->setValue( idx++ );
+
+    Pointer<ConsumerInfo> info( new ConsumerInfo() );
+    info->setConsumerId( id );
+
+    return info;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Pointer<ProducerInfo> FailoverTransportTest::createProducer( const Pointer<SessionInfo>&
parent ) {
+
+    static int idx = 1;
+
+    Pointer<ProducerId> id( new ProducerId() );
+    id->setConnectionId( parent->getSessionId()->getConnectionId() );
+    id->setSessionId( parent->getSessionId()->getValue() );
+    id->setValue( idx++ );
+
+    Pointer<ProducerInfo> info( new ProducerInfo() );
+    info->setProducerId( id );
+
+    return info;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void FailoverTransportTest::disposeOf( const Pointer<SessionInfo>& session,
+                                       Pointer<Transport>& transport ) {
+
+    Pointer<RemoveInfo> command( new RemoveInfo() );
+    command->setObjectId( session->getSessionId() );
+    transport->oneway( command );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void FailoverTransportTest::disposeOf( const Pointer<ConsumerInfo>& consumer,
+                                       Pointer<Transport>& transport ) {
+
+    Pointer<RemoveInfo> command( new RemoveInfo() );
+    command->setObjectId( consumer->getConsumerId() );
+    transport->oneway( command );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void FailoverTransportTest::disposeOf( const Pointer<ProducerInfo>& producer,
+                                       Pointer<Transport>& transport ) {
+
+    Pointer<RemoveInfo> command( new RemoveInfo() );
+    command->setObjectId( producer->getProducerId() );
+    transport->oneway( command );
+}

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=755380&r1=755379&r2=755380&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
Tue Mar 17 20:10:31 2009
@@ -22,10 +22,21 @@
 #include <cppunit/extensions/HelperMacros.h>
 #include <activemq/util/Config.h>
 
+#include <activemq/commands/ConnectionInfo.h>
+#include <activemq/commands/SessionInfo.h>
+#include <activemq/commands/ProducerInfo.h>
+#include <activemq/commands/ConsumerInfo.h>
+
+#include <activemq/transport/Transport.h>
+#include <decaf/lang/Pointer.h>
+
 namespace activemq {
 namespace transport {
 namespace failover {
 
+    using decaf::lang::Pointer;
+    using namespace activemq::commands;
+
     class FailoverTransportTest : public CppUnit::TestFixture {
 
         CPPUNIT_TEST_SUITE( FailoverTransportTest );
@@ -38,6 +49,7 @@
         CPPUNIT_TEST( testSendRequestMessage );
         CPPUNIT_TEST( testSendOnewayMessageFail );
         CPPUNIT_TEST( testSendRequestMessageFail );
+        CPPUNIT_TEST( testWithOpewireCommands );
         CPPUNIT_TEST_SUITE_END();
 
     public:
@@ -75,6 +87,25 @@
         void testSendOnewayMessageFail();
         void testSendRequestMessageFail();
 
+        // Test the transport using a realistic set of commands being sen through which
+        // simulates creation of a Connection, Session, Topics, Producers and Consumers
+        // and then removing them all as a normal shutdown would.
+        void testWithOpewireCommands();
+
+    private:
+
+        Pointer<ConnectionInfo> createConnection();
+        Pointer<SessionInfo> createSession( const Pointer<ConnectionInfo>&
parent );
+        Pointer<ConsumerInfo> createConsumer( const Pointer<SessionInfo>&
parent );
+        Pointer<ProducerInfo> createProducer( const Pointer<SessionInfo>&
parent );
+
+        void disposeOf( const Pointer<SessionInfo>& session,
+                        Pointer<Transport>& transport );
+        void disposeOf( const Pointer<ConsumerInfo>& consumer,
+                        Pointer<Transport>& transport );
+        void disposeOf( const Pointer<ProducerInfo>& producer,
+                        Pointer<Transport>& transport );
+
     };
 
 }}}

Modified: activemq/activemq-cpp/trunk/src/test/testRegistry.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/testRegistry.cpp?rev=755380&r1=755379&r2=755380&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/testRegistry.cpp (original)
+++ activemq/activemq-cpp/trunk/src/test/testRegistry.cpp Tue Mar 17 20:10:31 2009
@@ -75,22 +75,22 @@
 //CPPUNIT_TEST_SUITE_REGISTRATION( activemq::core::ActiveMQConnectionTest );
 //#include <activemq/core/ActiveMQSessionTest.h>
 //CPPUNIT_TEST_SUITE_REGISTRATION( activemq::core::ActiveMQSessionTest );
-
-#include <activemq/state/ConnectionStateTrackerTest.h>
-CPPUNIT_TEST_SUITE_REGISTRATION( activemq::state::ConnectionStateTrackerTest );
-#include <activemq/state/ConnectionStateTest.h>
-CPPUNIT_TEST_SUITE_REGISTRATION( activemq::state::ConnectionStateTest );
-#include <activemq/state/ConsumerStateTest.h>
-CPPUNIT_TEST_SUITE_REGISTRATION( activemq::state::ConsumerStateTest );
-#include <activemq/state/ProducerStateTest.h>
-CPPUNIT_TEST_SUITE_REGISTRATION( activemq::state::ProducerStateTest );
-#include <activemq/state/SessionStateTest.h>
-CPPUNIT_TEST_SUITE_REGISTRATION( activemq::state::SessionStateTest );
-#include <activemq/state/TransactionStateTest.h>
-CPPUNIT_TEST_SUITE_REGISTRATION( activemq::state::TransactionStateTest );
-
-//#include <activemq/transport/failover/FailoverTransportTest.h>
-//CPPUNIT_TEST_SUITE_REGISTRATION( activemq::transport::failover::FailoverTransportTest );
+//
+//#include <activemq/state/ConnectionStateTrackerTest.h>
+//CPPUNIT_TEST_SUITE_REGISTRATION( activemq::state::ConnectionStateTrackerTest );
+//#include <activemq/state/ConnectionStateTest.h>
+//CPPUNIT_TEST_SUITE_REGISTRATION( activemq::state::ConnectionStateTest );
+//#include <activemq/state/ConsumerStateTest.h>
+//CPPUNIT_TEST_SUITE_REGISTRATION( activemq::state::ConsumerStateTest );
+//#include <activemq/state/ProducerStateTest.h>
+//CPPUNIT_TEST_SUITE_REGISTRATION( activemq::state::ProducerStateTest );
+//#include <activemq/state/SessionStateTest.h>
+//CPPUNIT_TEST_SUITE_REGISTRATION( activemq::state::SessionStateTest );
+//#include <activemq/state/TransactionStateTest.h>
+//CPPUNIT_TEST_SUITE_REGISTRATION( activemq::state::TransactionStateTest );
+//
+#include <activemq/transport/failover/FailoverTransportTest.h>
+CPPUNIT_TEST_SUITE_REGISTRATION( activemq::transport::failover::FailoverTransportTest );
 //
 //#include <activemq/transport/correlator/ResponseCorrelatorTest.h>
 //CPPUNIT_TEST_SUITE_REGISTRATION( activemq::transport::correlator::ResponseCorrelatorTest
);



Mime
View raw message