activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nmitt...@apache.org
Subject svn commit: r630699 - in /activemq/activemq-cpp/trunk/src/test-integration/integration: TestRegistry.cpp connector/openwire/OpenwireCmsTemplateTest.cpp connector/openwire/OpenwireCmsTemplateTest.h
Date Sun, 24 Feb 2008 22:43:32 GMT
Author: nmittler
Date: Sun Feb 24 14:43:32 2008
New Revision: 630699

URL: http://svn.apache.org/viewvc?rev=630699&view=rev
Log:
AMQCPP-152 - Adding integ tests for CmsTemplate with OpenWire

Added:
    activemq/activemq-cpp/trunk/src/test-integration/integration/connector/openwire/OpenwireCmsTemplateTest.cpp
    activemq/activemq-cpp/trunk/src/test-integration/integration/connector/openwire/OpenwireCmsTemplateTest.h
Modified:
    activemq/activemq-cpp/trunk/src/test-integration/integration/TestRegistry.cpp

Modified: activemq/activemq-cpp/trunk/src/test-integration/integration/TestRegistry.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test-integration/integration/TestRegistry.cpp?rev=630699&r1=630698&r2=630699&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/test-integration/integration/TestRegistry.cpp (original)
+++ activemq/activemq-cpp/trunk/src/test-integration/integration/TestRegistry.cpp Sun Feb
24 14:43:32 2008
@@ -16,6 +16,7 @@
  */
 
 #include "connector/openwire/OpenwireAsyncSenderTest.h"
+#include "connector/openwire/OpenwireCmsTemplateTest.h"
 #include "connector/openwire/OpenwireDurableTest.h"
 #include "connector/openwire/OpenwireExpirationTest.h"
 #include "connector/openwire/OpenwireSimpleRollbackTest.h"
@@ -34,6 +35,7 @@
 #include "connector/stomp/StompStressTests.h"
 
 CPPUNIT_TEST_SUITE_REGISTRATION( integration::connector::openwire::OpenwireAsyncSenderTest
);
+CPPUNIT_TEST_SUITE_REGISTRATION( integration::connector::openwire::OpenwireCmsTemplateTest
);
 CPPUNIT_TEST_SUITE_REGISTRATION( integration::connector::openwire::OpenwireDurableTest );
 CPPUNIT_TEST_SUITE_REGISTRATION( integration::connector::openwire::OpenwireExpirationTest
);
 CPPUNIT_TEST_SUITE_REGISTRATION( integration::connector::openwire::OpenwireSimpleRollbackTest
);
@@ -50,3 +52,4 @@
 CPPUNIT_TEST_SUITE_REGISTRATION( integration::connector::stomp::SimpleTest );
 CPPUNIT_TEST_SUITE_REGISTRATION( integration::connector::stomp::TransactionTest );
 CPPUNIT_TEST_SUITE_REGISTRATION( integration::connector::stomp::StompStressTests );
+

Added: activemq/activemq-cpp/trunk/src/test-integration/integration/connector/openwire/OpenwireCmsTemplateTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test-integration/integration/connector/openwire/OpenwireCmsTemplateTest.cpp?rev=630699&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test-integration/integration/connector/openwire/OpenwireCmsTemplateTest.cpp
(added)
+++ activemq/activemq-cpp/trunk/src/test-integration/integration/connector/openwire/OpenwireCmsTemplateTest.cpp
Sun Feb 24 14:43:32 2008
@@ -0,0 +1,186 @@
+/*
+ * 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 "OpenwireCmsTemplateTest.h"
+#include <integration/IntegrationCommon.h>
+
+#include <decaf/lang/Thread.h>
+#include <decaf/util/Properties.h>
+#include <activemq/transport/TransportFactory.h>
+#include <decaf/util/UUID.h>
+#include <decaf/util/Properties.h>
+#include <decaf/util/StringTokenizer.h>
+#include <activemq/connector/ConnectorFactoryMap.h>
+#include <decaf/net/SocketFactory.h>
+#include <activemq/transport/TransportFactory.h>
+#include <decaf/net/Socket.h>
+#include <decaf/lang/exceptions/NullPointerException.h>
+#include <activemq/core/ActiveMQConnectionFactory.h>
+#include <activemq/core/ActiveMQConnection.h>
+#include <activemq/core/ActiveMQConsumer.h>
+#include <activemq/core/ActiveMQProducer.h>
+#include <decaf/util/StringTokenizer.h>
+#include <decaf/lang/Boolean.h>
+
+#include <cms/Connection.h>
+#include <cms/MessageConsumer.h>
+#include <cms/MessageProducer.h>
+#include <cms/MessageListener.h>
+#include <cms/Startable.h>
+#include <cms/Closeable.h>
+#include <cms/MessageListener.h>
+#include <cms/ExceptionListener.h>
+#include <cms/Topic.h>
+#include <cms/Queue.h>
+#include <cms/TemporaryTopic.h>
+#include <cms/TemporaryQueue.h>
+#include <cms/Session.h>
+#include <cms/BytesMessage.h>
+#include <cms/TextMessage.h>
+#include <cms/MapMessage.h>
+
+using namespace activemq::transport;
+using namespace std;
+using namespace cms;
+using namespace activemq;
+using namespace activemq::core;
+using namespace activemq::connector;
+using namespace activemq::exceptions;
+using namespace decaf::net;
+using namespace activemq::transport;
+using namespace decaf::util::concurrent;
+using namespace decaf::lang;
+using namespace decaf::util;
+
+using namespace integration;
+using namespace integration::connector::openwire;
+using namespace activemq::cmsutil;
+
+////////////////////////////////////////////////////////////////////////////////
+void OpenwireCmsTemplateTest::setUp() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void OpenwireCmsTemplateTest::tearDown() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void OpenwireCmsTemplateTest::testBasics()
+{
+    try {
+        const unsigned int NUM_MESSAGES = IntegrationCommon::defaultMsgCount;
+        
+        Receiver receiver( IntegrationCommon::getInstance().getOpenwireURL(), 
+                false, 
+                "testBasics1", 
+                NUM_MESSAGES);
+        Thread rt(&receiver);
+        rt.start();
+        
+        // Wait for receiver thread to start.
+        decaf::lang::Thread::sleep(100);
+        
+        Sender sender( IntegrationCommon::getInstance().getOpenwireURL(), 
+                false, 
+                "testBasics1", 
+                NUM_MESSAGES);
+        Thread st(&sender);
+        st.start();
+        
+        st.join();
+        rt.join();
+        
+        unsigned int numReceived = receiver.getNumReceived();
+        if( IntegrationCommon::debug ) {
+            printf("received: %d\n", numReceived );
+        }
+        CPPUNIT_ASSERT(
+            numReceived == NUM_MESSAGES );
+    } catch ( ActiveMQException e ) {
+        e.printStackTrace();
+        throw e;
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void OpenwireCmsTemplateTest::testReceiveException()
+{
+    try {
+        // First, try receiving from a bad url
+        activemq::core::ActiveMQConnectionFactory cf("tcp://localhost:61666"); // Invalid
URL (at least by default)
+        activemq::cmsutil::CmsTemplate cmsTemplate(&cf);
+        cmsTemplate.setDefaultDestinationName("testReceive1");
+        try {                
+            cmsTemplate.receive();
+            CPPUNIT_FAIL("failed to throw expected exception");
+        }
+        catch( ActiveMQException& ex) {
+            // Expected.
+        }
+        
+        // Now change to a good url and verify that we can reuse the same
+        // CmsTemplate successfully.
+        activemq::core::ActiveMQConnectionFactory cf2(IntegrationCommon::getInstance().getOpenwireURL());
+        cmsTemplate.setConnectionFactory(&cf2);
+        
+        // Send 1 message.
+        Sender sender( IntegrationCommon::getInstance().getOpenwireURL(), 
+                false, 
+                "testReceive1", 
+                1);
+        Thread st(&sender);
+        st.start();
+        
+        // Receive the message.
+        cms::Message* message = cmsTemplate.receive();
+        CPPUNIT_ASSERT(message != NULL);
+        delete message;
+    }
+    catch ( ActiveMQException e ) {
+        e.printStackTrace();
+        throw e;
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void OpenwireCmsTemplateTest::testSendException()
+{
+    try {
+        // First, try sending to a bad url.
+        activemq::core::ActiveMQConnectionFactory cf("tcp://localhost:61666"); // Invalid
URL (at least by default)
+        activemq::cmsutil::CmsTemplate cmsTemplate(&cf);
+        cmsTemplate.setDefaultDestinationName("testSend1");
+        try {                      
+            TextMessageCreator msgCreator("hello world");
+            cmsTemplate.send(&msgCreator);
+            CPPUNIT_FAIL("failed to throw expected exception");
+        }
+        catch( ActiveMQException& ex) {
+            // Expected.
+        }
+        
+        // Now change to a good url and verify that we can reuse the same
+        // CmsTemplate successfully.
+        activemq::core::ActiveMQConnectionFactory cf2(IntegrationCommon::getInstance().getOpenwireURL());
+        cmsTemplate.setConnectionFactory(&cf2);
+        TextMessageCreator msgCreator("hello world");
+        cmsTemplate.send(&msgCreator);
+    } catch ( ActiveMQException e ) {
+        e.printStackTrace();
+        throw e;
+    }
+}

Added: activemq/activemq-cpp/trunk/src/test-integration/integration/connector/openwire/OpenwireCmsTemplateTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test-integration/integration/connector/openwire/OpenwireCmsTemplateTest.h?rev=630699&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test-integration/integration/connector/openwire/OpenwireCmsTemplateTest.h
(added)
+++ activemq/activemq-cpp/trunk/src/test-integration/integration/connector/openwire/OpenwireCmsTemplateTest.h
Sun Feb 24 14:43:32 2008
@@ -0,0 +1,150 @@
+/*
+ * 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.
+ */
+
+#ifndef _INTEGRATION_CONNECTOR_OPENWIRE_OPENWIRECMSTEMPLATETEST_H_
+#define _INTEGRATION_CONNECTOR_OPENWIRE_OPENWIRECMSTEMPLATETEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <integration/TestSupport.h>
+#include <activemq/core/ActiveMQConnectionFactory.h>
+#include <activemq/cmsutil/CmsTemplate.h>
+#include <activemq/cmsutil/MessageCreator.h>
+
+namespace integration{
+namespace connector{
+namespace openwire{
+
+    class OpenwireCmsTemplateTest : public CppUnit::TestFixture
+    {
+        CPPUNIT_TEST_SUITE( OpenwireCmsTemplateTest );
+        CPPUNIT_TEST( testBasics );
+        CPPUNIT_TEST( testReceiveException );
+        CPPUNIT_TEST( testSendException );        
+        CPPUNIT_TEST_SUITE_END();
+        
+        class TextMessageCreator : public activemq::cmsutil::MessageCreator {
+        private:
+            std::string text;
+        public:
+            TextMessageCreator( const std::string& text) {
+                this->text = text;
+            }
+            virtual ~TextMessageCreator() {}
+            
+            std::string getText() const {
+                return text;
+            }
+            
+            virtual cms::Message* createMessage(cms::Session* session ) 
+                        throw (cms::CMSException) {
+                return session->createTextMessage(text);
+            } 
+        };
+        
+        class Sender : public decaf::lang::Runnable {
+        private:
+                    
+            activemq::core::ActiveMQConnectionFactory cf;
+            activemq::cmsutil::CmsTemplate cmsTemplate;
+            int count;
+            
+        public:
+            
+            Sender( const std::string& url, bool pubSub, const std::string& destName,
int count ) {
+                cf.setBrokerURL(url);
+                cmsTemplate.setConnectionFactory(&cf);
+                cmsTemplate.setPubSubDomain(pubSub);
+                cmsTemplate.setDefaultDestinationName(destName);
+                this->count = count;
+            }
+            
+            virtual ~Sender(){
+            }
+            
+            virtual void run() {                
+                try {
+                                    
+                    // Send a batch of messages.
+                    TextMessageCreator tmc("hello world");
+                    for( int ix=0; ix<count; ++ix ) {
+                        cmsTemplate.send(&tmc);
+                    }
+                                                        
+                } catch( cms::CMSException& ex) {
+                    ex.printStackTrace();
+                }
+            }
+        };
+        
+        class Receiver : public decaf::lang::Runnable {
+        private:
+            
+            activemq::core::ActiveMQConnectionFactory cf;
+            activemq::cmsutil::CmsTemplate cmsTemplate;
+            int count;
+            int numReceived;
+            
+        public:
+            
+            Receiver( const std::string& url, bool pubSub, const std::string& destName,
int count ) {
+                cf.setBrokerURL(url);
+                cmsTemplate.setConnectionFactory(&cf);
+                cmsTemplate.setPubSubDomain(pubSub);
+                cmsTemplate.setDefaultDestinationName(destName);
+                this->count = count;
+            }
+            virtual ~Receiver(){
+            }
+            int getNumReceived() const {
+                return numReceived;
+            }
+            virtual void run() {
+                
+                try {
+                    numReceived = 0;
+                    
+                    // Receive a batch of messages.
+                    for( int ix=0; ix<count; ++ix ) {
+                        cms::Message* message = cmsTemplate.receive();
+                        numReceived++;
+                        delete message;                    
+                    }
+                } catch( cms::CMSException& ex) {
+                    ex.printStackTrace();
+                }
+            }
+        };
+        
+    public:
+
+        OpenwireCmsTemplateTest(){}
+        virtual ~OpenwireCmsTemplateTest(){}
+
+        virtual void setUp();
+        virtual void tearDown();
+                
+        virtual void testBasics();
+        virtual void testReceiveException();
+        virtual void testSendException();
+
+    };
+
+}}}
+
+#endif /*_INTEGRATION_CONNECTOR_OPENWIRE_OPENWIRECMSTEMPLATETEST_H_*/



Mime
View raw message