From 93a87010ba58b42e2fe153504b4781978d128a6c Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Fri, 7 Dec 2007 19:13:09 +0000 Subject: Summary: - Replaced InProcessBroker with BrokerFixture, uses a full loopback broker for more realistic tests. - Extracted non-generated parts of Session_0_10 into SessionBase. - Sundry small fixes. src/tests/BrokerFixture.h - in process broker with loopback connections. - tests can force a disorderly disconnect. src/qpid/client/Connector.h - back door to private members for BrokerFixture. - close() in destructor to avoid leaks. src/qpid/client/ConnectionImpl.h,cpp: - close() in destructor, to fix hang when destroyed without being closed. src/qpid/client/CompletionTracker.h,.cpp: - Fixed race in close/add. src/qpid/client/SessionBase.h,cpp: - Extracted all non-generated code from Session_0_10 into SessionBase - Added sync() src/tests/exception_test.cpp: Converted to boost & BrokerFixture src/tests/ClientChannelTest.cpp, ClientSessionTest.cpp: Use BrokerFixture git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@602182 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/src/tests/exception_test.cpp | 112 +++++++++++++++++----------------- 1 file changed, 56 insertions(+), 56 deletions(-) (limited to 'qpid/cpp/src/tests/exception_test.cpp') diff --git a/qpid/cpp/src/tests/exception_test.cpp b/qpid/cpp/src/tests/exception_test.cpp index d7094c9bfd..e774c48070 100644 --- a/qpid/cpp/src/tests/exception_test.cpp +++ b/qpid/cpp/src/tests/exception_test.cpp @@ -20,7 +20,7 @@ */ #include "unit_test.h" -#include "InProcessBroker.h" +#include "BrokerFixture.h" #include "qpid/client/SubscriptionManager.h" #include "qpid/sys/Runnable.h" #include "qpid/sys/Thread.h" @@ -31,74 +31,74 @@ QPID_AUTO_TEST_SUITE(exception_test) using namespace std; using namespace qpid; +using namespace sys; using namespace client; using namespace framing; -struct Fixture { - InProcessConnection connection; - InProcessConnection connection2; - Session_0_10 session; - SubscriptionManager sub; - LocalQueue q; +using boost::bind; +using boost::function; - Fixture() : connection(), - connection2(connection.getBroker()), - session(connection.newSession()), - sub(session) - { - session.queueDeclare(arg::queue="q"); +template +struct Catcher : public Runnable { + function f; + bool caught; + Thread thread; + + Catcher(function f_) : f(f_), caught(false), thread(this) {} + ~Catcher() { join(); } + + void run() { + try { f(); } + catch(const Ex& e) { + caught=true; + BOOST_MESSAGE(e.what()); + } + catch(const std::exception& e) { + BOOST_ERROR(string("Bad exception: ")+e.what()); + } + catch(...) { + BOOST_ERROR(string("Bad exception: unknown")); + } + } + + bool join() { + if (thread.id()) { + thread.join(); + thread=Thread(); + } + return caught; } }; +BOOST_FIXTURE_TEST_CASE(DisconnectedGet, BrokerFixture) { + Catcher get(bind(&Session_0_10::get, session)); + disconnect(connection); + BOOST_CHECK(get.join()); +} -// TODO aconway 2007-11-30: need InProcessBroker to be a more accurate -// simulation of shutdown behaviour. It should override only -// Connector.run() to substitute NetworkQueues for the Dispatcher. -// -// template -// struct Catcher : public sys::Runnable { -// Session_0_10 s; -// boost::function f; -// bool caught; -// Catcher(Session_0_10 s_, boost::function f_) -// : s(s_), f(f_), caught(false) {} -// void run() { -// try { f(); } catch(const Ex& e) { -// caught=true; -// BOOST_MESSAGE(e.what()); -// } -// } -// }; +BOOST_FIXTURE_TEST_CASE(DisconnectedPop, BrokerFixture) { + session.queueDeclare(arg::queue="q"); + subs.subscribe(lq, "q"); + Catcher pop(bind(&LocalQueue::pop, boost::ref(lq))); + disconnect(connection); + BOOST_CHECK(pop.join()); +} -// BOOST_FIXTURE_TEST_CASE(DisconnectedGet, Fixture) { -// Catcher get(session, boost::bind(&Session_0_10::get, session)); -// sub.subscribe(q, "q"); -// sys::Thread t(get); -// connection.disconnect(); -// t.join(); -// BOOST_CHECK(get.caught); -// } - -// BOOST_FIXTURE_TEST_CASE(DisconnectedListen, Fixture) { +// FIXME aconway 2007-12-07: This test hangs sporadically at t.join +// BOOST_FIXTURE_TEST_CASE(DisconnectedListen, BrokerFixture) { // struct NullListener : public MessageListener { // void received(Message&) { BOOST_FAIL("Unexpected message"); } // } l; -// sub.subscribe(l, "q"); -// connection.disconnect(); -// try { -// sub.run(); -// BOOST_FAIL("Expected exception"); -// } catch (const Exception&e) { BOOST_FAIL(e.what()); } -// try { -// session.queueDeclare(arg::queue="foo"); -// BOOST_FAIL("Expected exception"); -// } catch (const Exception&e) { BOOST_FAIL(e.what()); } +// session.queueDeclare(arg::queue="q"); +// subs.subscribe(l, "q"); +// Thread t(subs); +// disconnect(connection); +// t.join(); +// BOOST_CHECK_THROW(session.close(), InternalErrorException); // } -// TODO aconway 2007-11-30: setSynchronous appears not to work. -// BOOST_FIXTURE_TEST_CASE(NoSuchQueueTest, Fixture) { -// session.setSynchronous(true); -// BOOST_CHECK_THROW(sub.subscribe(q, "no such queue"), NotFoundException); -// } +BOOST_FIXTURE_TEST_CASE(NoSuchQueueTest, BrokerFixture) { + BOOST_CHECK_THROW(subs.subscribe(lq, "no such queue").sync(), NotFoundException); +} QPID_AUTO_TEST_SUITE_END() -- cgit v1.2.1