diff options
Diffstat (limited to 'cpp/src/tests/test_store.cpp')
-rw-r--r-- | cpp/src/tests/test_store.cpp | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/cpp/src/tests/test_store.cpp b/cpp/src/tests/test_store.cpp index c675c6daa3..257e77b6b4 100644 --- a/cpp/src/tests/test_store.cpp +++ b/cpp/src/tests/test_store.cpp @@ -34,11 +34,14 @@ #include "qpid/broker/NullMessageStore.h" #include "qpid/broker/Broker.h" +#include "qpid/framing/AMQFrame.h" #include "qpid/log/Statement.h" #include "qpid/Plugin.h" #include "qpid/Options.h" #include <boost/cast.hpp> #include <boost/lexical_cast.hpp> +#include <memory> +#include <fstream> using namespace qpid; using namespace broker; @@ -51,10 +54,13 @@ namespace tests { struct TestStoreOptions : public Options { string name; + string dump; TestStoreOptions() : Options("Test Store Options") { addOptions() - ("test-store-name", optValue(name, "NAME"), "Name to identify test store instance."); + ("test-store-name", optValue(name, "NAME"), "Name of test store instance.") + ("test-store-dump", optValue(dump, "FILE"), "File to dump enqueued messages.") + ; } }; @@ -71,19 +77,38 @@ struct Completer : public Runnable { class TestStore : public NullMessageStore { public: - TestStore(const string& name_, Broker& broker_) : name(name_), broker(broker_) {} + TestStore(const TestStoreOptions& opts, Broker& broker_) + : options(opts), name(opts.name), broker(broker_) + { + QPID_LOG(info, "TestStore name=" << name << " dump=" << options.dump); + if (!options.dump.empty()) + dump.reset(new ofstream(options.dump.c_str())); + } ~TestStore() { for_each(threads.begin(), threads.end(), boost::bind(&Thread::join, _1)); } + virtual bool isNull() const { return false; } + void enqueue(TransactionContext* , - const boost::intrusive_ptr<PersistableMessage>& msg, + const boost::intrusive_ptr<PersistableMessage>& pmsg, const PersistableQueue& ) { - string data = boost::polymorphic_downcast<Message*>(msg.get())->getFrames().getContent(); + Message* msg = dynamic_cast<Message*>(pmsg.get()); + assert(msg); + + // Dump the message if there is a dump file. + if (dump.get()) { + msg->getFrames().getMethod()->print(*dump); + *dump << endl << " "; + msg->getFrames().getHeaders()->print(*dump); + *dump << endl << " "; + *dump << msg->getFrames().getContentSize() << endl; + } // Check the message for special instructions. + string data = msg->getFrames().getContent(); size_t i = string::npos; size_t j = string::npos; if (strncmp(data.c_str(), TEST_STORE_DO.c_str(), strlen(TEST_STORE_DO.c_str())) == 0 @@ -119,9 +144,11 @@ class TestStore : public NullMessageStore { private: static const string TEST_STORE_DO, EXCEPTION, EXIT_PROCESS, ASYNC; + TestStoreOptions options; string name; Broker& broker; vector<Thread> threads; + std::auto_ptr<ofstream> dump; }; const string TestStore::TEST_STORE_DO = "TEST_STORE_DO: "; @@ -139,7 +166,7 @@ struct TestStorePlugin : public Plugin { { Broker* broker = dynamic_cast<Broker*>(&target); if (!broker) return; - boost::shared_ptr<MessageStore> p(new TestStore(options.name, *broker)); + boost::shared_ptr<MessageStore> p(new TestStore(options, *broker)); broker->setStore (p); } |