From a60f37242a56cd00e223b81e963b61fe66f55b72 Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Sat, 1 Dec 2007 05:11:38 +0000 Subject: Fix problem where client does notice disconnection from Broker. src/qpid/client/SessionCore.cpp: close/open Demux on suspend/resume. src/tests/exception_test.cpp: convert to Session API, boost test. - Temporarily disabled due issues noted in TODO comments git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@600046 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/src/tests/exception_test.cpp | 116 ++++++++++++++++++++++------------ 1 file changed, 77 insertions(+), 39 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 3783ae6901..d7094c9bfd 100644 --- a/qpid/cpp/src/tests/exception_test.cpp +++ b/qpid/cpp/src/tests/exception_test.cpp @@ -19,48 +19,86 @@ * */ -#include +#include "unit_test.h" +#include "InProcessBroker.h" +#include "qpid/client/SubscriptionManager.h" +#include "qpid/sys/Runnable.h" +#include "qpid/sys/Thread.h" +#include "qpid/framing/reply_exceptions.h" -#include "TestOptions.h" -#include "qpid/client/Channel.h" -#include "qpid/client/Connection.h" -#include "qpid/client/Message.h" +QPID_AUTO_TEST_SUITE(exception_test) -using namespace qpid::client; -using namespace qpid::sys; -using std::string; -int main(int argc, char** argv) -{ - qpid::TestOptions opts; - opts.parse(argc, argv); +using namespace std; +using namespace qpid; +using namespace client; +using namespace framing; - try { - Connection con(opts.trace); - con.open(opts.host, opts.port, opts.username, opts.password, opts.virtualhost); +struct Fixture { + InProcessConnection connection; + InProcessConnection connection2; + Session_0_10 session; + SubscriptionManager sub; + LocalQueue q; - Queue queue("I don't exist!"); - Channel channel; - con.openChannel(channel); - channel.start(); - //test handling of get (which is a bit odd) - try { - Message msg; - if (channel.get(msg, queue)) { - std::cout << "Received " << msg.getData() << " from " << queue.getName() << std::endl; - } else { - std::cout << "Queue " << queue.getName() << " was empty." << std::endl; - } - con.close(); - return 1; - } catch (const qpid::ChannelException& e) { - std::cout << "get failed as expected: " << e.what() << std::endl; - } - - con.close(); - return 0; - } catch(const std::exception& e) { - std::cout << "got unexpected exception: " << e.what() << std::endl; - return 1; + Fixture() : connection(), + connection2(connection.getBroker()), + session(connection.newSession()), + sub(session) + { + session.queueDeclare(arg::queue="q"); } -} +}; + + +// 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(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) { +// 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()); } +// } + +// 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); +// } + +QPID_AUTO_TEST_SUITE_END() -- cgit v1.2.1