Repository: activemq-cpp Updated Branches: refs/heads/master d96e76169 -> b8564c672
Fix and enable some more tests Project: http://git-wip-us.apache.org/repos/asf/activemq-cpp/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq-cpp/commit/b8564c67 Tree: http://git-wip-us.apache.org/repos/asf/activemq-cpp/tree/b8564c67 Diff: http://git-wip-us.apache.org/repos/asf/activemq-cpp/diff/b8564c67 Branch: refs/heads/master Commit: b8564c672f97bdff07a6ea9056c48996ee219744 Parents: d96e761 Author: Timothy Bish <[email protected]> Authored: Thu Jul 30 11:16:45 2015 -0400 Committer: Timothy Bish <[email protected]> Committed: Thu Jul 30 11:16:45 2015 -0400 ---------------------------------------------------------------------- .../src/test-integration/TestRegistry.cpp | 7 +- .../activemq/test/TransactionTest.cpp | 207 ++++++++++--------- .../test/openwire/OpenwireTransactionTest.h | 2 +- .../test/openwire/OpenwireVirtualTopicTest.h | 2 +- .../failover/FailoverTransportTest.cpp | 8 +- 5 files changed, 113 insertions(+), 113 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/b8564c67/activemq-cpp/src/test-integration/TestRegistry.cpp ---------------------------------------------------------------------- diff --git a/activemq-cpp/src/test-integration/TestRegistry.cpp b/activemq-cpp/src/test-integration/TestRegistry.cpp index a1244ce..deaf816 100644 --- a/activemq-cpp/src/test-integration/TestRegistry.cpp +++ b/activemq-cpp/src/test-integration/TestRegistry.cpp @@ -61,24 +61,23 @@ CPPUNIT_TEST_SUITE_REGISTRATION( activemq::test::openwire::OpenwireCmsConnection CPPUNIT_TEST_SUITE_REGISTRATION( activemq::test::openwire::OpenWireCmsSendWithAsyncCallbackTest ); CPPUNIT_TEST_SUITE_REGISTRATION( activemq::test::openwire::OpenwireCmsTemplateTest ); CPPUNIT_TEST_SUITE_REGISTRATION( activemq::test::openwire::OpenwireDurableTest ); -CPPUNIT_TEST_SUITE_REGISTRATION( activemq::test::openwire::OpenwireExpirationTest ); CPPUNIT_TEST_SUITE_REGISTRATION( activemq::test::openwire::OpenwireEnhancedConnectionTest ); +CPPUNIT_TEST_SUITE_REGISTRATION( activemq::test::openwire::OpenwireExpirationTest ); CPPUNIT_TEST_SUITE_REGISTRATION( activemq::test::openwire::OpenwireIndividualAckTest ); CPPUNIT_TEST_SUITE_REGISTRATION( activemq::test::openwire::OpenwireJmsMessageGroupsTest ); CPPUNIT_TEST_SUITE_REGISTRATION( activemq::test::openwire::OpenwireJmsRecoverTest ); +CPPUNIT_TEST_SUITE_REGISTRATION( activemq::test::openwire::OpenwireMapMessageTest ); CPPUNIT_TEST_SUITE_REGISTRATION( activemq::test::openwire::OpenwireMessageCompressionTest ); CPPUNIT_TEST_SUITE_REGISTRATION( activemq::test::openwire::OpenwireMessagePriorityTest ); -CPPUNIT_TEST_SUITE_REGISTRATION( activemq::test::openwire::OpenwireMapMessageTest ); CPPUNIT_TEST_SUITE_REGISTRATION( activemq::test::openwire::OpenwireNonBlockingRedeliveryTest ); CPPUNIT_TEST_SUITE_REGISTRATION( activemq::test::openwire::OpenwireOptimizedAckTest ); CPPUNIT_TEST_SUITE_REGISTRATION( activemq::test::openwire::OpenwireQueueBrowserTest ); CPPUNIT_TEST_SUITE_REGISTRATION( activemq::test::openwire::OpenWireRedeliveryPolicyTest ); CPPUNIT_TEST_SUITE_REGISTRATION( activemq::test::openwire::OpenwireSimpleRollbackTest ); -CPPUNIT_TEST_SUITE_REGISTRATION( activemq::test::openwire::OpenwireSimpleRollbackTest ); CPPUNIT_TEST_SUITE_REGISTRATION( activemq::test::openwire::OpenwireSimpleTest ); -CPPUNIT_TEST_SUITE_REGISTRATION( activemq::test::openwire::OpenwireTransactionTest ); CPPUNIT_TEST_SUITE_REGISTRATION( activemq::test::openwire::OpenwireSlowListenerTest ); CPPUNIT_TEST_SUITE_REGISTRATION( activemq::test::openwire::OpenwireTempDestinationTest ); +CPPUNIT_TEST_SUITE_REGISTRATION( activemq::test::openwire::OpenwireTransactionTest ); CPPUNIT_TEST_SUITE_REGISTRATION( activemq::test::openwire::OpenwireVirtualTopicTest ); CPPUNIT_TEST_SUITE_REGISTRATION( activemq::test::openwire::OpenwireXATransactionsTest ); http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/b8564c67/activemq-cpp/src/test-integration/activemq/test/TransactionTest.cpp ---------------------------------------------------------------------- diff --git a/activemq-cpp/src/test-integration/activemq/test/TransactionTest.cpp b/activemq-cpp/src/test-integration/activemq/test/TransactionTest.cpp index a731b97..0133f2b 100644 --- a/activemq-cpp/src/test-integration/activemq/test/TransactionTest.cpp +++ b/activemq-cpp/src/test-integration/activemq/test/TransactionTest.cpp @@ -18,6 +18,7 @@ #include "TransactionTest.h" #include <activemq/core/ActiveMQConnectionFactory.h> +#include <activemq/core/ActiveMQConnection.h> #include <activemq/util/CMSListener.h> #include <activemq/exceptions/ActiveMQException.h> #include <stdexcept> @@ -41,83 +42,72 @@ TransactionTest::~TransactionTest() { //////////////////////////////////////////////////////////////////////////////// void TransactionTest::testSendReceiveTransactedBatches() { - 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(); - for (int j = 0; j < batchCount - 8; j++) { + producer->setDeliveryMode(DeliveryMode::NON_PERSISTENT); - auto_ptr<TextMessage> message(session->createTextMessage("Batch Message")); + for (int j = 0; j < batchCount - 8; j++) { - for (int i = 0; i < batchSize; i++) { - CPPUNIT_ASSERT_NO_THROW_MESSAGE("Send should not throw an exception here.", producer->send(message.get())); - } + auto_ptr<TextMessage> message(session->createTextMessage("Batch Message")); - CPPUNIT_ASSERT_NO_THROW_MESSAGE("Session Commit should not throw an exception here:", session->commit()); + for (int i = 0; i < batchSize; i++) { + CPPUNIT_ASSERT_NO_THROW_MESSAGE("Send should not throw an exception here.", producer->send(message.get())); + } - for (int i = 0; i < batchSize; i++) { - CPPUNIT_ASSERT_NO_THROW_MESSAGE("Receive Shouldn't throw a Message here:", - message.reset(dynamic_cast<TextMessage*>(consumer->receive(1000 * 5)))); + CPPUNIT_ASSERT_NO_THROW_MESSAGE("Session Commit should not throw an exception here:", session->commit()); - CPPUNIT_ASSERT_MESSAGE("Failed to receive all messages in batch", message.get() != NULL); - CPPUNIT_ASSERT(string("Batch Message") == message->getText()); - } + for (int i = 0; i < batchSize; i++) { + CPPUNIT_ASSERT_NO_THROW_MESSAGE("Receive Shouldn't throw a Message here:", + message.reset(dynamic_cast<TextMessage*>(consumer->receive(1000 * 5)))); - CPPUNIT_ASSERT_NO_THROW_MESSAGE("Session Commit should not throw an exception here:", session->commit()); + CPPUNIT_ASSERT_MESSAGE("Failed to receive all messages in batch", message.get() != NULL); + CPPUNIT_ASSERT(string("Batch Message") == message->getText()); } - } catch (std::exception& ex) { - std::cout << ex.what() << std::endl; - throw ex; + + CPPUNIT_ASSERT_NO_THROW_MESSAGE("Session Commit should not throw an exception here:", session->commit()); } } //////////////////////////////////////////////////////////////////////////////// void TransactionTest::testSendRollback() { - try { - - // Create CMS Object for Comms - cms::Session* session = cmsProvider->getSession(); - cms::MessageConsumer* consumer = cmsProvider->getConsumer(); - cms::MessageProducer* producer = cmsProvider->getProducer(); + // 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); + producer->setDeliveryMode(DeliveryMode::NON_PERSISTENT); - auto_ptr<TextMessage> outbound1(session->createTextMessage("First Message")); - auto_ptr<TextMessage> outbound2(session->createTextMessage("Second Message")); + auto_ptr<TextMessage> outbound1(session->createTextMessage("First Message")); + auto_ptr<TextMessage> outbound2(session->createTextMessage("Second Message")); - // sends a message - producer->send(outbound1.get()); - session->commit(); + // sends a message + producer->send(outbound1.get()); + session->commit(); - // sends a message that gets rollbacked - auto_ptr<Message> rollback(session->createTextMessage("I'm going to get rolled back.")); - producer->send(rollback.get()); - session->rollback(); + // sends a message that gets rollbacked + auto_ptr<Message> rollback(session->createTextMessage("I'm going to get rolled back.")); + producer->send(rollback.get()); + session->rollback(); - // sends a message - producer->send(outbound2.get()); - session->commit(); + // sends a message + producer->send(outbound2.get()); + session->commit(); - // receives the first message - auto_ptr<TextMessage> inbound1(dynamic_cast<TextMessage*>(consumer->receive(1500))); + // receives the first message + auto_ptr<TextMessage> inbound1(dynamic_cast<TextMessage*>(consumer->receive(1500))); - // receives the second message - auto_ptr<TextMessage> inbound2(dynamic_cast<TextMessage*>(consumer->receive(4000))); + // receives the second message + auto_ptr<TextMessage> inbound2(dynamic_cast<TextMessage*>(consumer->receive(4000))); - // validates that the rollbacked was not consumed - session->commit(); + // validates that the rollbacked was not consumed + session->commit(); - CPPUNIT_ASSERT(outbound1->getText() == inbound1->getText()); - CPPUNIT_ASSERT(outbound2->getText() == inbound2->getText()); - } - AMQ_CATCH_RETHROW(ActiveMQException) - AMQ_CATCHALL_THROW(ActiveMQException) + CPPUNIT_ASSERT(outbound1->getText() == inbound1->getText()); + CPPUNIT_ASSERT(outbound2->getText() == inbound2->getText()); } //////////////////////////////////////////////////////////////////////////////// @@ -162,79 +152,90 @@ void TransactionTest::testSendRollbackCommitRollback() { //////////////////////////////////////////////////////////////////////////////// void TransactionTest::testSendSessionClose() { - try { + Pointer<ActiveMQConnectionFactory> connectionFactory( + new ActiveMQConnectionFactory(getBrokerURL())); - cmsProvider->getProducer()->setDeliveryMode(DeliveryMode::NON_PERSISTENT); + Pointer<Connection> connection(connectionFactory->createConnection()); + Pointer<ActiveMQConnection> amqConnection = connection.dynamicCast<ActiveMQConnection>(); - auto_ptr<TextMessage> outbound1(cmsProvider->getSession()->createTextMessage("First Message")); - auto_ptr<TextMessage> outbound2(cmsProvider->getSession()->createTextMessage("Second Message")); + connection->start(); + Pointer<Session> session(connection->createSession(Session::SESSION_TRANSACTED)); + Pointer<Queue> destination(session->createQueue("testSendSessionClose")); - // sends a message - cmsProvider->getProducer()->send(outbound1.get()); - cmsProvider->getSession()->commit(); + // Create the messages used for this test + auto_ptr<TextMessage> outbound1(session->createTextMessage("First Message")); + auto_ptr<TextMessage> outbound2(session->createTextMessage("Second Message")); - // sends a message that gets rolled back - auto_ptr<cms::Message> rollback(cmsProvider->getSession()->createTextMessage("I'm going to get rolled back.")); - cmsProvider->getProducer()->send(rollback.get()); - cmsProvider->getConsumer()->close(); + Pointer<MessageConsumer> consumer(session->createConsumer(destination.get())); + Pointer<MessageProducer> producer(session->createProducer(destination.get())); + producer->setDeliveryMode(DeliveryMode::NON_PERSISTENT); - cmsProvider->reconnectSession(); + // Send Message #1 + producer->send(outbound1.get()); + session->commit(); - // sends a message - cmsProvider->getProducer()->send(outbound2.get()); - cmsProvider->getSession()->commit(); + // Send a Message but roll it back by closing the session that owns the resources + auto_ptr<cms::Message> rollback(session->createTextMessage("I'm going to get rolled back.")); + producer->send(outbound2.get()); + session->close(); - // receives the first message - auto_ptr<TextMessage> inbound1(dynamic_cast<TextMessage*>(cmsProvider->getConsumer()->receive(1500))); + session.reset(connection->createSession(Session::SESSION_TRANSACTED)); + destination.reset(session->createQueue("testSendSessionClose")); + consumer.reset(session->createConsumer(destination.get())); + producer.reset(session->createProducer(destination.get())); + producer->setDeliveryMode(DeliveryMode::NON_PERSISTENT); - // receives the second message - auto_ptr<cms::TextMessage> inbound2(dynamic_cast<TextMessage*>(cmsProvider->getConsumer()->receive(4000))); + // Send Message #2 + producer->send(outbound2.get()); + session->commit(); - // validates that the rolled back was not consumed - cmsProvider->getSession()->commit(); + // receives the first message + auto_ptr<TextMessage> inbound1(dynamic_cast<TextMessage*>(consumer->receive(1500))); - CPPUNIT_ASSERT(inbound1.get() != NULL); - CPPUNIT_ASSERT(inbound2.get() != NULL); + // receives the second message + auto_ptr<TextMessage> inbound2(dynamic_cast<TextMessage*>(consumer->receive(4000))); - CPPUNIT_ASSERT(outbound1->getText() == inbound1->getText()); - CPPUNIT_ASSERT(outbound2->getText() == inbound2->getText()); - } - AMQ_CATCH_RETHROW(ActiveMQException) - AMQ_CATCHALL_THROW(ActiveMQException) + // validates that the rolled back was not consumed + session->commit(); + + CPPUNIT_ASSERT_MESSAGE("Failed to receive first message", inbound1.get() != NULL); + CPPUNIT_ASSERT_MESSAGE("Failed to receive second message", inbound2.get() != NULL); + + CPPUNIT_ASSERT_MESSAGE("First messages aren't equal", outbound1->getText() == inbound1->getText()); + CPPUNIT_ASSERT_MESSAGE("Second messages aren't equal", outbound2->getText() == inbound2->getText()); + + session->close(); + amqConnection->destroyDestination(destination.get()); } //////////////////////////////////////////////////////////////////////////////// void TransactionTest::testWithTTLSet() { - try { - cmsProvider->getProducer()->setDeliveryMode(DeliveryMode::PERSISTENT); - - cms::MessageConsumer* consumer = cmsProvider->getConsumer(); + cmsProvider->getProducer()->setDeliveryMode(DeliveryMode::PERSISTENT); - auto_ptr<TextMessage> outbound1(cmsProvider->getSession()->createTextMessage("First Message")); + cms::MessageConsumer* consumer = cmsProvider->getConsumer(); - const std::size_t NUM_MESSAGES = 50; + auto_ptr<TextMessage> outbound1(cmsProvider->getSession()->createTextMessage("First Message")); - // sends a message - for (std::size_t i = 0; i < NUM_MESSAGES; ++i) { - cmsProvider->getProducer()->send(outbound1.get(), cms::DeliveryMode::PERSISTENT, - cmsProvider->getProducer()->getPriority(), 120 * 1000); - } + const std::size_t NUM_MESSAGES = 50; - cmsProvider->getSession()->commit(); + // sends a message + for (std::size_t i = 0; i < NUM_MESSAGES; ++i) { + cmsProvider->getProducer()->send(outbound1.get(), cms::DeliveryMode::PERSISTENT, + cmsProvider->getProducer()->getPriority(), 120 * 1000); + } - for (std::size_t i = 0; i < NUM_MESSAGES; ++i) { + cmsProvider->getSession()->commit(); - // receives the second message - auto_ptr<TextMessage> inbound1(dynamic_cast<TextMessage*>(consumer->receive(600000))); - CPPUNIT_ASSERT(inbound1.get() != NULL); - CPPUNIT_ASSERT(outbound1->getText() == inbound1->getText()); - } + for (std::size_t i = 0; i < NUM_MESSAGES; ++i) { - cmsProvider->getSession()->commit(); + // receives the second message + auto_ptr<TextMessage> inbound1(dynamic_cast<TextMessage*>(consumer->receive(600000))); + CPPUNIT_ASSERT(inbound1.get() != NULL); + CPPUNIT_ASSERT(outbound1->getText() == inbound1->getText()); } - AMQ_CATCH_RETHROW(ActiveMQException) - AMQ_CATCHALL_THROW(ActiveMQException) + + cmsProvider->getSession()->commit(); } //////////////////////////////////////////////////////////////////////////////// http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/b8564c67/activemq-cpp/src/test-integration/activemq/test/openwire/OpenwireTransactionTest.h ---------------------------------------------------------------------- diff --git a/activemq-cpp/src/test-integration/activemq/test/openwire/OpenwireTransactionTest.h b/activemq-cpp/src/test-integration/activemq/test/openwire/OpenwireTransactionTest.h index 71e40cc..8e228aa 100644 --- a/activemq-cpp/src/test-integration/activemq/test/openwire/OpenwireTransactionTest.h +++ b/activemq-cpp/src/test-integration/activemq/test/openwire/OpenwireTransactionTest.h @@ -32,7 +32,7 @@ namespace openwire{ CPPUNIT_TEST( testWithTTLSet ); CPPUNIT_TEST( testSendRollbackCommitRollback ); CPPUNIT_TEST( testSessionCommitAfterConsumerClosed ); -// CPPUNIT_TEST( testSendSessionClose ); + CPPUNIT_TEST( testSendSessionClose ); CPPUNIT_TEST_SUITE_END(); public: http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/b8564c67/activemq-cpp/src/test-integration/activemq/test/openwire/OpenwireVirtualTopicTest.h ---------------------------------------------------------------------- diff --git a/activemq-cpp/src/test-integration/activemq/test/openwire/OpenwireVirtualTopicTest.h b/activemq-cpp/src/test-integration/activemq/test/openwire/OpenwireVirtualTopicTest.h index d31efb6..ed0276c 100644 --- a/activemq-cpp/src/test-integration/activemq/test/openwire/OpenwireVirtualTopicTest.h +++ b/activemq-cpp/src/test-integration/activemq/test/openwire/OpenwireVirtualTopicTest.h @@ -30,7 +30,7 @@ namespace openwire { CPPUNIT_TEST_SUITE( OpenwireVirtualTopicTest ); CPPUNIT_TEST( testVirtualTopicSyncReceiveAutoAck ); CPPUNIT_TEST( testVirtualTopicSyncReceiveClinetAck ); -// CPPUNIT_TEST( testVirtualTopicSyncReceiveTransacted ); + CPPUNIT_TEST( testVirtualTopicSyncReceiveTransacted ); CPPUNIT_TEST_SUITE_END(); public: http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/b8564c67/activemq-cpp/src/test/activemq/transport/failover/FailoverTransportTest.cpp ---------------------------------------------------------------------- diff --git a/activemq-cpp/src/test/activemq/transport/failover/FailoverTransportTest.cpp b/activemq-cpp/src/test/activemq/transport/failover/FailoverTransportTest.cpp index 6ba74c3..54802df 100644 --- a/activemq-cpp/src/test/activemq/transport/failover/FailoverTransportTest.cpp +++ b/activemq-cpp/src/test/activemq/transport/failover/FailoverTransportTest.cpp @@ -674,14 +674,14 @@ void FailoverTransportTest::testUriOptionsApplied() { //////////////////////////////////////////////////////////////////////////////// void FailoverTransportTest::testConnectedToMockBroker() { - MockBrokerService broker1(61616); - MockBrokerService broker2(61618); + MockBrokerService broker1(61626); + MockBrokerService broker2(61628); broker1.start(); broker1.waitUntilStarted(); - std::string uri = "failover://(tcp://localhost:61616," - "tcp://localhost:61618)?randomize=false"; + std::string uri = "failover://(tcp://localhost:61626," + "tcp://localhost:61628)?randomize=false"; DefaultTransportListener listener; FailoverTransportFactory factory;
