diff options
| author | Alan Conway <aconway@apache.org> | 2008-05-06 17:52:03 +0000 |
|---|---|---|
| committer | Alan Conway <aconway@apache.org> | 2008-05-06 17:52:03 +0000 |
| commit | e1d873e3b4528141b9401bad9070bc205de40504 (patch) | |
| tree | bee155f0513021a3e8cf2dc142a6ce765dfe18e4 /qpid/cpp/src/tests | |
| parent | e6ced35fbdd3385e2a660f5b40366f0382796d01 (diff) | |
| download | qpid-python-e1d873e3b4528141b9401bad9070bc205de40504.tar.gz | |
From https://issues.apache.org/jira/browse/QPID-879 contributed by Jonathan Robie.
XML exchange allowing messages to be routed base on XQuery expressions.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@653854 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/cpp/src/tests')
| -rw-r--r-- | qpid/cpp/src/tests/.valgrind.supp | 8 | ||||
| -rw-r--r-- | qpid/cpp/src/tests/Makefile.am | 8 | ||||
| -rw-r--r-- | qpid/cpp/src/tests/QueueTest.cpp | 2 | ||||
| -rw-r--r-- | qpid/cpp/src/tests/XmlClientSessionTest.cpp | 157 |
4 files changed, 174 insertions, 1 deletions
diff --git a/qpid/cpp/src/tests/.valgrind.supp b/qpid/cpp/src/tests/.valgrind.supp index e0abf0dd43..3b7b7c9803 100644 --- a/qpid/cpp/src/tests/.valgrind.supp +++ b/qpid/cpp/src/tests/.valgrind.supp @@ -30,3 +30,11 @@ fun:epoll_ctl } +{ + "Conditional jump or move depends on uninitialised value(s)" from Xerces parser + Memcheck:Cond + fun:_ZN11xercesc_2_717XMLUTF8Transcoder13transcodeFromEPKhjPtjRjPh + fun:_ZN11xercesc_2_79XMLReader14xcodeMoreCharsEPtPhj + fun:_ZN11xercesc_2_79XMLReader17refreshCharBufferEv +} + diff --git a/qpid/cpp/src/tests/Makefile.am b/qpid/cpp/src/tests/Makefile.am index f215c9f0b4..6fd9cbcb76 100644 --- a/qpid/cpp/src/tests/Makefile.am +++ b/qpid/cpp/src/tests/Makefile.am @@ -1,4 +1,4 @@ -AM_CXXFLAGS = $(WARNING_CFLAGS) $(CPPUNIT_CXXFLAGS) $(APR_CXXFLAGS) -DBOOST_TEST_DYN_LINK +AM_CXXFLAGS = $(WARNING_CFLAGS) $(CPPUNIT_CXXFLAGS) $(CFLAGS) $(APR_CXXFLAGS) -DBOOST_TEST_DYN_LINK INCLUDES = -I$(srcdir)/.. -I$(srcdir)/../gen -I$(top_builddir)/src/gen abs_builddir=@abs_builddir@ @@ -29,6 +29,7 @@ TESTS+=unit_test check_PROGRAMS+=unit_test unit_test_LDADD=-lboost_unit_test_framework -lboost_regex \ $(lib_client) $(lib_broker) # $(lib_amqp_0_10) + unit_test_SOURCES= unit_test.cpp unit_test.h \ BrokerFixture.h SocketProxy.h \ exception_test.cpp \ @@ -45,6 +46,11 @@ unit_test_SOURCES= unit_test.cpp unit_test.h \ IncompleteMessageList.cpp \ RangeSet.cpp +if HAVE_XML +unit_test_SOURCES+= XmlClientSessionTest.cpp +endif + + # Disabled till we move to amqp_0_10 codec. # amqp_0_10/serialize.cpp allSegmentTypes.h \ # amqp_0_10/ProxyTemplate.cpp \ diff --git a/qpid/cpp/src/tests/QueueTest.cpp b/qpid/cpp/src/tests/QueueTest.cpp index aec59a58bc..9abf863ad4 100644 --- a/qpid/cpp/src/tests/QueueTest.cpp +++ b/qpid/cpp/src/tests/QueueTest.cpp @@ -54,11 +54,13 @@ public: class FailOnDeliver : public Deliverable { + Message msg; public: void deliverTo(Queue::shared_ptr& queue) { throw Exception(QPID_MSG("Invalid delivery to " << queue->getName())); } + Message& getMessage() { return msg; } }; class QueueTest : public CppUnit::TestCase diff --git a/qpid/cpp/src/tests/XmlClientSessionTest.cpp b/qpid/cpp/src/tests/XmlClientSessionTest.cpp new file mode 100644 index 0000000000..b5c685abbf --- /dev/null +++ b/qpid/cpp/src/tests/XmlClientSessionTest.cpp @@ -0,0 +1,157 @@ +/* + * + * Licensed to the Apachef Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +#include "unit_test.h" +#include "BrokerFixture.h" +#include "qpid/sys/Monitor.h" +#include "qpid/sys/Thread.h" +#include "qpid/sys/Runnable.h" +#include "qpid/framing/TransferContent.h" +#include "qpid/framing/reply_exceptions.h" +#include "qpid/client/Connection.h" +#include "qpid/client/Dispatcher.h" +#include "qpid/client/LocalQueue.h" +#include "qpid/client/Session.h" +#include "qpid/client/SubscriptionManager.h" + +#include <boost/optional.hpp> +#include <boost/lexical_cast.hpp> + +#include <vector> + +QPID_AUTO_TEST_SUITE(XmlClientSessionTest) + +using namespace qpid::client; + +using namespace qpid::client::arg; +using namespace qpid::framing; +using namespace qpid; +using qpid::sys::Monitor; +using std::string; +using std::cout; +using std::endl; + + +struct DummyListener : public sys::Runnable, public MessageListener { + std::vector<Message> messages; + string name; + uint expected; + Dispatcher dispatcher; + + DummyListener(Session& session, const string& n, uint ex) : + name(n), expected(ex), dispatcher(session) {} + + void run() + { + dispatcher.listen(name, this); + dispatcher.run(); + } + + void received(Message& msg) + { + messages.push_back(msg); + if (--expected == 0) + dispatcher.stop(); + } +}; + + +class SubscribedLocalQueue : public LocalQueue { + private: + SubscriptionManager& subscriptions; + public: + SubscribedLocalQueue(SubscriptionManager& subs) : subscriptions(subs) {} + Message get () { return pop(); } + virtual ~SubscribedLocalQueue() {} +}; + + +struct SimpleListener : public MessageListener +{ + Monitor lock; + std::vector<Message> messages; + + void received(Message& msg) + { + Monitor::ScopedLock l(lock); + messages.push_back(msg); + lock.notifyAll(); + } + + void waitFor(const uint n) + { + Monitor::ScopedLock l(lock); + while (messages.size() < n) { + lock.wait(); + } + } +}; + +struct ClientSessionFixture : public ProxySessionFixture +{ + void declareSubscribe(const string& q="odd_blue", + const string& dest="xml") + { + session.queueDeclare(queue=q); + session.messageSubscribe(queue=q, destination=dest, acquireMode=1); + session.messageFlow(destination=dest, unit=0, value=0xFFFFFFFF);//messages + session.messageFlow(destination=dest, unit=1, value=0xFFFFFFFF);//bytes + } +}; + +// ########### START HERE #################################### + +BOOST_AUTO_TEST_CASE(testXmlBinding) { + ClientSessionFixture f; + + Session session = f.connection.newSession(ASYNC); + SubscriptionManager subscriptions(session); + SubscribedLocalQueue localQueue(subscriptions); + + session.exchangeDeclare(qpid::client::arg::exchange="xml", qpid::client::arg::type="xml"); + session.queueDeclare(qpid::client::arg::queue="odd_blue"); + subscriptions.subscribe(localQueue, "odd_blue"); + + FieldTable binding; + binding.setString("xquery", "declare variable $color external;" + "(./message/id mod 2 = 1) and ($color = 'blue')"); + session.exchangeBind(qpid::client::arg::exchange="xml", qpid::client::arg::queue="odd_blue", qpid::client::arg::bindingKey="query_name", qpid::client::arg::arguments=binding); + + Message message; + message.getDeliveryProperties().setRoutingKey("query_name"); + + message.getHeaders().setString("color", "blue"); + string m = "<message><id>1</id></message>"; + message.setData(m); + + session.messageTransfer(qpid::client::arg::content=message, qpid::client::arg::destination="xml"); + + Message m2 = localQueue.get(); + BOOST_CHECK_EQUAL(m, m2.getData()); +} + +//### Test: Bad XML does not kill the server + +//### Test: Bad XQuery does not kill the server + +//### Test: Bindings persist, surviving broker restart + +QPID_AUTO_TEST_SUITE_END() + |
