diff options
Diffstat (limited to 'cpp/src/tests/exception_test.cpp')
-rw-r--r-- | cpp/src/tests/exception_test.cpp | 112 |
1 files changed, 56 insertions, 56 deletions
diff --git a/cpp/src/tests/exception_test.cpp b/cpp/src/tests/exception_test.cpp index d7094c9bfd..e774c48070 100644 --- a/cpp/src/tests/exception_test.cpp +++ b/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 <class Ex> +struct Catcher : public Runnable { + function<void ()> f; + bool caught; + Thread thread; + + Catcher(function<void ()> 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<ClosedException> 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 <class Ex> -// struct Catcher : public sys::Runnable { -// Session_0_10 s; -// boost::function<void ()> f; -// bool caught; -// Catcher(Session_0_10 s_, boost::function<void ()> 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<ClosedException> pop(bind(&LocalQueue::pop, boost::ref(lq))); + disconnect(connection); + BOOST_CHECK(pop.join()); +} -// BOOST_FIXTURE_TEST_CASE(DisconnectedGet, Fixture) { -// Catcher<Exception> 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() |