You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2010/11/18 00:20:02 UTC

svn commit: r1036279 - in /activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/activemq/test/openwire: OpenwireXATransactionsTest.cpp OpenwireXATransactionsTest.h

Author: tabish
Date: Wed Nov 17 23:20:01 2010
New Revision: 1036279

URL: http://svn.apache.org/viewvc?rev=1036279&view=rev
Log:
https://issues.apache.org/activemq/browse/AMQCPP-329

Some initial tests showing that creating and basic usage of the XA objects works.

Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/activemq/test/openwire/OpenwireXATransactionsTest.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/activemq/test/openwire/OpenwireXATransactionsTest.h

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/activemq/test/openwire/OpenwireXATransactionsTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/activemq/test/openwire/OpenwireXATransactionsTest.cpp?rev=1036279&r1=1036278&r2=1036279&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/activemq/test/openwire/OpenwireXATransactionsTest.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/activemq/test/openwire/OpenwireXATransactionsTest.cpp Wed Nov 17 23:20:01 2010
@@ -17,12 +17,23 @@
 
 #include "OpenwireXATransactionsTest.h"
 
+#include <activemq/core/ActiveMQXAConnectionFactory.h>
+#include <activemq/core/ActiveMQXAConnection.h>
+#include <activemq/core/ActiveMQXASession.h>
 #include <activemq/exceptions/ActiveMQException.h>
 
 #include <decaf/lang/Thread.h>
 
+#include <cms/ConnectionFactory.h>
+#include <cms/Connection.h>
 #include <cms/Session.h>
+#include <cms/MessageConsumer.h>
+#include <cms/MessageProducer.h>
 #include <cms/MessageListener.h>
+#include <cms/XAConnectionFactory.h>
+#include <cms/XAConnection.h>
+#include <cms/Message.h>
+#include <cms/TextMessage.h>
 
 #include <memory>
 
@@ -31,6 +42,7 @@ using namespace std;
 using namespace decaf;
 using namespace decaf::lang;
 using namespace activemq;
+using namespace activemq::core;
 using namespace activemq::test;
 using namespace activemq::test::openwire;
 
@@ -45,4 +57,90 @@ OpenwireXATransactionsTest::~OpenwireXAT
 ////////////////////////////////////////////////////////////////////////////////
 void OpenwireXATransactionsTest::testCreateXAConnectionFactory() {
 
+    std::auto_ptr<XAConnectionFactory> factory(
+        XAConnectionFactory::createCMSXAConnectionFactory( getBrokerURL() ) );
+    CPPUNIT_ASSERT( factory.get() != NULL );
+
+    ConnectionFactory* cmsFactory = dynamic_cast<ConnectionFactory*>( factory.get() );
+    CPPUNIT_ASSERT( cmsFactory != NULL );
+
+    ActiveMQConnectionFactory* amqFactory = dynamic_cast<ActiveMQConnectionFactory*>( factory.get() );
+    CPPUNIT_ASSERT( amqFactory != NULL );
+
+    ActiveMQXAConnectionFactory* amqXAFactory = dynamic_cast<ActiveMQXAConnectionFactory*>( factory.get() );
+    CPPUNIT_ASSERT( amqXAFactory != NULL );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void OpenwireXATransactionsTest::testCreateXAConnection() {
+
+    std::auto_ptr<XAConnectionFactory> factory(
+        XAConnectionFactory::createCMSXAConnectionFactory( getBrokerURL() ) );
+    CPPUNIT_ASSERT( factory.get() != NULL );
+
+    std::auto_ptr<XAConnection> connection( factory->createXAConnection() );
+    CPPUNIT_ASSERT( connection.get() != NULL );
+
+    Connection* cmsConnection = dynamic_cast<Connection*>( connection.get() );
+    CPPUNIT_ASSERT( cmsConnection != NULL );
+
+    ActiveMQConnection* amqConnection = dynamic_cast<ActiveMQConnection*>( connection.get() );
+    CPPUNIT_ASSERT( amqConnection != NULL );
+
+    ActiveMQXAConnection* amqXAConnection = dynamic_cast<ActiveMQXAConnection*>( connection.get() );
+    CPPUNIT_ASSERT( amqXAConnection != NULL );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void OpenwireXATransactionsTest::testCreateXASession() {
+
+    std::auto_ptr<XAConnectionFactory> factory(
+        XAConnectionFactory::createCMSXAConnectionFactory( getBrokerURL() ) );
+    CPPUNIT_ASSERT( factory.get() != NULL );
+
+    std::auto_ptr<XAConnection> connection( factory->createXAConnection() );
+    CPPUNIT_ASSERT( connection.get() != NULL );
+
+    std::auto_ptr<XASession> session( connection->createXASession() );
+    CPPUNIT_ASSERT( session.get() != NULL );
+
+    Session* cmsSession = dynamic_cast<Session*>( session.get() );
+    CPPUNIT_ASSERT( cmsSession != NULL );
+
+    ActiveMQSession* amqSession = dynamic_cast<ActiveMQSession*>( session.get() );
+    CPPUNIT_ASSERT( amqSession != NULL );
+
+    ActiveMQXASession* amqXASession = dynamic_cast<ActiveMQXASession*>( session.get() );
+    CPPUNIT_ASSERT( amqXASession != NULL );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void OpenwireXATransactionsTest::testSendReceiveOutsideTX() {
+
+    std::auto_ptr<XAConnectionFactory> factory(
+        XAConnectionFactory::createCMSXAConnectionFactory( getBrokerURL() ) );
+    CPPUNIT_ASSERT( factory.get() != NULL );
+
+    std::auto_ptr<XAConnection> connection( factory->createXAConnection() );
+    CPPUNIT_ASSERT( connection.get() != NULL );
+
+    std::auto_ptr<XASession> session( connection->createXASession() );
+    CPPUNIT_ASSERT( session.get() != NULL );
+
+    std::auto_ptr<Destination> destination( session->createTemporaryQueue() );
+    std::auto_ptr<MessageProducer> producer( session->createProducer( destination.get() ) );
+    std::auto_ptr<MessageConsumer> consumer( session->createConsumer( destination.get() ) );
+
+    connection->start();
+
+    for( int i = 0; i < 50; ++i ) {
+        std::auto_ptr<Message> message( session->createTextMessage( "TEST" ) );
+        producer->send( message.get() );
+    }
+
+    for( int i = 0; i < 50; ++i ) {
+        std::auto_ptr<Message> message( consumer->receive( 3000 ) );
+        CPPUNIT_ASSERT( message.get() != NULL );
+        CPPUNIT_ASSERT( dynamic_cast<TextMessage*>( message.get() ) != NULL );
+    }
 }

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/activemq/test/openwire/OpenwireXATransactionsTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/activemq/test/openwire/OpenwireXATransactionsTest.h?rev=1036279&r1=1036278&r2=1036279&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/activemq/test/openwire/OpenwireXATransactionsTest.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/activemq/test/openwire/OpenwireXATransactionsTest.h Wed Nov 17 23:20:01 2010
@@ -29,6 +29,9 @@ namespace openwire {
 
         CPPUNIT_TEST_SUITE( OpenwireXATransactionsTest );
         CPPUNIT_TEST( testCreateXAConnectionFactory );
+        CPPUNIT_TEST( testCreateXAConnection );
+        CPPUNIT_TEST( testCreateXASession );
+        CPPUNIT_TEST( testSendReceiveOutsideTX );
         CPPUNIT_TEST_SUITE_END();
 
     public:
@@ -41,6 +44,9 @@ namespace openwire {
         }
 
         void testCreateXAConnectionFactory();
+        void testCreateXAConnection();
+        void testCreateXASession();
+        void testSendReceiveOutsideTX();
 
     };