activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r528222 [4/5] - in /activemq/activemq-cpp/trunk/activemq-cpp/src: examples/ main/ main/activemq/connector/openwire/ main/activemq/connector/openwire/commands/ main/activemq/connector/stomp/ main/activemq/connector/stomp/commands/ main/activ...
Date Thu, 12 Apr 2007 20:29:43 GMT
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/integration/connector/stomp/SimpleTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/integration/connector/stomp/SimpleTest.cpp?view=diff&rev=528222&r1=528221&r2=528222
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/integration/connector/stomp/SimpleTest.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/integration/connector/stomp/SimpleTest.cpp Thu Apr 12 13:29:39 2007
@@ -85,47 +85,47 @@
     {
         TestSupport testSupport("tcp://localhost:61613?wireFormat=stomp");
         testSupport.initialize();
-        
+
         if( IntegrationCommon::debug ) {
             cout << "Starting activemqcms test (sending "
                  << IntegrationCommon::defaultMsgCount
                  << " messages per type and sleeping "
-                 << IntegrationCommon::defaultDelay 
+                 << IntegrationCommon::defaultDelay
                  << " milli-seconds) ...\n"
                  << endl;
         }
-        
+
         // Create CMS Object for Comms
         cms::Session* session = testSupport.getSession();
         cms::Topic* topic = session->createTopic("mytopic");
-        cms::MessageConsumer* consumer = 
-            session->createConsumer( topic );            
+        cms::MessageConsumer* consumer =
+            session->createConsumer( topic );
         consumer->setMessageListener( &testSupport );
-        cms::MessageProducer* producer = 
+        cms::MessageProducer* producer =
             session->createProducer( topic );
 
         // Send some text messages
-        testSupport.produceTextMessages( 
+        testSupport.produceTextMessages(
             *producer, IntegrationCommon::defaultMsgCount );
-        
+
         // Send some bytes messages.
-        testSupport.produceTextMessages( 
+        testSupport.produceTextMessages(
             *producer, IntegrationCommon::defaultMsgCount );
 
         // Wait for the messages to get here
         testSupport.waitForMessages( IntegrationCommon::defaultMsgCount * 2 );
-        
+
         unsigned int numReceived = testSupport.getNumReceived();
         if( IntegrationCommon::debug ) {
             printf("received: %d\n", numReceived );
         }
-        CPPUNIT_ASSERT( 
+        CPPUNIT_ASSERT(
             numReceived == IntegrationCommon::defaultMsgCount * 2 );
 
         if( IntegrationCommon::debug ) {
             printf("Shutting Down\n" );
         }
-        delete producer;                      
+        delete producer;
         delete consumer;
         delete topic;
     }
@@ -138,47 +138,47 @@
     {
         TestSupport testSupport("tcp://localhost:61613?wireFormat=stomp", cms::Session::CLIENT_ACKNOWLEDGE );
         testSupport.initialize();
-        
+
         if( IntegrationCommon::debug ) {
             cout << "Starting activemqcms test (sending "
                  << IntegrationCommon::defaultMsgCount
                  << " messages per type and sleeping "
-                 << IntegrationCommon::defaultDelay 
+                 << IntegrationCommon::defaultDelay
                  << " milli-seconds) ...\n"
                  << endl;
         }
-        
+
         // Create CMS Object for Comms
         cms::Session* session = testSupport.getSession();
         cms::Topic* topic = session->createTopic("mytopic");
-        cms::MessageConsumer* consumer = 
-            session->createConsumer( topic );            
+        cms::MessageConsumer* consumer =
+            session->createConsumer( topic );
         consumer->setMessageListener( &testSupport );
-        cms::MessageProducer* producer = 
+        cms::MessageProducer* producer =
             session->createProducer( topic );
 
         // Send some text messages
-        testSupport.produceTextMessages( 
+        testSupport.produceTextMessages(
             *producer, IntegrationCommon::defaultMsgCount );
-        
+
         // Send some bytes messages.
-        testSupport.produceTextMessages( 
+        testSupport.produceTextMessages(
             *producer, IntegrationCommon::defaultMsgCount );
 
         // Wait for the messages to get here
         testSupport.waitForMessages( IntegrationCommon::defaultMsgCount * 2 );
-        
+
         unsigned int numReceived = testSupport.getNumReceived();
         if( IntegrationCommon::debug ) {
             printf("received: %d\n", numReceived );
         }
-        CPPUNIT_ASSERT( 
+        CPPUNIT_ASSERT(
             numReceived == IntegrationCommon::defaultMsgCount * 2 );
 
         if( IntegrationCommon::debug ) {
             printf("Shutting Down\n" );
         }
-        delete producer;                      
+        delete producer;
         delete consumer;
         delete topic;
     }
@@ -191,33 +191,33 @@
     {
         TestSupport testSupport("tcp://localhost:61613?wireFormat=stomp", cms::Session::CLIENT_ACKNOWLEDGE );
         testSupport.initialize();
-        
+
         if( IntegrationCommon::debug ) {
             cout << "Starting activemqcms test (sending "
                  << IntegrationCommon::defaultMsgCount
                  << " messages per type and sleeping "
-                 << IntegrationCommon::defaultDelay 
+                 << IntegrationCommon::defaultDelay
                  << " milli-seconds) ...\n"
                  << endl;
         }
-        
+
         // Create CMS Object for Comms
         cms::Session* session = testSupport.getSession();
         cms::Topic* topic = session->createTopic(Guid::createGUIDString());
-        cms::MessageConsumer* consumer =  session->createConsumer( topic );            
+        cms::MessageConsumer* consumer =  session->createConsumer( topic );
         consumer->setMessageListener( &testSupport );
         cms::MessageProducer* producer = session->createProducer( NULL );
 
         cms::TextMessage* textMsg = session->createTextMessage();
-        
+
         // Send some text messages
         producer->send( topic, textMsg );
-        
+
         delete textMsg;
 
         // Wait for the messages to get here
         testSupport.waitForMessages( 1 );
-        
+
         unsigned int numReceived = testSupport.getNumReceived();
         if( IntegrationCommon::debug ) {
             printf("received: %d\n", numReceived );
@@ -227,7 +227,7 @@
         if( IntegrationCommon::debug ) {
             printf("Shutting Down\n" );
         }
-        delete producer;                      
+        delete producer;
         delete consumer;
         delete topic;
     }
@@ -238,18 +238,61 @@
 {
     try
     {
+        TestSupport testSupport("tcp://localhost:61613?wireFormat=stomp", cms::Session::AUTO_ACKNOWLEDGE );
+        testSupport.initialize();
+
+        if( IntegrationCommon::debug ) {
+            cout << "Starting activemqcms test (sending "
+                 << IntegrationCommon::defaultMsgCount
+                 << " messages per type and sleeping "
+                 << IntegrationCommon::defaultDelay
+                 << " milli-seconds) ...\n"
+                 << endl;
+        }
+
+        // Create CMS Object for Comms
+        cms::Session* session = testSupport.getSession();
+        cms::Topic* topic = session->createTopic(Guid::createGUIDString());
+        cms::MessageConsumer* consumer = session->createConsumer( topic );
+        cms::MessageProducer* producer = session->createProducer( topic );
+
+        cms::TextMessage* textMsg = session->createTextMessage();
+
+        // Send some text messages
+        producer->send( textMsg );
+
+        delete textMsg;
+
+        cms::Message* message = consumer->receive(1000);
+        CPPUNIT_ASSERT( message != NULL );
+        delete message;
+
+        if( IntegrationCommon::debug ) {
+            printf("Shutting Down\n" );
+        }
+        delete producer;
+        delete consumer;
+        delete topic;
+    }
+    AMQ_CATCH_RETHROW( ActiveMQException )
+}
+
+void SimpleTest::testSyncReceiveClientAck()
+{
+    try
+    {
         TestSupport testSupport("tcp://localhost:61613?wireFormat=stomp", cms::Session::CLIENT_ACKNOWLEDGE );
         testSupport.initialize();
-        
+
         if( IntegrationCommon::debug ) {
             cout << "Starting activemqcms test (sending "
                  << IntegrationCommon::defaultMsgCount
                  << " messages per type and sleeping "
-                 << IntegrationCommon::defaultDelay 
+                 << IntegrationCommon::defaultDelay
                  << " milli-seconds) ...\n"
                  << endl;
         }
-        
+
         // Create CMS Object for Comms
         cms::Session* session = testSupport.getSession();
         cms::Topic* topic = session->createTopic(Guid::createGUIDString());
@@ -257,20 +300,21 @@
         cms::MessageProducer* producer = session->createProducer( topic );
 
         cms::TextMessage* textMsg = session->createTextMessage();
-        
+
         // Send some text messages
         producer->send( textMsg );
-        
+
         delete textMsg;
 
         cms::Message* message = consumer->receive(1000);
         CPPUNIT_ASSERT( message != NULL );
+        message->acknowledge();
         delete message;
 
         if( IntegrationCommon::debug ) {
             printf("Shutting Down\n" );
         }
-        delete producer;                      
+        delete producer;
         delete consumer;
         delete topic;
     }
@@ -281,48 +325,48 @@
 {
     try
     {
-        
+
         if( IntegrationCommon::debug ) {
             cout << "Starting activemqcms test (sending "
                  << IntegrationCommon::defaultMsgCount
                  << " messages per type and sleeping "
-                 << IntegrationCommon::defaultDelay 
+                 << IntegrationCommon::defaultDelay
                  << " milli-seconds) ...\n"
                  << endl;
         }
-        
+
         // Create CMS Object for Comms
         cms::ConnectionFactory* factory = new ActiveMQConnectionFactory("tcp://localhost:61613?wireFormat=stomp");
         cms::Connection* connection1 = factory->createConnection();
         connection1->start();
-        
+
         cms::Connection* connection2 = factory->createConnection();
         connection2->start();
-        
+
         CPPUNIT_ASSERT( connection1->getClientID() != connection2->getClientID() );
-        
+
         cms::Session* session1 = connection1->createSession();
         cms::Session* session2 = connection2->createSession();
-        
+
         cms::Topic* topic = session1->createTopic(Guid::createGUIDString());
-        
-        
+
+
         cms::MessageConsumer* consumer1 = session1->createConsumer( topic );
         cms::MessageConsumer* consumer2 = session2->createConsumer( topic );
-        
+
         cms::MessageProducer* producer = session2->createProducer( topic );
 
         cms::TextMessage* textMsg = session2->createTextMessage();
-        
+
         // Send some text messages
         producer->send( textMsg );
-        
+
         delete textMsg;
 
         cms::Message* message = consumer1->receive(1000);
         CPPUNIT_ASSERT( message != NULL );
         delete message;
-        
+
         message = consumer2->receive(1000);
         CPPUNIT_ASSERT( message != NULL );
         delete message;
@@ -330,11 +374,11 @@
         if( IntegrationCommon::debug ) {
             printf("Shutting Down\n" );
         }
-        
+
         connection1->close();
         connection2->close();
-        
-        delete producer;                      
+
+        delete producer;
         delete consumer1;
         delete consumer2;
         delete topic;
@@ -351,42 +395,42 @@
 {
     try
     {
-        
+
         if( IntegrationCommon::debug ) {
             cout << "Starting activemqcms test (sending "
                  << IntegrationCommon::defaultMsgCount
                  << " messages per type and sleeping "
-                 << IntegrationCommon::defaultDelay 
+                 << IntegrationCommon::defaultDelay
                  << " milli-seconds) ...\n"
                  << endl;
         }
-        
+
         // Create CMS Object for Comms
         cms::ConnectionFactory* factory = new ActiveMQConnectionFactory("tcp://localhost:61613?wireFormat=stomp");
         cms::Connection* connection = factory->createConnection();
         connection->start();
-        
+
         cms::Session* session1 = connection->createSession();
         cms::Session* session2 = connection->createSession();
-        
+
         cms::Topic* topic = session1->createTopic(Guid::createGUIDString());
-        
+
         cms::MessageConsumer* consumer1 = session1->createConsumer( topic );
         cms::MessageConsumer* consumer2 = session2->createConsumer( topic );
-        
+
         cms::MessageProducer* producer = session2->createProducer( topic );
 
         cms::TextMessage* textMsg = session2->createTextMessage();
-        
+
         // Send some text messages
         producer->send( textMsg );
-        
+
         delete textMsg;
 
         cms::Message* message = consumer1->receive(1000);
         CPPUNIT_ASSERT( message != NULL );
         delete message;
-        
+
         message = consumer2->receive(1000);
         CPPUNIT_ASSERT( message != NULL );
         delete message;
@@ -394,10 +438,10 @@
         if( IntegrationCommon::debug ) {
             printf("Shutting Down\n" );
         }
-        
+
         connection->close();
-        
-        delete producer;                      
+
+        delete producer;
         delete consumer1;
         delete consumer2;
         delete topic;
@@ -410,40 +454,40 @@
 }
 
 void SimpleTest::testReceiveAlreadyInQueue() {
-    
+
         try
     {
-        
+
         if( IntegrationCommon::debug ) {
             cout << "Starting activemqcms test (sending "
                  << IntegrationCommon::defaultMsgCount
                  << " messages per type and sleeping "
-                 << IntegrationCommon::defaultDelay 
+                 << IntegrationCommon::defaultDelay
                  << " milli-seconds) ...\n"
                  << endl;
         }
-        
+
         // Create CMS Object for Comms
         cms::ConnectionFactory* factory = new ActiveMQConnectionFactory("tcp://localhost:61613?wireFormat=stomp");
         cms::Connection* connection = factory->createConnection();
 
         cms::Session* session = connection->createSession();
-        
+
         cms::Topic* topic = session->createTopic(Guid::createGUIDString());
-        
+
         cms::MessageConsumer* consumer = session->createConsumer( topic );
-        
+
         cms::MessageProducer* producer = session->createProducer( topic );
 
         cms::TextMessage* textMsg = session->createTextMessage();
-        
+
         // Send some text messages
         producer->send( textMsg );
-        
+
         delete textMsg;
-        
+
         Thread::sleep( 100 );
-        
+
         connection->start();
 
         cms::Message* message = consumer->receive(1000);
@@ -453,10 +497,10 @@
         if( IntegrationCommon::debug ) {
             printf("Shutting Down\n" );
         }
-        
+
         connection->close();
-        
-        delete producer;                      
+
+        delete producer;
         delete consumer;
         delete topic;
         delete session;

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/integration/connector/stomp/SimpleTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/integration/connector/stomp/SimpleTest.h?view=diff&rev=528222&r1=528221&r2=528222
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/integration/connector/stomp/SimpleTest.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/integration/connector/stomp/SimpleTest.h Thu Apr 12 13:29:39 2007
@@ -26,7 +26,7 @@
 namespace integration{
 namespace connector{
 namespace stomp{
-    
+
     class SimpleTest : public CppUnit::TestFixture
     {
         CPPUNIT_TEST_SUITE( SimpleTest );
@@ -34,20 +34,22 @@
         CPPUNIT_TEST( testClientAck );
         CPPUNIT_TEST( testProducerWithNullDestination );
         CPPUNIT_TEST( testSyncReceive );
+        CPPUNIT_TEST( testSyncReceiveClientAck );
         CPPUNIT_TEST( testMultipleConnections );
         CPPUNIT_TEST( testMultipleSessions );
         CPPUNIT_TEST( testReceiveAlreadyInQueue );
         CPPUNIT_TEST_SUITE_END();
-        
+
     public:
 
-    	SimpleTest();
-    	virtual ~SimpleTest();
+        SimpleTest();
+        virtual ~SimpleTest();
 
         virtual void testAutoAck();
         virtual void testClientAck();
         virtual void testProducerWithNullDestination();
         virtual void testSyncReceive();
+        virtual void testSyncReceiveClientAck();
         virtual void testMultipleConnections();
         virtual void testMultipleSessions();
         virtual void testReceiveAlreadyInQueue();

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am?view=diff&rev=528222&r1=528221&r2=528222
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am Thu Apr 12 13:29:39 2007
@@ -38,6 +38,7 @@
   activemq/connector/stomp/commands/TextMessageCommandTest.cpp \
   activemq/connector/stomp/commands/UnsubscribeCommandTest.cpp \
   activemq/connector/stomp/marshal/MarshalerTest.cpp \
+  activemq/connector/stomp/StompResponseBuilder.cpp \
   activemq/connector/stomp/StompCommandReaderTest.cpp \
   activemq/connector/stomp/StompCommandWriterTest.cpp \
   activemq/connector/stomp/StompConnectorTest.cpp \
@@ -76,9 +77,10 @@
   activemq/logger/LoggerTest.cpp \
   activemq/network/SocketFactoryTest.cpp \
   activemq/network/SocketTest.cpp \
+  activemq/transport/DummyTransport.cpp \
   activemq/transport/DummyTransportFactory.cpp \
   activemq/transport/IOTransportTest.cpp \
-  activemq/transport/ResponseCorrelatorTest.cpp \
+  activemq/transport/filters/ResponseCorrelatorTest.cpp \
   activemq/transport/TransportFactoryMapRegistrarTest.cpp \
   activemq/transport/TransportFactoryMapTest.cpp \
   activemq/util/BooleanTest.cpp \

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompResponseBuilder.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompResponseBuilder.cpp?view=auto&rev=528222
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompResponseBuilder.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompResponseBuilder.cpp Thu Apr 12 13:29:39 2007
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "StompResponseBuilder.h"
+
+#include <activemq/connector/stomp/commands/ConnectCommand.h>
+#include <activemq/connector/stomp/commands/ConnectedCommand.h>
+
+using namespace activemq;
+using namespace activemq::connector;
+using namespace activemq::connector::stomp;
+using namespace activemq::transport;
+
+////////////////////////////////////////////////////////////////////////////////
+Response* StompResponseBuilder::buildResponse( const transport::Command* cmd ){
+
+    const commands::ConnectCommand* connectCommand =
+        dynamic_cast<const commands::ConnectCommand*>(cmd);
+
+    if( connectCommand != NULL ){
+        commands::ConnectedCommand* resp = new commands::ConnectedCommand();
+        resp->setCorrelationId( connectCommand->getCommandId() );
+
+        if( connectCommand->getClientId() == NULL )
+        {
+            resp->setSessionId( sessionId );
+        }
+        else
+        {
+            resp->setSessionId( connectCommand->getClientId() );
+        }
+
+        return resp;
+    }
+
+    // If this command requires a response we don't know what it is
+    // so we throw an exception.
+    if( cmd->isResponseRequired() ) {
+
+        throw transport::CommandIOException( __FILE__, __LINE__,
+            "StompResponseBuilder - unrecognized command" );
+    }
+
+    return NULL;
+}

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompResponseBuilder.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompResponseBuilder.h?view=diff&rev=528222&r1=528221&r2=528222
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompResponseBuilder.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompResponseBuilder.h Thu Apr 12 13:29:39 2007
@@ -19,53 +19,29 @@
 #define ACTIVEMQ_CONNECTOR_STOMP_STOMPRESPONSEBUILDER_H_
 
 #include <activemq/transport/DummyTransport.h>
-#include <activemq/connector/stomp/commands/ConnectCommand.h>
-#include <activemq/connector/stomp/commands/ConnectedCommand.h>
 
 namespace activemq{
 namespace connector{
 namespace stomp{
-    
+
     class StompResponseBuilder : public transport::DummyTransport::ResponseBuilder{
-        
+
     private:
-    
+
         std::string sessionId;
-        
+
     public:
-    
+
         StompResponseBuilder( const std::string& sessionId ){
             this->sessionId = sessionId;
         }
-        
+
         virtual ~StompResponseBuilder(){}
-        
-        virtual transport::Response* buildResponse( const transport::Command* cmd ){
-            
-            const commands::ConnectCommand* connectCommand = 
-                dynamic_cast<const commands::ConnectCommand*>(cmd);
-                
-            if( connectCommand != NULL ){
-                commands::ConnectedCommand* resp = new commands::ConnectedCommand();
-                resp->setCorrelationId( connectCommand->getCommandId() );
-
-                if( connectCommand->getClientId() == NULL )
-                {
-                    resp->setSessionId( sessionId );
-                }
-                else
-                {
-                    resp->setSessionId( connectCommand->getClientId() );
-                }
-
-                return resp;                
-            }
-            
-            throw transport::CommandIOException( __FILE__, __LINE__,
-                "StompResponseBuilder - unrecognized command" );
-        }
+
+        virtual transport::Response* buildResponse( const transport::Command* cmd );
+
     };
-    
+
 }}}
 
 #endif /*ACTIVEMQ_CONNECTOR_STOMP_STOMPRESPONSEBUILDER_H_*/

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQConnectionFactoryTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQConnectionFactoryTest.cpp?view=diff&rev=528222&r1=528221&r2=528222
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQConnectionFactoryTest.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQConnectionFactoryTest.cpp Thu Apr 12 13:29:39 2007
@@ -18,3 +18,87 @@
 #include "ActiveMQConnectionFactoryTest.h"
 
 CPPUNIT_TEST_SUITE_REGISTRATION( activemq::core::ActiveMQConnectionFactoryTest );
+
+#include <activemq/concurrent/Concurrent.h>
+#include <activemq/concurrent/Mutex.h>
+#include <activemq/concurrent/Thread.h>
+#include <activemq/core/ActiveMQConnectionFactory.h>
+#include <activemq/core/ActiveMQConnection.h>
+#include <cms/Connection.h>
+#include <activemq/transport/TransportFactoryMapRegistrar.h>
+#include <activemq/transport/DummyTransportFactory.h>
+#include <activemq/connector/Connector.h>
+
+using namespace activemq;
+using namespace activemq::core;
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQConnectionFactoryTest::test()
+{
+    try
+    {
+        transport::TransportFactoryMapRegistrar registrar(
+            "dummy", new transport::DummyTransportFactory() );
+
+        std::string URI =
+            "dummy://127.0.0.1:23232&wireFormat=stomp";
+
+        ActiveMQConnectionFactory connectionFactory( URI );
+
+        cms::Connection* connection =
+            connectionFactory.createConnection();
+
+        CPPUNIT_ASSERT( connection != NULL );
+
+        delete connection;
+
+        return;
+    }
+    AMQ_CATCH_NOTHROW( exceptions::ActiveMQException )
+    AMQ_CATCHALL_NOTHROW( )
+
+    CPPUNIT_ASSERT( false );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQConnectionFactoryTest::test2()
+{
+    try
+    {
+        transport::TransportFactoryMapRegistrar registrar(
+            "dummy", new transport::DummyTransportFactory() );
+
+        std::string URI = std::string() +
+            "dummy://127.0.0.1:23232&wireFormat=stomp?"
+            "username=" + username + "?password=" + password +
+            "?client-id=" + clientId;
+
+        ActiveMQConnectionFactory connectionFactory( URI );
+
+        cms::Connection* connection =
+            connectionFactory.createConnection();
+        CPPUNIT_ASSERT( connection != NULL );
+
+        ActiveMQConnection* amqConnection =
+            dynamic_cast< ActiveMQConnection* >( connection );
+        CPPUNIT_ASSERT( amqConnection != NULL );
+
+        connector::Connector* connector =
+            dynamic_cast< connector::Connector* >(
+            amqConnection->getConnectionData()->getConnector() );
+        CPPUNIT_ASSERT( connector != NULL );
+
+        CPPUNIT_ASSERT( username == connector->getUsername() );
+        CPPUNIT_ASSERT( password == connector->getPassword() );
+        CPPUNIT_ASSERT( clientId == connector->getClientId() );
+
+        // Free the allocated connection object.
+        delete connection;
+
+        return;
+    }
+    AMQ_CATCH_NOTHROW( exceptions::ActiveMQException )
+    AMQ_CATCHALL_NOTHROW( )
+
+    CPPUNIT_ASSERT( false );
+}

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQConnectionFactoryTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQConnectionFactoryTest.h?view=diff&rev=528222&r1=528221&r2=528222
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQConnectionFactoryTest.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQConnectionFactoryTest.h Thu Apr 12 13:29:39 2007
@@ -21,18 +21,6 @@
 #include <cppunit/TestFixture.h>
 #include <cppunit/extensions/HelperMacros.h>
 
-#include <activemq/network/Socket.h>
-#include <activemq/network/ServerSocket.h>
-#include <activemq/concurrent/Concurrent.h>
-#include <activemq/concurrent/Mutex.h>
-#include <activemq/concurrent/Thread.h>
-#include <activemq/core/ActiveMQConnectionFactory.h>
-#include <activemq/core/ActiveMQConnection.h>
-#include <cms/Connection.h>
-#include <activemq/transport/TransportFactoryMapRegistrar.h>
-#include <activemq/transport/DummyTransportFactory.h>
-#include <activemq/connector/Connector.h>
-
 namespace activemq{
 namespace core{
 
@@ -49,84 +37,17 @@
         std::string password;
         std::string clientId;
 
-    	ActiveMQConnectionFactoryTest(){
+        ActiveMQConnectionFactoryTest(){
             username = "timmy";
             password = "auth";
             clientId = "12345";
         }
-    	virtual ~ActiveMQConnectionFactoryTest() {}
-        
-        void test()
-        {
-            try
-            {
-                transport::TransportFactoryMapRegistrar registrar(
-                    "dummy", new transport::DummyTransportFactory() );
-                    
-                std::string URI = 
-                    "dummy://127.0.0.1:23232&wireFormat=stomp";
-
-                ActiveMQConnectionFactory connectionFactory( URI );
-
-                cms::Connection* connection = 
-                    connectionFactory.createConnection();
-
-                CPPUNIT_ASSERT( connection != NULL );
-                
-                delete connection;
-                
-                return;
-            }
-            AMQ_CATCH_NOTHROW( exceptions::ActiveMQException )
-            AMQ_CATCHALL_NOTHROW( )
-            
-            CPPUNIT_ASSERT( false );
-        }
-        
-        void test2()
-        {
-            try
-            {
-                transport::TransportFactoryMapRegistrar registrar(
-                    "dummy", new transport::DummyTransportFactory() );
-                
-                std::string URI = std::string() + 
-                    "dummy://127.0.0.1:23232&wireFormat=stomp?"
-                    "username=" + username + "?password=" + password + 
-                    "?client-id=" + clientId;
-
-                ActiveMQConnectionFactory connectionFactory( URI );
-
-                cms::Connection* connection = 
-                    connectionFactory.createConnection();
-                CPPUNIT_ASSERT( connection != NULL );                
-
-                ActiveMQConnection* amqConnection = 
-                    dynamic_cast< ActiveMQConnection* >( connection );
-                CPPUNIT_ASSERT( amqConnection != NULL );
-
-                connector::Connector* connector = 
-                    dynamic_cast< connector::Connector* >( 
-                    amqConnection->getConnectionData()->getConnector() );
-                CPPUNIT_ASSERT( connector != NULL );
-
-                CPPUNIT_ASSERT( username == connector->getUsername() );
-                CPPUNIT_ASSERT( password == connector->getPassword() );
-                CPPUNIT_ASSERT( clientId == connector->getClientId() );
-
-                // Free the allocated connection object.
-                delete connection;
-                
-                return;
-            }
-            AMQ_CATCH_NOTHROW( exceptions::ActiveMQException )
-            AMQ_CATCHALL_NOTHROW( )
-            
-            CPPUNIT_ASSERT( false );
-        }
+        virtual ~ActiveMQConnectionFactoryTest() {}
 
+        void test();
+        void test2();
     };
-    
+
 }}
 
 #endif /*_ACTIVEMQ_CORE_ACTIVEMQCONNECTIONFACTORYTEST_H_*/

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQConnectionTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQConnectionTest.cpp?view=diff&rev=528222&r1=528221&r2=528222
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQConnectionTest.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQConnectionTest.cpp Thu Apr 12 13:29:39 2007
@@ -19,3 +19,164 @@
 
 CPPUNIT_TEST_SUITE_REGISTRATION( activemq::core::ActiveMQConnectionTest );
 
+#include <activemq/concurrent/Concurrent.h>
+#include <activemq/concurrent/Mutex.h>
+#include <activemq/concurrent/Thread.h>
+#include <activemq/core/ActiveMQConnectionFactory.h>
+#include <activemq/transport/DummyTransport.h>
+#include <activemq/core/ActiveMQConnection.h>
+#include <activemq/core/ActiveMQConnectionData.h>
+#include <activemq/connector/stomp/StompConnector.h>
+#include <activemq/util/SimpleProperties.h>
+#include <activemq/transport/DummyTransportFactory.h>
+#include <activemq/transport/TransportFactoryMap.h>
+#include <activemq/transport/TransportFactoryMapRegistrar.h>
+#include <activemq/connector/stomp/StompConsumerInfo.h>
+#include <activemq/connector/stomp/StompProducerInfo.h>
+#include <activemq/connector/stomp/StompTransactionInfo.h>
+#include <activemq/connector/stomp/StompSessionInfo.h>
+#include <activemq/connector/stomp/StompTopic.h>
+#include <activemq/connector/stomp/commands/TextMessageCommand.h>
+#include <activemq/util/Config.h>
+
+using namespace activemq;
+using namespace activemq::core;
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQConnectionTest::test()
+{
+    try
+    {
+        transport::TransportFactoryMapRegistrar registrar(
+            "dummy", new transport::DummyTransportFactory() );
+
+        MyMessageListener listener;
+        MyExceptionListener exListener;
+        MyCommandListener cmdListener;
+        MyDispatcher msgListener;
+        std::string connectionId = "testConnectionId";
+        util::SimpleProperties* properties =
+            new util::SimpleProperties();
+        transport::Transport* transport = NULL;
+
+        transport::TransportFactory* factory =
+            transport::TransportFactoryMap::getInstance().lookup(
+                "dummy" );
+        if( factory == NULL ){
+            CPPUNIT_ASSERT( false );
+        }
+
+        // Create the transport.
+        transport = factory->createTransport( *properties );
+        if( transport == NULL ){
+            CPPUNIT_ASSERT( false );
+        }
+
+        transport::DummyTransport* dTransport =
+            dynamic_cast< transport::DummyTransport*>( transport );
+
+        CPPUNIT_ASSERT( dTransport != NULL );
+
+        dTransport->setCommandListener( &cmdListener );
+
+        connector::stomp::StompConnector* connector =
+            new connector::stomp::StompConnector(
+                transport, *properties );
+
+        connector->start();
+
+        ActiveMQConnection connection(
+            new ActiveMQConnectionData(
+                connector, transport, properties) );
+
+        // First - make sure exceptions are working.
+        connection.setExceptionListener( &exListener );
+        CPPUNIT_ASSERT( exListener.caughtOne == false );
+        dTransport->fireException( exceptions::ActiveMQException( __FILE__, __LINE__, "test" ) );
+        CPPUNIT_ASSERT( exListener.caughtOne == true );
+
+        cms::Session* session1 = connection.createSession();
+        cms::Session* session2 = connection.createSession();
+        cms::Session* session3 = connection.createSession();
+
+        CPPUNIT_ASSERT( session1 != NULL );
+        CPPUNIT_ASSERT( session2 != NULL );
+        CPPUNIT_ASSERT( session3 != NULL );
+
+        connector::stomp::StompSessionInfo session;
+        connector::stomp::StompConsumerInfo consumer;
+
+        session.setSessionId( 1 );
+        session.setConnectionId( "TEST:123" );
+        session.setAckMode( cms::Session::AUTO_ACKNOWLEDGE );
+
+        connector::stomp::StompTopic myTopic( "test" );
+        consumer.setConsumerId( 1 );
+        consumer.setSessionInfo( &session );
+        consumer.setDestination( &myTopic );
+
+        connection.addDispatcher( &consumer, &msgListener );
+
+        connector::stomp::commands::TextMessageCommand* cmd =
+            new connector::stomp::commands::TextMessageCommand;
+        connector::stomp::StompTopic topic1( "test" );
+        cmd->setCMSDestination( &topic1 );
+
+        connector::ConsumerMessageListener* consumerListener =
+            dynamic_cast< connector::ConsumerMessageListener* >(
+                &connection );
+
+        connection.start();
+
+        CPPUNIT_ASSERT( consumerListener != NULL );
+
+        consumerListener->onConsumerMessage( &consumer, cmd );
+
+        CPPUNIT_ASSERT_EQUAL( 1, (int)msgListener.messages.size() );
+
+        connection.removeDispatcher( &consumer );
+
+        msgListener.messages.clear();
+        consumerListener->onConsumerMessage( &consumer, cmd );
+
+        CPPUNIT_ASSERT_EQUAL( 0, (int)msgListener.messages.size() );
+
+        connection.addDispatcher( &consumer, &msgListener );
+
+        connection.stop();
+        consumerListener->onConsumerMessage( &consumer, cmd );
+        connection.start();
+        CPPUNIT_ASSERT_EQUAL( 1, (int)msgListener.messages.size() );
+
+        delete cmd;
+        cmd = new connector::stomp::commands::TextMessageCommand;
+
+        connector::stomp::StompTopic topic2( "test" );
+        cmd->setCMSDestination( &topic2 );
+
+        consumerListener->onConsumerMessage( &consumer, cmd );
+        CPPUNIT_ASSERT_EQUAL( 2, (int)msgListener.messages.size() );
+
+        connection.removeDispatcher( &consumer );
+        msgListener.messages.clear();
+
+        session1->close();
+        session2->close();
+        session3->close();
+        connection.close();
+
+        exListener.caughtOne = false;
+        consumerListener->onConsumerMessage( &consumer, cmd );
+        CPPUNIT_ASSERT( exListener.caughtOne == true );
+
+        delete cmd;
+
+        delete session1;
+        delete session2;
+        delete session3;
+
+    } catch( exceptions::ActiveMQException& ex ) {
+        ex.printStackTrace();
+        throw ex;
+    }
+}

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQConnectionTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQConnectionTest.h?view=diff&rev=528222&r1=528221&r2=528222
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQConnectionTest.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQConnectionTest.h Thu Apr 12 13:29:39 2007
@@ -21,30 +21,16 @@
 #include <cppunit/TestFixture.h>
 #include <cppunit/extensions/HelperMacros.h>
 
-#include <activemq/network/Socket.h>
-#include <activemq/network/ServerSocket.h>
-#include <activemq/concurrent/Concurrent.h>
-#include <activemq/concurrent/Mutex.h>
-#include <activemq/concurrent/Thread.h>
-#include <activemq/core/ActiveMQConnectionFactory.h>
 #include <cms/Connection.h>
-#include <activemq/transport/DummyTransport.h>
-#include <activemq/core/ActiveMQConnection.h>
-#include <activemq/core/ActiveMQConnectionData.h>
+#include <cms/ExceptionListener.h>
+
+#include <activemq/core/ActiveMQMessage.h>
 #include <activemq/connector/ConsumerMessageListener.h>
 #include <activemq/connector/ConsumerInfo.h>
-#include <activemq/connector/stomp/StompConnector.h>
-#include <activemq/util/SimpleProperties.h>
-#include <activemq/transport/DummyTransportFactory.h>
-#include <activemq/transport/TransportFactoryMap.h>
-#include <activemq/transport/TransportFactoryMapRegistrar.h>
-#include <activemq/connector/stomp/StompConsumerInfo.h>
-#include <activemq/connector/stomp/StompProducerInfo.h>
-#include <activemq/connector/stomp/StompTransactionInfo.h>
-#include <activemq/connector/stomp/StompSessionInfo.h>
-#include <activemq/connector/stomp/StompTopic.h>
-#include <activemq/connector/stomp/commands/TextMessageCommand.h>
+#include <activemq/transport/Transport.h>
+#include <activemq/transport/CommandListener.h>
 #include <activemq/util/Config.h>
+#include <activemq/core/ActiveMQConnection.h>
 
 namespace activemq{
 namespace core{
@@ -57,8 +43,8 @@
 
     public:
 
-    	ActiveMQConnectionTest() {};
-    	virtual ~ActiveMQConnectionTest() {}
+        ActiveMQConnectionTest() {};
+        virtual ~ActiveMQConnectionTest() {}
 
         class MyCommandListener : public transport::CommandListener{
         public:
@@ -126,143 +112,7 @@
             }
         };
 
-        void test()
-        {
-            try
-            {
-                transport::TransportFactoryMapRegistrar registrar(
-                    "dummy", new transport::DummyTransportFactory() );
-
-                MyMessageListener listener;
-                MyExceptionListener exListener;
-                MyCommandListener cmdListener;
-                MyDispatcher msgListener;
-                std::string connectionId = "testConnectionId";
-                util::SimpleProperties* properties =
-                    new util::SimpleProperties();
-                transport::Transport* transport = NULL;
-
-                transport::TransportFactory* factory =
-                    transport::TransportFactoryMap::getInstance().lookup(
-                        "dummy" );
-                if( factory == NULL ){
-                    CPPUNIT_ASSERT( false );
-                }
-
-                // Create the transport.
-                transport = factory->createTransport( *properties );
-                if( transport == NULL ){
-                    CPPUNIT_ASSERT( false );
-                }
-
-                transport::DummyTransport* dTransport =
-                    dynamic_cast< transport::DummyTransport*>( transport );
-
-                CPPUNIT_ASSERT( dTransport != NULL );
-
-                dTransport->setCommandListener( &cmdListener );
-
-                connector::stomp::StompConnector* connector =
-                    new connector::stomp::StompConnector(
-                        transport, *properties );
-
-                connector->start();
-
-                ActiveMQConnection connection(
-                    new ActiveMQConnectionData(
-                        connector, transport, properties) );
-
-                // First - make sure exceptions are working.
-                connection.setExceptionListener( &exListener );
-                CPPUNIT_ASSERT( exListener.caughtOne == false );
-                dTransport->fireException( exceptions::ActiveMQException( __FILE__, __LINE__, "test" ) );
-                CPPUNIT_ASSERT( exListener.caughtOne == true );
-
-                cms::Session* session1 = connection.createSession();
-                cms::Session* session2 = connection.createSession();
-                cms::Session* session3 = connection.createSession();
-
-                CPPUNIT_ASSERT( session1 != NULL );
-                CPPUNIT_ASSERT( session2 != NULL );
-                CPPUNIT_ASSERT( session3 != NULL );
-
-                connector::stomp::StompSessionInfo session;
-                connector::stomp::StompConsumerInfo consumer;
-
-                session.setSessionId( 1 );
-                session.setConnectionId( "TEST:123" );
-                session.setAckMode( cms::Session::AUTO_ACKNOWLEDGE );
-
-                connector::stomp::StompTopic myTopic( "test" );
-                consumer.setConsumerId( 1 );
-                consumer.setSessionInfo( &session );
-                consumer.setDestination( &myTopic );
-
-                connection.addDispatcher( &consumer, &msgListener );
-
-                connector::stomp::commands::TextMessageCommand* cmd =
-                    new connector::stomp::commands::TextMessageCommand;
-                connector::stomp::StompTopic topic1( "test" );
-                cmd->setCMSDestination( &topic1 );
-
-                connector::ConsumerMessageListener* consumerListener =
-                    dynamic_cast< connector::ConsumerMessageListener* >(
-                        &connection );
-
-                connection.start();
-
-                CPPUNIT_ASSERT( consumerListener != NULL );
-
-                consumerListener->onConsumerMessage( &consumer, cmd );
-
-                CPPUNIT_ASSERT_EQUAL( 1, (int)msgListener.messages.size() );
-
-                connection.removeDispatcher( &consumer );
-
-                msgListener.messages.clear();
-                consumerListener->onConsumerMessage( &consumer, cmd );
-
-                CPPUNIT_ASSERT_EQUAL( 0, (int)msgListener.messages.size() );
-
-                connection.addDispatcher( &consumer, &msgListener );
-
-                connection.stop();
-                consumerListener->onConsumerMessage( &consumer, cmd );
-                connection.start();
-                CPPUNIT_ASSERT_EQUAL( 1, (int)msgListener.messages.size() );
-
-                delete cmd;
-                cmd = new connector::stomp::commands::TextMessageCommand;
-
-                connector::stomp::StompTopic topic2( "test" );
-                cmd->setCMSDestination( &topic2 );
-
-                consumerListener->onConsumerMessage( &consumer, cmd );
-                CPPUNIT_ASSERT_EQUAL( 2, (int)msgListener.messages.size() );
-
-                connection.removeDispatcher( &consumer );
-                msgListener.messages.clear();
-
-                session1->close();
-                session2->close();
-                session3->close();
-                connection.close();
-
-                exListener.caughtOne = false;
-                consumerListener->onConsumerMessage( &consumer, cmd );
-                CPPUNIT_ASSERT( exListener.caughtOne == true );
-
-                delete cmd;
-
-                delete session1;
-                delete session2;
-                delete session3;
-
-            } catch( exceptions::ActiveMQException& ex ) {
-                ex.printStackTrace();
-                throw ex;
-            }
-        }
+        void test();
 
     };
 

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQSessionTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQSessionTest.cpp?view=diff&rev=528222&r1=528221&r2=528222
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQSessionTest.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQSessionTest.cpp Thu Apr 12 13:29:39 2007
@@ -18,3 +18,546 @@
 #include "ActiveMQSessionTest.h"
 
 CPPUNIT_TEST_SUITE_REGISTRATION( activemq::core::ActiveMQSessionTest );
+
+#include <activemq/concurrent/Thread.h>
+#include <activemq/transport/DummyTransportFactory.h>
+#include <activemq/transport/TransportFactoryMap.h>
+#include <activemq/transport/TransportFactoryMapRegistrar.h>
+#include <activemq/connector/ConsumerInfo.h>
+#include <activemq/connector/stomp/StompConnector.h>
+#include <activemq/connector/stomp/StompConsumerInfo.h>
+#include <activemq/connector/stomp/StompProducerInfo.h>
+#include <activemq/connector/stomp/StompTransactionInfo.h>
+#include <activemq/connector/stomp/StompSessionInfo.h>
+#include <activemq/connector/stomp/StompTopic.h>
+#include <activemq/connector/stomp/commands/TextMessageCommand.h>
+#include <activemq/network/Socket.h>
+#include <activemq/network/ServerSocket.h>
+#include <activemq/core/ActiveMQConnectionFactory.h>
+#include <activemq/core/ActiveMQConnectionData.h>
+#include <activemq/core/ActiveMQSession.h>
+#include <activemq/core/ActiveMQConsumer.h>
+#include <activemq/core/ActiveMQProducer.h>
+#include <activemq/util/SimpleProperties.h>
+#include <activemq/util/Date.h>
+#include <activemq/connector/ConsumerMessageListener.h>
+
+using namespace std;
+using namespace activemq;
+using namespace activemq::core;
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQSessionTest::testAutoAcking() {
+
+    MyCMSMessageListener msgListener1;
+    MyCMSMessageListener msgListener2;
+
+    CPPUNIT_ASSERT( connection != NULL );
+
+    // Create an Auto Ack Session
+    cms::Session* session = connection->createSession();
+
+    // Create a Topic
+    cms::Topic* topic1 = session->createTopic( "TestTopic1");
+    cms::Topic* topic2 = session->createTopic( "TestTopic2");
+
+    CPPUNIT_ASSERT( topic1 != NULL );
+    CPPUNIT_ASSERT( topic2 != NULL );
+
+    // Create a consumer
+    cms::MessageConsumer* consumer1 =
+        session->createConsumer( topic1 );
+    cms::MessageConsumer* consumer2 =
+        session->createConsumer( topic2 );
+
+    CPPUNIT_ASSERT( consumer1 != NULL );
+    CPPUNIT_ASSERT( consumer2 != NULL );
+
+    CPPUNIT_ASSERT( consumer1->getMessageSelector() == "" );
+    CPPUNIT_ASSERT( consumer2->getMessageSelector() == "" );
+
+    CPPUNIT_ASSERT( consumer1->receiveNoWait() == NULL );
+    CPPUNIT_ASSERT( consumer1->receive( 5 ) == NULL );
+    CPPUNIT_ASSERT( consumer2->receiveNoWait() == NULL );
+    CPPUNIT_ASSERT( consumer2->receive( 5 ) == NULL );
+
+    consumer1->setMessageListener( &msgListener1 );
+    consumer2->setMessageListener( &msgListener2 );
+
+    injectTextMessage( "This is a Test 1" , *topic1 );
+
+    synchronized( &msgListener1.mutex )
+    {
+        if( msgListener1.messages.size() == 0 )
+        {
+            msgListener1.mutex.wait( 3000 );
+        }
+    }
+
+    CPPUNIT_ASSERT( msgListener1.messages.size() == 1 );
+
+    injectTextMessage( "This is a Test 2" , *topic2 );
+
+    synchronized( &msgListener2.mutex )
+    {
+        if( msgListener2.messages.size() == 0 )
+        {
+            msgListener2.mutex.wait( 3000 );
+        }
+    }
+
+    CPPUNIT_ASSERT( msgListener2.messages.size() == 1 );
+
+    cms::TextMessage* msg1 =
+        dynamic_cast< cms::TextMessage* >(
+            msgListener1.messages[0] );
+    cms::TextMessage* msg2 =
+        dynamic_cast< cms::TextMessage* >(
+            msgListener2.messages[0] );
+
+    CPPUNIT_ASSERT( msg1 != NULL );
+    CPPUNIT_ASSERT( msg2 != NULL );
+
+    std::string text1 = msg1->getText();
+    std::string text2 = msg2->getText();
+
+    CPPUNIT_ASSERT( text1 == "This is a Test 1" );
+    CPPUNIT_ASSERT( text2 == "This is a Test 2" );
+
+    delete topic1;
+    delete topic2;
+
+    delete consumer1;
+    delete consumer2;
+
+    delete session;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQSessionTest::testClientAck()
+{
+    MyCMSMessageListener msgListener1( true );
+    MyCMSMessageListener msgListener2( true );
+
+    CPPUNIT_ASSERT( connection != NULL );
+
+    // Create an Auto Ack Session
+    cms::Session* session = connection->createSession(
+        cms::Session::CLIENT_ACKNOWLEDGE );
+
+    // Create a Topic
+    cms::Topic* topic1 = session->createTopic( "TestTopic1");
+    cms::Topic* topic2 = session->createTopic( "TestTopic2");
+
+    CPPUNIT_ASSERT( topic1 != NULL );
+    CPPUNIT_ASSERT( topic2 != NULL );
+
+    // Create a consumer
+    cms::MessageConsumer* consumer1 =
+        session->createConsumer( topic1 );
+    cms::MessageConsumer* consumer2 =
+        session->createConsumer( topic2 );
+
+    CPPUNIT_ASSERT( consumer1 != NULL );
+    CPPUNIT_ASSERT( consumer2 != NULL );
+
+    CPPUNIT_ASSERT( consumer1->getMessageSelector() == "" );
+    CPPUNIT_ASSERT( consumer2->getMessageSelector() == "" );
+
+    CPPUNIT_ASSERT( consumer1->receiveNoWait() == NULL );
+    CPPUNIT_ASSERT( consumer1->receive( 5 ) == NULL );
+    CPPUNIT_ASSERT( consumer2->receiveNoWait() == NULL );
+    CPPUNIT_ASSERT( consumer2->receive( 5 ) == NULL );
+
+    consumer1->setMessageListener( &msgListener1 );
+    consumer2->setMessageListener( &msgListener2 );
+
+    injectTextMessage( "This is a Test 1" , *topic1 );
+
+    synchronized( &msgListener1.mutex )
+    {
+        if( msgListener1.messages.size() == 0 )
+        {
+            msgListener1.mutex.wait( 3000 );
+        }
+    }
+
+    CPPUNIT_ASSERT_EQUAL( 1, (int)msgListener1.messages.size() );
+
+    msgListener1.messages[0]->acknowledge();
+
+    injectTextMessage( "This is a Test 2" , *topic2 );
+
+    synchronized( &msgListener2.mutex )
+    {
+        if( msgListener2.messages.size() == 0 )
+        {
+            msgListener2.mutex.wait( 3000 );
+        }
+    }
+
+    CPPUNIT_ASSERT_EQUAL( 1, (int)msgListener2.messages.size() );
+
+    msgListener2.messages[0]->acknowledge();
+
+    cms::TextMessage* msg1 =
+        dynamic_cast< cms::TextMessage* >(
+            msgListener1.messages[0] );
+    cms::TextMessage* msg2 =
+        dynamic_cast< cms::TextMessage* >(
+            msgListener2.messages[0] );
+
+    CPPUNIT_ASSERT( msg1 != NULL );
+    CPPUNIT_ASSERT( msg2 != NULL );
+
+    std::string text1 = msg1->getText();
+    std::string text2 = msg2->getText();
+
+    CPPUNIT_ASSERT( text1 == "This is a Test 1" );
+    CPPUNIT_ASSERT( text2 == "This is a Test 2" );
+
+    delete topic1;
+    delete topic2;
+
+    delete consumer1;
+    delete consumer2;
+
+    delete session;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQSessionTest::testTransactional()
+{
+    MyCMSMessageListener msgListener1;
+    MyCMSMessageListener msgListener2;
+
+    CPPUNIT_ASSERT( connection != NULL );
+
+    // Create an Auto Ack Session
+    cms::Session* session = connection->createSession(
+        cms::Session::SESSION_TRANSACTED );
+
+    // Create a Topic
+    cms::Topic* topic1 = session->createTopic( "TestTopic1");
+    cms::Topic* topic2 = session->createTopic( "TestTopic2");
+
+    CPPUNIT_ASSERT( topic1 != NULL );
+    CPPUNIT_ASSERT( topic2 != NULL );
+
+    // Create a consumer
+    cms::MessageConsumer* consumer1 =
+        session->createConsumer( topic1 );
+    cms::MessageConsumer* consumer2 =
+        session->createConsumer( topic2 );
+
+    CPPUNIT_ASSERT( consumer1 != NULL );
+    CPPUNIT_ASSERT( consumer2 != NULL );
+
+    CPPUNIT_ASSERT( consumer1->getMessageSelector() == "" );
+    CPPUNIT_ASSERT( consumer2->getMessageSelector() == "" );
+
+    CPPUNIT_ASSERT( consumer1->receiveNoWait() == NULL );
+    CPPUNIT_ASSERT( consumer1->receive( 5 ) == NULL );
+    CPPUNIT_ASSERT( consumer2->receiveNoWait() == NULL );
+    CPPUNIT_ASSERT( consumer2->receive( 5 ) == NULL );
+
+    consumer1->setMessageListener( &msgListener1 );
+    consumer2->setMessageListener( &msgListener2 );
+
+    injectTextMessage( "This is a Test 1" , *topic1 );
+
+    synchronized( &msgListener1.mutex )
+    {
+        if( msgListener1.messages.size() == 0 )
+        {
+            msgListener1.mutex.wait( 3000 );
+        }
+    }
+
+    CPPUNIT_ASSERT_EQUAL( 1, (int)msgListener1.messages.size() );
+
+    session->commit();
+
+    injectTextMessage( "This is a Test 2" , *topic2 );
+
+    synchronized( &msgListener2.mutex )
+    {
+        if( msgListener2.messages.size() == 0 )
+        {
+            msgListener2.mutex.wait( 3000 );
+        }
+    }
+
+    CPPUNIT_ASSERT( msgListener2.messages.size() == 1 );
+
+    session->commit();
+
+    cms::TextMessage* msg1 =
+        dynamic_cast< cms::TextMessage* >(
+            msgListener1.messages[0] );
+    cms::TextMessage* msg2 =
+        dynamic_cast< cms::TextMessage* >(
+            msgListener2.messages[0] );
+
+    CPPUNIT_ASSERT( msg1 != NULL );
+    CPPUNIT_ASSERT( msg2 != NULL );
+
+    std::string text1 = msg1->getText();
+    std::string text2 = msg2->getText();
+
+    CPPUNIT_ASSERT( text1 == "This is a Test 1" );
+    CPPUNIT_ASSERT( text2 == "This is a Test 2" );
+
+    msgListener1.clear();
+    msgListener2.clear();
+
+    const unsigned int msgCount = 50;
+
+    for( unsigned int i = 0; i < msgCount; ++i )
+    {
+        std::ostringstream stream;
+
+        stream << "This is test message #" << i << std::ends;
+
+        injectTextMessage( stream.str() , *topic1 );
+    }
+
+    for( unsigned int i = 0; i < msgCount; ++i )
+    {
+        std::ostringstream stream;
+
+        stream << "This is test message #" << i << std::ends;
+
+        injectTextMessage( stream.str() , *topic2 );
+    }
+
+    synchronized( &msgListener1.mutex )
+    {
+        const unsigned int interval = msgCount + 10;
+        unsigned int count = 0;
+
+        while( msgListener1.messages.size() != msgCount &&
+               count < interval )
+        {
+            msgListener1.mutex.wait( 3000 );
+
+            ++count;
+        }
+    }
+
+    CPPUNIT_ASSERT( msgListener1.messages.size() == msgCount );
+
+    synchronized( &msgListener2.mutex )
+    {
+        const int interval = msgCount + 10;
+        int count = 0;
+
+        while( msgListener2.messages.size() != msgCount &&
+               count < interval )
+        {
+            msgListener2.mutex.wait( 3000 );
+
+            ++count;
+        }
+    }
+
+    CPPUNIT_ASSERT( msgListener2.messages.size() == msgCount );
+
+    msgListener1.clear();
+    msgListener2.clear();
+
+    session->rollback();
+
+    synchronized( &msgListener1.mutex )
+    {
+        const int interval = msgCount + 10;
+        int count = 0;
+
+        while( msgListener1.messages.size() != msgCount &&
+               count < interval )
+        {
+            msgListener1.mutex.wait( 3000 );
+
+            ++count;
+        }
+    }
+
+    CPPUNIT_ASSERT( msgListener1.messages.size() == msgCount );
+
+    synchronized( &msgListener2.mutex )
+    {
+        const int interval = msgCount + 10;
+        int count = 0;
+
+        while( msgListener2.messages.size() != msgCount &&
+               count < interval )
+        {
+            msgListener2.mutex.wait( 3000 );
+
+            ++count;
+        }
+    }
+
+    CPPUNIT_ASSERT( msgListener2.messages.size() == msgCount );
+
+    delete topic1;
+    delete topic2;
+
+    delete consumer1;
+    delete consumer2;
+
+    delete session;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQSessionTest::testExpiration()
+{
+    MyCMSMessageListener msgListener1;
+    MyCMSMessageListener msgListener2;
+
+    CPPUNIT_ASSERT( connection != NULL );
+
+    // Create an Auto Ack Session
+    cms::Session* session = connection->createSession();
+
+    // Create a Topic
+    cms::Topic* topic1 = session->createTopic( "TestTopic1");
+    cms::Topic* topic2 = session->createTopic( "TestTopic2");
+
+    CPPUNIT_ASSERT( topic1 != NULL );
+    CPPUNIT_ASSERT( topic2 != NULL );
+
+    // Create a consumer
+    cms::MessageConsumer* consumer1 =
+        session->createConsumer( topic1 );
+    cms::MessageConsumer* consumer2 =
+        session->createConsumer( topic2 );
+
+    CPPUNIT_ASSERT( consumer1 != NULL );
+    CPPUNIT_ASSERT( consumer2 != NULL );
+
+    consumer1->setMessageListener( &msgListener1 );
+    consumer2->setMessageListener( &msgListener2 );
+
+    injectTextMessage( "This is a Test 1" ,
+                       *topic1,
+                       activemq::util::Date::getCurrentTimeMilliseconds(),
+                       50 );
+
+    synchronized( &msgListener1.mutex )
+    {
+        if( msgListener1.messages.size() == 0 )
+        {
+            msgListener1.mutex.wait( 3000 );
+        }
+    }
+
+    CPPUNIT_ASSERT( msgListener1.messages.size() == 1 );
+
+    injectTextMessage( "This is a Test 2" ,
+                       *topic2,
+                       activemq::util::Date::getCurrentTimeMilliseconds() - 100,
+                       1 );
+
+    synchronized( &msgListener2.mutex )
+    {
+        if( msgListener2.messages.size() == 0 )
+        {
+            msgListener2.mutex.wait( 100 );
+        }
+    }
+
+    CPPUNIT_ASSERT( msgListener2.messages.size() == 0 );
+
+    cms::TextMessage* msg1 =
+        dynamic_cast< cms::TextMessage* >(
+            msgListener1.messages[0] );
+
+    CPPUNIT_ASSERT( msg1 != NULL );
+
+    std::string text1 = msg1->getText();
+
+    CPPUNIT_ASSERT( text1 == "This is a Test 1" );
+
+    delete topic1;
+    delete topic2;
+
+    delete consumer1;
+    delete consumer2;
+
+    delete session;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQSessionTest::setUp()
+{
+    try
+    {
+        transport::TransportFactoryMapRegistrar registrar(
+            "dummy", new transport::DummyTransportFactory() );
+
+        ActiveMQConnectionFactory factory("dummy://127.0.0.1:12345?wireFormat=stomp");
+
+        connection = dynamic_cast< ActiveMQConnection*>(
+            factory.createConnection() );
+
+        // Get the Transport and make sure we got a dummy Transport
+        dTransport = transport::DummyTransport::getInstance();
+        CPPUNIT_ASSERT( dTransport != NULL );
+
+        connection->setExceptionListener( &exListener );
+        connection->start();
+    }
+    catch(...)
+    {
+        bool exceptionThrown = false;
+
+        CPPUNIT_ASSERT( exceptionThrown );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQSessionTest::tearDown()
+{
+    delete connection;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQSessionTest::injectTextMessage( const std::string message,
+                                             const cms::Destination& destination,
+                                             const long long timeStamp,
+                                             const long long timeToLive )
+{
+    connector::stomp::StompFrame* frame =
+        new connector::stomp::StompFrame();
+    frame->setCommand( "MESSAGE" );
+    frame->getProperties().setProperty(
+        "destination", destination.toProviderString() );
+    const char* buffer = message.c_str();
+    frame->setBody( (unsigned char*)buffer, 12 );
+
+    connector::stomp::commands::TextMessageCommand* msg =
+        new connector::stomp::commands::TextMessageCommand( frame );
+
+    // Init Message
+    msg->setText( message.c_str() );
+    msg->setCMSDestination( &destination );
+    msg->setCMSMessageID( "Id: 123456" );
+
+    long long expiration = 0LL;
+
+    if( timeStamp != 0 ) {
+        msg->setCMSTimestamp( timeStamp );
+
+        if( timeToLive > 0LL ) {
+            expiration = timeToLive + timeStamp;
+        }
+    }
+
+    msg->setCMSExpiration( expiration );
+
+    // Send the Message
+    CPPUNIT_ASSERT( dTransport != NULL );
+
+    dTransport->fireCommand( msg );
+}

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQSessionTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQSessionTest.h?view=diff&rev=528222&r1=528221&r2=528222
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQSessionTest.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQSessionTest.h Thu Apr 12 13:29:39 2007
@@ -24,32 +24,10 @@
 #include <cms/Connection.h>
 #include <cms/MessageListener.h>
 
-#include <activemq/network/Socket.h>
-#include <activemq/network/ServerSocket.h>
 #include <activemq/concurrent/Concurrent.h>
 #include <activemq/concurrent/Mutex.h>
-#include <activemq/concurrent/Thread.h>
-#include <activemq/core/ActiveMQConnectionFactory.h>
 #include <activemq/core/ActiveMQConnection.h>
-#include <activemq/core/ActiveMQConnectionData.h>
-#include <activemq/core/ActiveMQSession.h>
-#include <activemq/core/ActiveMQConsumer.h>
-#include <activemq/core/ActiveMQProducer.h>
-#include <activemq/util/SimpleProperties.h>
-#include <activemq/util/Date.h>
 #include <activemq/transport/DummyTransport.h>
-#include <activemq/transport/DummyTransportFactory.h>
-#include <activemq/transport/TransportFactoryMap.h>
-#include <activemq/transport/TransportFactoryMapRegistrar.h>
-#include <activemq/connector/ConsumerMessageListener.h>
-#include <activemq/connector/ConsumerInfo.h>
-#include <activemq/connector/stomp/StompConnector.h>
-#include <activemq/connector/stomp/StompConsumerInfo.h>
-#include <activemq/connector/stomp/StompProducerInfo.h>
-#include <activemq/connector/stomp/StompTransactionInfo.h>
-#include <activemq/connector/stomp/StompSessionInfo.h>
-#include <activemq/connector/stomp/StompTopic.h>
-#include <activemq/connector/stomp/commands/TextMessageCommand.h>
 #include <activemq/util/Config.h>
 
 namespace activemq{
@@ -66,23 +44,6 @@
 
     private:
 
-        class MyCommandListener : public transport::CommandListener{
-        public:
-
-            transport::Command* cmd;
-
-        public:
-
-            MyCommandListener(){
-                cmd = NULL;
-            }
-            virtual ~MyCommandListener(){}
-
-            virtual void onCommand( transport::Command* command ){
-                cmd = command;
-            }
-        };
-
         class MyExceptionListener : public cms::ExceptionListener{
         public:
 
@@ -150,527 +111,26 @@
         ActiveMQConnection* connection;
         transport::DummyTransport* dTransport;
         MyExceptionListener exListener;
-        MyCommandListener cmdListener;
 
     public:    // CPPUNIT Method Overrides.
 
-        void setUp()
-        {
-            try
-            {
-                transport::TransportFactoryMapRegistrar registrar(
-                    "dummy", new transport::DummyTransportFactory() );
-
-                ActiveMQConnectionFactory factory("dummy://127.0.0.1:12345?wireFormat=stomp");
-
-                connection = dynamic_cast< ActiveMQConnection*>(
-                    factory.createConnection() );
-
-                // Get the Transport and make sure we got a dummy Transport
-                // then add our command listener, so we can verify that when
-                // we send a message it hits the wire.
-                dTransport = dynamic_cast< transport::DummyTransport*>(
-                    connection->getConnectionData()->getTransport() );
-                CPPUNIT_ASSERT( dTransport != NULL );
-                dTransport->setOutgoingCommandListener( &cmdListener );
-
-                connection->setExceptionListener( &exListener );
-                connection->start();
-            }
-            catch(...)
-            {
-                bool exceptionThrown = false;
-
-                CPPUNIT_ASSERT( exceptionThrown );
-            }
-        }
-
-        void tearDown()
-        {
-            delete connection;
-        }
-
+        void setUp();
+        void tearDown();
         void injectTextMessage( const std::string message,
                                 const cms::Destination& destination,
                                 const long long timeStamp = -1,
-                                const long long timeToLive = -1 )
-        {
-            connector::stomp::StompFrame* frame =
-                new connector::stomp::StompFrame();
-            frame->setCommand( "MESSAGE" );
-            frame->getProperties().setProperty(
-                "destination", destination.toProviderString() );
-            const char* buffer = message.c_str();
-            frame->setBody( (unsigned char*)buffer, 12 );
-
-            connector::stomp::commands::TextMessageCommand* msg =
-                new connector::stomp::commands::TextMessageCommand( frame );
-
-            // Init Message
-            msg->setText( message.c_str() );
-            msg->setCMSDestination( &destination );
-            msg->setCMSMessageID( "Id: 123456" );
-
-            long long expiration = 0LL;
-
-            if( timeStamp != 0 ) {
-                msg->setCMSTimestamp( timeStamp );
-
-                if( timeToLive > 0LL ) {
-                    expiration = timeToLive + timeStamp;
-                }
-            }
-
-            msg->setCMSExpiration( expiration );
-
-            // Send the Message
-            CPPUNIT_ASSERT( dTransport != NULL );
-
-            dTransport->fireCommand( msg );
-        }
+                                const long long timeToLive = -1 );
 
     public:
 
         ActiveMQSessionTest(void) {}
         virtual ~ActiveMQSessionTest(void) {}
 
-        void testAutoAcking()
-        {
-            MyCMSMessageListener msgListener1;
-            MyCMSMessageListener msgListener2;
-
-            CPPUNIT_ASSERT( connection != NULL );
-
-            // Create an Auto Ack Session
-            cms::Session* session = connection->createSession();
-
-            // Create a Topic
-            cms::Topic* topic1 = session->createTopic( "TestTopic1");
-            cms::Topic* topic2 = session->createTopic( "TestTopic2");
-
-            CPPUNIT_ASSERT( topic1 != NULL );
-            CPPUNIT_ASSERT( topic2 != NULL );
-
-            // Create a consumer
-            cms::MessageConsumer* consumer1 =
-                session->createConsumer( topic1 );
-            cms::MessageConsumer* consumer2 =
-                session->createConsumer( topic2 );
-
-            CPPUNIT_ASSERT( consumer1 != NULL );
-            CPPUNIT_ASSERT( consumer2 != NULL );
-
-            CPPUNIT_ASSERT( consumer1->getMessageSelector() == "" );
-            CPPUNIT_ASSERT( consumer2->getMessageSelector() == "" );
-
-            CPPUNIT_ASSERT( consumer1->receiveNoWait() == NULL );
-            CPPUNIT_ASSERT( consumer1->receive( 5 ) == NULL );
-            CPPUNIT_ASSERT( consumer2->receiveNoWait() == NULL );
-            CPPUNIT_ASSERT( consumer2->receive( 5 ) == NULL );
-
-            consumer1->setMessageListener( &msgListener1 );
-            consumer2->setMessageListener( &msgListener2 );
-
-            injectTextMessage( "This is a Test 1" , *topic1 );
-
-            synchronized( &msgListener1.mutex )
-            {
-                if( msgListener1.messages.size() == 0 )
-                {
-                    msgListener1.mutex.wait( 3000 );
-                }
-            }
-
-            CPPUNIT_ASSERT( msgListener1.messages.size() == 1 );
-
-            injectTextMessage( "This is a Test 2" , *topic2 );
-
-            synchronized( &msgListener2.mutex )
-            {
-                if( msgListener2.messages.size() == 0 )
-                {
-                    msgListener2.mutex.wait( 3000 );
-                }
-            }
-
-            CPPUNIT_ASSERT( msgListener2.messages.size() == 1 );
-
-            cms::TextMessage* msg1 =
-                dynamic_cast< cms::TextMessage* >(
-                    msgListener1.messages[0] );
-            cms::TextMessage* msg2 =
-                dynamic_cast< cms::TextMessage* >(
-                    msgListener2.messages[0] );
-
-            CPPUNIT_ASSERT( msg1 != NULL );
-            CPPUNIT_ASSERT( msg2 != NULL );
-
-            std::string text1 = msg1->getText();
-            std::string text2 = msg2->getText();
-
-            CPPUNIT_ASSERT( text1 == "This is a Test 1" );
-            CPPUNIT_ASSERT( text2 == "This is a Test 2" );
-
-            delete topic1;
-            delete topic2;
-
-            delete consumer1;
-            delete consumer2;
-
-            delete session;
-        }
-
-        void testClientAck()
-        {
-            MyCMSMessageListener msgListener1( true );
-            MyCMSMessageListener msgListener2( true );
-
-            CPPUNIT_ASSERT( connection != NULL );
-
-            // Create an Auto Ack Session
-            cms::Session* session = connection->createSession(
-                cms::Session::CLIENT_ACKNOWLEDGE );
-
-            // Create a Topic
-            cms::Topic* topic1 = session->createTopic( "TestTopic1");
-            cms::Topic* topic2 = session->createTopic( "TestTopic2");
-
-            CPPUNIT_ASSERT( topic1 != NULL );
-            CPPUNIT_ASSERT( topic2 != NULL );
-
-            // Create a consumer
-            cms::MessageConsumer* consumer1 =
-                session->createConsumer( topic1 );
-            cms::MessageConsumer* consumer2 =
-                session->createConsumer( topic2 );
-
-            CPPUNIT_ASSERT( consumer1 != NULL );
-            CPPUNIT_ASSERT( consumer2 != NULL );
-
-            CPPUNIT_ASSERT( consumer1->getMessageSelector() == "" );
-            CPPUNIT_ASSERT( consumer2->getMessageSelector() == "" );
-
-            CPPUNIT_ASSERT( consumer1->receiveNoWait() == NULL );
-            CPPUNIT_ASSERT( consumer1->receive( 5 ) == NULL );
-            CPPUNIT_ASSERT( consumer2->receiveNoWait() == NULL );
-            CPPUNIT_ASSERT( consumer2->receive( 5 ) == NULL );
-
-            consumer1->setMessageListener( &msgListener1 );
-            consumer2->setMessageListener( &msgListener2 );
-
-            injectTextMessage( "This is a Test 1" , *topic1 );
-
-            synchronized( &msgListener1.mutex )
-            {
-                if( msgListener1.messages.size() == 0 )
-                {
-                    msgListener1.mutex.wait( 3000 );
-                }
-            }
-
-            CPPUNIT_ASSERT_EQUAL( 1, (int)msgListener1.messages.size() );
-
-            msgListener1.messages[0]->acknowledge();
-
-            injectTextMessage( "This is a Test 2" , *topic2 );
-
-            synchronized( &msgListener2.mutex )
-            {
-                if( msgListener2.messages.size() == 0 )
-                {
-                    msgListener2.mutex.wait( 3000 );
-                }
-            }
-
-            CPPUNIT_ASSERT_EQUAL( 1, (int)msgListener2.messages.size() );
-
-            msgListener2.messages[0]->acknowledge();
-
-            cms::TextMessage* msg1 =
-                dynamic_cast< cms::TextMessage* >(
-                    msgListener1.messages[0] );
-            cms::TextMessage* msg2 =
-                dynamic_cast< cms::TextMessage* >(
-                    msgListener2.messages[0] );
-
-            CPPUNIT_ASSERT( msg1 != NULL );
-            CPPUNIT_ASSERT( msg2 != NULL );
-
-            std::string text1 = msg1->getText();
-            std::string text2 = msg2->getText();
-
-            CPPUNIT_ASSERT( text1 == "This is a Test 1" );
-            CPPUNIT_ASSERT( text2 == "This is a Test 2" );
-
-            delete topic1;
-            delete topic2;
-
-            delete consumer1;
-            delete consumer2;
-
-            delete session;
-        }
-
-        void testTransactional()
-        {
-            MyCMSMessageListener msgListener1;
-            MyCMSMessageListener msgListener2;
-
-            CPPUNIT_ASSERT( connection != NULL );
-
-            // Create an Auto Ack Session
-            cms::Session* session = connection->createSession(
-                cms::Session::SESSION_TRANSACTED );
-
-            // Create a Topic
-            cms::Topic* topic1 = session->createTopic( "TestTopic1");
-            cms::Topic* topic2 = session->createTopic( "TestTopic2");
-
-            CPPUNIT_ASSERT( topic1 != NULL );
-            CPPUNIT_ASSERT( topic2 != NULL );
-
-            // Create a consumer
-            cms::MessageConsumer* consumer1 =
-                session->createConsumer( topic1 );
-            cms::MessageConsumer* consumer2 =
-                session->createConsumer( topic2 );
-
-            CPPUNIT_ASSERT( consumer1 != NULL );
-            CPPUNIT_ASSERT( consumer2 != NULL );
-
-            CPPUNIT_ASSERT( consumer1->getMessageSelector() == "" );
-            CPPUNIT_ASSERT( consumer2->getMessageSelector() == "" );
-
-            CPPUNIT_ASSERT( consumer1->receiveNoWait() == NULL );
-            CPPUNIT_ASSERT( consumer1->receive( 5 ) == NULL );
-            CPPUNIT_ASSERT( consumer2->receiveNoWait() == NULL );
-            CPPUNIT_ASSERT( consumer2->receive( 5 ) == NULL );
-
-            consumer1->setMessageListener( &msgListener1 );
-            consumer2->setMessageListener( &msgListener2 );
-
-            injectTextMessage( "This is a Test 1" , *topic1 );
-
-            synchronized( &msgListener1.mutex )
-            {
-                if( msgListener1.messages.size() == 0 )
-                {
-                    msgListener1.mutex.wait( 3000 );
-                }
-            }
-
-            CPPUNIT_ASSERT_EQUAL( 1, (int)msgListener1.messages.size() );
-
-            session->commit();
-
-            injectTextMessage( "This is a Test 2" , *topic2 );
-
-            synchronized( &msgListener2.mutex )
-            {
-                if( msgListener2.messages.size() == 0 )
-                {
-                    msgListener2.mutex.wait( 3000 );
-                }
-            }
-
-            CPPUNIT_ASSERT( msgListener2.messages.size() == 1 );
-
-            session->commit();
-
-            cms::TextMessage* msg1 =
-                dynamic_cast< cms::TextMessage* >(
-                    msgListener1.messages[0] );
-            cms::TextMessage* msg2 =
-                dynamic_cast< cms::TextMessage* >(
-                    msgListener2.messages[0] );
-
-            CPPUNIT_ASSERT( msg1 != NULL );
-            CPPUNIT_ASSERT( msg2 != NULL );
-
-            std::string text1 = msg1->getText();
-            std::string text2 = msg2->getText();
-
-            CPPUNIT_ASSERT( text1 == "This is a Test 1" );
-            CPPUNIT_ASSERT( text2 == "This is a Test 2" );
-
-            msgListener1.clear();
-            msgListener2.clear();
-
-            const unsigned int msgCount = 50;
-
-            for( unsigned int i = 0; i < msgCount; ++i )
-            {
-                std::ostringstream stream;
-
-                stream << "This is test message #" << i << std::ends;
-
-                injectTextMessage( stream.str() , *topic1 );
-            }
-
-            for( unsigned int i = 0; i < msgCount; ++i )
-            {
-                std::ostringstream stream;
-
-                stream << "This is test message #" << i << std::ends;
-
-                injectTextMessage( stream.str() , *topic2 );
-            }
-
-            synchronized( &msgListener1.mutex )
-            {
-                const unsigned int interval = msgCount + 10;
-                unsigned int count = 0;
-
-                while( msgListener1.messages.size() != msgCount &&
-                       count < interval )
-                {
-                    msgListener1.mutex.wait( 3000 );
-
-                    ++count;
-                }
-            }
-
-            CPPUNIT_ASSERT( msgListener1.messages.size() == msgCount );
-
-            synchronized( &msgListener2.mutex )
-            {
-                const int interval = msgCount + 10;
-                int count = 0;
-
-                while( msgListener2.messages.size() != msgCount &&
-                       count < interval )
-                {
-                    msgListener2.mutex.wait( 3000 );
-
-                    ++count;
-                }
-            }
-
-            CPPUNIT_ASSERT( msgListener2.messages.size() == msgCount );
-
-            msgListener1.clear();
-            msgListener2.clear();
-
-            session->rollback();
-
-            synchronized( &msgListener1.mutex )
-            {
-                const int interval = msgCount + 10;
-                int count = 0;
-
-                while( msgListener1.messages.size() != msgCount &&
-                       count < interval )
-                {
-                    msgListener1.mutex.wait( 3000 );
-
-                    ++count;
-                }
-            }
-
-            CPPUNIT_ASSERT( msgListener1.messages.size() == msgCount );
-
-            synchronized( &msgListener2.mutex )
-            {
-                const int interval = msgCount + 10;
-                int count = 0;
-
-                while( msgListener2.messages.size() != msgCount &&
-                       count < interval )
-                {
-                    msgListener2.mutex.wait( 3000 );
-
-                    ++count;
-                }
-            }
-
-            CPPUNIT_ASSERT( msgListener2.messages.size() == msgCount );
-
-            delete topic1;
-            delete topic2;
-
-            delete consumer1;
-            delete consumer2;
-
-            delete session;
-        }
-
-        void testExpiration()
-        {
-            MyCMSMessageListener msgListener1;
-            MyCMSMessageListener msgListener2;
-
-            CPPUNIT_ASSERT( connection != NULL );
-
-            // Create an Auto Ack Session
-            cms::Session* session = connection->createSession();
-
-            // Create a Topic
-            cms::Topic* topic1 = session->createTopic( "TestTopic1");
-            cms::Topic* topic2 = session->createTopic( "TestTopic2");
-
-            CPPUNIT_ASSERT( topic1 != NULL );
-            CPPUNIT_ASSERT( topic2 != NULL );
-
-            // Create a consumer
-            cms::MessageConsumer* consumer1 =
-                session->createConsumer( topic1 );
-            cms::MessageConsumer* consumer2 =
-                session->createConsumer( topic2 );
-
-            CPPUNIT_ASSERT( consumer1 != NULL );
-            CPPUNIT_ASSERT( consumer2 != NULL );
-
-            consumer1->setMessageListener( &msgListener1 );
-            consumer2->setMessageListener( &msgListener2 );
-
-            injectTextMessage( "This is a Test 1" ,
-                               *topic1,
-                               activemq::util::Date::getCurrentTimeMilliseconds(),
-                               50 );
-
-            synchronized( &msgListener1.mutex )
-            {
-                if( msgListener1.messages.size() == 0 )
-                {
-                    msgListener1.mutex.wait( 3000 );
-                }
-            }
-
-            CPPUNIT_ASSERT( msgListener1.messages.size() == 1 );
-
-            injectTextMessage( "This is a Test 2" ,
-                               *topic2,
-                               activemq::util::Date::getCurrentTimeMilliseconds() - 100,
-                               1 );
-
-            synchronized( &msgListener2.mutex )
-            {
-                if( msgListener2.messages.size() == 0 )
-                {
-                    msgListener2.mutex.wait( 100 );
-                }
-            }
-
-            CPPUNIT_ASSERT( msgListener2.messages.size() == 0 );
-
-            cms::TextMessage* msg1 =
-                dynamic_cast< cms::TextMessage* >(
-                    msgListener1.messages[0] );
-
-            CPPUNIT_ASSERT( msg1 != NULL );
-
-            std::string text1 = msg1->getText();
-
-            CPPUNIT_ASSERT( text1 == "This is a Test 1" );
-
-            delete topic1;
-            delete topic2;
-
-            delete consumer1;
-            delete consumer2;
+        void testAutoAcking();
+        void testClientAck();
+        void testTransactional();
+        void testExpiration();
 
-            delete session;
-        }
     };
 
 }}

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/network/SocketFactoryTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/network/SocketFactoryTest.cpp?view=diff&rev=528222&r1=528221&r2=528222
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/network/SocketFactoryTest.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/network/SocketFactoryTest.cpp Thu Apr 12 13:29:39 2007
@@ -18,3 +18,62 @@
 #include "SocketFactoryTest.h"
 
 CPPUNIT_TEST_SUITE_REGISTRATION( activemq::network::SocketFactoryTest );
+
+using namespace activemq;
+using namespace activemq::network;
+
+////////////////////////////////////////////////////////////////////////////////
+void SocketFactoryTest::test()
+{
+    try
+    {
+        MyServerThread serverThread;
+        serverThread.start();
+
+        concurrent::Thread::sleep( 40 );
+
+        util::SimpleProperties properties;
+
+        std::ostringstream ostream;
+
+        ostream << "127.0.0.1:" << port;
+
+        properties.setProperty("soLinger", "false");
+
+        Socket* client = SocketFactory::createSocket(
+            ostream.str(), properties );
+
+        synchronized(&serverThread.mutex)
+        {
+            if(serverThread.getNumClients() != 1)
+            {
+                serverThread.mutex.wait(1000);
+            }
+        }
+
+        CPPUNIT_ASSERT( client->isConnected() );
+
+        CPPUNIT_ASSERT( serverThread.getNumClients() == 1 );
+
+        client->close();
+
+        synchronized(&serverThread.mutex)
+        {
+            if(serverThread.getNumClients() != 0)
+            {
+                serverThread.mutex.wait(1000);
+            }
+        }
+
+        CPPUNIT_ASSERT( serverThread.getNumClients() == 0 );
+
+        serverThread.stop();
+        serverThread.join();
+
+        delete client;
+    }
+    catch(exceptions::ActiveMQException ex)
+    {
+        CPPUNIT_ASSERT( false );
+    }
+}

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/network/SocketFactoryTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/network/SocketFactoryTest.h?view=diff&rev=528222&r1=528221&r2=528222
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/network/SocketFactoryTest.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/network/SocketFactoryTest.h Thu Apr 12 13:29:39 2007
@@ -43,49 +43,49 @@
       CPPUNIT_TEST_SUITE_END();
 
       static const int port = 23232;
-      
+
       class MyServerThread : public concurrent::Thread{
       private:
-      
+
          bool done;
          int numClients;
          std::string lastMessage;
-         
+
       public:
-      
+
          concurrent::Mutex mutex;
-         
+
       public:
          MyServerThread(){
             done = false;
             numClients = 0;
          }
          virtual ~MyServerThread(){
-            stop();        
+            stop();
          }
-         
+
          std::string getLastMessage(){
             return lastMessage;
          }
-         
+
          int getNumClients(){
             return numClients;
          }
-         
+
          virtual void stop(){
             done = true;
          }
-         
+
          virtual void run(){
             try{
                unsigned char buf[1000];
-               
+
                ServerSocket server;
                server.bind( "127.0.0.1", port );
-               
+
                network::Socket* socket = server.accept();
                server.close();
-               
+
                //socket->setSoTimeout( 10 );
                socket->setSoLinger( false );
 
@@ -97,34 +97,34 @@
                }
 
                while( !done && socket != NULL ){
-                                    
+
                   io::InputStream* stream = socket->getInputStream();
                   memset( buf, 0, 1000 );
                   try{
                       stream->read( buf, 1000 );
-                    
+
                       lastMessage = (char*)buf;
-                    
+
                       if( strcmp( (char*)buf, "reply" ) == 0 ){
                           io::OutputStream* output = socket->getOutputStream();
                           output->write( (unsigned char*)"hello", strlen("hello" ) );
                       }
-                     
+
                   }catch( io::IOException& ex ){
                       done = true;
                   }
                }
-               
+
                socket->close();
                delete socket;
-               
+
                numClients--;
-               
+
                synchronized(&mutex)
                {
                    mutex.notifyAll();
                }
-               
+
             }catch( io::IOException& ex ){
                printf("%s\n", ex.getMessage().c_str() );
                CPPUNIT_ASSERT( false );
@@ -132,73 +132,15 @@
                CPPUNIT_ASSERT( false );
             }
          }
-         
+
       };
-      
+
    public:
-   
-   	SocketFactoryTest() {}
-   	virtual ~SocketFactoryTest() {}
-      
-      void test(void)
-      {
-         try
-         {
-            MyServerThread serverThread;
-            serverThread.start();
-         
-            concurrent::Thread::sleep( 40 );
-            
-            util::SimpleProperties properties;
-            
-            std::ostringstream ostream;
-            
-            ostream << "127.0.0.1:" << port;
-            
-            properties.setProperty("uri", ostream.str());
-            properties.setProperty("soLinger", "false");
-            //properties.setProperty("soTimeout", "5");
-
-            Socket* client = SocketFactory::createSocket(properties);
-
-            //BufferedSocket* buffSocket = dynamic_cast<BufferedSocket*>(client);
-
-            //CPPUNIT_ASSERT( buffSocket != NULL );
-
-            synchronized(&serverThread.mutex)
-            {
-                if(serverThread.getNumClients() != 1)
-                {
-                    serverThread.mutex.wait(1000);
-                }
-            }
-            
-            CPPUNIT_ASSERT( client->isConnected() );
-            
-            CPPUNIT_ASSERT( serverThread.getNumClients() == 1 );
-            
-            client->close();
-            
-            synchronized(&serverThread.mutex)
-            {
-                if(serverThread.getNumClients() != 0)
-                {
-                    serverThread.mutex.wait(1000);
-                }
-            }
 
-            CPPUNIT_ASSERT( serverThread.getNumClients() == 0 );
-            
-            serverThread.stop();
-            serverThread.join();
-
-            delete client;
-         }
-         catch(exceptions::ActiveMQException ex)
-         {
-            CPPUNIT_ASSERT( false );
-         }
-      }
+       SocketFactoryTest() {}
+       virtual ~SocketFactoryTest() {}
+
+      void test();
 
    };
 



Mime
View raw message