summaryrefslogtreecommitdiff
path: root/cpp/src/tests/exception_test.cpp
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2007-12-01 05:11:38 +0000
committerAlan Conway <aconway@apache.org>2007-12-01 05:11:38 +0000
commit9a5521b5aaaf1f620c4210ecf09e180ed2934988 (patch)
tree9f71cab2186c5c3ccf4730efb1a3bf819f535a9b /cpp/src/tests/exception_test.cpp
parent1ef2d3ad182ca4ec136632c35f7ac173a1601eb5 (diff)
downloadqpid-python-9a5521b5aaaf1f620c4210ecf09e180ed2934988.tar.gz
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/qpid@600046 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/tests/exception_test.cpp')
-rw-r--r--cpp/src/tests/exception_test.cpp116
1 files changed, 77 insertions, 39 deletions
diff --git a/cpp/src/tests/exception_test.cpp b/cpp/src/tests/exception_test.cpp
index 3783ae6901..d7094c9bfd 100644
--- a/cpp/src/tests/exception_test.cpp
+++ b/cpp/src/tests/exception_test.cpp
@@ -19,48 +19,86 @@
*
*/
-#include <iostream>
+#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 <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(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) {
+// 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()