You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2007/06/18 21:46:27 UTC
svn commit: r548464 - in /activemq/activemq-cpp/trunk/src:
main/activemq/transport/MockTransport.cpp
main/activemq/transport/MockTransport.h
main/activemq/transport/MockTransportFactory.cpp
test/activemq/core/ActiveMQSessionTest.cpp
Author: tabish
Date: Mon Jun 18 12:46:26 2007
New Revision: 548464
URL: http://svn.apache.org/viewvc?view=rev&rev=548464
Log:
https://issues.apache.org/activemq/browse/AMQCPP-130
Modified:
activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransport.cpp
activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransport.h
activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransportFactory.cpp
activemq/activemq-cpp/trunk/src/test/activemq/core/ActiveMQSessionTest.cpp
Modified: activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransport.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransport.cpp?view=diff&rev=548464&r1=548463&r2=548464
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransport.cpp (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransport.cpp Mon Jun 18 12:46:26 2007
@@ -22,9 +22,11 @@
using namespace activemq::exceptions;
////////////////////////////////////////////////////////////////////////////////
+MockTransport* MockTransport::instance = NULL;
+
+////////////////////////////////////////////////////////////////////////////////
MockTransport::MockTransport( ResponseBuilder* responseBuilder ,
- bool own,
- bool useDefOutgoing ){
+ bool own ){
this->responseBuilder = NULL;
this->commandListener = NULL;
@@ -33,12 +35,11 @@
this->responseBuilder = responseBuilder;
this->own = own;
this->nextCommandId = 0;
- if( useDefOutgoing )
- {
- this->outgoingCommandListener = &defaultListener;
- this->defaultListener.setTransport( this );
- this->defaultListener.setResponseBuilder( responseBuilder );
- }
+ this->instance = this;
+
+ // Configure the Internal Listener this is the Fake Broker.
+ this->internalListener.setTransport( this );
+ this->internalListener.setResponseBuilder( responseBuilder );
}
////////////////////////////////////////////////////////////////////////////////
@@ -68,6 +69,10 @@
void MockTransport::oneway( Command* command )
throw(CommandIOException, exceptions::UnsupportedOperationException)
{
+ // Process and send any new Commands back.
+ internalListener.onCommand( command );
+
+ // Notify external Client of command that we "sent"
if( outgoingCommandListener != NULL ){
outgoingCommandListener->onCommand( command );
return;
@@ -80,6 +85,12 @@
exceptions::UnsupportedOperationException)
{
if( responseBuilder != NULL ){
+
+ // Notify external Client of command that we "sent"
+ if( outgoingCommandListener != NULL ){
+ outgoingCommandListener->onCommand( command );
+ }
+
command->setCommandId( getNextCommandId() );
command->setResponseRequired( true );
return responseBuilder->buildResponse( command );
Modified: activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransport.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransport.h?view=diff&rev=548464&r1=548463&r2=548464
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransport.h (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransport.h Mon Jun 18 12:46:26 2007
@@ -173,24 +173,32 @@
unsigned int nextCommandId;
concurrent::Mutex commandIdMutex;
bool own;
- InternalCommandListener defaultListener;
+ InternalCommandListener internalListener;
+ static MockTransport* instance;
public:
MockTransport( ResponseBuilder* responseBuilder ,
- bool own = false,
- bool useDefOutgoing = true );
+ bool own = false );
virtual ~MockTransport();
+ static MockTransport* getInstance() {
+ return instance;
+ }
+
+ /**
+ * Sets the ResponseBuilder that this class uses to create Responses to
+ * Commands sent. These are either real Response Objects, or Commands that
+ * would have been sent Asynchronously be the Broker.
+ * @param responseBuilder - The ResponseBuilder to use from now on.
+ */
void setResponseBuilder( ResponseBuilder* responseBuilder ){
this->responseBuilder = responseBuilder;
}
- unsigned int getNextCommandId() throw (exceptions::ActiveMQException);
-
virtual void oneway( Command* command )
- throw(CommandIOException, exceptions::UnsupportedOperationException);
+ throw(CommandIOException, exceptions::UnsupportedOperationException);
virtual Response* request( Command* command )
throw(CommandIOException,
@@ -200,12 +208,18 @@
this->commandListener = listener;
}
+ /**
+ * Sets a Command Listener that gets notified for every command that would
+ * have been sent by this transport to the Broker, this allows a client
+ * to verify that its messages are making it to the wire.
+ * @param listener - The CommandListener to notify for each message
+ */
virtual void setOutgoingCommandListener( CommandListener* listener ){
outgoingCommandListener = listener;
}
+ // Not impl is needed in this transport for these methods.
virtual void setCommandReader( CommandReader* reader AMQCPP_UNUSED){}
-
virtual void setCommandWriter( CommandWriter* writer AMQCPP_UNUSED){}
virtual void setTransportExceptionListener(
@@ -214,20 +228,36 @@
this->exceptionListener = listener;
}
- virtual void fireCommand( Command* cmd ){
+ /**
+ * Fires a Command back through this transport to its registered
+ * CommandListener if there is one.
+ * @param command - Command to send to the Listener.
+ */
+ virtual void fireCommand( Command* command ){
if( commandListener != NULL ){
- commandListener->onCommand( cmd );
+ commandListener->onCommand( command );
}
}
+ /**
+ * Fires a Exception back through this transport to its registered
+ * ExceptionListener if there is one.
+ * @param command - Command to send to the Listener.
+ */
virtual void fireException( const exceptions::ActiveMQException& ex ){
if( exceptionListener != NULL ){
exceptionListener->onTransportException( this, ex );
}
}
+ // No Impl needed for this Transport.
virtual void start() throw (cms::CMSException){}
virtual void close() throw (cms::CMSException){}
+
+ protected:
+
+ unsigned int getNextCommandId() throw( exceptions::ActiveMQException );
+
};
}}
Modified: activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransportFactory.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransportFactory.cpp?view=diff&rev=548464&r1=548463&r2=548464
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransportFactory.cpp (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransportFactory.cpp Mon Jun 18 12:46:26 2007
@@ -52,7 +52,7 @@
"transport.sessionId", "testSessionId" ) );
}
- return new MockTransport( builder, true, true );
+ return new MockTransport( builder, true );
}
////////////////////////////////////////////////////////////////////////////////
Modified: activemq/activemq-cpp/trunk/src/test/activemq/core/ActiveMQSessionTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/activemq/core/ActiveMQSessionTest.cpp?view=diff&rev=548464&r1=548463&r2=548464
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/activemq/core/ActiveMQSessionTest.cpp (original)
+++ activemq/activemq-cpp/trunk/src/test/activemq/core/ActiveMQSessionTest.cpp Mon Jun 18 12:46:26 2007
@@ -498,6 +498,10 @@
connection = dynamic_cast< ActiveMQConnection*>(
factory.createConnection() );
+ // Get the Transport and make sure we got a dummy Transport
+ dTransport = transport::MockTransport::getInstance();
+ CPPUNIT_ASSERT( dTransport != NULL );
+
connection->setExceptionListener( &exListener );
connection->start();
}