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 2008/02/04 01:13:12 UTC

svn commit: r618129 - in /activemq/activemq-cpp/trunk/src: main/activemq/cmsutil/CmsTemplate.cpp main/activemq/cmsutil/SessionPool.cpp test/Makefile.am test/activemq/cmsutil/CmsTemplateTest.cpp test/activemq/cmsutil/CmsTemplateTest.h

Author: nmittler
Date: Sun Feb  3 16:13:11 2008
New Revision: 618129

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

Added:
    activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/CmsTemplateTest.cpp
    activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/CmsTemplateTest.h
Modified:
    activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsTemplate.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/SessionPool.cpp
    activemq/activemq-cpp/trunk/src/test/Makefile.am

Modified: activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsTemplate.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsTemplate.cpp?rev=618129&r1=618128&r2=618129&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsTemplate.cpp (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsTemplate.cpp Sun Feb  3 16:13:11 2008
@@ -20,10 +20,12 @@
 #include <activemq/exceptions/ExceptionDefines.h>
 #include "ProducerCallback.h"
 #include "MessageCreator.h"
+#include <iostream>
 
 using namespace activemq::cmsutil;
 using namespace activemq::exceptions;
 using namespace decaf::lang::exceptions;
+using namespace std;
 
 ////////////////////////////////////////////////////////////////////////////////
 CmsTemplate::CmsTemplate() {
@@ -54,6 +56,14 @@
     deliveryMode = cms::DeliveryMode::PERSISTENT;
     priority = DEFAULT_PRIORITY;
     timeToLive = DEFAULT_TIME_TO_LIVE;
+    
+    // Initialize the connection object.
+    connection = NULL;
+    
+    // Initialize the session pools.
+    for( int ix=0; ix<NUM_SESSION_POOLS; ++ix) {
+        sessionPools[ix] = NULL;
+    }
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -145,7 +155,7 @@
         
         // If we don't have a connection, create one.
         if( connection == NULL ) {
-        
+            
             // Invoke the base class to create the connection and add it
             // to the resource lifecycle manager.
             connection = createConnection();
@@ -169,6 +179,10 @@
 
     try {
         
+        // Get the connection resource to verify that the connection and session
+        // pools have been allocated.
+        getConnection();
+        
         // Take a session from the pool.
         return sessionPools[getSessionAcknowledgeMode()]->takeSession();        
     }
@@ -301,7 +315,7 @@
         if( action == NULL ) {
             return;
         }
-    
+        
         // Take a session from the pool.
         pooledSession = takeSession();
         

Modified: activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/SessionPool.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/SessionPool.cpp?rev=618129&r1=618128&r2=618129&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/SessionPool.cpp (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/SessionPool.cpp Sun Feb  3 16:13:11 2008
@@ -61,7 +61,7 @@
             resourceLifecycleManager->addSession(session);
 
             // Now wrap the session with a pooled session.
-            PooledSession* pooledSession = new PooledSession(this, session);
+            pooledSession = new PooledSession(this, session);
 
             // Add to the sessions list.
             sessions.push_back(pooledSession);

Modified: activemq/activemq-cpp/trunk/src/test/Makefile.am
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/Makefile.am?rev=618129&r1=618128&r2=618129&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/Makefile.am (original)
+++ activemq/activemq-cpp/trunk/src/test/Makefile.am Sun Feb  3 16:13:11 2008
@@ -64,6 +64,7 @@
   activemq/cmsutil/CmsAccessorTest.cpp \
   activemq/cmsutil/CmsDestinationAccessorTest.cpp \
   activemq/cmsutil/SessionPoolTest.cpp \
+  activemq/cmsutil/CmsTemplateTest.cpp \
   activemq/exceptions/ActiveMQExceptionTest.cpp \
   activemq/transport/IOTransportTest.cpp \
   activemq/transport/filters/ResponseCorrelatorTest.cpp \

Added: activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/CmsTemplateTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/CmsTemplateTest.cpp?rev=618129&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/CmsTemplateTest.cpp (added)
+++ activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/CmsTemplateTest.cpp Sun Feb  3 16:13:11 2008
@@ -0,0 +1,69 @@
+/*
+ * 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 "CmsTemplateTest.h"
+#include <activemq/cmsutil/DynamicDestinationResolver.h>
+#include <activemq/cmsutil/ResourceLifecycleManager.h>
+#include "DummyConnectionFactory.h"
+
+CPPUNIT_TEST_SUITE_REGISTRATION( activemq::cmsutil::CmsTemplateTest );
+
+using namespace activemq;
+using namespace activemq::cmsutil;
+
+////////////////////////////////////////////////////////////////////////////////
+void CmsTemplateTest::setUp() {
+    cf = new DummyConnectionFactory();
+    cmsTemplate = new CmsTemplate(cf);
+    cmsTemplate->setDefaultDestinationName("test");
+    cmsTemplate->init();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CmsTemplateTest::tearDown() {
+    cmsTemplate->destroy();
+    delete cmsTemplate;
+    delete cf;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CmsTemplateTest::testExecuteSession() {
+
+    cmsTemplate->setSessionAcknowledgeMode(cms::Session::CLIENT_ACKNOWLEDGE);
+    
+    // Test basics.
+    MySessionCallback sessionCallback;    
+    cmsTemplate->execute(&sessionCallback);    
+    CPPUNIT_ASSERT(sessionCallback.session != NULL);
+    CPPUNIT_ASSERT(sessionCallback.ackMode == cms::Session::CLIENT_ACKNOWLEDGE);
+    
+    // Try again and make sure we get the same session
+    MySessionCallback sessionCallback2;
+    cmsTemplate->execute(&sessionCallback2);    
+    CPPUNIT_ASSERT(sessionCallback2.session == sessionCallback.session);
+    CPPUNIT_ASSERT(sessionCallback2.ackMode == cms::Session::CLIENT_ACKNOWLEDGE);
+    
+    // Now try different ack mode and make sure we have a different session.
+    cmsTemplate->setSessionAcknowledgeMode(cms::Session::AUTO_ACKNOWLEDGE);
+    MySessionCallback sessionCallback3;
+    cmsTemplate->execute(&sessionCallback3);  
+    CPPUNIT_ASSERT(sessionCallback3.session != NULL);
+    CPPUNIT_ASSERT(sessionCallback3.session != sessionCallback.session);
+    CPPUNIT_ASSERT(sessionCallback3.ackMode == cms::Session::AUTO_ACKNOWLEDGE);
+}
+
+

Added: activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/CmsTemplateTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/CmsTemplateTest.h?rev=618129&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/CmsTemplateTest.h (added)
+++ activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/CmsTemplateTest.h Sun Feb  3 16:13:11 2008
@@ -0,0 +1,92 @@
+/*
+ * 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 _ACTIVEMQ_CMSUTIL_CMSTEMPLATETEST_H_
+#define _ACTIVEMQ_CMSUTIL_CMSTEMPLATETEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <activemq/cmsutil/CmsTemplate.h>
+#include <activemq/cmsutil/SessionCallback.h>
+#include <activemq/cmsutil/ProducerCallback.h>
+
+namespace activemq{
+namespace cmsutil{
+
+    class DummyConnectionFactory;
+    
+    class CmsTemplateTest : public CppUnit::TestFixture
+    {
+        CPPUNIT_TEST_SUITE( CmsTemplateTest );
+        CPPUNIT_TEST( testExecuteSession );
+        CPPUNIT_TEST_SUITE_END();               
+             
+
+        CmsTemplate* cmsTemplate;
+        DummyConnectionFactory* cf;
+        
+        class MySessionCallback : public SessionCallback {
+        public:
+            
+            cms::Session* session;
+            cms::Session::AcknowledgeMode ackMode;
+            
+            MySessionCallback() {
+                session = NULL;
+            }
+            virtual ~MySessionCallback(){}
+            
+            virtual void doInCms(cms::Session* session) throw (cms::CMSException) {            
+                this->session = session;
+                this->ackMode = session->getAcknowledgeMode();
+            }
+        };
+        
+        class MyProducerCallback : public ProducerCallback {
+        public:
+            
+            cms::Session* session;
+            cms::MessageProducer* producer;
+            
+            MyProducerCallback() {
+                session = NULL;
+                producer = NULL;
+            }
+            virtual ~MyProducerCallback(){}
+            
+            virtual void doInCms(cms::Session* session, 
+                    cms::MessageProducer* producer) throw (cms::CMSException) {
+                this->session = session;
+                this->producer = producer;
+            }
+        };
+        
+    public:
+
+        CmsTemplateTest() {}
+        virtual ~CmsTemplateTest() {}
+
+        virtual void setUp();
+        virtual void tearDown();
+        
+        void testExecuteSession();
+    };
+
+}}
+
+#endif /*_ACTIVEMQ_CMSUTIL_CMSTEMPLATETEST_H_*/