activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1434357 - /activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/activemq/test/SimpleTest.cpp
Date Wed, 16 Jan 2013 20:02:51 GMT
Author: tabish
Date: Wed Jan 16 20:02:50 2013
New Revision: 1434357

URL: http://svn.apache.org/viewvc?rev=1434357&view=rev
Log:
https://issues.apache.org/jira/browse/AMQCPP-448

Add some additional testing to check if there's an issue here.

Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/activemq/test/SimpleTest.cpp

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/activemq/test/SimpleTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/activemq/test/SimpleTest.cpp?rev=1434357&r1=1434356&r2=1434357&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/activemq/test/SimpleTest.cpp
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/activemq/test/SimpleTest.cpp
Wed Jan 16 20:02:50 2013
@@ -39,105 +39,90 @@ using namespace decaf::util;
 ////////////////////////////////////////////////////////////////////////////////
 void SimpleTest::testAutoAck() {
 
-    try {
-
-        // Create CMS Object for Comms
-        cms::Session* session( cmsProvider->getSession() );
+    // Create CMS Object for Comms
+    cms::Session* session( cmsProvider->getSession() );
 
-        CMSListener listener( session );
+    CMSListener listener( session );
 
-        cms::MessageConsumer* consumer = cmsProvider->getConsumer();
-        consumer->setMessageListener( &listener );
-        cms::MessageProducer* producer = cmsProvider->getProducer();
-        producer->setDeliveryMode( DeliveryMode::NON_PERSISTENT );
+    cms::MessageConsumer* consumer = cmsProvider->getConsumer();
+    consumer->setMessageListener( &listener );
+    cms::MessageProducer* producer = cmsProvider->getProducer();
+    producer->setDeliveryMode( DeliveryMode::NON_PERSISTENT );
 
-        auto_ptr<cms::TextMessage> txtMessage( session->createTextMessage( "TEST
MESSAGE" ) );
-        auto_ptr<cms::BytesMessage> bytesMessage( session->createBytesMessage()
);
+    auto_ptr<cms::TextMessage> txtMessage( session->createTextMessage( "TEST MESSAGE"
) );
+    auto_ptr<cms::BytesMessage> bytesMessage( session->createBytesMessage() );
 
-        for( unsigned int i = 0; i < IntegrationCommon::defaultMsgCount; ++i ) {
-            producer->send( txtMessage.get() );
-        }
+    for( unsigned int i = 0; i < IntegrationCommon::defaultMsgCount; ++i ) {
+        producer->send( txtMessage.get() );
+    }
 
-        for( unsigned int i = 0; i < IntegrationCommon::defaultMsgCount; ++i ) {
-            producer->send( bytesMessage.get() );
-        }
+    for( unsigned int i = 0; i < IntegrationCommon::defaultMsgCount; ++i ) {
+        producer->send( bytesMessage.get() );
+    }
 
-        // Wait for the messages to get here
-        listener.asyncWaitForMessages( IntegrationCommon::defaultMsgCount * 2 );
+    // Wait for the messages to get here
+    listener.asyncWaitForMessages( IntegrationCommon::defaultMsgCount * 2 );
 
-        unsigned int numReceived = listener.getNumReceived();
-        CPPUNIT_ASSERT( numReceived == IntegrationCommon::defaultMsgCount * 2 );
-    }
-    AMQ_CATCH_RETHROW( ActiveMQException )
-    AMQ_CATCHALL_THROW( ActiveMQException )
+    unsigned int numReceived = listener.getNumReceived();
+    CPPUNIT_ASSERT( numReceived == IntegrationCommon::defaultMsgCount * 2 );
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 void SimpleTest::testClientAck() {
 
-    try {
-
-        cmsProvider->setAckMode( cms::Session::CLIENT_ACKNOWLEDGE );
-        cmsProvider->reconnectSession();
+    cmsProvider->setAckMode( cms::Session::CLIENT_ACKNOWLEDGE );
+    cmsProvider->reconnectSession();
 
-        // Create CMS Object for Comms
-        cms::Session* session( cmsProvider->getSession() );
+    // Create CMS Object for Comms
+    cms::Session* session( cmsProvider->getSession() );
 
-        CMSListener listener( session );
+    CMSListener listener( session );
 
-        cms::MessageConsumer* consumer = cmsProvider->getConsumer();
-        consumer->setMessageListener( &listener );
-        cms::MessageProducer* producer = cmsProvider->getProducer();
-        producer->setDeliveryMode( DeliveryMode::NON_PERSISTENT );
+    cms::MessageConsumer* consumer = cmsProvider->getConsumer();
+    consumer->setMessageListener( &listener );
+    cms::MessageProducer* producer = cmsProvider->getProducer();
+    producer->setDeliveryMode( DeliveryMode::NON_PERSISTENT );
 
-        auto_ptr<cms::TextMessage> txtMessage( session->createTextMessage( "TEST
MESSAGE" ) );
-        auto_ptr<cms::BytesMessage> bytesMessage( session->createBytesMessage()
);
+    auto_ptr<cms::TextMessage> txtMessage( session->createTextMessage( "TEST MESSAGE"
) );
+    auto_ptr<cms::BytesMessage> bytesMessage( session->createBytesMessage() );
 
-        for( unsigned int i = 0; i < IntegrationCommon::defaultMsgCount; ++i ) {
-            producer->send( txtMessage.get() );
-        }
+    for( unsigned int i = 0; i < IntegrationCommon::defaultMsgCount; ++i ) {
+        producer->send( txtMessage.get() );
+    }
 
-        for( unsigned int i = 0; i < IntegrationCommon::defaultMsgCount; ++i ) {
-            producer->send( bytesMessage.get() );
-        }
+    for( unsigned int i = 0; i < IntegrationCommon::defaultMsgCount; ++i ) {
+        producer->send( bytesMessage.get() );
+    }
 
-        // Wait for the messages to get here
-        listener.asyncWaitForMessages( IntegrationCommon::defaultMsgCount * 2 );
+    // Wait for the messages to get here
+    listener.asyncWaitForMessages( IntegrationCommon::defaultMsgCount * 2 );
 
-        unsigned int numReceived = listener.getNumReceived();
-        CPPUNIT_ASSERT( numReceived == IntegrationCommon::defaultMsgCount * 2 );
-    }
-    AMQ_CATCH_RETHROW( ActiveMQException )
-    AMQ_CATCHALL_THROW( ActiveMQException )
+    unsigned int numReceived = listener.getNumReceived();
+    CPPUNIT_ASSERT( numReceived == IntegrationCommon::defaultMsgCount * 2 );
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 void SimpleTest::testProducerWithNullDestination() {
 
-    try{
-
-        // Create CMS Object for Comms
-        cms::Session* session( cmsProvider->getSession() );
+    // Create CMS Object for Comms
+    cms::Session* session( cmsProvider->getSession() );
 
-        CMSListener listener( session );
+    CMSListener listener( session );
 
-        cms::MessageConsumer* consumer = cmsProvider->getConsumer();
-        consumer->setMessageListener( &listener );
-        cms::MessageProducer* producer = cmsProvider->getNoDestProducer();
-        producer->setDeliveryMode( DeliveryMode::NON_PERSISTENT );
+    cms::MessageConsumer* consumer = cmsProvider->getConsumer();
+    consumer->setMessageListener( &listener );
+    cms::MessageProducer* producer = cmsProvider->getNoDestProducer();
+    producer->setDeliveryMode( DeliveryMode::NON_PERSISTENT );
 
-        auto_ptr<cms::TextMessage> txtMessage( session->createTextMessage( "TEST
MESSAGE" ) );
+    auto_ptr<cms::TextMessage> txtMessage( session->createTextMessage( "TEST MESSAGE"
) );
 
-        producer->send( cmsProvider->getDestination(), txtMessage.get() );
+    producer->send( cmsProvider->getDestination(), txtMessage.get() );
 
-        // Wait for the messages to get here
-        listener.asyncWaitForMessages( 1 );
+    // Wait for the messages to get here
+    listener.asyncWaitForMessages( 1 );
 
-        unsigned int numReceived = listener.getNumReceived();
-        CPPUNIT_ASSERT( numReceived == 1 );
-    }
-    AMQ_CATCH_RETHROW( ActiveMQException )
-    AMQ_CATCHALL_THROW( ActiveMQException )
+    unsigned int numReceived = listener.getNumReceived();
+    CPPUNIT_ASSERT( numReceived == 1 );
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -190,256 +175,228 @@ void SimpleTest::testProducerSendToNonDe
 ////////////////////////////////////////////////////////////////////////////////
 void SimpleTest::testSyncReceive() {
 
-    try {
-
-        // Create CMS Object for Comms
-        cms::Session* session( cmsProvider->getSession() );
-        cms::MessageConsumer* consumer = cmsProvider->getConsumer();
-        cms::MessageProducer* producer = cmsProvider->getProducer();
-        producer->setDeliveryMode( DeliveryMode::NON_PERSISTENT );
+    // Create CMS Object for Comms
+    cms::Session* session( cmsProvider->getSession() );
+    cms::MessageConsumer* consumer = cmsProvider->getConsumer();
+    cms::MessageProducer* producer = cmsProvider->getProducer();
+    producer->setDeliveryMode( DeliveryMode::NON_PERSISTENT );
 
-        auto_ptr<cms::TextMessage> txtMessage( session->createTextMessage( "TEST
MESSAGE" ) );
+    auto_ptr<cms::TextMessage> txtMessage( session->createTextMessage( "TEST MESSAGE"
) );
 
-        // Send some text messages
-        producer->send( txtMessage.get() );
+    // Send some text messages
+    producer->send( txtMessage.get() );
 
-        auto_ptr<cms::Message> message( consumer->receive( 2000 ) );
-        CPPUNIT_ASSERT( message.get() != NULL );
-    }
-    AMQ_CATCH_RETHROW( ActiveMQException )
-    AMQ_CATCHALL_THROW( ActiveMQException )
+    auto_ptr<cms::Message> message( consumer->receive( 2000 ) );
+    CPPUNIT_ASSERT( message.get() != NULL );
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 void SimpleTest::testSyncReceiveClientAck() {
 
-    try {
-
-        cmsProvider->setAckMode( cms::Session::CLIENT_ACKNOWLEDGE );
-        cmsProvider->reconnectSession();
+    cmsProvider->setAckMode( cms::Session::CLIENT_ACKNOWLEDGE );
+    cmsProvider->reconnectSession();
 
-        // Create CMS Object for Comms
-        cms::Session* session( cmsProvider->getSession() );
-        cms::MessageConsumer* consumer = cmsProvider->getConsumer();
-        cms::MessageProducer* producer = cmsProvider->getProducer();
-        producer->setDeliveryMode( DeliveryMode::NON_PERSISTENT );
+    // Create CMS Object for Comms
+    cms::Session* session( cmsProvider->getSession() );
+    cms::MessageConsumer* consumer = cmsProvider->getConsumer();
+    cms::MessageProducer* producer = cmsProvider->getProducer();
+    producer->setDeliveryMode( DeliveryMode::NON_PERSISTENT );
 
-        auto_ptr<cms::TextMessage> txtMessage( session->createTextMessage( "TEST
MESSAGE" ) );
+    auto_ptr<cms::TextMessage> txtMessage( session->createTextMessage( "TEST MESSAGE"
) );
 
-        // Send some text messages
-        producer->send( txtMessage.get() );
+    // Send some text messages
+    producer->send( txtMessage.get() );
 
-        auto_ptr<cms::Message> message( consumer->receive( 2000 ) );
-        CPPUNIT_ASSERT( message.get() != NULL );
-    }
-    AMQ_CATCH_RETHROW( ActiveMQException )
-    AMQ_CATCHALL_THROW( ActiveMQException )
+    auto_ptr<cms::Message> message( consumer->receive( 2000 ) );
+    CPPUNIT_ASSERT( message.get() != NULL );
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 void SimpleTest::testMultipleConnections() {
 
-    try {
-
-        // Create CMS Object for Comms
-        auto_ptr<ActiveMQConnectionFactory> factory(new ActiveMQConnectionFactory(cmsProvider->getBrokerURL()));
-        auto_ptr<cms::Connection> connection1( factory->createConnection() );
-        connection1->start();
+    // Create CMS Object for Comms
+    auto_ptr<ActiveMQConnectionFactory> factory(new ActiveMQConnectionFactory(cmsProvider->getBrokerURL()));
+    auto_ptr<cms::Connection> connection1( factory->createConnection() );
+    connection1->start();
 
-        auto_ptr<cms::Connection> connection2( factory->createConnection() );
-        connection2->start();
+    auto_ptr<cms::Connection> connection2( factory->createConnection() );
+    connection2->start();
 
-        CPPUNIT_ASSERT( connection1->getClientID() != connection2->getClientID() );
+    CPPUNIT_ASSERT( connection1->getClientID() != connection2->getClientID() );
 
-        auto_ptr<cms::Session> session1( connection1->createSession() );
-        auto_ptr<cms::Session> session2( connection1->createSession() );
+    auto_ptr<cms::Session> session1( connection1->createSession() );
+    auto_ptr<cms::Session> session2( connection1->createSession() );
 
-        auto_ptr<cms::Topic> topic( session1->createTopic( UUID::randomUUID().toString()
) );
+    auto_ptr<cms::Topic> topic( session1->createTopic( UUID::randomUUID().toString()
) );
 
-        auto_ptr<cms::MessageConsumer> consumer1( session1->createConsumer( topic.get()
) );
-        auto_ptr<cms::MessageConsumer> consumer2( session2->createConsumer( topic.get()
) );
+    auto_ptr<cms::MessageConsumer> consumer1( session1->createConsumer( topic.get()
) );
+    auto_ptr<cms::MessageConsumer> consumer2( session2->createConsumer( topic.get()
) );
 
-        auto_ptr<cms::MessageProducer> producer( session2->createProducer( topic.get()
) );
-        producer->setDeliveryMode( DeliveryMode::NON_PERSISTENT );
+    auto_ptr<cms::MessageProducer> producer( session2->createProducer( topic.get()
) );
+    producer->setDeliveryMode( DeliveryMode::NON_PERSISTENT );
 
-        auto_ptr<cms::TextMessage> textMessage( session2->createTextMessage() );
+    auto_ptr<cms::TextMessage> textMessage( session2->createTextMessage() );
 
-        // Send some text messages
-        producer->send( textMessage.get() );
+    // Send some text messages
+    producer->send( textMessage.get() );
 
-        auto_ptr<cms::Message> message( consumer1->receive( 2000 ) );
-        CPPUNIT_ASSERT( message.get() != NULL );
+    auto_ptr<cms::Message> message( consumer1->receive( 2000 ) );
+    CPPUNIT_ASSERT( message.get() != NULL );
 
-        message.reset( consumer2->receive( 2000 ) );
-        CPPUNIT_ASSERT( message.get() != NULL );
+    message.reset( consumer2->receive( 2000 ) );
+    CPPUNIT_ASSERT( message.get() != NULL );
 
-        // Clean up if we can
-        consumer1->close();
-        consumer2->close();
-        producer->close();
-        session1->close();
-        session2->close();
+    // Clean up if we can
+    consumer1->close();
+    consumer2->close();
+    producer->close();
+    session1->close();
+    session2->close();
 
-        this->cmsProvider->destroyDestination( topic.get() );
-    }
-    AMQ_CATCH_RETHROW( ActiveMQException )
-    AMQ_CATCHALL_THROW( ActiveMQException )
+    this->cmsProvider->destroyDestination( topic.get() );
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 void SimpleTest::testMultipleSessions() {
-    try {
 
-        // Create CMS Object for Comms
-        auto_ptr<cms::Session> session1( cmsProvider->getConnection()->createSession()
);
-        auto_ptr<cms::Session> session2( cmsProvider->getConnection()->createSession()
);
+    // Create CMS Object for Comms
+    auto_ptr<cms::Session> session1( cmsProvider->getConnection()->createSession()
);
+    auto_ptr<cms::Session> session2( cmsProvider->getConnection()->createSession()
);
 
-        auto_ptr<cms::Topic> topic( session1->createTopic( UUID::randomUUID().toString()
) );
+    auto_ptr<cms::Topic> topic( session1->createTopic( UUID::randomUUID().toString()
) );
 
-        auto_ptr<cms::MessageConsumer> consumer1( session1->createConsumer( topic.get()
) );
-        auto_ptr<cms::MessageConsumer> consumer2( session2->createConsumer( topic.get()
) );
+    auto_ptr<cms::MessageConsumer> consumer1( session1->createConsumer( topic.get()
) );
+    auto_ptr<cms::MessageConsumer> consumer2( session2->createConsumer( topic.get()
) );
 
-        auto_ptr<cms::MessageProducer> producer( session2->createProducer( topic.get()
) );
-        producer->setDeliveryMode( DeliveryMode::NON_PERSISTENT );
+    auto_ptr<cms::MessageProducer> producer( session2->createProducer( topic.get()
) );
+    producer->setDeliveryMode( DeliveryMode::NON_PERSISTENT );
 
-        auto_ptr<cms::TextMessage> textMessage( session2->createTextMessage() );
+    auto_ptr<cms::TextMessage> textMessage( session2->createTextMessage() );
 
-        // Send some text messages
-        producer->send( textMessage.get() );
+    // Send some text messages
+    producer->send( textMessage.get() );
 
-        auto_ptr<cms::Message> message( consumer1->receive( 2000 ) );
-        CPPUNIT_ASSERT( message.get() != NULL );
+    auto_ptr<cms::Message> message( consumer1->receive( 2000 ) );
+    CPPUNIT_ASSERT( message.get() != NULL );
 
-        message.reset( consumer2->receive( 2000 ) );
-        CPPUNIT_ASSERT( message.get() != NULL );
+    message.reset( consumer2->receive( 2000 ) );
+    CPPUNIT_ASSERT( message.get() != NULL );
 
-        // Clean up if we can
-        consumer1->close();
-        consumer2->close();
-        producer->close();
-        session1->close();
-        session2->close();
+    // Clean up if we can
+    consumer1->close();
+    consumer2->close();
+    producer->close();
+    session1->close();
+    session2->close();
 
-        this->cmsProvider->destroyDestination( topic.get() );
-    }
-    AMQ_CATCH_RETHROW( ActiveMQException )
-    AMQ_CATCHALL_THROW( ActiveMQException )
+    this->cmsProvider->destroyDestination( topic.get() );
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 void SimpleTest::testReceiveAlreadyInQueue() {
 
-    try {
-
-        // Create CMS Object for Comms
-        auto_ptr<ActiveMQConnectionFactory> factory(new ActiveMQConnectionFactory(cmsProvider->getBrokerURL()));
-        auto_ptr<cms::Connection> connection(factory->createConnection());
+    // Create CMS Object for Comms
+    auto_ptr<ActiveMQConnectionFactory> factory(new ActiveMQConnectionFactory(cmsProvider->getBrokerURL()));
+    auto_ptr<cms::Connection> connection(factory->createConnection());
 
-        auto_ptr<cms::Session> session(connection->createSession());
-        auto_ptr<cms::Topic> topic(session->createTopic(UUID::randomUUID().toString()));
-        auto_ptr<cms::MessageConsumer> consumer(session->createConsumer(topic.get()));
-        auto_ptr<cms::MessageProducer> producer(session->createProducer(topic.get()));
-        producer->setDeliveryMode(DeliveryMode::NON_PERSISTENT);
-        auto_ptr<cms::TextMessage> textMessage(session->createTextMessage());
+    auto_ptr<cms::Session> session(connection->createSession());
+    auto_ptr<cms::Topic> topic(session->createTopic(UUID::randomUUID().toString()));
+    auto_ptr<cms::MessageConsumer> consumer(session->createConsumer(topic.get()));
+    auto_ptr<cms::MessageProducer> producer(session->createProducer(topic.get()));
+    producer->setDeliveryMode(DeliveryMode::NON_PERSISTENT);
+    auto_ptr<cms::TextMessage> textMessage(session->createTextMessage());
 
-        // Send some text messages
-        producer->send(textMessage.get());
+    // Send some text messages
+    producer->send(textMessage.get());
 
-        Thread::sleep(250);
+    Thread::sleep(250);
 
-        connection->start();
+    connection->start();
 
-        auto_ptr<cms::Message> message(consumer->receive(2000));
-        CPPUNIT_ASSERT( message.get() != NULL );
+    auto_ptr<cms::Message> message(consumer->receive(2000));
+    CPPUNIT_ASSERT( message.get() != NULL );
 
-        // Clean up if we can
-        consumer->close();
-        producer->close();
-        session->close();
+    // Clean up if we can
+    consumer->close();
+    producer->close();
+    session->close();
 
-        this->cmsProvider->destroyDestination(topic.get());
-    }
-    AMQ_CATCH_RETHROW( ActiveMQException )
-    AMQ_CATCHALL_THROW( ActiveMQException )
+    this->cmsProvider->destroyDestination(topic.get());
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 void SimpleTest::testQuickCreateAndDestroy() {
 
-    try{
-
-        auto_ptr<ActiveMQConnectionFactory> factory(new ActiveMQConnectionFactory(cmsProvider->getBrokerURL()));
-        auto_ptr<cms::Connection> connection( factory->createConnection() );
-        auto_ptr<cms::Session> session( connection->createSession() );
-
-        session.reset( NULL );
-        connection.reset( NULL );
-
-        connection.reset( factory->createConnection() );
-        session.reset( connection->createSession() );
-        connection->start();
-
-        session.reset( NULL );
-        connection.reset( NULL );
-
-        for( int i = 0; i < 50; ++i ) {
-            CMSProvider lcmsProvider( this->getBrokerURL() );
-            lcmsProvider.getSession();
-            lcmsProvider.getConsumer();
-            lcmsProvider.getProducer();
-        }
-
-    } catch ( CMSException& e ) {
-        e.printStackTrace();
-        CPPUNIT_ASSERT( false );
+    auto_ptr<ActiveMQConnectionFactory> factory(new ActiveMQConnectionFactory(cmsProvider->getBrokerURL()));
+    auto_ptr<cms::Connection> connection( factory->createConnection() );
+    auto_ptr<cms::Session> session( connection->createSession() );
+
+    session.reset( NULL );
+    connection.reset( NULL );
+
+    connection.reset( factory->createConnection() );
+    session.reset( connection->createSession() );
+    connection->start();
+
+    session.reset( NULL );
+    connection.reset( NULL );
+
+    for( int i = 0; i < 50; ++i ) {
+        CMSProvider lcmsProvider( this->getBrokerURL() );
+        lcmsProvider.getSession();
+        lcmsProvider.getConsumer();
+        lcmsProvider.getProducer();
     }
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 void SimpleTest::testBytesMessageSendRecv() {
 
-    try {
+    // Create CMS Object for Comms
+    cms::Session* session(cmsProvider->getSession());
+    cms::MessageConsumer* consumer = cmsProvider->getConsumer();
+    cms::MessageProducer* producer = cmsProvider->getProducer();
+    producer->setDeliveryMode(DeliveryMode::NON_PERSISTENT);
 
-        // Create CMS Object for Comms
-        cms::Session* session(cmsProvider->getSession());
-        cms::MessageConsumer* consumer = cmsProvider->getConsumer();
-        cms::MessageProducer* producer = cmsProvider->getProducer();
-        producer->setDeliveryMode(DeliveryMode::NON_PERSISTENT);
-
-        auto_ptr<cms::BytesMessage> bytesMessage(session->createBytesMessage());
-
-        bytesMessage->writeBoolean(true);
-        bytesMessage->writeByte(127);
-        bytesMessage->writeDouble(123456.789);
-        bytesMessage->writeInt(65537);
-        bytesMessage->writeString("TEST-STRING");
+    auto_ptr<cms::BytesMessage> bytesMessage(session->createBytesMessage());
 
-        // Send some text messages
-        producer->send( bytesMessage.get() );
+    bytesMessage->writeBoolean(true);
+    bytesMessage->writeByte(127);
+    bytesMessage->writeDouble(123456.789);
+    bytesMessage->writeInt(65537);
+    bytesMessage->writeString("TEST-STRING");
 
-        auto_ptr<cms::Message> message( consumer->receive( 2000 ) );
-        CPPUNIT_ASSERT( message.get() != NULL );
+    // Send some text messages
+    producer->send( bytesMessage.get() );
 
-        CPPUNIT_ASSERT_THROW_MESSAGE(
-            "Should throw an ActiveMQExceptio",
-            message->setStringProperty( "FOO", "BAR" ),
-            cms::CMSException );
-
-        BytesMessage* bytesMessage2 = dynamic_cast<cms::BytesMessage*>( message.get()
);
-        CPPUNIT_ASSERT( bytesMessage2 != NULL );
-        CPPUNIT_ASSERT_THROW_MESSAGE(
-            "Should throw an ActiveMQExceptio",
-            bytesMessage2->writeBoolean( false ),
-            cms::CMSException );
-
-        CPPUNIT_ASSERT( bytesMessage2->readBoolean() == true );
-        CPPUNIT_ASSERT( bytesMessage2->readByte() == 127 );
-        CPPUNIT_ASSERT( bytesMessage2->readDouble() == 123456.789 );
-        CPPUNIT_ASSERT( bytesMessage2->readInt() == 65537 );
-        CPPUNIT_ASSERT( bytesMessage2->readString() == "TEST-STRING" );
-    }
-    AMQ_CATCH_RETHROW( ActiveMQException )
-    AMQ_CATCHALL_THROW( ActiveMQException )
+    auto_ptr<cms::Message> message( consumer->receive( 2000 ) );
+    CPPUNIT_ASSERT( message.get() != NULL );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw an ActiveMQExceptio",
+        message->setStringProperty( "FOO", "BAR" ),
+        cms::CMSException );
+
+    BytesMessage* bytesMessage2 = dynamic_cast<cms::BytesMessage*>( message.get() );
+    CPPUNIT_ASSERT( bytesMessage2 != NULL );
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw an ActiveMQExceptio",
+        bytesMessage2->writeBoolean( false ),
+        cms::CMSException );
+
+    CPPUNIT_ASSERT( bytesMessage2->getBodyLength() > 0 );
+
+    unsigned char* result = bytesMessage2->getBodyBytes();
+    CPPUNIT_ASSERT( result != NULL );
+    delete result;
+
+    bytesMessage2->reset();
+
+    CPPUNIT_ASSERT( bytesMessage2->readBoolean() == true );
+    CPPUNIT_ASSERT( bytesMessage2->readByte() == 127 );
+    CPPUNIT_ASSERT( bytesMessage2->readDouble() == 123456.789 );
+    CPPUNIT_ASSERT( bytesMessage2->readInt() == 65537 );
+    CPPUNIT_ASSERT( bytesMessage2->readString() == "TEST-STRING" );
 }
 
 ////////////////////////////////////////////////////////////////////////////////



Mime
View raw message