You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by nm...@apache.org on 2007/03/11 15:05:39 UTC

svn commit: r516902 - in /activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/integration/connector/stomp: ExpirationTest.cpp ExpirationTest.h

Author: nmittler
Date: Sun Mar 11 07:05:39 2007
New Revision: 516902

URL: http://svn.apache.org/viewvc?view=rev&rev=516902
Log:
cleaning up integration tests

Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/integration/connector/stomp/ExpirationTest.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/integration/connector/stomp/ExpirationTest.h

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/integration/connector/stomp/ExpirationTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/integration/connector/stomp/ExpirationTest.cpp?view=diff&rev=516902&r1=516901&r2=516902
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/integration/connector/stomp/ExpirationTest.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/integration/connector/stomp/ExpirationTest.cpp Sun Mar 11 07:05:39 2007
@@ -77,75 +77,62 @@
 using namespace integration;
 using namespace integration::connector::stomp;
 
-std::string messageTag = Guid().createGUID();
 
-class Producer : public Runnable {
-private:
 
-    ActiveMQConnectionFactory* connectionFactory;
-    Connection* connection;
-    Session* session;
-    Topic* destination;
-    MessageProducer* producer;
-    int numMessages;
-    long long timeToLive;
-    bool disableTimeStamps;
-
-public:
-
-    Producer( int numMessages, long long timeToLive ){
-        connection = NULL;
-        session = NULL;
-        destination = NULL;
-        producer = NULL;
-        this->numMessages = numMessages;
-        this->timeToLive = timeToLive;
-        this->disableTimeStamps = false;
-    }
-
-    virtual ~Producer(){
-        cleanup();
-    }
-
-    virtual bool getDisableTimeStamps() const {
-        return disableTimeStamps;
-    }
-
-    virtual void setDisableTimeStamps( bool value ) {
-        this->disableTimeStamps = value;
-    }
-
-    virtual void run() {
-        try {
-            // Create a ConnectionFactory
-            connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61613?wireFormat=stomp");
+ExpirationTest::Producer::Producer( string topic, int numMessages, long long timeToLive ){
+    connection = NULL;
+    session = NULL;
+    destination = NULL;
+    producer = NULL;
+    this->numMessages = numMessages;
+    this->timeToLive = timeToLive;
+    this->disableTimeStamps = false;
+    this->topic = topic;
+}
 
-            // Create a Connection
-            connection = connectionFactory->createConnection();
-            connection->start();
+ExpirationTest::Producer::~Producer(){
+    cleanup();
+}
 
-            string sss=connection->getClientId();
-            cout << sss << endl;
+bool ExpirationTest::Producer::getDisableTimeStamps() const {
+    return disableTimeStamps;
+}
 
-            session = connection->createSession( Session::AUTO_ACKNOWLEDGE);
-            destination = session->createTopic( "expirationTopic" );
+void ExpirationTest::Producer::setDisableTimeStamps( bool value ) {
+    this->disableTimeStamps = value;
+}
 
-            producer = session->createProducer( destination );
-            producer->setDeliveryMode( DeliveryMode::PERSISTENT );
-            producer->setDisableMessageTimeStamp( disableTimeStamps );
+void ExpirationTest::Producer::run() {
+    try {
+        // Create a ConnectionFactory
+        ActiveMQConnectionFactory* connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61613?wireFormat=stomp");
+
+        // Create a Connection
+        connection = connectionFactory->createConnection();
+        delete connectionFactory;
+        connection->start();
+
+        string sss=connection->getClientId();
+        cout << sss << endl;
+
+        session = connection->createSession( Session::AUTO_ACKNOWLEDGE);
+        destination = session->createTopic( topic );
+
+        producer = session->createProducer( destination );
+        producer->setDeliveryMode( DeliveryMode::PERSISTENT );
+        producer->setDisableMessageTimeStamp( disableTimeStamps );
 
-            //unsigned long ttt=getcurt();
-            producer->setTimeToLive( 1);
+        //unsigned long ttt=getcurt();
+        producer->setTimeToLive( 1);
 
-            // Create the Thread Id String
-            string threadIdStr = Integer::toString( Thread::getId() );
+        // Create the Thread Id String
+        string threadIdStr = Integer::toString( Thread::getId() );
 
-            // Create a messages
-            string text = (string)"Hello world! from thread " + threadIdStr;
+        // Create a messages
+        string text = (string)"Hello world! from thread " + threadIdStr;
 
             for( int ix=0; ix<numMessages; ++ix ){
                 TextMessage* message = session->createTextMessage( text );
-                message->setStringProperty( "messageTag", messageTag );
                 producer->send( message );
                 delete message;
            }
@@ -155,195 +142,171 @@
        }
    }
 
-private:
-
-    void cleanup(){
+void ExpirationTest::Producer::cleanup(){
 
         // Destroy resources.
-        try{
-            if( destination != NULL ) delete destination;
-        }catch ( CMSException& e ) {}
-        destination = NULL;
-
-        try{
-            if( producer != NULL ) delete producer;
-        }catch ( CMSException& e ) {}
-        producer = NULL;
-
-        // Close open resources.
-        try{
-            if( session != NULL ) session->close();
-            if( connection != NULL ) connection->close();
-        }catch ( CMSException& e ) {}
-
-        try{
-            if( session != NULL ) delete session;
-        }catch ( CMSException& e ) {}
-        session = NULL;
-
-        try{
-            if( connection != NULL ) delete connection;
-        }catch ( CMSException& e ) {}
-        connection = NULL;
-
-        try{
-            if( connectionFactory != NULL ) delete connectionFactory;
-        }catch ( CMSException& e ) {}
-        connectionFactory = NULL;
-    }
-};
+    try{
+        if( destination != NULL ) delete destination;
+    }catch ( CMSException& e ) {}
+    destination = NULL;
+
+    try{
+        if( producer != NULL ) delete producer;
+    }catch ( CMSException& e ) {}
+    producer = NULL;
+
+    // Close open resources.
+    try{
+        if( session != NULL ) session->close();
+        if( connection != NULL ) connection->close();
+    }catch ( CMSException& e ) {}
+
+    try{
+        if( session != NULL ) delete session;
+    }catch ( CMSException& e ) {}
+    session = NULL;
+
+    try{
+        if( connection != NULL ) delete connection;
+    }catch ( CMSException& e ) {}
+    connection = NULL;
+}
 
-class Consumer : public MessageListener, public Runnable {
+ExpirationTest::Consumer::Consumer( string topic, long waitMillis ){
+    connection = NULL;
+    session = NULL;
+    destination = NULL;
+    consumer = NULL;
+    this->waitMillis = waitMillis;
+    numReceived = 0;
+    this->topic = topic;
+}
 
-private:
+ExpirationTest::Consumer::~Consumer(){
+    cleanup();
+}
 
-    Connection* connection;
-    Session* session;
-    Topic* destination;
-    MessageConsumer* consumer;
-    long waitMillis;
-    int numReceived;
-
-public:
-
-    Consumer( long waitMillis ){
-        connection = NULL;
-        session = NULL;
-        destination = NULL;
-        consumer = NULL;
-        this->waitMillis = waitMillis;
-        numReceived = 0;
-    }
-    
-    virtual ~Consumer(){
-        cleanup();
-    }
+int ExpirationTest::Consumer::getNumReceived() const{
+    return numReceived;
+}
 
-    virtual int getNumReceived() const{
-        return numReceived;
-    }
-    
-    virtual void run() {
+void ExpirationTest::Consumer::run() {
 
-        try {
+    try {
 
-            string user,passwd,sID;
-            user="default";
-            passwd="";
-            sID="lsgID";
-            
-            // Create a ConnectionFactory
-            ActiveMQConnectionFactory* connectionFactory =
-               new ActiveMQConnectionFactory("tcp://localhost:61613?wireFormat=stomp",user,passwd,sID);
+        string user,passwd,sID;
+        user="default";
+        passwd="";
+        sID="lsgID";
+        
+        // Create a ConnectionFactory
+        ActiveMQConnectionFactory* connectionFactory =
+           new ActiveMQConnectionFactory("tcp://localhost:61613?wireFormat=stomp",user,passwd,sID);
 
-            // Create a Connection
-            connection = connectionFactory->createConnection();
-            delete connectionFactory;
-            connection->start();
+        // Create a Connection
+        connection = connectionFactory->createConnection();
+        delete connectionFactory;
+        connection->start();
 
-            // Create a Session
-            session = connection->createSession( Session::AUTO_ACKNOWLEDGE);
+        // Create a Session
+        session = connection->createSession( Session::AUTO_ACKNOWLEDGE);
 
-            // Create the destination (Topic or Queue)
-            destination = session->createTopic( "expirationTopic?consumer.retroactive=true");
+        // Create the destination (Topic or Queue)
+        string t = topic + "?consumer.retroactive=true";
+        
+        destination = session->createTopic( t );
 
-            consumer = session->createConsumer( destination );
+        consumer = session->createConsumer( destination );
 
-            consumer->setMessageListener( this );
+        consumer->setMessageListener( this );
 
-            // Sleep while asynchronous messages come in.
-            Thread::sleep( waitMillis );
+        // Sleep while asynchronous messages come in.
+        Thread::sleep( waitMillis );
 
-        } catch (CMSException& e) {
-            e.printStackTrace();
-        }
+    } catch (CMSException& e) {
+        e.printStackTrace();
     }
+}
 
-    virtual void onMessage( const Message* message ){
+void ExpirationTest::Consumer::onMessage( const Message* message ){
 
-        try
-        {
-            if( !message->propertyExists( "messageTag" ) || 
-                message->getStringProperty("messageTag") != messageTag ){
-                return;
-            }
-            
-            const TextMessage* textMessage =
-                dynamic_cast< const TextMessage* >( message );
-            string text = textMessage->getText();
-            numReceived++;
-        } catch (CMSException& e) {
-            e.printStackTrace();
-        }
+    try
+    {
+        const TextMessage* textMessage =
+            dynamic_cast< const TextMessage* >( message );
+        string text = textMessage->getText();
+        numReceived++;
+    } catch (CMSException& e) {
+        e.printStackTrace();
     }
+}
 
-private:
-
-    void cleanup(){
-
-        // Destroy resources.
-        try{
-            if( destination != NULL ) delete destination;
-        }catch (CMSException& e) {}
-        destination = NULL;
-
-        try{
-            if( consumer != NULL ) delete consumer;
-        }catch (CMSException& e) {}
-        consumer = NULL;
-
-        // Close open resources.
-        try{
-            if( session != NULL ) session->close();
-            if( connection != NULL ) connection->close();
-        }catch (CMSException& e) {}
-
-        try{
-            if( session != NULL ) delete session;
-        }catch (CMSException& e) {}
-        session = NULL;
-
-        try{
-            if( connection != NULL ) delete connection;
-        }catch (CMSException& e) {}
-        connection = NULL;
-    }
-};
+void ExpirationTest::Consumer::cleanup(){
 
+    // Destroy resources.
+    try{
+        if( destination != NULL ) delete destination;
+    }catch (CMSException& e) {}
+    destination = NULL;
+
+    try{
+        if( consumer != NULL ) delete consumer;
+    }catch (CMSException& e) {}
+    consumer = NULL;
+
+    // Close open resources.
+    try{
+        if( session != NULL ) session->close();
+        if( connection != NULL ) connection->close();
+    }catch (CMSException& e) {}
+
+    try{
+        if( session != NULL ) delete session;
+    }catch (CMSException& e) {}
+    session = NULL;
+
+    try{
+        if( connection != NULL ) delete connection;
+    }catch (CMSException& e) {}
+    connection = NULL;
+}
+    
 void ExpirationTest::testExpired()
 {
-    Producer producer( 1, 1 );
+    string topic = Guid().createGUID();
+    Producer producer( topic, 1, 1 );
     Thread producerThread( &producer );
     producerThread.start();
     producerThread.join();
     
     Thread::sleep( 100 );
 
-    Consumer consumer( 2000 );
+    Consumer consumer( topic, 2000 );
     Thread consumerThread( &consumer );
     consumerThread.start();
     consumerThread.join();
     
     Thread::sleep( 100 );
 
-    CPPUNIT_ASSERT( consumer.getNumReceived() == 0 );
+    CPPUNIT_ASSERT_EQUAL( 0, consumer.getNumReceived() );
 }
 
 void ExpirationTest::testNotExpired()
 {
-    Producer producer( 2, 2000 );
+    string topic = Guid().createGUID();
+    Producer producer( topic, 2, 2000 );
     producer.setDisableTimeStamps( true );
     Thread producerThread( &producer );
     producerThread.start();
     producerThread.join();
     
-    Consumer consumer( 3000 );
+    Consumer consumer( topic, 3000 );
     Thread consumerThread( &consumer );
     consumerThread.start();
     consumerThread.join();
 
     Thread::sleep( 50 );
     
-    CPPUNIT_ASSERT( consumer.getNumReceived() == 2 );
+    CPPUNIT_ASSERT_EQUAL( 2, consumer.getNumReceived() );
 }
 

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/integration/connector/stomp/ExpirationTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/integration/connector/stomp/ExpirationTest.h?view=diff&rev=516902&r1=516901&r2=516902
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/integration/connector/stomp/ExpirationTest.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/integration/connector/stomp/ExpirationTest.h Sun Mar 11 07:05:39 2007
@@ -28,6 +28,8 @@
 #include <cms/Session.h>
 #include <cms/MessageProducer.h>
 
+#include <activemq/concurrent/Runnable.h>
+
 namespace integration{
 namespace connector{
 namespace stomp{
@@ -46,6 +48,67 @@
         
         virtual void testExpired();
         virtual void testNotExpired();
+        
+    public:
+    
+        class Producer : public activemq::concurrent::Runnable {
+        private:
+        
+            cms::Connection* connection;
+            cms::Session* session;
+            cms::Topic* destination;
+            cms::MessageProducer* producer;
+            int numMessages;
+            long long timeToLive;
+            bool disableTimeStamps;
+            std::string topic;
+        
+        public:
+        
+            Producer( std::string topic, int numMessages, long long timeToLive );
+        
+            virtual ~Producer();
+        
+            virtual bool getDisableTimeStamps() const;
+        
+            virtual void setDisableTimeStamps( bool value );
+        
+            virtual void run();
+        
+        private:
+        
+            void cleanup();
+        };
+
+        class Consumer : public cms::MessageListener, public activemq::concurrent::Runnable {
+        
+        private:
+        
+            cms::Connection* connection;
+            cms::Session* session;
+            cms::Topic* destination;
+            cms::MessageConsumer* consumer;
+            long waitMillis;
+            int numReceived;
+            std::string topic;
+        
+        public:
+        
+            Consumer( std::string topic, long waitMillis );
+            
+            virtual ~Consumer();
+        
+            virtual int getNumReceived() const;
+            
+            virtual void run();
+        
+            virtual void onMessage( const cms::Message* message );
+        
+        private:
+        
+            void cleanup();
+        };
+
     };
 
 }}}