Author: tabish Date: Wed Nov 9 21:00:05 2011 New Revision: 1199959 URL: http://svn.apache.org/viewvc?rev=1199959&view=rev Log: Fix for: https://issues.apache.org/jira/browse/AMQCPP-382 Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConsumer.cpp activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/activemq/test/openwire/OpenwireSimpleTest.cpp activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/activemq/test/openwire/OpenwireSimpleTest.h Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConsumer.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConsumer.cpp?rev=1199959&r1=1199958&r2=1199959&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConsumer.cpp (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConsumer.cpp Wed Nov 9 21:00:05 2011 @@ -1124,7 +1124,7 @@ void ActiveMQConsumer::dispatch( const P if( !this->internal->unconsumedMessages->isClosed() ) { // Don't dispatch expired messages, ack it and then destroy it - if( dispatch->getMessage()->isExpired() ) { + if( dispatch->getMessage() != NULL && dispatch->getMessage()->isExpired() ) { this->ackLater( dispatch, ActiveMQConstants::ACK_TYPE_CONSUMED ); // stop now, don't queue Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/activemq/test/openwire/OpenwireSimpleTest.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/activemq/test/openwire/OpenwireSimpleTest.cpp?rev=1199959&r1=1199958&r2=1199959&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/activemq/test/openwire/OpenwireSimpleTest.cpp (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/activemq/test/openwire/OpenwireSimpleTest.cpp Wed Nov 9 21:00:05 2011 @@ -45,164 +45,174 @@ OpenwireSimpleTest::~OpenwireSimpleTest( //////////////////////////////////////////////////////////////////////////////// void OpenwireSimpleTest::testWithZeroConsumerPrefetch() { - try { + cmsProvider->setTopic( false ); + cmsProvider->setDestinationName( + UUID::randomUUID().toString() + "?consumer.prefetchSize=0" ); - cmsProvider->setTopic( false ); - cmsProvider->setDestinationName( - UUID::randomUUID().toString() + "?consumer.prefetchSize=0" ); + cmsProvider->reconnectSession(); - 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 txtMessage( session->createTextMessage( "TEST MESSAGE" ) ); - auto_ptr txtMessage( session->createTextMessage( "TEST MESSAGE" ) ); + // Send some text messages + producer->send( txtMessage.get() ); - // Send some text messages - producer->send( txtMessage.get() ); + auto_ptr message( consumer->receive( 1000 ) ); + CPPUNIT_ASSERT( message.get() != NULL ); +} - auto_ptr message( consumer->receive( 1000 ) ); - CPPUNIT_ASSERT( message.get() != NULL ); - } - AMQ_CATCH_RETHROW( ActiveMQException ) - AMQ_CATCHALL_THROW( ActiveMQException ) +//////////////////////////////////////////////////////////////////////////////// +void OpenwireSimpleTest::testWithZeroConsumerPrefetchAndNoMessage() { + + cmsProvider->setTopic( false ); + cmsProvider->setDestinationName( + UUID::randomUUID().toString() + "?consumer.prefetchSize=0" ); + + cmsProvider->reconnectSession(); + + // Create CMS Object for Comms + cms::Session* session( cmsProvider->getSession() ); + cms::MessageConsumer* consumer = cmsProvider->getConsumer(); + + // Should be no message and no exceptions + auto_ptr message( consumer->receiveNoWait() ); + CPPUNIT_ASSERT( message.get() == NULL ); + + // Should be no message and no exceptions + message.reset( consumer->receive(1000) ); + CPPUNIT_ASSERT( message.get() == NULL ); + + consumer->close(); + session->close(); } //////////////////////////////////////////////////////////////////////////////// void OpenwireSimpleTest::testMapMessageSendToQueue() { - try { + cmsProvider->setTopic( false ); + cmsProvider->setDestinationName( + UUID::randomUUID().toString() + "?consumer.prefetchSize=0" ); - cmsProvider->setTopic( false ); - cmsProvider->setDestinationName( - UUID::randomUUID().toString() + "?consumer.prefetchSize=0" ); + cmsProvider->reconnectSession(); - 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 ); + unsigned char byteValue = 'A'; + char charValue = 'B'; + bool booleanValue = true; + short shortValue = 2048; + int intValue = 655369; + long long longValue = 0xFFFFFFFF00000000ULL; + float floatValue = 45.6545f; + double doubleValue = 654564.654654; + std::string stringValue = "The test string"; - unsigned char byteValue = 'A'; - char charValue = 'B'; - bool booleanValue = true; - short shortValue = 2048; - int intValue = 655369; - long long longValue = 0xFFFFFFFF00000000ULL; - float floatValue = 45.6545f; - double doubleValue = 654564.654654; - std::string stringValue = "The test string"; - - auto_ptr mapMessage( session->createMapMessage() ); - - mapMessage->setString( "stringKey", stringValue ); - mapMessage->setBoolean( "boolKey", booleanValue ); - mapMessage->setByte( "byteKey", byteValue ); - mapMessage->setChar( "charKey", charValue ); - mapMessage->setShort( "shortKey", shortValue ); - mapMessage->setInt( "intKey", intValue ); - mapMessage->setLong( "longKey", longValue ); - mapMessage->setFloat( "floatKey", floatValue ); - mapMessage->setDouble( "doubleKey", doubleValue ); - - std::vector bytes; - bytes.push_back( 65 ); - bytes.push_back( 66 ); - bytes.push_back( 67 ); - bytes.push_back( 68 ); - bytes.push_back( 69 ); - mapMessage->setBytes( "bytesKey", bytes ); + auto_ptr mapMessage( session->createMapMessage() ); - // Send some text messages - producer->send( mapMessage.get() ); + mapMessage->setString( "stringKey", stringValue ); + mapMessage->setBoolean( "boolKey", booleanValue ); + mapMessage->setByte( "byteKey", byteValue ); + mapMessage->setChar( "charKey", charValue ); + mapMessage->setShort( "shortKey", shortValue ); + mapMessage->setInt( "intKey", intValue ); + mapMessage->setLong( "longKey", longValue ); + mapMessage->setFloat( "floatKey", floatValue ); + mapMessage->setDouble( "doubleKey", doubleValue ); - auto_ptr message( consumer->receive( 2000 ) ); - CPPUNIT_ASSERT( message.get() != NULL ); + std::vector bytes; + bytes.push_back( 65 ); + bytes.push_back( 66 ); + bytes.push_back( 67 ); + bytes.push_back( 68 ); + bytes.push_back( 69 ); + mapMessage->setBytes( "bytesKey", bytes ); - cms::MapMessage* recvMapMessage = dynamic_cast( message.get() ); - CPPUNIT_ASSERT( recvMapMessage != NULL ); - CPPUNIT_ASSERT( recvMapMessage->getString( "stringKey" ) == stringValue ); - CPPUNIT_ASSERT( recvMapMessage->getBoolean( "boolKey" ) == booleanValue ); - CPPUNIT_ASSERT( recvMapMessage->getByte( "byteKey" ) == byteValue ); - CPPUNIT_ASSERT( recvMapMessage->getChar( "charKey" ) == charValue ); - CPPUNIT_ASSERT( recvMapMessage->getShort( "shortKey" ) == shortValue ); - CPPUNIT_ASSERT( recvMapMessage->getInt( "intKey" ) == intValue ); - CPPUNIT_ASSERT( recvMapMessage->getLong( "longKey" ) == longValue ); - CPPUNIT_ASSERT( recvMapMessage->getFloat( "floatKey" ) == floatValue ); - CPPUNIT_ASSERT( recvMapMessage->getDouble( "doubleKey" ) == doubleValue ); - CPPUNIT_ASSERT( recvMapMessage->getBytes( "bytesKey" ) == bytes ); - } - AMQ_CATCH_RETHROW( ActiveMQException ) - AMQ_CATCHALL_THROW( ActiveMQException ) + // Send some text messages + producer->send( mapMessage.get() ); + + auto_ptr message( consumer->receive( 2000 ) ); + CPPUNIT_ASSERT( message.get() != NULL ); + + cms::MapMessage* recvMapMessage = dynamic_cast( message.get() ); + CPPUNIT_ASSERT( recvMapMessage != NULL ); + CPPUNIT_ASSERT( recvMapMessage->getString( "stringKey" ) == stringValue ); + CPPUNIT_ASSERT( recvMapMessage->getBoolean( "boolKey" ) == booleanValue ); + CPPUNIT_ASSERT( recvMapMessage->getByte( "byteKey" ) == byteValue ); + CPPUNIT_ASSERT( recvMapMessage->getChar( "charKey" ) == charValue ); + CPPUNIT_ASSERT( recvMapMessage->getShort( "shortKey" ) == shortValue ); + CPPUNIT_ASSERT( recvMapMessage->getInt( "intKey" ) == intValue ); + CPPUNIT_ASSERT( recvMapMessage->getLong( "longKey" ) == longValue ); + CPPUNIT_ASSERT( recvMapMessage->getFloat( "floatKey" ) == floatValue ); + CPPUNIT_ASSERT( recvMapMessage->getDouble( "doubleKey" ) == doubleValue ); + CPPUNIT_ASSERT( recvMapMessage->getBytes( "bytesKey" ) == bytes ); } //////////////////////////////////////////////////////////////////////////////// void OpenwireSimpleTest::testMapMessageSendToTopic() { - 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 ); + unsigned char byteValue = 'A'; + char charValue = 'B'; + bool booleanValue = true; + short shortValue = 2048; + int intValue = 655369; + long long longValue = 0xFFFFFFFF00000000ULL; + float floatValue = 45.6545f; + double doubleValue = 654564.654654; + std::string stringValue = "The test string"; - unsigned char byteValue = 'A'; - char charValue = 'B'; - bool booleanValue = true; - short shortValue = 2048; - int intValue = 655369; - long long longValue = 0xFFFFFFFF00000000ULL; - float floatValue = 45.6545f; - double doubleValue = 654564.654654; - std::string stringValue = "The test string"; - - auto_ptr mapMessage( session->createMapMessage() ); - - mapMessage->setString( "stringKey", stringValue ); - mapMessage->setBoolean( "boolKey", booleanValue ); - mapMessage->setByte( "byteKey", byteValue ); - mapMessage->setChar( "charKey", charValue ); - mapMessage->setShort( "shortKey", shortValue ); - mapMessage->setInt( "intKey", intValue ); - mapMessage->setLong( "longKey", longValue ); - mapMessage->setFloat( "floatKey", floatValue ); - mapMessage->setDouble( "doubleKey", doubleValue ); - - std::vector bytes; - bytes.push_back( 65 ); - bytes.push_back( 66 ); - bytes.push_back( 67 ); - bytes.push_back( 68 ); - bytes.push_back( 69 ); - mapMessage->setBytes( "bytesKey", bytes ); + auto_ptr mapMessage( session->createMapMessage() ); - // Send some text messages - producer->send( mapMessage.get() ); + mapMessage->setString( "stringKey", stringValue ); + mapMessage->setBoolean( "boolKey", booleanValue ); + mapMessage->setByte( "byteKey", byteValue ); + mapMessage->setChar( "charKey", charValue ); + mapMessage->setShort( "shortKey", shortValue ); + mapMessage->setInt( "intKey", intValue ); + mapMessage->setLong( "longKey", longValue ); + mapMessage->setFloat( "floatKey", floatValue ); + mapMessage->setDouble( "doubleKey", doubleValue ); - auto_ptr message( consumer->receive( 2000 ) ); - CPPUNIT_ASSERT( message.get() != NULL ); + std::vector bytes; + bytes.push_back( 65 ); + bytes.push_back( 66 ); + bytes.push_back( 67 ); + bytes.push_back( 68 ); + bytes.push_back( 69 ); + mapMessage->setBytes( "bytesKey", bytes ); - cms::MapMessage* recvMapMessage = dynamic_cast( message.get() ); - CPPUNIT_ASSERT( recvMapMessage != NULL ); - CPPUNIT_ASSERT( recvMapMessage->getString( "stringKey" ) == stringValue ); - CPPUNIT_ASSERT( recvMapMessage->getBoolean( "boolKey" ) == booleanValue ); - CPPUNIT_ASSERT( recvMapMessage->getByte( "byteKey" ) == byteValue ); - CPPUNIT_ASSERT( recvMapMessage->getChar( "charKey" ) == charValue ); - CPPUNIT_ASSERT( recvMapMessage->getShort( "shortKey" ) == shortValue ); - CPPUNIT_ASSERT( recvMapMessage->getInt( "intKey" ) == intValue ); - CPPUNIT_ASSERT( recvMapMessage->getLong( "longKey" ) == longValue ); - CPPUNIT_ASSERT( recvMapMessage->getFloat( "floatKey" ) == floatValue ); - CPPUNIT_ASSERT( recvMapMessage->getDouble( "doubleKey" ) == doubleValue ); - CPPUNIT_ASSERT( recvMapMessage->getBytes( "bytesKey" ) == bytes ); - } - AMQ_CATCH_RETHROW( ActiveMQException ) - AMQ_CATCHALL_THROW( ActiveMQException ) + // Send some text messages + producer->send( mapMessage.get() ); + + auto_ptr message( consumer->receive( 2000 ) ); + CPPUNIT_ASSERT( message.get() != NULL ); + + cms::MapMessage* recvMapMessage = dynamic_cast( message.get() ); + CPPUNIT_ASSERT( recvMapMessage != NULL ); + CPPUNIT_ASSERT( recvMapMessage->getString( "stringKey" ) == stringValue ); + CPPUNIT_ASSERT( recvMapMessage->getBoolean( "boolKey" ) == booleanValue ); + CPPUNIT_ASSERT( recvMapMessage->getByte( "byteKey" ) == byteValue ); + CPPUNIT_ASSERT( recvMapMessage->getChar( "charKey" ) == charValue ); + CPPUNIT_ASSERT( recvMapMessage->getShort( "shortKey" ) == shortValue ); + CPPUNIT_ASSERT( recvMapMessage->getInt( "intKey" ) == intValue ); + CPPUNIT_ASSERT( recvMapMessage->getLong( "longKey" ) == longValue ); + CPPUNIT_ASSERT( recvMapMessage->getFloat( "floatKey" ) == floatValue ); + CPPUNIT_ASSERT( recvMapMessage->getDouble( "doubleKey" ) == doubleValue ); + CPPUNIT_ASSERT( recvMapMessage->getBytes( "bytesKey" ) == bytes ); } //////////////////////////////////////////////////////////////////////////////// @@ -245,7 +255,7 @@ void OpenwireSimpleTest::testDestroyDest } catch( ActiveMQException& ex ) { ex.printStackTrace(); CPPUNIT_ASSERT_MESSAGE( "CAUGHT EXCEPTION", false ); - } AMQ_CATCHALL_THROW( ActiveMQException ) + } } //////////////////////////////////////////////////////////////////////////////// Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/activemq/test/openwire/OpenwireSimpleTest.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/activemq/test/openwire/OpenwireSimpleTest.h?rev=1199959&r1=1199958&r2=1199959&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/activemq/test/openwire/OpenwireSimpleTest.h (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/test-integration/activemq/test/openwire/OpenwireSimpleTest.h Wed Nov 9 21:00:05 2011 @@ -40,6 +40,7 @@ namespace openwire{ CPPUNIT_TEST( testBytesMessageSendRecv ); CPPUNIT_TEST( testQuickCreateAndDestroy ); CPPUNIT_TEST( testWithZeroConsumerPrefetch ); + CPPUNIT_TEST( testWithZeroConsumerPrefetchAndNoMessage ); CPPUNIT_TEST( testMapMessageSendToQueue ); CPPUNIT_TEST( testMapMessageSendToTopic ); CPPUNIT_TEST( testDestroyDestination ); @@ -57,6 +58,7 @@ namespace openwire{ } void testWithZeroConsumerPrefetch(); + void testWithZeroConsumerPrefetchAndNoMessage(); void testMapMessageSendToQueue(); void testMapMessageSendToTopic(); void tesstStreamMessage();