Return-Path: X-Original-To: apmail-activemq-commits-archive@www.apache.org Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 485E0C8D1 for ; Thu, 13 Jun 2013 17:27:53 +0000 (UTC) Received: (qmail 14821 invoked by uid 500); 13 Jun 2013 17:27:53 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 14737 invoked by uid 500); 13 Jun 2013 17:27:52 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 14730 invoked by uid 99); 13 Jun 2013 17:27:52 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 13 Jun 2013 17:27:52 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 13 Jun 2013 17:27:50 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id D094E23888E4; Thu, 13 Jun 2013 17:27:30 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1492773 - in /activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core: ActiveMQConnectionTest.cpp ActiveMQConnectionTest.h Date: Thu, 13 Jun 2013 17:27:30 -0000 To: commits@activemq.apache.org From: tabish@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130613172730.D094E23888E4@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: tabish Date: Thu Jun 13 17:27:30 2013 New Revision: 1492773 URL: http://svn.apache.org/r1492773 Log: Adds test patch for: https://issues.apache.org/jira/browse/AMQCPP-490 Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQConnectionTest.cpp activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQConnectionTest.h Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQConnectionTest.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQConnectionTest.cpp?rev=1492773&r1=1492772&r2=1492773&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQConnectionTest.cpp (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQConnectionTest.cpp Thu Jun 13 17:27:30 2013 @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -40,6 +41,7 @@ using namespace activemq::core; using namespace activemq::transport; using namespace decaf; using namespace decaf::util; +using namespace decaf::util::concurrent; using namespace decaf::lang; namespace activemq { @@ -57,10 +59,9 @@ namespace core { public: - MyCommandListener() : cmd(NULL) { - } - virtual ~MyCommandListener() { - } + MyCommandListener() : cmd(NULL) {} + + virtual ~MyCommandListener() {} virtual void onCommand(commands::Command* command) { cmd = command; @@ -70,18 +71,27 @@ namespace core { class MyExceptionListener: public cms::ExceptionListener { public: - bool caughtOne; + CountDownLatch caughtOne; + bool throwInCallback; public: - MyExceptionListener() : caughtOne(false) { + MyExceptionListener() : caughtOne(1), throwInCallback(false) { } virtual ~MyExceptionListener() { } virtual void onException(const cms::CMSException& ex AMQCPP_UNUSED) { - caughtOne = true; + caughtOne.countDown(); + + if (throwInCallback) { + throw std::exception(); + } + } + + bool waitForException(int millisecs) { + return caughtOne.await(millisecs, TimeUnit::MILLISECONDS); } }; @@ -92,11 +102,9 @@ namespace core { public: - MyDispatcher() : - messages() { - } - virtual ~MyDispatcher() { - } + MyDispatcher() : messages() {} + + virtual ~MyDispatcher() {} virtual void dispatch(const decaf::lang::Pointer& data) throw (exceptions::ActiveMQException) { messages.push_back(data->getMessage()); @@ -111,7 +119,6 @@ namespace core { //////////////////////////////////////////////////////////////////////////////// void ActiveMQConnectionTest::test2WithOpenwire() { try { - MyExceptionListener exListener; MyCommandListener cmdListener; MyDispatcher msgListener; std::string connectionId = "testConnectionId"; @@ -210,3 +217,32 @@ void ActiveMQConnectionTest::testCloseCa runner.join(2000); CPPUNIT_ASSERT(!runner.isAlive()); } + +//////////////////////////////////////////////////////////////////////////////// +void ActiveMQConnectionTest::testExceptionInOnException() { + + try { + MyExceptionListener exListener; + std::auto_ptr factory( + new ActiveMQConnectionFactory("mock://mock")); + std::auto_ptr connection(factory->createConnection()); + + connection->setExceptionListener(&exListener); + CPPUNIT_ASSERT(exListener.waitForException(0) == false); + + transport::mock::MockTransport* transport = transport::mock::MockTransport::getInstance(); + CPPUNIT_ASSERT(transport != NULL); + + // Setup our ExceptionListener to throw inside the onException callback + exListener.throwInCallback = true; + + // Trigger the onException callback + transport->fireException( + exceptions::ActiveMQException(__FILE__, __LINE__, "test")); + CPPUNIT_ASSERT(exListener.waitForException(2000) == true); + connection->close(); + } catch (exceptions::ActiveMQException& ex) { + ex.printStackTrace(); + throw ex; + } +} Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQConnectionTest.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQConnectionTest.h?rev=1492773&r1=1492772&r2=1492773&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQConnectionTest.h (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQConnectionTest.h Thu Jun 13 17:27:30 2013 @@ -29,6 +29,7 @@ namespace core { CPPUNIT_TEST_SUITE( ActiveMQConnectionTest ); CPPUNIT_TEST( test2WithOpenwire ); CPPUNIT_TEST( testCloseCancelsHungStart ); + CPPUNIT_TEST( testExceptionInOnException ); CPPUNIT_TEST_SUITE_END(); public: @@ -38,6 +39,7 @@ namespace core { void test2WithOpenwire(); void testCloseCancelsHungStart(); + void testExceptionInOnException(); };