Author: tabish Date: Fri Apr 6 07:12:28 2007 New Revision: 526175 URL: http://svn.apache.org/viewvc?view=rev&rev=526175 Log: Updating the 2.0 release candidate code Modified: activemq/activemq-cpp/tags/activemq-cpp-2.0/src/main/activemq/concurrent/CountDownLatch.h activemq/activemq-cpp/tags/activemq-cpp-2.0/src/main/activemq/connector/stomp/commands/CommandConstants.cpp activemq/activemq-cpp/tags/activemq-cpp-2.0/src/main/activemq/connector/stomp/commands/CommandConstants.h activemq/activemq-cpp/tags/activemq-cpp-2.0/src/main/activemq/core/ActiveMQConsumer.cpp activemq/activemq-cpp/tags/activemq-cpp-2.0/src/test/activemq/concurrent/ThreadPoolTest.cpp activemq/activemq-cpp/tags/activemq-cpp-2.0/src/test/activemq/concurrent/ThreadPoolTest.h activemq/activemq-cpp/tags/activemq-cpp-2.0/src/test/activemq/connector/openwire/commands/ActiveMQMessageTest.cpp activemq/activemq-cpp/tags/activemq-cpp-2.0/src/test/activemq/connector/stomp/commands/MessageCommandTest.h Modified: activemq/activemq-cpp/tags/activemq-cpp-2.0/src/main/activemq/concurrent/CountDownLatch.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/tags/activemq-cpp-2.0/src/main/activemq/concurrent/CountDownLatch.h?view=diff&rev=526175&r1=526174&r2=526175 ============================================================================== --- activemq/activemq-cpp/tags/activemq-cpp-2.0/src/main/activemq/concurrent/CountDownLatch.h (original) +++ activemq/activemq-cpp/tags/activemq-cpp-2.0/src/main/activemq/concurrent/CountDownLatch.h Fri Apr 6 07:12:28 2007 @@ -49,7 +49,8 @@ virtual ~CountDownLatch(); /** - * Waits for the Count to be zero, and then + * Waits for the Count to be zero, and then returns + * @throws CMSException */ virtual void await() throw ( cms::CMSException ); Modified: activemq/activemq-cpp/tags/activemq-cpp-2.0/src/main/activemq/connector/stomp/commands/CommandConstants.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/tags/activemq-cpp-2.0/src/main/activemq/connector/stomp/commands/CommandConstants.cpp?view=diff&rev=526175&r1=526174&r2=526175 ============================================================================== --- activemq/activemq-cpp/tags/activemq-cpp-2.0/src/main/activemq/connector/stomp/commands/CommandConstants.cpp (original) +++ activemq/activemq-cpp/tags/activemq-cpp-2.0/src/main/activemq/connector/stomp/commands/CommandConstants.cpp Fri Apr 6 07:12:28 2007 @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - + #include "CommandConstants.h" #include @@ -44,7 +44,7 @@ //////////////////////////////////////////////////////////////////////////////// CommandConstants::StaticInitializer::StaticInitializer(){ - + stompHeaders[HEADER_DESTINATION] = "destination"; stompHeaders[HEADER_TRANSACTIONID] = "transaction"; stompHeaders[HEADER_CONTENTLENGTH] = "content-length"; @@ -67,8 +67,6 @@ stompHeaders[HEADER_REPLYTO] = "reply-to"; stompHeaders[HEADER_TYPE] = "type"; stompHeaders[HEADER_AMQMSGTYPE] = "amq-msg-type"; - stompHeaders[HEADER_JMSXGROUPID] = "JMSXGroupID"; - stompHeaders[HEADER_JMSXGROUPSEQNO] = "JMSXGroupSeq"; stompHeaders[HEADER_SELECTOR] = "selector"; stompHeaders[HEADER_DISPATCH_ASYNC] = "activemq.dispatchAsync"; stompHeaders[HEADER_EXCLUSIVE] = "activemq.exclusive"; @@ -105,11 +103,11 @@ for( int ix=0; ix::iterator iter = + + static CommandId toCommandId( const std::string& cmd ){ + std::map::iterator iter = StaticInitializer::commandMap.find(cmd); if( iter == StaticInitializer::commandMap.end() ){ return NUM_COMMANDS; } - + return iter->second; } - + static bool isCommandId( const std::string& str ){ - std::map::iterator iter = + std::map::iterator iter = StaticInitializer::commandMap.find(str); return iter != StaticInitializer::commandMap.end(); - } - + } + static std::string toString( const StompHeader header ){ return StaticInitializer::stompHeaders[header]; } - - static StompHeader toStompHeader( const std::string& header ){ - - std::map::iterator iter = + + static StompHeader toStompHeader( const std::string& header ){ + + std::map::iterator iter = StaticInitializer::stompHeaderMap.find(header); if( iter == StaticInitializer::stompHeaderMap.end() ){ return NUM_STOMP_HEADERS; } - - return iter->second; + + return iter->second; } - + static bool isStompHeader( const std::string& str ){ - std::map::iterator iter = + std::map::iterator iter = StaticInitializer::stompHeaderMap.find(str); return iter != StaticInitializer::stompHeaderMap.end(); - } - + } + static std::string toString( const AckMode mode ){ return StaticInitializer::ackModes[mode]; } - + static AckMode toAckMode( const std::string& mode ){ - std::map::iterator iter = + std::map::iterator iter = StaticInitializer::ackModeMap.find(mode); if( iter == StaticInitializer::ackModeMap.end() ){ return NUM_ACK_MODES; } - + return iter->second; - } - + } + static std::string toString( const MessageType type ){ return StaticInitializer::msgTypes[type]; } - + static MessageType toMessageType( const std::string& type ){ - std::map::iterator iter = + std::map::iterator iter = StaticInitializer::msgTypeMap.find(type); if( iter == StaticInitializer::msgTypeMap.end() ){ return NUM_MSG_TYPES; } - + return iter->second; - } + } static cms::Destination* toDestination( const std::string& dest ) throw ( exceptions::IllegalArgumentException ); @@ -187,7 +185,7 @@ public: StaticInitializer(); virtual ~StaticInitializer(){} - + static std::string stompHeaders[NUM_STOMP_HEADERS]; static std::string commands[NUM_COMMANDS]; static std::string ackModes[NUM_ACK_MODES]; @@ -197,12 +195,12 @@ static std::map ackModeMap; static std::map msgTypeMap; }; - + private: - - static StaticInitializer staticInits; + + static StaticInitializer staticInits; }; - + }}}} #endif /*ACTIVEMQ_CONNECTOR_STOMP_COMMANDS_COMMANDCONSTANTS_H_*/ Modified: activemq/activemq-cpp/tags/activemq-cpp-2.0/src/main/activemq/core/ActiveMQConsumer.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/tags/activemq-cpp-2.0/src/main/activemq/core/ActiveMQConsumer.cpp?view=diff&rev=526175&r1=526174&r2=526175 ============================================================================== --- activemq/activemq-cpp/tags/activemq-cpp-2.0/src/main/activemq/core/ActiveMQConsumer.cpp (original) +++ activemq/activemq-cpp/tags/activemq-cpp-2.0/src/main/activemq/core/ActiveMQConsumer.cpp Fri Apr 6 07:12:28 2007 @@ -362,7 +362,7 @@ //////////////////////////////////////////////////////////////////////////////// void ActiveMQConsumer::afterMessageIsConsumed( ActiveMQMessage* message, - bool messageExpired ) + bool messageExpired AMQCPP_UNUSED ) { try { Modified: activemq/activemq-cpp/tags/activemq-cpp-2.0/src/test/activemq/concurrent/ThreadPoolTest.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/tags/activemq-cpp-2.0/src/test/activemq/concurrent/ThreadPoolTest.cpp?view=diff&rev=526175&r1=526174&r2=526175 ============================================================================== --- activemq/activemq-cpp/tags/activemq-cpp-2.0/src/test/activemq/concurrent/ThreadPoolTest.cpp (original) +++ activemq/activemq-cpp/tags/activemq-cpp-2.0/src/test/activemq/concurrent/ThreadPoolTest.cpp Fri Apr 6 07:12:28 2007 @@ -18,3 +18,132 @@ #include "ThreadPoolTest.h" CPPUNIT_TEST_SUITE_REGISTRATION( activemq::concurrent::ThreadPoolTest ); + +using namespace std; +using namespace activemq; +using namespace activemq::concurrent; + +/////////////////////////////////////////////////////////////////////////////// +void ThreadPoolTest::test1() +{ + CountDownLatch myLatch( 3 ); + this->latch = &myLatch; + + MyTask task1( 1 ); + MyTask task2( 2 ); + MyTask task3( 3 ); + + this->complete = 0; + this->tasksToComplete = 3; + + ThreadPool* pool = ThreadPool::getInstance(); + + pool->queueTask( ThreadPool::Task( &task1, this ) ); + pool->queueTask( ThreadPool::Task( &task2, this ) ); + pool->queueTask( ThreadPool::Task( &task3, this ) ); + + // Wait for them to finish, if we can't do this in 30 seconds then + // there's probably something really wrong. + myLatch.await( 30000 ); + + CPPUNIT_ASSERT( this->complete == this->tasksToComplete ); + + CPPUNIT_ASSERT( task1.value == 101 ); + CPPUNIT_ASSERT( task2.value == 102 ); + CPPUNIT_ASSERT( task3.value == 103 ); + + CPPUNIT_ASSERT( pool->getPoolSize() > 0 ); + CPPUNIT_ASSERT( pool->getBacklog() == 0 ); + + CPPUNIT_ASSERT( pool->getMaxThreads() == ThreadPool::DEFAULT_MAX_POOL_SIZE ); + CPPUNIT_ASSERT( pool->getBlockSize() == ThreadPool::DEFAULT_MAX_BLOCK_SIZE ); + + pool->setMaxThreads(50); + pool->setBlockSize(50); + + CPPUNIT_ASSERT( pool->getMaxThreads() == 50 ); + CPPUNIT_ASSERT( pool->getBlockSize() == 50 ); + + // Give it a little time to create all those threads. + for( int i = 0; i < 1000; ++i ) { + if( pool->getFreeThreadCount() == pool->getPoolSize() ) { + break; + } + + Thread::sleep( 100 ); + } + + CPPUNIT_ASSERT( pool->getFreeThreadCount() == pool->getPoolSize() ); + CPPUNIT_ASSERT( this->caughtEx == false ); +} + +/////////////////////////////////////////////////////////////////////////////// +void ThreadPoolTest::test2() { + + try + { + ThreadPool pool; + Mutex myMutex; + + CPPUNIT_ASSERT( pool.getMaxThreads() == ThreadPool::DEFAULT_MAX_POOL_SIZE ); + CPPUNIT_ASSERT( pool.getBlockSize() == ThreadPool::DEFAULT_MAX_BLOCK_SIZE ); + pool.setMaxThreads(3); + pool.setBlockSize(1); + CPPUNIT_ASSERT( pool.getMaxThreads() == 3 ); + CPPUNIT_ASSERT( pool.getBlockSize() == 1 ); + CPPUNIT_ASSERT( pool.getPoolSize() == 0 ); + pool.reserve( 4 ); + CPPUNIT_ASSERT( pool.getPoolSize() == 3 ); + CPPUNIT_ASSERT( pool.getFreeThreadCount() == 3 ); + + CountDownLatch startedLatch1(3); // First three should go right away + CountDownLatch startedLatch2(1); // The fourth one goes after others finish + CountDownLatch doneLatch(4); // All should be done when we are at the end. + + this->latch = &doneLatch; + + MyWaitingTask task1( &myMutex, &startedLatch1 ); + MyWaitingTask task2( &myMutex, &startedLatch1 ); + MyWaitingTask task3( &myMutex, &startedLatch1 ); + MyWaitingTask task4( &myMutex, &startedLatch2 ); + + this->complete = 0; + this->tasksToComplete = 4; + + pool.queueTask( ThreadPool::Task( &task1, this ) ); + pool.queueTask( ThreadPool::Task( &task2, this ) ); + pool.queueTask( ThreadPool::Task( &task3, this ) ); + pool.queueTask( ThreadPool::Task( &task4, this ) ); + + // Wait 30 seconds, then we let it fail because something is + // probably very wrong. + startedLatch1.await( 30000 ); + + CPPUNIT_ASSERT( pool.getFreeThreadCount() == 0 ); + CPPUNIT_ASSERT( pool.getBacklog() == 1 ); + + // Wake up the tasks. + synchronized(&myMutex) { + myMutex.notifyAll(); + } + + // Wait 30 seconds, then we let it fail because something is + // probably very wrong. + startedLatch2.await( 30000 ); + + // Wake up the last task. + synchronized(&myMutex) { + myMutex.notifyAll(); + } + + // Wait for them to finish, if it takes longer than 30 seconds + // something is not right. + doneLatch.await( 30000 ); + + CPPUNIT_ASSERT( this->complete == this->tasksToComplete ); + CPPUNIT_ASSERT( this->caughtEx == false ); + } + catch( exceptions::ActiveMQException& ex ) { + ex.setMark( __FILE__, __LINE__ ); + } +} Modified: activemq/activemq-cpp/tags/activemq-cpp-2.0/src/test/activemq/concurrent/ThreadPoolTest.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/tags/activemq-cpp-2.0/src/test/activemq/concurrent/ThreadPoolTest.h?view=diff&rev=526175&r1=526174&r2=526175 ============================================================================== --- activemq/activemq-cpp/tags/activemq-cpp-2.0/src/test/activemq/concurrent/ThreadPoolTest.h (original) +++ activemq/activemq-cpp/tags/activemq-cpp-2.0/src/test/activemq/concurrent/ThreadPoolTest.h Fri Apr 6 07:12:28 2007 @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -31,221 +32,104 @@ namespace activemq{ namespace concurrent{ - class ThreadPoolTest : - public CppUnit::TestFixture, - public TaskListener - { - CPPUNIT_TEST_SUITE( ThreadPoolTest ); - CPPUNIT_TEST( test1 ); - CPPUNIT_TEST( test2 ); - CPPUNIT_TEST_SUITE_END(); - - int tasksToComplete; - int complete; - Mutex mutex; - Mutex completeMutex; - bool caughtEx; - - public: - - ThreadPoolTest() - { - complete = 0; - tasksToComplete = 0; - caughtEx = false; - } - - virtual ~ThreadPoolTest() {}; - - virtual void onTaskComplete(Runnable* task AMQCPP_UNUSED) - { - try{ - synchronized(&mutex) - { + class ThreadPoolTest : + public CppUnit::TestFixture, + public TaskListener + { + CPPUNIT_TEST_SUITE( ThreadPoolTest ); + CPPUNIT_TEST( test1 ); + CPPUNIT_TEST( test2 ); + CPPUNIT_TEST_SUITE_END(); + + int tasksToComplete; + int complete; + Mutex mutex; + bool caughtEx; + CountDownLatch* latch; + + public: + + ThreadPoolTest() { + complete = 0; + tasksToComplete = 0; + caughtEx = false; + latch = NULL; + } + + virtual ~ThreadPoolTest() {} + + virtual void onTaskComplete(Runnable* task AMQCPP_UNUSED) + { + try{ + complete++; - - if(tasksToComplete == complete) - { - mutex.notifyAll(); + + if( latch != NULL ) { + latch->countDown(); } - } - }catch( exceptions::ActiveMQException& ex ){ - ex.setMark( __FILE__, __LINE__ ); + }catch( exceptions::ActiveMQException& ex ){ + ex.setMark( __FILE__, __LINE__ ); + } } - } - virtual void onTaskException(Runnable* task AMQCPP_UNUSED, - exceptions::ActiveMQException& ex AMQCPP_UNUSED) - { - caughtEx = true; - } - - public: - - class MyTask : public Runnable - { - public: - - int value; - - MyTask(int x) - { - value = x; - } - - virtual ~MyTask() {}; - - virtual void run(void) - { - value += 100; - } - }; - - class MyWaitingTask : public Runnable - { - public: - - Mutex* mutex; - Mutex* complete; - - MyWaitingTask(Mutex* mutex, Mutex* complete) - { - this->mutex = mutex; - this->complete = complete; - } - - virtual ~MyWaitingTask() {}; - - virtual void run(void) - { - try - { - synchronized(mutex) - { - mutex->wait(); - } - - synchronized(complete) - { - complete->notify(); - } + virtual void onTaskException(Runnable* task AMQCPP_UNUSED, + exceptions::ActiveMQException& ex AMQCPP_UNUSED) { + caughtEx = true; + } + + public: + + class MyTask : public Runnable + { + public: + + int value; + + MyTask( int x ) { + value = x; } - catch( exceptions::ActiveMQException& ex ) - { - ex.setMark( __FILE__, __LINE__ ); + + virtual ~MyTask() {}; + + virtual void run(void) { + value += 100; } - } - }; + }; - public: - - void test2() - { - try - { - ThreadPool pool; - Mutex myMutex; - - CPPUNIT_ASSERT( pool.getMaxThreads() == ThreadPool::DEFAULT_MAX_POOL_SIZE ); - CPPUNIT_ASSERT( pool.getBlockSize() == ThreadPool::DEFAULT_MAX_BLOCK_SIZE ); - pool.setMaxThreads(3); - pool.setBlockSize(1); - CPPUNIT_ASSERT( pool.getMaxThreads() == 3 ); - CPPUNIT_ASSERT( pool.getBlockSize() == 1 ); - CPPUNIT_ASSERT( pool.getPoolSize() == 0 ); - pool.reserve( 4 ); - CPPUNIT_ASSERT( pool.getPoolSize() == 3 ); - CPPUNIT_ASSERT( pool.getFreeThreadCount() == 3 ); - - MyWaitingTask task1(&myMutex, &completeMutex); - MyWaitingTask task2(&myMutex, &completeMutex); - MyWaitingTask task3(&myMutex, &completeMutex); - MyWaitingTask task4(&myMutex, &completeMutex); - - complete = 0; - tasksToComplete = 4; - - pool.queueTask(ThreadPool::Task(&task1, this)); - pool.queueTask(ThreadPool::Task(&task2, this)); - pool.queueTask(ThreadPool::Task(&task3, this)); - pool.queueTask(ThreadPool::Task(&task4, this)); - - Thread::sleep( 1000 ); - - CPPUNIT_ASSERT( pool.getFreeThreadCount() == 0 ); - CPPUNIT_ASSERT( pool.getBacklog() == 1 ); - - int count = 0; - while(complete != tasksToComplete && count < 100) - { - synchronized(&myMutex) - { - myMutex.notifyAll(); - } - - synchronized(&completeMutex) - { - completeMutex.wait(1000); - } + class MyWaitingTask : public Runnable + { + public: + + Mutex* mutex; + CountDownLatch* startedLatch; + + MyWaitingTask( Mutex* mutex, CountDownLatch* startedLatch ) { + this->mutex = mutex; + this->startedLatch = startedLatch; + } - count++; + virtual ~MyWaitingTask() {}; + + virtual void run(void) { + try + { + synchronized(mutex) { + startedLatch->countDown(); + mutex->wait(); + } + } + catch( exceptions::ActiveMQException& ex ) { + ex.setMark( __FILE__, __LINE__ ); + } } - - CPPUNIT_ASSERT( complete == tasksToComplete ); - CPPUNIT_ASSERT( caughtEx == false ); - } - catch( exceptions::ActiveMQException& ex ) - { - ex.setMark( __FILE__, __LINE__ ); - } - } - - void test1() - { - MyTask task1(1); - MyTask task2(2); - MyTask task3(3); - - complete = 0; - tasksToComplete = 3; - - ThreadPool* pool = ThreadPool::getInstance(); - - // Can't check this here since one of the other tests might - // have used the global thread pool. - // CPPUNIT_ASSERT( pool->getPoolSize() == 0 ); - - pool->queueTask(ThreadPool::Task(&task1, this)); - pool->queueTask(ThreadPool::Task(&task2, this)); - pool->queueTask(ThreadPool::Task(&task3, this)); - - Thread::sleep(500); - - CPPUNIT_ASSERT( complete == tasksToComplete ); - - CPPUNIT_ASSERT( task1.value == 101 ); - CPPUNIT_ASSERT( task2.value == 102 ); - CPPUNIT_ASSERT( task3.value == 103 ); - - CPPUNIT_ASSERT( pool->getPoolSize() > 0 ); - CPPUNIT_ASSERT( pool->getBacklog() == 0 ); - - CPPUNIT_ASSERT( pool->getMaxThreads() == ThreadPool::DEFAULT_MAX_POOL_SIZE ); - CPPUNIT_ASSERT( pool->getBlockSize() == ThreadPool::DEFAULT_MAX_BLOCK_SIZE ); - - pool->setMaxThreads(50); - pool->setBlockSize(50); - - CPPUNIT_ASSERT( pool->getMaxThreads() == 50 ); - CPPUNIT_ASSERT( pool->getBlockSize() == 50 ); - - Thread::sleep(500); - - CPPUNIT_ASSERT( pool->getFreeThreadCount() == pool->getPoolSize() ); - CPPUNIT_ASSERT( caughtEx == false ); - - } - }; + }; + + public: + + virtual void test1(); + virtual void test2(); + + }; }} Modified: activemq/activemq-cpp/tags/activemq-cpp-2.0/src/test/activemq/connector/openwire/commands/ActiveMQMessageTest.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/tags/activemq-cpp-2.0/src/test/activemq/connector/openwire/commands/ActiveMQMessageTest.cpp?view=diff&rev=526175&r1=526174&r2=526175 ============================================================================== --- activemq/activemq-cpp/tags/activemq-cpp-2.0/src/test/activemq/connector/openwire/commands/ActiveMQMessageTest.cpp (original) +++ activemq/activemq-cpp/tags/activemq-cpp-2.0/src/test/activemq/connector/openwire/commands/ActiveMQMessageTest.cpp Fri Apr 6 07:12:28 2007 @@ -36,20 +36,20 @@ MyAckHandler ackHandler; CPPUNIT_ASSERT( myMessage.getDataStructureType() == ActiveMQMessage::ID_ACTIVEMQMESSAGE ); - + myMessage.setAckHandler( &ackHandler ); myMessage.acknowledge(); - + CPPUNIT_ASSERT( ackHandler.wasAcked == true ); - + CPPUNIT_ASSERT( myMessage.getPropertyNames().size() == 0 ); CPPUNIT_ASSERT( myMessage.propertyExists( "something" ) == false ); - + try { myMessage.getBooleanProperty( "somethingElse" ); CPPUNIT_ASSERT( false ); } catch(...) {} - + myMessage.setBooleanProperty( "boolean", false ); myMessage.setByteProperty( "byte", 60 ); myMessage.setDoubleProperty( "double", 642.5643 ); @@ -58,7 +58,7 @@ myMessage.setLongProperty( "long", 0xFFFFFFFF0000000LL ); myMessage.setShortProperty( "short", 512 ); myMessage.setStringProperty( "string", "This is a test String" ); - + CPPUNIT_ASSERT( myMessage.getBooleanProperty( "boolean" ) == false ); CPPUNIT_ASSERT( myMessage.getByteProperty( "byte" ) == 60 ); CPPUNIT_ASSERT( myMessage.getDoubleProperty( "double" ) == 642.5643 ); @@ -67,4 +67,7 @@ CPPUNIT_ASSERT( myMessage.getLongProperty( "long" ) == 0xFFFFFFFF0000000LL ); CPPUNIT_ASSERT( myMessage.getShortProperty( "short" ) == 512 ); CPPUNIT_ASSERT( myMessage.getStringProperty( "string" ) == "This is a test String" ); + + myMessage.setStringProperty( "JMSXGroupID", "hello" ); + CPPUNIT_ASSERT( myMessage.getStringProperty( "JMSXGroupID" ) == "hello" ); } Modified: activemq/activemq-cpp/tags/activemq-cpp-2.0/src/test/activemq/connector/stomp/commands/MessageCommandTest.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/tags/activemq-cpp-2.0/src/test/activemq/connector/stomp/commands/MessageCommandTest.h?view=diff&rev=526175&r1=526174&r2=526175 ============================================================================== --- activemq/activemq-cpp/tags/activemq-cpp-2.0/src/test/activemq/connector/stomp/commands/MessageCommandTest.h (original) +++ activemq/activemq-cpp/tags/activemq-cpp-2.0/src/test/activemq/connector/stomp/commands/MessageCommandTest.h Fri Apr 6 07:12:28 2007 @@ -43,39 +43,39 @@ CPPUNIT_TEST_SUITE_END(); protected: - + class TestAckHandler : public core::ActiveMQAckHandler { public: - + TestAckHandler(void) { wasAcked = false; } virtual ~TestAckHandler(void) {} - + virtual void acknowledgeMessage( const core::ActiveMQMessage* message AMQCPP_UNUSED) - throw ( cms::CMSException ) + throw ( cms::CMSException ) { wasAcked = true; } - + public: - + bool wasAcked; }; - + public: - MessageCommandTest() {} - virtual ~MessageCommandTest() {} + MessageCommandTest() {} + virtual ~MessageCommandTest() {} void test(void) { TestAckHandler ackHandler; MessageCommand cmd; - CPPUNIT_ASSERT( cmd.getStompCommandId() == + CPPUNIT_ASSERT( cmd.getStompCommandId() == CommandConstants::SEND ); - + CPPUNIT_ASSERT( cmd.isResponseRequired() == false ); cmd.setResponseRequired( true ); cmd.setCommandId( 123 ); @@ -85,53 +85,53 @@ CPPUNIT_ASSERT( cmd.getCorrelationId() == 0 ); CPPUNIT_ASSERT( cmd.getTransactionId() == "" ); cmd.setTransactionId( "ID:123456" ); - CPPUNIT_ASSERT( std::string( cmd.getTransactionId() ) == + CPPUNIT_ASSERT( std::string( cmd.getTransactionId() ) == "ID:123456" ); StompTopic topic("testTopic"); cmd.setCMSDestination( &topic ); - + StompFrame* frame = cmd.marshal().clone(); - + CPPUNIT_ASSERT( frame != NULL ); - + MessageCommand cmd1( frame ); - + CPPUNIT_ASSERT( cmd.getCommandId() == cmd1.getCommandId() ); CPPUNIT_ASSERT( cmd.getStompCommandId() == CommandConstants::SEND ); CPPUNIT_ASSERT( cmd.isResponseRequired() == cmd1.isResponseRequired() ); CPPUNIT_ASSERT( cmd.getCorrelationId() == cmd1.getCorrelationId() ); CPPUNIT_ASSERT( std::string(cmd.getTransactionId()) == cmd1.getTransactionId() ); - + cmd.setAckHandler( &ackHandler ); cmd.acknowledge(); CPPUNIT_ASSERT( ackHandler.wasAcked == true ); - - CPPUNIT_ASSERT( + + CPPUNIT_ASSERT( cmd.getProperties().hasProperty( "test" ) == false ); cmd.getProperties().setProperty( "test", "value" ); - CPPUNIT_ASSERT( + CPPUNIT_ASSERT( cmd.getProperties().hasProperty( "test" ) == true ); - CPPUNIT_ASSERT( - std::string( cmd.getProperties().getProperty( "test" ) ) == + CPPUNIT_ASSERT( + std::string( cmd.getProperties().getProperty( "test" ) ) == "value" ); - + CPPUNIT_ASSERT( cmd.getCMSCorrelationID() == "" ); cmd.setCMSCorrelationID( "ID:1234567" ); - CPPUNIT_ASSERT( std::string( cmd.getCMSCorrelationID() ) == + CPPUNIT_ASSERT( std::string( cmd.getCMSCorrelationID() ) == "ID:1234567" ); - CPPUNIT_ASSERT( cmd.getCMSDeliveryMode() == + CPPUNIT_ASSERT( cmd.getCMSDeliveryMode() == cms::DeliveryMode::PERSISTENT ); cmd.setCMSDeliveryMode( cms::DeliveryMode::NON_PERSISTENT ); - CPPUNIT_ASSERT( cmd.getCMSDeliveryMode() == + CPPUNIT_ASSERT( cmd.getCMSDeliveryMode() == cms::DeliveryMode::NON_PERSISTENT ); - CPPUNIT_ASSERT( cmd.getCMSDestination()->toProviderString() == + CPPUNIT_ASSERT( cmd.getCMSDestination()->toProviderString() == "/topic/testTopic" ); CPPUNIT_ASSERT( cmd.getCMSExpiration() == 0 ); cmd.setCMSExpiration( 123 ); CPPUNIT_ASSERT( cmd.getCMSExpiration() == 123 ); CPPUNIT_ASSERT( cmd.getCMSMessageID() == "" ); cmd.setCMSMessageID( "ID:1234567" ); - CPPUNIT_ASSERT( std::string( cmd.getCMSMessageID() ) == + CPPUNIT_ASSERT( std::string( cmd.getCMSMessageID() ) == "ID:1234567" ); CPPUNIT_ASSERT( cmd.getCMSPriority() == 0 ); cmd.setCMSPriority( 5 ); @@ -141,21 +141,21 @@ CPPUNIT_ASSERT( cmd.getCMSRedelivered() == true ); CPPUNIT_ASSERT( cmd.getCMSReplyTo() == NULL ); cmd.setCMSReplyTo( &topic ); - CPPUNIT_ASSERT( cmd.getCMSReplyTo()->toProviderString() == + CPPUNIT_ASSERT( cmd.getCMSReplyTo()->toProviderString() == "/topic/testTopic" ); CPPUNIT_ASSERT( cmd.getCMSTimestamp() == 0 ); cmd.setCMSTimestamp( 123 ); CPPUNIT_ASSERT( cmd.getCMSTimestamp() == 123 ); CPPUNIT_ASSERT( cmd.getCMSType() == "" ); cmd.setCMSType( "test" ); - CPPUNIT_ASSERT( std::string( cmd.getCMSType() ) == + CPPUNIT_ASSERT( std::string( cmd.getCMSType() ) == "test" ); CPPUNIT_ASSERT( cmd.getRedeliveryCount() == 0 ); cmd.setRedeliveryCount( 123 ); CPPUNIT_ASSERT( cmd.getRedeliveryCount() == 123 ); cms::Message* cmd2 = cmd.clone(); - + CPPUNIT_ASSERT( cmd.getCMSPriority() == cmd2->getCMSPriority() ); CPPUNIT_ASSERT( cmd.getCMSTimestamp() == cmd2->getCMSTimestamp() ); CPPUNIT_ASSERT( cmd.getCMSExpiration() == cmd2->getCMSExpiration() ); @@ -165,14 +165,14 @@ CPPUNIT_ASSERT( std::string(cmd.getCMSType()) == cmd2->getCMSType() ); CPPUNIT_ASSERT( std::string(cmd.getCMSMessageID()) == cmd2->getCMSMessageID() ); - core::ActiveMQMessage* message = + core::ActiveMQMessage* message = dynamic_cast< core::ActiveMQMessage* >( cmd2 ); - + CPPUNIT_ASSERT( message != NULL ); - CPPUNIT_ASSERT( cmd.getRedeliveryCount() == + CPPUNIT_ASSERT( cmd.getRedeliveryCount() == message->getRedeliveryCount() ); - - StompCommand* cmd4 = + + StompCommand* cmd4 = dynamic_cast< StompCommand* >( cmd2 ); CPPUNIT_ASSERT( cmd4 != NULL ); @@ -180,7 +180,7 @@ CPPUNIT_ASSERT( cmd.getStompCommandId() == cmd4->getStompCommandId() ); CPPUNIT_ASSERT( cmd.isResponseRequired() == cmd4->isResponseRequired() ); CPPUNIT_ASSERT( cmd.getCorrelationId() == cmd4->getCorrelationId() ); - CPPUNIT_ASSERT( std::string(cmd.getTransactionId()) == + CPPUNIT_ASSERT( std::string(cmd.getTransactionId()) == cmd4->getTransactionId() ); delete cmd2; @@ -188,43 +188,46 @@ void testSetProperties(){ MessageCommand cmd; - + cmd.setBooleanProperty( "bool", true ); CPPUNIT_ASSERT( cmd.getBooleanProperty( "bool" ) == true ); - + cmd.setByteProperty( "byte", 1 ); CPPUNIT_ASSERT( cmd.getByteProperty( "byte" ) == 1 ); - + cmd.setDoubleProperty( "double", 2.2 ); CPPUNIT_ASSERT( cmd.getDoubleProperty( "double" ) == 2.2 ); - + cmd.setFloatProperty( "float", 3.3f ); CPPUNIT_ASSERT( cmd.getFloatProperty( "float" ) == 3.3f ); - + cmd.setIntProperty( "int", 4 ); CPPUNIT_ASSERT( cmd.getIntProperty( "int" ) == 4 ); - + cmd.setLongProperty( "long", 5LL ); CPPUNIT_ASSERT( cmd.getLongProperty( "long" ) == 5LL ); - + cmd.setShortProperty( "short", 6 ); CPPUNIT_ASSERT( cmd.getShortProperty( "short" ) == 6 ); - + cmd.setStringProperty( "string", "hello" ); - CPPUNIT_ASSERT( cmd.getStringProperty( "string" ) == "hello" ); + CPPUNIT_ASSERT( cmd.getStringProperty( "string" ) == "hello" ); + + cmd.setStringProperty( "JMSXGroupID", "hello" ); + CPPUNIT_ASSERT( cmd.getStringProperty( "JMSXGroupID" ) == "hello" ); } void testFailedGetProperties(){ MessageCommand cmd; - - // Test getting a string property that doesn't exist. + + // Test getting a string property that doesn't exist. try { std::string str = cmd.getStringProperty( "text" ); CPPUNIT_ASSERT(false); } catch( cms::CMSException& e){ } - - // Test getting a bool property that doesn't exist. + + // Test getting a bool property that doesn't exist. try { cmd.getBooleanProperty( "text" ); CPPUNIT_ASSERT(false); @@ -235,57 +238,57 @@ try{ cmd.getIntProperty("string"); CPPUNIT_ASSERT(false); - } catch( cms::CMSException& e ){ + } catch( cms::CMSException& e ){ } - + // Test failed extraction try{ cmd.setStringProperty("string", "hello"); cmd.getIntProperty("string"); CPPUNIT_ASSERT(false); - } catch( cms::CMSException& e ){ + } catch( cms::CMSException& e ){ } - } - + } + void testGetPropertyNames(){ - + MessageCommand cmd; - + std::vector names = cmd.getPropertyNames(); CPPUNIT_ASSERT( names.size() == 0 ); - + cmd.setIntProperty( "int1", 1 ); names = cmd.getPropertyNames(); CPPUNIT_ASSERT( names.size() == 1 ); CPPUNIT_ASSERT( names[0] == "int1" ); - + cmd.setIntProperty( "int2", 2 ); names = cmd.getPropertyNames(); CPPUNIT_ASSERT( names.size() == 2 ); CPPUNIT_ASSERT( names[0] == "int1" || names[1] == "int1" ); CPPUNIT_ASSERT( names[0] == "int2" || names[1] == "int2" ); - + // Make sure headers aren't included in the property names. cmd.setCMSExpiration( 10000 ); names = cmd.getPropertyNames(); CPPUNIT_ASSERT( names.size() == 2 ); } - + void testClearProperties(){ MessageCommand cmd; - + cmd.setIntProperty( "int1", 1 ); cmd.setIntProperty( "int2", 2 ); - + CPPUNIT_ASSERT( cmd.propertyExists( "int1" ) == true ); CPPUNIT_ASSERT( cmd.propertyExists( "int2" ) == true ); - + cmd.clearProperties(); - + CPPUNIT_ASSERT( cmd.propertyExists( "int1" ) == false ); - CPPUNIT_ASSERT( cmd.propertyExists( "int2" ) == false ); + CPPUNIT_ASSERT( cmd.propertyExists( "int2" ) == false ); } - + }; }}}}