activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nmitt...@apache.org
Subject svn commit: r418749 [13/17] - in /incubator/activemq/trunk/activemq-cpp: ./ src/ src/main/ src/main/activemq/ src/main/activemq/concurrent/ src/main/activemq/connector/ src/main/activemq/connector/openwire/ src/main/activemq/connector/stomp/ src/main/a...
Date Mon, 03 Jul 2006 11:51:54 GMT
Added: incubator/activemq/trunk/activemq-cpp/src/test-integration/integration/common/AbstractTester.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/test-integration/integration/common/AbstractTester.cpp?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/test-integration/integration/common/AbstractTester.cpp (added)
+++ incubator/activemq/trunk/activemq-cpp/src/test-integration/integration/common/AbstractTester.cpp Mon Jul  3 04:51:36 2006
@@ -0,0 +1,227 @@
+#include "AbstractTester.h"
+
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <integration/common/IntegrationCommon.h>
+
+#include <activemq/core/ActiveMQConnectionFactory.h>
+#include <activemq/exceptions/ActiveMQException.h>
+#include <activemq/concurrent/Thread.h>
+#include <activemq/util/Guid.h>
+
+#include <cms/Connection.h>
+#include <cms/Session.h>
+
+#include <sstream>
+
+using namespace std;
+using namespace cms;
+using namespace activemq;
+using namespace activemq::core;
+using namespace activemq::util;
+using namespace activemq::exceptions;
+using namespace activemq::concurrent;
+
+using namespace integration;
+using namespace integration::common;
+
+AbstractTester::AbstractTester( cms::Session::AcknowledgeMode ackMode )
+{
+    try
+    {
+        string url = IntegrationCommon::defaultURL;
+        numReceived = 0;
+    
+        // Create a Factory
+        connectionFactory = new ActiveMQConnectionFactory( url );
+
+        // Now create the connection
+        connection = connectionFactory->createConnection(
+            "", "", Guid().createGUIDString() );
+    
+        // Set ourself as a recipient of Exceptions        
+        connection->setExceptionListener( this );
+        connection->start();
+        
+        // Create a Session
+        session = connection->createSession( ackMode );
+    }
+    AMQ_CATCH_RETHROW( ActiveMQException )
+    AMQ_CATCHALL_THROW( ActiveMQException )
+}
+
+AbstractTester::~AbstractTester()
+{
+    try
+    {
+        session->close();
+        connection->close();
+
+        delete session;
+        delete connection;
+        delete connectionFactory;
+    }
+    AMQ_CATCH_NOTHROW( ActiveMQException )
+    AMQ_CATCHALL_NOTHROW( )
+}
+
+void AbstractTester::doSleep(void) 
+{
+    Thread::sleep( IntegrationCommon::defaultDelay );
+}
+
+unsigned int AbstractTester::produceTextMessages( 
+    cms::MessageProducer& producer,
+    unsigned int count )
+{
+    try
+    {
+        // Send some text messages.
+        ostringstream stream;
+        string text = "this is a test text message: id = ";
+        
+        cms::TextMessage* textMsg = 
+            session->createTextMessage();
+
+        unsigned int realCount = 0;
+                     
+        for( unsigned int ix=0; ix<count; ++ix ){
+            stream << text << ix << ends;
+            textMsg->setText( stream.str().c_str() );        
+            stream.str("");  
+            producer.send( *textMsg );
+            doSleep();
+            ++realCount;
+        }
+
+        delete textMsg;
+
+        return realCount;
+    }
+    AMQ_CATCH_RETHROW( ActiveMQException )
+    AMQ_CATCHALL_THROW( ActiveMQException )    
+}
+
+unsigned int AbstractTester::produceBytesMessages( 
+    cms::MessageProducer& producer,
+    unsigned int count )
+{
+    try
+    {
+        unsigned char buf[10];
+        memset( buf, 0, 10 );
+        buf[0] = 0;
+        buf[1] = 1;
+        buf[2] = 2;
+        buf[3] = 3;
+        buf[4] = 0;
+        buf[5] = 4;
+        buf[6] = 5;
+        buf[7] = 6;
+
+        cms::BytesMessage* bytesMsg = 
+            session->createBytesMessage();
+        bytesMsg->setBodyBytes( buf, 10 );
+
+        unsigned int realCount = 0;
+        for( unsigned int ix=0; ix<count; ++ix ){                
+            producer.send( *bytesMsg ); 
+            doSleep();
+            ++realCount;
+        }
+
+        delete bytesMsg;
+
+        return realCount;
+    }
+    AMQ_CATCH_RETHROW( ActiveMQException )
+    AMQ_CATCHALL_THROW( ActiveMQException )    
+}
+
+void AbstractTester::waitForMessages( unsigned int count )
+{
+    try
+    {
+        synchronized( &mutex )
+        {
+            int stopAtZero = count + 5;
+            
+            while( numReceived < count )
+            {
+                mutex.wait( 500 );
+                
+                if( --stopAtZero == 0 )
+                {
+                    break;
+                }
+            }
+        }
+    }
+    AMQ_CATCH_RETHROW( ActiveMQException )
+    AMQ_CATCHALL_THROW( ActiveMQException )    
+}
+
+void AbstractTester::onException( const cms::CMSException& error )
+{
+    bool AbstractTester = false;
+    CPPUNIT_ASSERT( AbstractTester );
+}
+
+void AbstractTester::onMessage( const cms::Message& message )
+{
+    try
+    {
+        // Got a text message.
+        const cms::TextMessage& txtMsg = 
+            dynamic_cast<const cms::TextMessage&>(message);
+            
+        std::string text = txtMsg.getText();
+
+//            printf("received text msg: %s\n", txtMsg.getText() );
+
+        numReceived++;
+
+        // Signal that we got one
+        synchronized( &mutex )
+        {
+            mutex.notifyAll();
+        }
+
+        return;
+    }
+    catch( std::bad_cast& ex )
+    {}
+    
+    try
+    {
+        // Got a bytes msg.
+        const cms::BytesMessage& bytesMsg = 
+            dynamic_cast<const cms::BytesMessage&>(message);
+
+        const unsigned char* bytes = bytesMsg.getBodyBytes();
+        
+        string transcode( (const char*)bytes, bytesMsg.getBodyLength() );
+
+        //printf("received bytes msg: " );
+        //int numBytes = bytesMsg.getBodyLength();
+        //for( int ix=0; ix<numBytes; ++ix ){
+           // printf("[%d]", bytes[ix] );
+        //}
+        //printf("\n");
+
+        numReceived++;
+        
+        // Signal that we got one
+        synchronized( &mutex )
+        {
+            mutex.notifyAll();
+        }
+
+        return;
+    }
+    catch( std::bad_cast& ex )
+    {
+        bool AbstractTester = false;
+        CPPUNIT_ASSERT( AbstractTester );
+    }
+}

Added: incubator/activemq/trunk/activemq-cpp/src/test-integration/integration/common/AbstractTester.h
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/test-integration/integration/common/AbstractTester.h?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/test-integration/integration/common/AbstractTester.h (added)
+++ incubator/activemq/trunk/activemq-cpp/src/test-integration/integration/common/AbstractTester.h Mon Jul  3 04:51:36 2006
@@ -0,0 +1,51 @@
+#ifndef _INTEGRATION_COMMON_ABSTRACTTESTER_H_
+#define _INTEGRATION_COMMON_ABSTRACTTESTER_H_
+
+#include "Tester.h"
+
+#include <activemq/concurrent/Mutex.h>
+
+#include <cms/ConnectionFactory.h>
+#include <cms/Connection.h>
+#include <cms/Session.h>
+#include <cms/MessageProducer.h>
+
+namespace integration{
+namespace common{
+
+    class AbstractTester : public Tester
+    {
+    public:
+    
+    	AbstractTester( cms::Session::AcknowledgeMode ackMode = 
+                            cms::Session::AutoAcknowledge );
+    	virtual ~AbstractTester();
+    
+        virtual void doSleep(void);
+
+        virtual unsigned int produceTextMessages( 
+            cms::MessageProducer& producer,
+            unsigned int count );
+        virtual unsigned int produceBytesMessages( 
+            cms::MessageProducer& producer,
+            unsigned int count );
+
+        virtual void waitForMessages( unsigned int count );
+
+        virtual void onException( const cms::CMSException& error );
+        virtual void onMessage( const cms::Message& message );
+
+    public:
+        
+        cms::ConnectionFactory* connectionFactory;
+        cms::Connection* connection;
+        cms::Session* session;
+
+        unsigned int numReceived;
+        activemq::concurrent::Mutex mutex;
+
+    };
+
+}}
+
+#endif /*_INTEGRATION_COMMON_ABSTRACTTESTER_H_*/

Added: incubator/activemq/trunk/activemq-cpp/src/test-integration/integration/common/IntegrationCommon.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/test-integration/integration/common/IntegrationCommon.cpp?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/test-integration/integration/common/IntegrationCommon.cpp (added)
+++ incubator/activemq/trunk/activemq-cpp/src/test-integration/integration/common/IntegrationCommon.cpp Mon Jul  3 04:51:36 2006
@@ -0,0 +1,8 @@
+#include "IntegrationCommon.h"
+
+using namespace integration;
+using namespace integration::common;
+
+const std::string IntegrationCommon::defaultURL = "tcp://127.0.0.1:61613";
+const int         IntegrationCommon::defaultDelay = 5;
+const unsigned int         IntegrationCommon::defaultMsgCount = 1000;

Added: incubator/activemq/trunk/activemq-cpp/src/test-integration/integration/common/IntegrationCommon.h
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/test-integration/integration/common/IntegrationCommon.h?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/test-integration/integration/common/IntegrationCommon.h (added)
+++ incubator/activemq/trunk/activemq-cpp/src/test-integration/integration/common/IntegrationCommon.h Mon Jul  3 04:51:36 2006
@@ -0,0 +1,23 @@
+#ifndef _INTEGRATION_COMMON_INTEGRATIONCOMMON_H_
+#define _INTEGRATION_COMMON_INTEGRATIONCOMMON_H_
+
+#include <string>
+
+namespace integration{
+namespace common{
+
+    class IntegrationCommon
+    {
+    public:
+    
+    	virtual ~IntegrationCommon();
+    
+        static const std::string  defaultURL;
+        static const int          defaultDelay;
+        static const unsigned int defaultMsgCount;
+        
+    };
+
+}}
+
+#endif /*_INTEGRATION_COMMON_INTEGRATIONCOMMON_H_*/

Added: incubator/activemq/trunk/activemq-cpp/src/test-integration/integration/common/Tester.h
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/test-integration/integration/common/Tester.h?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/test-integration/integration/common/Tester.h (added)
+++ incubator/activemq/trunk/activemq-cpp/src/test-integration/integration/common/Tester.h Mon Jul  3 04:51:36 2006
@@ -0,0 +1,24 @@
+#ifndef _INTEGRATION_COMMON_TESTER_H_
+#define _INTEGRATION_COMMON_TESTER_H_
+
+#include <cms/MessageListener.h>
+#include <cms/ExceptionListener.h>
+
+
+namespace integration{
+namespace common{
+
+    class Tester : public cms::ExceptionListener,
+                   public cms::MessageListener
+    {
+    public:
+    
+    	virtual ~Tester() {}
+        
+        virtual void test(void) = 0;
+
+    };
+
+}}
+
+#endif /*_INTEGRATION_COMMON_TESTER_H_*/

Added: incubator/activemq/trunk/activemq-cpp/src/test-integration/integration/durable/DurableTester.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/test-integration/integration/durable/DurableTester.cpp?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/test-integration/integration/durable/DurableTester.cpp (added)
+++ incubator/activemq/trunk/activemq-cpp/src/test-integration/integration/durable/DurableTester.cpp Mon Jul  3 04:51:36 2006
@@ -0,0 +1,120 @@
+#include "DurableTester.h"
+#include <integration/common/IntegrationCommon.h>
+
+CPPUNIT_TEST_SUITE_REGISTRATION( integration::durable::DurableTester );
+
+#include <activemq/concurrent/Thread.h>
+#include <activemq/connector/stomp/StompConnector.h>
+#include <activemq/util/SimpleProperties.h>
+#include <activemq/transport/TransportFactory.h>
+#include <activemq/util/Guid.h>
+#include <activemq/util/SimpleProperties.h>
+#include <activemq/util/StringTokenizer.h>
+#include <activemq/connector/ConnectorFactoryMap.h>
+#include <activemq/network/SocketFactory.h>
+#include <activemq/transport/TransportFactory.h>
+#include <activemq/network/Socket.h>
+#include <activemq/exceptions/NullPointerException.h>
+#include <activemq/core/ActiveMQConnection.h>
+#include <activemq/core/ActiveMQConsumer.h>
+#include <activemq/core/ActiveMQProducer.h>
+#include <activemq/util/StringTokenizer.h>
+#include <activemq/util/Boolean.h>
+
+#include <cms/Connection.h>
+#include <cms/MessageConsumer.h>
+#include <cms/MessageProducer.h>
+#include <cms/MessageListener.h>
+#include <cms/Startable.h>
+#include <cms/Closeable.h>
+#include <cms/MessageListener.h>
+#include <cms/ExceptionListener.h>
+#include <cms/Topic.h>
+#include <cms/Queue.h>
+#include <cms/TemporaryTopic.h>
+#include <cms/TemporaryQueue.h>
+#include <cms/Session.h>
+#include <cms/BytesMessage.h>
+#include <cms/TextMessage.h>
+#include <cms/MapMessage.h>
+
+using namespace activemq::connector::stomp;
+using namespace activemq::transport;
+using namespace activemq::util;
+using namespace std;
+using namespace cms;
+using namespace activemq;
+using namespace activemq::core;
+using namespace activemq::util;
+using namespace activemq::connector;
+using namespace activemq::exceptions;
+using namespace activemq::network;
+using namespace activemq::transport;
+using namespace activemq::concurrent;
+
+using namespace integration;
+using namespace integration::durable;
+using namespace integration::common;
+
+DurableTester::DurableTester() : AbstractTester()
+{}
+
+DurableTester::~DurableTester()
+{}
+
+void DurableTester::test()
+{
+    try
+    {
+        cout << "Starting activemqcms durable test (sending "
+             << IntegrationCommon::defaultMsgCount
+             << " messages per type and sleeping "
+             << IntegrationCommon::defaultDelay 
+             << " milli-seconds) ...\n"
+             << endl;
+        
+        std::string subName = Guid().createGUID();
+
+        // Create CMS Object for Comms
+        cms::Topic* topic = session->createTopic("mytopic");
+        cms::MessageConsumer* consumer = 
+            session->createDurableConsumer( *topic, subName, "" );            
+        consumer->setMessageListener( this );
+        cms::MessageProducer* producer = 
+            session->createProducer( *topic );
+
+        unsigned int sent;
+
+        // Send some text messages
+        sent = this->produceTextMessages( *producer, 3 );
+        
+        // Wait for all messages
+        waitForMessages( sent );
+
+        printf("received: %d\n", numReceived );
+        CPPUNIT_ASSERT( numReceived == sent );
+
+        // Nuke the consumer
+        delete consumer;
+
+        // Send some text messages
+        sent += this->produceTextMessages( *producer, 3 );
+
+        consumer = session->createDurableConsumer( *topic, subName, "" );            
+
+        // Send some text messages
+        sent += this->produceTextMessages( *producer, 3 );
+
+        // Wait for all remaining messages
+        waitForMessages( sent - numReceived );
+        
+        printf("received: %d\n", numReceived );
+ //       CPPUNIT_ASSERT( numReceived == sent );
+
+        printf("Shutting Down\n" );
+        delete producer;                      
+        delete consumer;
+    }
+    AMQ_CATCH_RETHROW( ActiveMQException )
+    AMQ_CATCHALL_THROW( ActiveMQException )
+}

Added: incubator/activemq/trunk/activemq-cpp/src/test-integration/integration/durable/DurableTester.h
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/test-integration/integration/durable/DurableTester.h?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/test-integration/integration/durable/DurableTester.h (added)
+++ incubator/activemq/trunk/activemq-cpp/src/test-integration/integration/durable/DurableTester.h Mon Jul  3 04:51:36 2006
@@ -0,0 +1,32 @@
+#ifndef _INTEGRATION_TRANSACTIONAL_DURABLETESTER_H_
+#define _INTEGRATION_TRANSACTIONAL_DURABLETESTER_H_
+
+#include <integration/common/AbstractTester.h>
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+namespace integration{
+namespace durable{
+
+    class DurableTester : public CppUnit::TestFixture,
+                          public common::AbstractTester
+    {
+        CPPUNIT_TEST_SUITE( DurableTester );
+        CPPUNIT_TEST( test );
+        CPPUNIT_TEST_SUITE_END();
+
+    public:
+
+    	DurableTester();
+    	virtual ~DurableTester();
+
+        virtual void test(void);
+
+    private:
+        
+    };
+
+}}
+
+#endif /*_INTEGRATION_TRANSACTIONAL_DURABLETESTER_H_*/

Added: incubator/activemq/trunk/activemq-cpp/src/test-integration/integration/simple/SimpleTester.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/test-integration/integration/simple/SimpleTester.cpp?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/test-integration/integration/simple/SimpleTester.cpp (added)
+++ incubator/activemq/trunk/activemq-cpp/src/test-integration/integration/simple/SimpleTester.cpp Mon Jul  3 04:51:36 2006
@@ -0,0 +1,109 @@
+#include "SimpleTester.h"
+#include <integration/common/IntegrationCommon.h>
+
+CPPUNIT_TEST_SUITE_REGISTRATION( integration::simple::SimpleTester );
+
+#include <activemq/concurrent/Thread.h>
+#include <activemq/connector/stomp/StompConnector.h>
+#include <activemq/util/SimpleProperties.h>
+#include <activemq/transport/TransportFactory.h>
+#include <activemq/util/Guid.h>
+#include <activemq/util/SimpleProperties.h>
+#include <activemq/util/StringTokenizer.h>
+#include <activemq/connector/ConnectorFactoryMap.h>
+#include <activemq/network/SocketFactory.h>
+#include <activemq/transport/TransportFactory.h>
+#include <activemq/network/Socket.h>
+#include <activemq/exceptions/NullPointerException.h>
+#include <activemq/core/ActiveMQConnection.h>
+#include <activemq/core/ActiveMQConsumer.h>
+#include <activemq/core/ActiveMQProducer.h>
+#include <activemq/util/StringTokenizer.h>
+#include <activemq/util/Boolean.h>
+
+#include <cms/Connection.h>
+#include <cms/MessageConsumer.h>
+#include <cms/MessageProducer.h>
+#include <cms/MessageListener.h>
+#include <cms/Startable.h>
+#include <cms/Closeable.h>
+#include <cms/MessageListener.h>
+#include <cms/ExceptionListener.h>
+#include <cms/Topic.h>
+#include <cms/Queue.h>
+#include <cms/TemporaryTopic.h>
+#include <cms/TemporaryQueue.h>
+#include <cms/Session.h>
+#include <cms/BytesMessage.h>
+#include <cms/TextMessage.h>
+#include <cms/MapMessage.h>
+
+using namespace activemq::connector::stomp;
+using namespace activemq::transport;
+using namespace activemq::util;
+using namespace std;
+using namespace cms;
+using namespace activemq;
+using namespace activemq::core;
+using namespace activemq::util;
+using namespace activemq::connector;
+using namespace activemq::exceptions;
+using namespace activemq::network;
+using namespace activemq::transport;
+using namespace activemq::concurrent;
+
+using namespace integration;
+using namespace integration::simple;
+using namespace integration::common;
+
+SimpleTester::SimpleTester() : AbstractTester()
+{
+    numReceived = 0;
+}
+
+SimpleTester::~SimpleTester()
+{
+}
+
+void SimpleTester::test()
+{
+    try
+    {
+        cout << "Starting activemqcms test (sending "
+             << IntegrationCommon::defaultMsgCount
+             << " messages per type and sleeping "
+             << IntegrationCommon::defaultDelay 
+             << " milli-seconds) ...\n"
+             << endl;
+        
+        // Create CMS Object for Comms
+        cms::Topic* topic = session->createTopic("mytopic");
+        cms::MessageConsumer* consumer = 
+            session->createConsumer( *topic );            
+        consumer->setMessageListener( this );
+        cms::MessageProducer* producer = 
+            session->createProducer( *topic );
+
+        // Send some text messages
+        this->produceTextMessages( 
+            *producer, IntegrationCommon::defaultMsgCount );
+        
+        // Send some bytes messages.
+        this->produceTextMessages( 
+            *producer, IntegrationCommon::defaultMsgCount );
+
+        // Wait for the messages to get here
+        waitForMessages( IntegrationCommon::defaultMsgCount * 2 );
+        
+        printf("received: %d\n", numReceived );
+        CPPUNIT_ASSERT( 
+            numReceived == IntegrationCommon::defaultMsgCount * 2 );
+
+        printf("Shutting Down\n" );
+        delete producer;                      
+        delete consumer;
+    }
+    AMQ_CATCH_RETHROW( ActiveMQException )
+    AMQ_CATCHALL_THROW( ActiveMQException )
+}
+

Added: incubator/activemq/trunk/activemq-cpp/src/test-integration/integration/simple/SimpleTester.h
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/test-integration/integration/simple/SimpleTester.h?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/test-integration/integration/simple/SimpleTester.h (added)
+++ incubator/activemq/trunk/activemq-cpp/src/test-integration/integration/simple/SimpleTester.h Mon Jul  3 04:51:36 2006
@@ -0,0 +1,30 @@
+#ifndef _INTEGRATION_SIMPLE_SIMPLETESTER_H_
+#define _INTEGRATION_SIMPLE_SIMPLETESTER_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <integration/common/AbstractTester.h>
+
+namespace integration{
+namespace simple{
+    
+    class SimpleTester : public CppUnit::TestFixture,
+                         public common::AbstractTester
+    {
+        CPPUNIT_TEST_SUITE( SimpleTester );
+        CPPUNIT_TEST( test );
+        CPPUNIT_TEST_SUITE_END();
+
+    public:
+
+    	SimpleTester();
+    	virtual ~SimpleTester();
+
+        virtual void test(void);
+
+    };
+
+}}
+
+#endif /*_INTEGRATION_SIMPLE_SIMPLETESTER_H_*/

Added: incubator/activemq/trunk/activemq-cpp/src/test-integration/integration/transactional/TransactionTester.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/test-integration/integration/transactional/TransactionTester.cpp?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/test-integration/integration/transactional/TransactionTester.cpp (added)
+++ incubator/activemq/trunk/activemq-cpp/src/test-integration/integration/transactional/TransactionTester.cpp Mon Jul  3 04:51:36 2006
@@ -0,0 +1,125 @@
+#include "TransactionTester.h"
+#include <integration/common/IntegrationCommon.h>
+
+CPPUNIT_TEST_SUITE_REGISTRATION( integration::transactional::TransactionTester );
+
+#include <activemq/concurrent/Thread.h>
+#include <activemq/connector/stomp/StompConnector.h>
+#include <activemq/util/SimpleProperties.h>
+#include <activemq/transport/TransportFactory.h>
+#include <activemq/util/Guid.h>
+#include <activemq/util/SimpleProperties.h>
+#include <activemq/util/StringTokenizer.h>
+#include <activemq/connector/ConnectorFactoryMap.h>
+#include <activemq/network/SocketFactory.h>
+#include <activemq/transport/TransportFactory.h>
+#include <activemq/network/Socket.h>
+#include <activemq/exceptions/NullPointerException.h>
+#include <activemq/core/ActiveMQConnection.h>
+#include <activemq/core/ActiveMQConsumer.h>
+#include <activemq/core/ActiveMQProducer.h>
+#include <activemq/util/StringTokenizer.h>
+#include <activemq/util/Boolean.h>
+
+#include <cms/Connection.h>
+#include <cms/MessageConsumer.h>
+#include <cms/MessageProducer.h>
+#include <cms/MessageListener.h>
+#include <cms/Startable.h>
+#include <cms/Closeable.h>
+#include <cms/MessageListener.h>
+#include <cms/ExceptionListener.h>
+#include <cms/Topic.h>
+#include <cms/Queue.h>
+#include <cms/TemporaryTopic.h>
+#include <cms/TemporaryQueue.h>
+#include <cms/Session.h>
+#include <cms/BytesMessage.h>
+#include <cms/TextMessage.h>
+#include <cms/MapMessage.h>
+
+using namespace activemq::connector::stomp;
+using namespace activemq::transport;
+using namespace activemq::util;
+using namespace std;
+using namespace cms;
+using namespace activemq;
+using namespace activemq::core;
+using namespace activemq::util;
+using namespace activemq::connector;
+using namespace activemq::exceptions;
+using namespace activemq::network;
+using namespace activemq::transport;
+using namespace activemq::concurrent;
+
+using namespace integration;
+using namespace integration::transactional;
+using namespace integration::common;
+
+TransactionTester::TransactionTester() : AbstractTester( cms::Session::Transactional )
+{}
+
+TransactionTester::~TransactionTester()
+{}
+
+void TransactionTester::test()
+{
+    try
+    {
+        cout << "Starting activemqcms transactional test (sending "
+             << IntegrationCommon::defaultMsgCount
+             << " messages per type and sleeping "
+             << IntegrationCommon::defaultDelay 
+             << " milli-seconds) ...\n"
+             << endl;
+        
+        // Create CMS Object for Comms
+        cms::Topic* topic = session->createTopic("mytopic");
+        cms::MessageConsumer* consumer = 
+            session->createConsumer( *topic );            
+        consumer->setMessageListener( this );
+        cms::MessageProducer* producer = 
+            session->createProducer( *topic );
+
+        // Send some text messages
+        this->produceTextMessages( 
+            *producer, IntegrationCommon::defaultMsgCount );
+            
+        session->commit();
+        
+        // Send some bytes messages.
+        this->produceTextMessages( 
+            *producer, IntegrationCommon::defaultMsgCount );
+        
+        session->commit();
+
+        // Wait till we get all the messages
+        waitForMessages( IntegrationCommon::defaultMsgCount * 2 );
+        
+        printf("received: %d\n", numReceived );
+        CPPUNIT_ASSERT( 
+            numReceived == IntegrationCommon::defaultMsgCount * 2 );
+
+        numReceived = 0;
+
+        // Send some text messages
+        this->produceTextMessages( 
+            *producer, IntegrationCommon::defaultMsgCount );
+            
+        session->rollback();
+
+        // Wait till we get all the messages
+        waitForMessages( IntegrationCommon::defaultMsgCount * 2 );
+
+        printf("received: %d\n", numReceived );
+        CPPUNIT_ASSERT( 
+            numReceived == IntegrationCommon::defaultMsgCount );
+
+        printf("Shutting Down\n" );
+        delete producer;                      
+        delete consumer;
+    }
+    AMQ_CATCH_RETHROW( ActiveMQException )
+    AMQ_CATCHALL_THROW( ActiveMQException )
+}
+

Added: incubator/activemq/trunk/activemq-cpp/src/test-integration/integration/transactional/TransactionTester.h
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/test-integration/integration/transactional/TransactionTester.h?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/test-integration/integration/transactional/TransactionTester.h (added)
+++ incubator/activemq/trunk/activemq-cpp/src/test-integration/integration/transactional/TransactionTester.h Mon Jul  3 04:51:36 2006
@@ -0,0 +1,32 @@
+#ifndef _INTEGRATION_TRANSACTIONAL_TRANSACTIONTESTER_H_
+#define _INTEGRATION_TRANSACTIONAL_TRANSACTIONTESTER_H_
+
+#include <integration/common/AbstractTester.h>
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+namespace integration{
+namespace transactional{
+
+    class TransactionTester : public CppUnit::TestFixture,
+                              public common::AbstractTester
+    {
+        CPPUNIT_TEST_SUITE( TransactionTester );
+        CPPUNIT_TEST( test );
+        CPPUNIT_TEST_SUITE_END();
+
+    public:
+
+    	TransactionTester();
+    	virtual ~TransactionTester();
+
+        virtual void test(void);
+
+    private:
+        
+    };
+
+}}
+
+#endif /*_INTEGRATION_TRANSACTIONAL_TRANSACTIONTESTER_H_*/

Added: incubator/activemq/trunk/activemq-cpp/src/test-integration/main.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/test-integration/main.cpp?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/test-integration/main.cpp (added)
+++ incubator/activemq/trunk/activemq-cpp/src/test-integration/main.cpp Mon Jul  3 04:51:36 2006
@@ -0,0 +1,19 @@
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/ui/text/TestRunner.h>
+#include <cppunit/BriefTestProgressListener.h>
+#include <cppunit/TestResult.h>
+
+int main( int argc, char **argv)
+{
+    CppUnit::TextUi::TestRunner runner;
+    CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry();
+    runner.addTest( registry.makeTest() );
+
+    // Shows a message as each test starts
+    CppUnit::BriefTestProgressListener listener;
+    runner.eventManager().addListener( &listener );
+    
+    bool wasSuccessful = runner.run( "", false );
+    return !wasSuccessful;
+}
+

Added: incubator/activemq/trunk/activemq-cpp/src/test/activemq/concurrent/MutexTest.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/test/activemq/concurrent/MutexTest.cpp?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/test/activemq/concurrent/MutexTest.cpp (added)
+++ incubator/activemq/trunk/activemq-cpp/src/test/activemq/concurrent/MutexTest.cpp Mon Jul  3 04:51:36 2006
@@ -0,0 +1,4 @@
+#include "MutexTest.h"
+
+CPPUNIT_TEST_SUITE_REGISTRATION( activemq::concurrent::MutexTest );
+

Added: incubator/activemq/trunk/activemq-cpp/src/test/activemq/concurrent/MutexTest.h
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/test/activemq/concurrent/MutexTest.h?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/test/activemq/concurrent/MutexTest.h (added)
+++ incubator/activemq/trunk/activemq-cpp/src/test/activemq/concurrent/MutexTest.h Mon Jul  3 04:51:36 2006
@@ -0,0 +1,593 @@
+#ifndef ACTIVEMQ_CONCURRENT_MUTEXTEST_H_
+#define ACTIVEMQ_CONCURRENT_MUTEXTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <activemq/concurrent/Concurrent.h>
+#include <activemq/concurrent/Thread.h>
+#include <activemq/concurrent/Mutex.h>
+#include <time.h>
+
+namespace activemq{
+namespace concurrent{
+
+    class MutexTest : public CppUnit::TestFixture {
+
+        CPPUNIT_TEST_SUITE( MutexTest );
+        CPPUNIT_TEST( test );
+        CPPUNIT_TEST( testWait );
+        CPPUNIT_TEST( testTimedWait );
+        CPPUNIT_TEST( testNotify );
+        CPPUNIT_TEST( testNotifyAll );
+        CPPUNIT_TEST( testRecursiveLock );
+        CPPUNIT_TEST( testDoubleLock );
+        CPPUNIT_TEST_SUITE_END();
+
+    public:
+
+        class MyThread 
+        : 
+            public Thread,
+            public Synchronizable{
+    
+        private:
+        
+            Mutex mutex;
+            
+        public:
+        
+            int value;
+            MyThread(){ value = 0;}
+            virtual ~MyThread(){}
+            
+            virtual void lock() throw(exceptions::ActiveMQException){
+                mutex.lock();
+            }    
+            virtual void unlock() throw(exceptions::ActiveMQException){
+                mutex.unlock();
+            }       
+            virtual void wait() throw(exceptions::ActiveMQException){
+                mutex.wait();
+            }
+            virtual void wait(unsigned long millisecs) throw(exceptions::ActiveMQException){
+                mutex.wait( millisecs );
+            }  
+            virtual void notify() throw(exceptions::ActiveMQException){
+                mutex.notify();
+            }
+            virtual void notifyAll() throw(exceptions::ActiveMQException){
+                mutex.notifyAll();
+            }            
+        
+            virtual void run(){
+                
+                {
+                    Lock lock (this);
+                    
+                    value = value * 25;                 
+                }
+            }
+        
+        };
+      
+        class MyWaitingThread 
+        : 
+            public Thread,
+            public Synchronizable{
+         
+        private:
+      
+            Mutex mutex;
+         
+        public:
+     
+            int value;
+            MyWaitingThread(){ value = 0;}
+            virtual ~MyWaitingThread(){}
+            virtual void lock() throw(exceptions::ActiveMQException){
+                mutex.lock();
+            }    
+            virtual void unlock() throw(exceptions::ActiveMQException){
+                mutex.unlock();
+            }       
+            virtual void wait() throw(exceptions::ActiveMQException){
+                mutex.wait();
+            }
+            virtual void wait(unsigned long millisecs) throw(exceptions::ActiveMQException){
+                mutex.wait( millisecs );
+            }
+            virtual void notify() throw(exceptions::ActiveMQException){
+                mutex.notify();
+            }
+            virtual void notifyAll() throw(exceptions::ActiveMQException){
+                mutex.notifyAll();
+            }  
+         
+            virtual void run(){
+         
+                try
+                {
+                    synchronized(this)            
+                    {
+                        this->wait();
+            
+                        std::cout.flush();
+                 
+                        value = value * 25;              
+                    }
+                }
+                catch(exceptions::ActiveMQException& ex)
+                {
+                    ex.setMark( __FILE__, __LINE__ );
+                }
+            }
+      };
+
+      class MyTimedWaitingThread 
+      : 
+         public Thread,
+         public Synchronizable{
+        
+      private:
+    
+         Mutex mutex;
+         
+      public:
+     
+         int value;
+         MyTimedWaitingThread(){ value = 0;}
+         virtual ~MyTimedWaitingThread(){}
+         virtual void lock() throw(exceptions::ActiveMQException){
+             mutex.lock();
+         }    
+         virtual void unlock() throw(exceptions::ActiveMQException){
+             mutex.unlock();
+         }       
+         virtual void wait() throw(exceptions::ActiveMQException){
+             mutex.wait();
+         }
+         virtual void wait(unsigned long millisecs) throw(exceptions::ActiveMQException){
+             mutex.wait( millisecs );
+         }
+         virtual void notify() throw(exceptions::ActiveMQException){
+             mutex.notify();
+         }
+         virtual void notifyAll() throw(exceptions::ActiveMQException){
+             mutex.notifyAll();
+         }  
+        
+         virtual void run(){
+      
+            try
+            {
+               synchronized(this)            
+               {
+                  this->wait(2000);
+                        
+                  value = 666;              
+               }
+            }
+            catch(exceptions::ActiveMQException& ex)
+            {
+                ex.setMark( __FILE__, __LINE__ );
+            }
+         }
+      };
+     
+      class MyNotifiedThread 
+      : 
+         public Thread,
+         public Synchronizable{
+        
+      public:
+      
+         bool done;
+         Mutex* mutex;
+         
+      public:
+     
+         int value;
+         MyNotifiedThread(Mutex* mutex){ this->mutex = mutex; done = false; }
+         virtual ~MyNotifiedThread(){}
+         virtual void lock() throw(exceptions::ActiveMQException){
+             mutex->lock();
+         }    
+         virtual void unlock() throw(exceptions::ActiveMQException){
+             mutex->unlock();
+         }       
+         virtual void wait() throw(exceptions::ActiveMQException){
+             mutex->wait();
+         }
+         virtual void wait(unsigned long millisecs) throw(exceptions::ActiveMQException){
+             mutex->wait( millisecs );
+         }
+         virtual void notify() throw(exceptions::ActiveMQException){
+             mutex->notify();
+         }
+         virtual void notifyAll() throw(exceptions::ActiveMQException){
+             mutex->notifyAll();
+         }  
+        
+         virtual void run(){
+      
+            try
+            {
+               done = false;
+               synchronized(this)            
+               {                  
+                  this->wait();
+                  done = true;
+               }
+            }
+            catch(exceptions::ActiveMQException& ex)
+            {
+               ex.setMark( __FILE__, __LINE__ );
+            }
+         }
+      };
+      
+      class MyRecursiveLockThread 
+      : 
+         public Thread,
+         public Synchronizable{
+        
+      public:
+      
+         bool done;
+         Mutex* mutex;
+         
+      public:
+     
+         int value;
+         MyRecursiveLockThread(Mutex* mutex){ this->mutex = mutex; done = false; }
+         virtual ~MyRecursiveLockThread(){}
+         virtual void lock() throw(exceptions::ActiveMQException){
+             mutex->lock();
+         }    
+         virtual void unlock() throw(exceptions::ActiveMQException){
+             mutex->unlock();
+         }       
+         virtual void wait() throw(exceptions::ActiveMQException){
+             mutex->wait();
+         }
+         virtual void wait(unsigned long millisecs) throw(exceptions::ActiveMQException){
+             mutex->wait( millisecs );
+         }
+         virtual void notify() throw(exceptions::ActiveMQException){
+             mutex->notify();
+         }
+         virtual void notifyAll() throw(exceptions::ActiveMQException){
+             mutex->notifyAll();
+         }  
+        
+         virtual void run(){
+      
+            try
+            {
+               done = false;
+               synchronized(this)            
+               {
+                  synchronized(this)
+                  {
+                     this->wait();
+                     done = true;
+                  }
+               }
+            }
+            catch(exceptions::ActiveMQException& ex)
+            {
+               ex.setMark( __FILE__, __LINE__ );
+            }
+         }
+      };
+
+      class MyDoubleLockThread 
+      : 
+         public Thread
+      {
+        
+      public:
+      
+         bool done;
+         Mutex* mutex1;
+         Mutex* mutex2;
+         
+      public:
+     
+         int value;
+         MyDoubleLockThread(Mutex* mutex1, Mutex* mutex2)
+         {
+            this->mutex1 = mutex1;
+            this->mutex2 = mutex2;
+            done = false;
+         }
+
+         virtual ~MyDoubleLockThread(){}
+        
+         virtual void run(){
+      
+            try
+            {
+               done = false;
+               synchronized(mutex1)            
+               {
+                  synchronized(mutex2)
+                  {
+                     mutex2->wait();
+                     done = true;
+                  }
+               }
+            }
+            catch(exceptions::ActiveMQException& ex)
+            {
+               ex.setMark( __FILE__, __LINE__ );
+            }
+         }
+      };
+
+   public:
+    
+        virtual void setUp(){}; 
+        virtual void tearDown(){};
+        
+      void testTimedWait(){
+
+         try
+         {
+            MyTimedWaitingThread test;
+            time_t startTime = time( NULL );
+            test.start();
+            test.join();
+            time_t endTime = time( NULL );
+       
+            long delta = endTime - startTime;
+
+            CPPUNIT_ASSERT( delta >= 1 && delta <= 3 );
+        }
+        catch(exceptions::ActiveMQException& ex)
+        {
+           std::cout << ex.getMessage() << std::endl;
+        }
+      }
+
+        void testWait(){
+
+         try
+         {
+            MyWaitingThread test;
+            test.start();
+
+            Thread::sleep(1000);
+
+            synchronized(&test)
+            {
+                for( int ix=0; ix<100; ix++ ){
+                    test.value += 1;
+                }
+  
+               test.notify();
+            }
+   
+            test.join();
+          
+            CPPUNIT_ASSERT( test.value == 2500 );
+
+        }
+        catch(exceptions::ActiveMQException& ex)
+        {
+           ex.setMark( __FILE__, __LINE__ );
+        }
+        }
+      
+        void test()
+        {
+            MyThread test;
+            test.lock();
+
+            test.start();
+         
+            for( int ix=0; ix<100; ix++ ){
+                test.value += 1;
+            }
+         
+            test.unlock();
+            test.join();
+         
+            CPPUNIT_ASSERT( test.value == 2500 );
+        }
+      
+        void testNotify()
+        {
+            try{
+                Mutex mutex;
+                const int numThreads = 30;
+                MyNotifiedThread* threads[numThreads];
+             
+                // Create and start all the threads.
+                for( int ix=0; ix<numThreads; ++ix ){
+                    threads[ix] = new MyNotifiedThread( &mutex );
+                    threads[ix]->start();
+                }
+             
+                // Sleep so all the threads can get to the wait.
+                Thread::sleep( 1000 );
+             
+                synchronized(&mutex)
+                {
+                    mutex.notify();
+                }
+             
+                Thread::sleep( 1000 );
+             
+                int counter = 0;
+                for( int ix=0; ix<numThreads; ++ix ){
+                    if( threads[ix]->done ){
+                        counter++;
+                    }
+                }
+             
+                // Make sure only 1 thread was notified.
+                CPPUNIT_ASSERT( counter == 1 ); 
+             
+                synchronized(&mutex)
+                {
+                    // Notify all threads.
+                    for( int ix=0; ix<numThreads-1; ++ix ){
+                        mutex.notify();
+                    }
+                }
+             
+                // Sleep to give the threads time to wake up.
+                Thread::sleep( 1000 );
+             
+                int numComplete = 0;
+                for( int ix=0; ix<numThreads; ++ix ){
+                    if( threads[ix]->done ){
+                        numComplete++;
+                    }  
+                }
+                CPPUNIT_ASSERT( numComplete == numThreads );
+                
+                synchronized( &mutex )
+                {
+                    mutex.wait( 5 );
+                }
+                
+                synchronized( &mutex )
+                {
+                    mutex.notifyAll();
+                }
+                                
+            }catch( exceptions::ActiveMQException& ex ){
+                ex.setMark( __FILE__, __LINE__ );
+            }
+        }
+      
+        void testNotifyAll()
+        {
+            try{
+                Mutex mutex;
+             
+                const int numThreads = 100;
+                MyNotifiedThread* threads[numThreads];
+             
+                // Create and start all the threads.
+                for( int ix=0; ix<numThreads; ++ix ){
+                    threads[ix] = new MyNotifiedThread( &mutex );
+                    threads[ix]->start();
+                }
+             
+                // Sleep so all the threads can get to the wait.
+                Thread::sleep( 1000 );
+             
+                for( int ix=0; ix<numThreads; ++ix )
+                {
+                    if( threads[ix]->done == true ){
+                        printf("threads[%d] is done prematurely\n", ix );
+                    }
+                    CPPUNIT_ASSERT( threads[ix]->done == false );            
+                }
+             
+                // Notify all threads.
+                synchronized( &mutex ){
+                   mutex.notifyAll();
+                }
+             
+                // Sleep to give the threads time to wake up.
+                Thread::sleep( 1000 );
+             
+                int numComplete = 0;
+                for( int ix=0; ix<numThreads; ++ix ){
+                    if( threads[ix]->done ){
+                        numComplete++;
+                    }  
+                }
+                printf("numComplete: %d, numThreads: %d\n", numComplete, numThreads );
+                CPPUNIT_ASSERT( numComplete == numThreads );
+             
+            }catch( exceptions::ActiveMQException& ex ){
+                ex.setMark( __FILE__, __LINE__ );
+            }
+        }
+
+        void testRecursiveLock()
+        {
+            try{
+                Mutex mutex;
+             
+                const int numThreads = 30;
+                MyRecursiveLockThread* threads[numThreads];
+             
+                // Create and start all the threads.
+                for( int ix=0; ix<numThreads; ++ix ){
+                    threads[ix] = new MyRecursiveLockThread( &mutex );
+                    threads[ix]->start();
+                }
+             
+                // Sleep so all the threads can get to the wait.
+                Thread::sleep( 1000 );
+             
+                for( int ix=0; ix<numThreads; ++ix ){
+                    if( threads[ix]->done == true ){
+                        std::cout << "threads[" << ix 
+                                  << "] is done prematurely\n";
+                    }
+                    CPPUNIT_ASSERT( threads[ix]->done == false );            
+                }
+             
+                // Notify all threads.
+                synchronized( &mutex )
+                {
+                    synchronized( &mutex )
+                    {
+                        mutex.notifyAll();
+                    }
+                }
+             
+                // Sleep to give the threads time to wake up.
+                Thread::sleep( 1000 );
+             
+                for( int ix=0; ix<numThreads; ++ix ){
+                    if( threads[ix]->done != true ){
+                        std::cout<< "threads[" << ix << "] is not done\n";
+                    }
+                    CPPUNIT_ASSERT( threads[ix]->done == true );            
+                }
+            }catch( exceptions::ActiveMQException& ex ){
+                ex.setMark( __FILE__, __LINE__ );
+            }
+        }
+
+        void testDoubleLock()
+        {
+            try{
+                Mutex mutex1;
+                Mutex mutex2;
+
+                MyDoubleLockThread thread(&mutex1, &mutex2);
+    
+                thread.start();
+    
+                // Let the thread get both locks
+                Thread::sleep( 200 );
+    
+                // Lock mutex 2, thread is waiting on it
+                synchronized(&mutex2)
+                {
+                   mutex2.notify();
+                }
+    
+                // Let the thread die
+                thread.join();
+    
+                CPPUNIT_ASSERT( thread.done );
+            }catch( exceptions::ActiveMQException& ex ){
+                ex.setMark( __FILE__, __LINE__ );
+            }
+        }
+    };
+    
+}}
+
+#endif /*ACTIVEMQ_CONCURRENT_MUTEXTEST_H_*/

Added: incubator/activemq/trunk/activemq-cpp/src/test/activemq/concurrent/ThreadPoolTest.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/test/activemq/concurrent/ThreadPoolTest.cpp?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/test/activemq/concurrent/ThreadPoolTest.cpp (added)
+++ incubator/activemq/trunk/activemq-cpp/src/test/activemq/concurrent/ThreadPoolTest.cpp Mon Jul  3 04:51:36 2006
@@ -0,0 +1,3 @@
+#include "ThreadPoolTest.h"
+
+CPPUNIT_TEST_SUITE_REGISTRATION( activemq::concurrent::ThreadPoolTest );

Added: incubator/activemq/trunk/activemq-cpp/src/test/activemq/concurrent/ThreadPoolTest.h
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/test/activemq/concurrent/ThreadPoolTest.h?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/test/activemq/concurrent/ThreadPoolTest.h (added)
+++ incubator/activemq/trunk/activemq-cpp/src/test/activemq/concurrent/ThreadPoolTest.h Mon Jul  3 04:51:36 2006
@@ -0,0 +1,233 @@
+#ifndef THREADPOOLTEST_H_
+#define THREADPOOLTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <activemq/concurrent/Concurrent.h>
+#include <activemq/concurrent/Thread.h>
+#include <activemq/concurrent/ThreadPool.h>
+#include <activemq/concurrent/TaskListener.h>
+#include <activemq/concurrent/Mutex.h>
+
+namespace activemq{
+namespace concurrent{
+
+   class ThreadPoolTest : 
+      public CppUnit::TestFixture,
+      public TaskListener
+   {
+      CPPUNIT_TEST_SUITE( ThreadPoolTest );
+      CPPUNIT_TEST( test1 );
+      CPPUNIT_TEST( test2 );
+      CPPUNIT_TEST_SUITE_END();
+
+      int tasksToComplete;
+      int complete;
+      Mutex mutex;
+      Mutex completeMutex;
+      bool caughtEx;
+      
+   public:
+ 
+   	ThreadPoolTest() 
+      { 
+         complete = 0;
+         tasksToComplete = 0;
+         caughtEx = false;
+      }
+      
+   	virtual ~ThreadPoolTest() {};
+      
+      virtual void onTaskComplete(Runnable* task)
+      {
+        try{
+             synchronized(&mutex)
+             {
+                complete++;
+                
+                if(tasksToComplete == complete)
+                {
+                   mutex.notifyAll();
+                }
+             }
+        }catch( exceptions::ActiveMQException& ex ){
+            ex.setMark( __FILE__, __LINE__ );
+        }
+      }
+
+      virtual void onTaskException(Runnable* task, exceptions::ActiveMQException& ex)
+      {
+         caughtEx = true;
+      }
+      
+   public:
+   
+      class MyTask : public Runnable
+      {
+      public:
+      
+         int value;
+         
+         MyTask(int x)
+         {
+            value = x;
+         }
+         
+         virtual ~MyTask() {};
+         
+         virtual void run(void)
+         {
+            value += 100;
+         }
+      };
+
+      class MyWaitingTask : public Runnable
+      {
+      public:
+      
+         Mutex* mutex;
+         Mutex* complete;
+         
+         MyWaitingTask(Mutex* mutex, Mutex* complete)
+         {
+            this->mutex = mutex;
+            this->complete = complete;
+         }
+         
+         virtual ~MyWaitingTask() {};
+         
+         virtual void run(void)
+         {
+            try
+            {
+               synchronized(mutex)
+               {
+                  mutex->wait();
+               }
+
+               synchronized(complete)
+               {
+                   complete->notify();
+               }
+            }
+            catch( exceptions::ActiveMQException& ex )
+            {
+                ex.setMark( __FILE__, __LINE__ );
+            }
+         }
+      };
+
+   public:
+
+      void test2()
+      {
+         try
+         {
+            ThreadPool pool;
+            Mutex myMutex;
+    
+            CPPUNIT_ASSERT( pool.getMaxThreads() == ThreadPool::DEFAULT_MAX_POOL_SIZE );
+            CPPUNIT_ASSERT( pool.getBlockSize() == ThreadPool::DEFAULT_MAX_BLOCK_SIZE );
+            pool.setMaxThreads(3);
+            pool.setBlockSize(1);
+            CPPUNIT_ASSERT( pool.getMaxThreads() == 3 );
+            CPPUNIT_ASSERT( pool.getBlockSize() == 1 );
+            CPPUNIT_ASSERT( pool.getPoolSize() == 0 );
+            pool.reserve( 4 );
+            CPPUNIT_ASSERT( pool.getPoolSize() == 3 );
+            CPPUNIT_ASSERT( pool.getFreeThreadCount() == 3 );
+    
+            MyWaitingTask task1(&myMutex, &completeMutex);
+            MyWaitingTask task2(&myMutex, &completeMutex);
+            MyWaitingTask task3(&myMutex, &completeMutex);
+            MyWaitingTask task4(&myMutex, &completeMutex);
+    
+            complete = 0;
+            tasksToComplete = 4;
+    
+            pool.queueTask(ThreadPool::Task(&task1, this));
+            pool.queueTask(ThreadPool::Task(&task2, this));
+            pool.queueTask(ThreadPool::Task(&task3, this));
+            pool.queueTask(ThreadPool::Task(&task4, this));
+             
+            Thread::sleep( 1000 );
+             
+            CPPUNIT_ASSERT( pool.getFreeThreadCount() == 0 );
+            CPPUNIT_ASSERT( pool.getBacklog() == 1 );
+    
+            int count = 0;
+            while(complete != tasksToComplete && count < 100)
+            {
+               synchronized(&myMutex)
+               {
+                  myMutex.notifyAll();
+               }
+
+               synchronized(&completeMutex)
+               {
+                  completeMutex.wait(1000);
+               }
+
+               count++;
+            }
+    
+            CPPUNIT_ASSERT( complete == tasksToComplete );
+            CPPUNIT_ASSERT( caughtEx == false );
+         }
+         catch( exceptions::ActiveMQException& ex )
+         {
+            ex.setMark( __FILE__, __LINE__ );
+         }
+      }
+   
+      void test1()
+      {
+         MyTask task1(1);
+         MyTask task2(2);
+         MyTask task3(3);
+         
+         complete = 0;
+         tasksToComplete = 3;
+         
+         ThreadPool* pool = ThreadPool::getInstance();
+         
+         // Can't check this here since one of the other tests might
+         // have used the global thread pool.
+         // CPPUNIT_ASSERT( pool->getPoolSize() == 0 );
+
+         pool->queueTask(ThreadPool::Task(&task1, this));
+         pool->queueTask(ThreadPool::Task(&task2, this));
+         pool->queueTask(ThreadPool::Task(&task3, this));
+         
+         Thread::sleep(500);
+         
+         CPPUNIT_ASSERT( complete == tasksToComplete );
+
+         CPPUNIT_ASSERT( task1.value == 101 );
+         CPPUNIT_ASSERT( task2.value == 102 );
+         CPPUNIT_ASSERT( task3.value == 103 );
+         
+         CPPUNIT_ASSERT( pool->getPoolSize() > 0 );
+         CPPUNIT_ASSERT( pool->getBacklog() == 0 );
+
+         CPPUNIT_ASSERT( pool->getMaxThreads() == ThreadPool::DEFAULT_MAX_POOL_SIZE );
+         CPPUNIT_ASSERT( pool->getBlockSize() == ThreadPool::DEFAULT_MAX_BLOCK_SIZE );
+
+         pool->setMaxThreads(50);
+         pool->setBlockSize(50);
+
+         CPPUNIT_ASSERT( pool->getMaxThreads() == 50 );
+         CPPUNIT_ASSERT( pool->getBlockSize() == 50 );
+
+         Thread::sleep(500);
+
+         CPPUNIT_ASSERT( pool->getFreeThreadCount() == pool->getPoolSize() );
+         CPPUNIT_ASSERT( caughtEx == false );
+         
+      }
+   };
+
+}}
+
+#endif /*THREADPOOLTEST_H_*/

Added: incubator/activemq/trunk/activemq-cpp/src/test/activemq/concurrent/ThreadTest.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/test/activemq/concurrent/ThreadTest.cpp?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/test/activemq/concurrent/ThreadTest.cpp (added)
+++ incubator/activemq/trunk/activemq-cpp/src/test/activemq/concurrent/ThreadTest.cpp Mon Jul  3 04:51:36 2006
@@ -0,0 +1,4 @@
+#include "ThreadTest.h"
+
+CPPUNIT_TEST_SUITE_REGISTRATION( activemq::concurrent::ThreadTest );
+

Added: incubator/activemq/trunk/activemq-cpp/src/test/activemq/concurrent/ThreadTest.h
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/test/activemq/concurrent/ThreadTest.h?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/test/activemq/concurrent/ThreadTest.h (added)
+++ incubator/activemq/trunk/activemq-cpp/src/test/activemq/concurrent/ThreadTest.h Mon Jul  3 04:51:36 2006
@@ -0,0 +1,130 @@
+#ifndef ACTIVEMQ_CONCURRENT_THREADTEST_H_
+#define ACTIVEMQ_CONCURRENT_THREADTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <activemq/concurrent/Thread.h>
+#include <time.h>
+
+namespace activemq{
+namespace concurrent{
+	
+	class ThreadTest : public CppUnit::TestFixture {
+		
+	  CPPUNIT_TEST_SUITE( ThreadTest );
+	  CPPUNIT_TEST( testDelegate );
+	  CPPUNIT_TEST( testDerived );
+	  CPPUNIT_TEST( testJoin );
+	  CPPUNIT_TEST_SUITE_END();
+	  
+	public:
+	
+		class Delegate : public Runnable{
+		private:
+		
+			int stuff;
+			
+		public:
+		
+			Delegate(){ stuff = 0; }
+			virtual ~Delegate(){}
+			
+			int getStuff(){
+				return stuff;
+			}
+			
+			virtual void run(){
+				stuff = 1;
+			}
+		
+		};
+		
+		class Derived : public Thread{
+		private:
+		
+			int stuff;
+			
+		public:
+		
+			Derived(){ stuff = 0; }
+			virtual ~Derived(){}
+			
+			int getStuff(){
+				return stuff;
+			}
+			
+			virtual void run(){
+				stuff = 1;
+			}
+		
+		};
+		
+		class JoinTest : public Thread{
+		public:
+		
+			JoinTest(){}
+			virtual ~JoinTest(){}
+			
+			virtual void run(){
+				
+				// Sleep for 2 seconds.
+				Thread::sleep( 2000 );
+			}
+		
+		};
+		
+	public:
+	
+		virtual void setUp(){};	
+	 	virtual void tearDown(){};
+		void testDelegate(){
+		  	
+		  	Delegate test;
+		  	int initialValue = test.getStuff();
+		  	
+		  	Thread thread( &test );
+		  	thread.start();
+		  	thread.join();
+		  	
+		  	int finalValue = test.getStuff();
+		  	
+		  	// The values should be different - this proves
+		  	// that the runnable was run.
+		  	CPPUNIT_ASSERT( finalValue != initialValue );
+		}
+		
+		void testDerived(){
+		  	
+		  	Derived test;
+		  	int initialValue = test.getStuff();
+		  	
+		  	test.start();
+		  	test.join();
+		  	
+		  	int finalValue = test.getStuff();
+		  	
+		  	// The values should be different - this proves
+		  	// that the runnable was run.
+		  	CPPUNIT_ASSERT( finalValue != initialValue );
+		}
+		
+		void testJoin(){
+		  	
+		  	JoinTest test;
+		  	
+		  	time_t startTime = time( NULL );
+		  	test.start();
+		  	test.join();
+		  	time_t endTime = time( NULL );
+		  	
+		  	long delta = endTime - startTime;
+		  	
+		  	// Should be about 5 seconds that elapsed.
+		  	CPPUNIT_ASSERT( delta >= 1 && delta <= 3 );
+		}
+	};
+	
+}}
+
+#endif /*ACTIVEMQ_CONCURRENT_THREADTEST_H_*/

Added: incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/ConnectorFactoryMapRegistrarTest.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/ConnectorFactoryMapRegistrarTest.cpp?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/ConnectorFactoryMapRegistrarTest.cpp (added)
+++ incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/ConnectorFactoryMapRegistrarTest.cpp Mon Jul  3 04:51:36 2006
@@ -0,0 +1,3 @@
+#include "ConnectorFactoryMapRegistrarTest.h"
+
+CPPUNIT_TEST_SUITE_REGISTRATION( activemq::connector::ConnectorFactoryMapRegistrarTest );

Added: incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/ConnectorFactoryMapRegistrarTest.h
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/ConnectorFactoryMapRegistrarTest.h?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/ConnectorFactoryMapRegistrarTest.h (added)
+++ incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/ConnectorFactoryMapRegistrarTest.h Mon Jul  3 04:51:36 2006
@@ -0,0 +1,44 @@
+#ifndef ACTIVEMQ_CONNECTOR_CONNECTORFACTORYMAPREGISTRARTEST_H_
+#define ACTIVEMQ_CONNECTOR_CONNECTORFACTORYMAPREGISTRARTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <activemq/connector/ConnectorFactoryMap.h>
+#include <activemq/connector/ConnectorFactoryMapRegistrar.h>
+
+namespace activemq{
+namespace connector{
+	
+	class ConnectorFactoryMapRegistrarTest : public CppUnit::TestFixture {
+		
+	  CPPUNIT_TEST_SUITE( ConnectorFactoryMapRegistrarTest );
+	  CPPUNIT_TEST( test );
+	  CPPUNIT_TEST_SUITE_END();
+	  
+	public:
+	
+		class TestConnectoryFactory : public ConnectorFactory
+		{
+		public:
+		
+		   virtual Connector* createConnector(
+		      const activemq::util::Properties& properties,
+            activemq::transport::Transport*   transport) { return NULL; };
+		};
+		
+		void test(){
+			
+			{
+				ConnectorFactoryMapRegistrar registrar("Test", new TestConnectoryFactory());
+			
+				CPPUNIT_ASSERT( ConnectorFactoryMap::getInstance()->lookup("Test") != NULL);
+			}
+			
+			CPPUNIT_ASSERT( ConnectorFactoryMap::getInstance()->lookup( "Test" ) == NULL );
+		}
+	};
+	
+}}
+
+#endif /*ACTIVEMQ_CONNECTOR_CONNECTORFACTORYMAPREGISTRARTEST_H_*/

Added: incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/ConnectorFactoryMapTest.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/ConnectorFactoryMapTest.cpp?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/ConnectorFactoryMapTest.cpp (added)
+++ incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/ConnectorFactoryMapTest.cpp Mon Jul  3 04:51:36 2006
@@ -0,0 +1,4 @@
+#include "ConnectorFactoryMapTest.h"
+
+CPPUNIT_TEST_SUITE_REGISTRATION( activemq::connector::ConnectorFactoryMapTest );
+

Added: incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/ConnectorFactoryMapTest.h
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/ConnectorFactoryMapTest.h?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/ConnectorFactoryMapTest.h (added)
+++ incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/ConnectorFactoryMapTest.h Mon Jul  3 04:51:36 2006
@@ -0,0 +1,123 @@
+#ifndef ACTIVEMQ_CONNECTOR_CONNECTORFACTORYMAPTEST_H_
+#define ACTIVEMQ_CONNECTOR_CONNECTORFACTORYMAPTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <activemq/connector/ConnectorFactoryMap.h>
+#include <activemq/connector/SessionInfo.h>
+#include <activemq/connector/TransactionInfo.h>
+#include <cms/Topic.h>
+#include <cms/Queue.h>
+#include <cms/TemporaryTopic.h>
+#include <cms/TemporaryQueue.h>
+
+namespace activemq{
+namespace connector{
+	
+	class ConnectorFactoryMapTest : public CppUnit::TestFixture {
+		
+	  CPPUNIT_TEST_SUITE( ConnectorFactoryMapTest );
+	  CPPUNIT_TEST( test );
+	  CPPUNIT_TEST_SUITE_END();
+	  
+	public:
+	
+		class testConnector : public Connector
+		{
+		public:
+		
+		      virtual SessionInfo* createSessionInfo(void) throw( ConnectorException )
+		      { return NULL; };
+		
+		      virtual cms::Topic* createTopic(const std::string& name, SessionInfo* session)
+		          throw ( ConnectorException )
+		      { return NULL; };
+		      virtual cms::Queue* createQueue(const std::string& name, SessionInfo* session)
+		         throw ( ConnectorException )
+		      { return NULL; };
+		          
+		      virtual cms::TemporaryTopic* createTemporaryTopic(const std::string& name, 
+		                                                    SessionInfo*       session)
+		         throw ( ConnectorException )
+		     { return NULL; };
+		         
+		       virtual cms::TemporaryQueue* createTemporaryQueue(const std::string& name, 
+		                                                    SessionInfo*       session)
+		          throw ( ConnectorException )
+		       { return NULL; };
+		          
+		      virtual void Send(cms::Message* message) throw ( ConnectorException ) {};
+		      virtual void Send(std::list<cms::Message*>& messages) 
+		         throw ( ConnectorException ) {};
+            virtual void Acknowledge(cms::Message* message) throw ( ConnectorException ) {};
+		      virtual TransactionInfo* startTransaction(SessionInfo* session) 
+		         throw ( ConnectorException ) { return NULL; };
+		      virtual void commit(TransactionInfo* transaction, SessionInfo* session)
+		         throw ( ConnectorException ) {};
+		      virtual void rollback(TransactionInfo* transaction, SessionInfo* session)
+		         throw ( ConnectorException ) {};
+		
+		      virtual cms::BytesMessage* createByteMessage(SessionInfo*     session,
+		                                             TransactionInfo* transaction)
+		                                               throw ( ConnectorException )
+		      { return NULL; };
+		      virtual cms::TextMessage* createTextMessage(SessionInfo*     session,
+		                                             TransactionInfo* transaction)
+		                                               throw ( ConnectorException )
+		      { return NULL; };
+		      virtual void subscribe(cms::Destination* destination, SessionInfo* session)
+		         throw ( ConnectorException ) {};
+		      virtual void unsubscribe(cms::Destination* destination, SessionInfo* session)
+		         throw ( ConnectorException ) {};
+		      virtual void addMessageListener(cms::MessageListener* listener) {};
+		      virtual void removeMessageListener(cms::MessageListener* listener) {};
+            virtual void addExceptionListener(cms::ExceptionListener* listener) {};
+            virtual void removeExceptionListener(cms::ExceptionListener* listener) {};
+		
+		};
+		
+	public:
+	
+		class TestConnectoryFactory : public ConnectorFactory
+		{
+		public:
+		
+		   virtual Connector* createConnector(
+		      const activemq::util::Properties& properties,
+            activemq::transport::Transport*   transport) { return NULL; };
+		};
+		
+		void test(){
+			
+			ConnectorFactoryMap* factMap = ConnectorFactoryMap::getInstance();
+			CPPUNIT_ASSERT( factMap != NULL );
+			
+			TestConnectoryFactory testFactory;
+			
+			factMap->registerConnectorFactory( "test", &testFactory );
+			
+			CPPUNIT_ASSERT( factMap->lookup( "test" ) == &testFactory );
+			
+			std::vector<std::string> names;
+			CPPUNIT_ASSERT( factMap->getFactoryNames( names ) >= 1 );
+			
+            bool found = false;
+            for( unsigned int i = 0; i < names.size(); ++i )
+            {
+                if( names[i] == "test" )
+                {
+                    found = true;
+                    break;
+                }
+            }
+			CPPUNIT_ASSERT( found );
+			
+			factMap->unregisterConnectorFactory( "test" );
+			CPPUNIT_ASSERT( factMap->lookup( "test" ) == NULL );			
+		}
+	};
+	
+}}
+
+#endif /*ACTIVEMQ_CONNECTOR_CONNECTORFACTORYMAPTEST_H_*/

Added: incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompCommandReaderTest.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompCommandReaderTest.cpp?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompCommandReaderTest.cpp (added)
+++ incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompCommandReaderTest.cpp Mon Jul  3 04:51:36 2006
@@ -0,0 +1,3 @@
+#include "StompCommandReaderTest.h"
+
+CPPUNIT_TEST_SUITE_REGISTRATION( activemq::connector::stomp::StompCommandReaderTest );

Added: incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompCommandReaderTest.h
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompCommandReaderTest.h?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompCommandReaderTest.h (added)
+++ incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompCommandReaderTest.h Mon Jul  3 04:51:36 2006
@@ -0,0 +1,108 @@
+#ifndef _ACTIVEMQ_CONNECTOR_STOMP_STOMPCOMMANDREADERTEST_H_
+#define _ACTIVEMQ_CONNECTOR_STOMP_STOMPCOMMANDREADERTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <activemq/connector/stomp/StompCommandReader.h>
+#include <activemq/transport/Command.h>
+#include <activemq/connector/stomp/commands/ConnectedCommand.h>
+#include <activemq/connector/stomp/commands/TextMessageCommand.h>
+#include <activemq/connector/stomp/commands/BytesMessageCommand.h>
+
+#include <activemq/io/ByteArrayInputStream.h>
+
+namespace activemq{
+namespace connector{
+namespace stomp{
+
+    class StompCommandReaderTest : public CppUnit::TestFixture
+    {
+        CPPUNIT_TEST_SUITE( StompCommandReaderTest );
+        CPPUNIT_TEST( test );
+        CPPUNIT_TEST_SUITE_END();
+
+    public:
+    
+    	StompCommandReaderTest() {}
+    	virtual ~StompCommandReaderTest() {}
+
+        void test( void )
+        {
+            io::ByteArrayInputStream biStream;
+
+            StompCommandReader reader( &biStream );
+
+            const char* connectedStr = 
+                "CONNECTED\nsession:test\n\n\0\n";
+            const char* textStr = 
+                "MESSAGE\n"
+                "destination:/topic/a\n"
+                "message-id:123\n"
+                "sampleProperty:testvalue\n\n"
+                "testMessage\0\n";
+            const char* bytesStr = 
+                "MESSAGE\n"                    // 8
+                "destination:/topic/a\n"       // 21
+                "message-id:123\n"             // 15
+                "content-length:9\n"           // 17
+                "sampleProperty:testvalue\n\n" // 26
+                "123456789\0\n";               // 11
+            
+            biStream.setByteArray( 
+                (const unsigned char*)connectedStr, 27 );
+
+            transport::Command* command = reader.readCommand();
+
+            CPPUNIT_ASSERT( command != NULL );
+            
+            commands::ConnectedCommand* connected = 
+                dynamic_cast< commands::ConnectedCommand* >( command );
+
+            CPPUNIT_ASSERT( connected != NULL );
+
+            CPPUNIT_ASSERT( connected->getSessionId() != NULL );
+            std::string sessionId = connected->getSessionId();
+            CPPUNIT_ASSERT( sessionId == "test" );
+
+            biStream.setByteArray( 
+                (const unsigned char*)textStr, 83 );
+
+            command = reader.readCommand();
+
+            CPPUNIT_ASSERT( command != NULL );
+            
+            commands::TextMessageCommand* textMessage = 
+                dynamic_cast< commands::TextMessageCommand* >( command );
+
+            CPPUNIT_ASSERT( textMessage != NULL );
+
+            CPPUNIT_ASSERT( textMessage->getText() != NULL );
+            std::string text = textMessage->getText();
+            CPPUNIT_ASSERT( text == "testMessage" );
+
+            biStream.setByteArray( 
+                (const unsigned char*)bytesStr, 98 );
+
+            command = reader.readCommand();
+
+            CPPUNIT_ASSERT( command != NULL );
+            
+            commands::BytesMessageCommand* bytesMessage = 
+                dynamic_cast< commands::BytesMessageCommand* >( command );
+
+            CPPUNIT_ASSERT( bytesMessage != NULL );
+
+            CPPUNIT_ASSERT( bytesMessage->getBodyBytes() != NULL );
+            std::string bytesText( 
+                (const char*)bytesMessage->getBodyBytes(), 
+                (int)bytesMessage->getBodyLength() );
+            CPPUNIT_ASSERT( bytesText == "123456789" );
+
+        }
+        
+    };
+
+}}}
+
+#endif /*_ACTIVEMQ_CONNECTOR_STOMP_STOMPCOMMANDREADERTEST_H_*/

Added: incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompCommandWriterTest.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompCommandWriterTest.cpp?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompCommandWriterTest.cpp (added)
+++ incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompCommandWriterTest.cpp Mon Jul  3 04:51:36 2006
@@ -0,0 +1,3 @@
+#include "StompCommandWriterTest.h"
+
+CPPUNIT_TEST_SUITE_REGISTRATION( activemq::connector::stomp::StompCommandWriterTest );

Added: incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompCommandWriterTest.h
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompCommandWriterTest.h?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompCommandWriterTest.h (added)
+++ incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompCommandWriterTest.h Mon Jul  3 04:51:36 2006
@@ -0,0 +1,102 @@
+#ifndef _ACTIVEMQ_CONNECTOR_STOMP_STOMPCOMMANDWRITERTEST_H_
+#define _ACTIVEMQ_CONNECTOR_STOMP_STOMPCOMMANDWRITERTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <activemq/connector/stomp/StompCommandWriter.h>
+#include <activemq/transport/Command.h>
+#include <activemq/connector/stomp/commands/ConnectedCommand.h>
+#include <activemq/connector/stomp/commands/TextMessageCommand.h>
+#include <activemq/connector/stomp/commands/BytesMessageCommand.h>
+#include <activemq/connector/stomp/StompTopic.h>
+
+#include <activemq/io/ByteArrayOutputStream.h>
+#include <algorithm>
+
+namespace activemq{
+namespace connector{
+namespace stomp{
+
+    class StompCommandWriterTest : public CppUnit::TestFixture
+    {
+        CPPUNIT_TEST_SUITE( StompCommandWriterTest );
+        CPPUNIT_TEST( test );
+        CPPUNIT_TEST_SUITE_END();
+
+    public:
+    
+    	StompCommandWriterTest() {}
+    	virtual ~StompCommandWriterTest() {}
+    
+        void test( void )
+        {
+            io::ByteArrayOutputStream boStream;
+
+            StompCommandWriter writer( &boStream );
+
+            const char* result = 
+                "CONNECTED\nsession:test\n\n\0\n"   // 26 = 26
+                "SEND\n"                            // 5
+                "destination:/topic/a\n"            // 21
+                "message-id:123\n"                  // 15
+                "sampleProperty:testvalue\n\n"      // 26
+                "testMessage\0\n"                   // 13 = 80
+                "SEND\n"                            // 5
+                "content-length:9\n"                // 17
+                "destination:/topic/a\n"            // 21
+                "message-id:123\n"                  // 15
+                "sampleProperty:testvalue\n\n"      // 26
+                "123456789\0\n";                    // 11 = 95
+                                                    //      201
+            commands::ConnectedCommand connectedCommand;
+            commands::TextMessageCommand textCommand;
+            commands::BytesMessageCommand bytesCommand;
+            
+            // Sync to expected output
+            connectedCommand.setSessionId( "test" );
+
+            // Sync to expected output
+            textCommand.setCMSDestination( StompTopic("a") );
+            textCommand.setCMSMessageId( "123" );
+            textCommand.getProperties().setProperty( 
+                "sampleProperty", "testvalue" );
+            textCommand.setText( "testMessage" );
+
+            // Sync to expected output
+            bytesCommand.setCMSDestination( StompTopic("a") );
+            bytesCommand.setCMSMessageId( "123" );
+            bytesCommand.getProperties().setProperty( 
+                "sampleProperty", "testvalue" );
+            bytesCommand.setBodyBytes( 
+                (const unsigned char*)"123456789", 9 );
+
+            writer.writeCommand( &connectedCommand );
+            writer.writeCommand( &textCommand );
+            writer.writeCommand( &bytesCommand );
+
+            const unsigned char* alloc = boStream.getByteArray();
+
+            //for( int i = 0; i < 201; ++i )
+            //{
+            //    std::cout << result[i] << " == " << alloc[i] << std::endl;
+            //}
+
+            CPPUNIT_ASSERT( boStream.getByteArraySize() == 201 );
+
+            for( int i = 0; i < 201; ++i )
+            {
+                CPPUNIT_ASSERT( result[i] == alloc[i] );
+            }
+
+            // Use STL Compare
+            CPPUNIT_ASSERT( 
+                std::equal( &result[0], &result[200], 
+                            boStream.getByteArray() ) );
+        }
+
+    };
+
+}}}
+
+#endif /*_ACTIVEMQ_CONNECTOR_STOMP_STOMPCOMMANDWRITERTEST_H_*/

Added: incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompConnectorTest.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompConnectorTest.cpp?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompConnectorTest.cpp (added)
+++ incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompConnectorTest.cpp Mon Jul  3 04:51:36 2006
@@ -0,0 +1,3 @@
+#include "StompConnectorTest.h"
+
+CPPUNIT_TEST_SUITE_REGISTRATION( activemq::connector::stomp::StompConnectorTest );



Mime
View raw message