diff options
author | Alan Conway <aconway@apache.org> | 2007-12-07 19:13:09 +0000 |
---|---|---|
committer | Alan Conway <aconway@apache.org> | 2007-12-07 19:13:09 +0000 |
commit | 93a87010ba58b42e2fe153504b4781978d128a6c (patch) | |
tree | 27c545a130a3ed4c83472db2c2ae07306c862e5a /qpid/cpp/src/tests/exception_test.cpp | |
parent | 506d0479f23c39f75dc03a22f4b8adf52d281022 (diff) | |
download | qpid-python-93a87010ba58b42e2fe153504b4781978d128a6c.tar.gz |
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
Diffstat (limited to 'qpid/cpp/src/tests/exception_test.cpp')
-rw-r--r-- | qpid/cpp/src/tests/exception_test.cpp | 112 |
1 files changed, 56 insertions, 56 deletions
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 <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() |