diff options
author | Alan Conway <aconway@apache.org> | 2008-02-08 22:23:23 +0000 |
---|---|---|
committer | Alan Conway <aconway@apache.org> | 2008-02-08 22:23:23 +0000 |
commit | 94f3f2c02f1242b1c1d632954c6434defb86edd5 (patch) | |
tree | fd73c76a454813f034ffeb5ae36485fd895e0fe2 /cpp | |
parent | 753af4e75c0faaf12f9926e0f17354206377b3d6 (diff) | |
download | qpid-python-94f3f2c02f1242b1c1d632954c6434defb86edd5.tar.gz |
cpp/examples/direct, fanout: Converted listener.cpp to SubscriptionManager.
All python/cpp combos run as part of cpp/examples make check.
Fixed problems with verify scripts and VPATH builds.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@620014 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp')
28 files changed, 265 insertions, 214 deletions
diff --git a/cpp/examples/Makefile.am b/cpp/examples/Makefile.am index fdbea3b878..3c896e2f68 100644 --- a/cpp/examples/Makefile.am +++ b/cpp/examples/Makefile.am @@ -17,7 +17,33 @@ nobase_pkgdata_DATA= \ examples/direct/listener.cpp \ examples/direct/declare_queues.cpp -EXTRA_DIST=$(nobase_pkgdata_DATA) +VERIFY_FILES= verify verify_all \ + examples/request-response/verify \ + examples/request-response/verify.in \ + examples/request-response/verify_cpp_python \ + examples/request-response/verify_cpp_python.in \ + examples/request-response/verify_python_cpp \ + examples/request-response/verify_python_cpp.in \ + examples/fanout/verify \ + examples/fanout/verify.in \ + examples/fanout/verify_cpp_python \ + examples/fanout/verify_cpp_python.in \ + examples/fanout/verify_python_cpp \ + examples/fanout/verify_python_cpp.in \ + examples/pub-sub/verify \ + examples/pub-sub/verify.in \ + examples/pub-sub/verify_cpp_python \ + examples/pub-sub/verify_cpp_python.in \ + examples/pub-sub/verify_python_cpp \ + examples/pub-sub/verify_python_cpp.in \ + examples/direct/verify \ + examples/direct/verify.in \ + examples/direct/verify_cpp_python \ + examples/direct/verify_cpp_python.in \ + examples/direct/verify_python_cpp \ + examples/direct/verify_python_cpp.in + +EXTRA_DIST=$(nobase_pkgdata_DATA) $(VERIFY_FILES) # Note: we don't use normal automake SUBDIRS because the example # makefiles don't understand all the recursive automake targets. @@ -29,31 +55,24 @@ clean-local: abs_top_builddir=@abs_top_builddir@ abs_top_srcdir=@abs_top_srcdir@ -VERIFY=$(top_srcdir)/../bin/verify -PYTHON_EXAMPLES=$(top_srcdir)/../python/examples -EXAMPLES= \ - examples/pub-sub \ - examples/fanout \ - examples/direct \ - examples/request-response \ - $(PYTHON_EXAMPLES)/pubsub \ - $(PYTHON_EXAMPLES)/fanout \ - $(PYTHON_EXAMPLES)/direct \ - $(PYTHON_EXAMPLES)/request-response - -# Build the examples in the source tree. +# Build the examples - copy sources to the build tree in VPATH build. all-local: + test -d examples || cp -R $(srcdir)/examples . cd examples && $(MAKE) CXX="$(CXX)" CXXFLAGS="$(CXXFLAGS) -I../../$(top_srcdir)/src -I../../$(top_srcdir)/src/gen -I../../$(top_builddir)/src/gen -L../../$(top_builddir)/src/.libs -Wl,-rpath,$(abs_top_builddir)/src/.libs" all # Verify the examples in the buid tree. -check-local: all-local - QPID_DATA_DIR= QPIDD=$(top_builddir)/src/qpidd $(VERIFY) $(EXAMPLES) - -# Build and verify the installed examples, then clean up to avoid rpmbuild warnings. -EXAMPLE_FLAGS=-I$(DESTDIR)$(includedir) -L$(DESTDIR)$(libdir) -Wl,-rpath,$(DESTDIR)$(libdir) -EXAMPLE_DIR=$(DESTDIR)$(pkgdatadir)/examples -installcheck-local: - cd $(EXAMPLE_DIR) && $(MAKE) CXX="$(CXX)" CXXFLAGS="$(EXAMPLE_FLAGS)" all - cd $(EXAMPLE_DIR) && QPIDD=$(sbindir)/qpidd $(VERIFY) - cd $(EXAMPLE_DIR) && $(MAKE) clean +VERIFY=QPID_DATA_DIR= QPIDD=$(abs_top_builddir)/src/qpidd $(srcdir)/verify_all +check-local: all-local $(VERIFY_FILES) + PYTHON_EXAMPLES=$(abs_top_srcdir)/../python/examples $(srcdir)/verify_all $(srcdir)/verify $(top_builddir)/src/qpidd examples + +# TODO: +# create a tarball for testing installed examples. +# installcheck-local to use the tarball on installed example and clean up after. +# Build and verify installed C++ examples, clean up to avoid rpmbuild warnings. +# EXAMPLE_FLAGS=-I$(DESTDIR)$(includedir) -L$(DESTDIR)$(libdir) -Wl,-rpath,$(DESTDIR)$(libdir) +# EXAMPLE_DIR=$(DESTDIR)$(pkgdatadir)/examples/cpp +# installcheck-local: +# cd $(EXAMPLE_DIR) && $(MAKE) CXX="$(CXX)" CXXFLAGS="$(EXAMPLE_FLAGS)" all +# cd $(EXAMPLE_DIR) && QPIDD=$(sbindir)/qpidd $(srcdir)/verify * +# cd $(EXAMPLE_DIR) && $(MAKE) clean diff --git a/cpp/examples/examples/direct/listener.cpp b/cpp/examples/examples/direct/listener.cpp index 3f92d189de..91b5123c68 100644 --- a/cpp/examples/examples/direct/listener.cpp +++ b/cpp/examples/examples/direct/listener.cpp @@ -20,32 +20,15 @@ */ /** - * listener.cpp: - * - * This program is one of three programs designed to be used - * together. These programs do not specify the exchange type - the - * default exchange type is the direct exchange. - * - * declare_queues.cpp: - * - * Creates a queue on a broker, binding a routing key to route - * messages to that queue. - * - * direct_producer.cpp: - * - * Publishes to a broker, specifying a routing key. - * - * listener.cpp (this program): - * - * Reads from a queue on the broker using a message listener. - * + * listener.cpp: This program reads messages fro a queue on + * the broker using a message listener. */ #include <qpid/client/Dispatcher.h> #include <qpid/client/Connection.h> #include <qpid/client/Session.h> #include <qpid/client/Message.h> -#include <qpid/client/MessageListener.h> +#include <qpid/client/SubscriptionManager.h> #include <unistd.h> #include <cstdlib> @@ -56,42 +39,25 @@ using namespace qpid::framing; class Listener : public MessageListener{ -private: - std::string destination_name; - Dispatcher dispatcher; -public: - Listener(Session& session, string destination_name): - destination_name(destination_name), - dispatcher(session) - {}; - - virtual void listen(); - virtual void received(Message& message); - ~Listener() { }; + private: + SubscriptionManager& subscriptions; + public: + Listener(SubscriptionManager& subscriptions); + virtual void received(Message& message); }; - -void Listener::listen() { - std::cout << "Activating listener for: " <<destination_name << std::endl; - dispatcher.listen(destination_name, this); - - // The following line gives up control - - dispatcher.run(); -} - +Listener::Listener(SubscriptionManager& subs) : subscriptions(subs) +{} void Listener::received(Message& message) { std::cout << "Message: " << message.getData() << std::endl; - if (message.getData() == "That's all, folks!") { - std::cout << "Shutting down listener for " <<destination_name << std::endl; - dispatcher.stop(); + std::cout << "Shutting down listener for " << message.getDestination() + << std::endl; + subscriptions.cancel(message.getDestination()); } } - - int main(int argc, char** argv) { const char* host = argc>1 ? argv[1] : "127.0.0.1"; int port = argc>2 ? atoi(argv[2]) : 5672; @@ -103,25 +69,15 @@ int main(int argc, char** argv) { //--------- Main body of program -------------------------------------------- + SubscriptionManager subscriptions(session); + // Create a listener and subscribe it to the queue named "message_queue" + Listener listener(subscriptions); + subscriptions.subscribe(listener, "message_queue"); + // Deliver messages until the subscription is cancelled + // by Listener::received() + subscriptions.run(); - // Subscribe to the queue, route it to a client destination for - // the listener. (The destination name merely identifies the - // destination in the listener, you can use any name as long as - // you use the same name for the listener). - - session.messageSubscribe(arg::queue="message_queue", arg::destination="listener_destination"); - - //############## - session.messageFlow(arg::destination="listener_destination", arg::unit=0, arg::value=1);//messages ### Define a constant? - session.messageFlow(arg::destination="listener_destination", arg::unit=1, arg::value=0xFFFFFFFF);//bytes ###### Define a constant? - - // Tell the listener to listen to the destination we just - // created above. - - Listener listener(session, "listener_destination"); - listener.listen(); - - //----------------------------------------------------------------------------- + //--------------------------------------------------------------------------- connection.close(); return 0; diff --git a/cpp/examples/examples/direct/verify.in b/cpp/examples/examples/direct/verify.in index afe36335c7..d1e95f1151 100644 --- a/cpp/examples/examples/direct/verify.in +++ b/cpp/examples/examples/direct/verify.in @@ -1,7 +1,6 @@ -==== ./declare_queues.out -==== ./direct_producer.out -==== ./listener.out -Activating listener for: listener_destination +==== declare_queues.out +==== direct_producer.out +==== listener.out Message: Message 0 Message: Message 1 Message: Message 2 @@ -13,4 +12,4 @@ Message: Message 7 Message: Message 8 Message: Message 9 Message: That's all, folks! -Shutting down listener for listener_destination +Shutting down listener for message_queue diff --git a/cpp/examples/examples/direct/verify_cpp_python b/cpp/examples/examples/direct/verify_cpp_python index 5ce3681d90..4dc445ba27 100644 --- a/cpp/examples/examples/direct/verify_cpp_python +++ b/cpp/examples/examples/direct/verify_cpp_python @@ -1,4 +1,4 @@ # See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify -py=../../../../python/examples/direct +py=$PYTHON_EXAMPLES/direct clients ./declare_queues ./direct_producer $py/direct_consumer.py outputs ./declare_queues.out ./direct_producer.out $py/direct_consumer.py.out diff --git a/cpp/examples/examples/direct/verify_cpp_python.in b/cpp/examples/examples/direct/verify_cpp_python.in index 0952dbe405..1a329be59a 100644 --- a/cpp/examples/examples/direct/verify_cpp_python.in +++ b/cpp/examples/examples/direct/verify_cpp_python.in @@ -1,6 +1,6 @@ -==== ./declare_queues.out -==== ./direct_producer.out -==== ../../../../python/examples/direct/direct_consumer.py.out +==== declare_queues.out +==== direct_producer.out +==== direct_consumer.py.out Message 0 Message 1 Message 2 diff --git a/cpp/examples/examples/direct/verify_python_cpp b/cpp/examples/examples/direct/verify_python_cpp index 43c5339150..fe4893e120 100644 --- a/cpp/examples/examples/direct/verify_python_cpp +++ b/cpp/examples/examples/direct/verify_python_cpp @@ -1,5 +1,5 @@ # See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify -py=../../../../python/examples/direct +py=$PYTHON_EXAMPLES/direct clients $py/declare_queues.py $py/direct_producer.py ./listener outputs $py/declare_queues.py.out $py/direct_producer.py.out ./listener.out diff --git a/cpp/examples/examples/direct/verify_python_cpp.in b/cpp/examples/examples/direct/verify_python_cpp.in index b1907e6c3b..6f35255b18 100644 --- a/cpp/examples/examples/direct/verify_python_cpp.in +++ b/cpp/examples/examples/direct/verify_python_cpp.in @@ -1,7 +1,6 @@ -==== ../../../../python/examples/direct/declare_queues.py.out -==== ../../../../python/examples/direct/direct_producer.py.out -==== ./listener.out -Activating listener for: listener_destination +==== declare_queues.py.out +==== direct_producer.py.out +==== listener.out Message: message 0 Message: message 1 Message: message 2 @@ -13,4 +12,4 @@ Message: message 7 Message: message 8 Message: message 9 Message: That's all, folks! -Shutting down listener for listener_destination +Shutting down listener for message_queue diff --git a/cpp/examples/examples/fanout/declare_queues.cpp b/cpp/examples/examples/fanout/declare_queues.cpp index 6b1eabfeec..c76ed54730 100644 --- a/cpp/examples/examples/fanout/declare_queues.cpp +++ b/cpp/examples/examples/fanout/declare_queues.cpp @@ -20,21 +20,16 @@ */ /** - * direct_config_queues.cpp + * declare_queues.cpp (this program): * * This program is one of three programs designed to be used - * together. These programs use the "amq.direct" exchange. + * together. These programs use the "amq.fanout" exchange. * - * direct_config_queues.cpp (this program): - * - * Creates a queue on a broker, binding a routing key to route - * messages to that queue. - * - * direct_publisher.cpp: + * fanout_producer.cpp: * * Publishes to a broker, specifying a routing key. * - * direct_listener.cpp + * listener.cpp * * Reads from a queue on the broker using a message listener. * @@ -65,9 +60,7 @@ int main(int argc, char** argv) { //--------- Main body of program -------------------------------------------- - // Create a queue named "message_queue", and route all messages whose - // routing key is "routing_key to this newly created queue. - + // Create and bind a queue named "message_queue". session.queueDeclare(arg::queue="message_queue"); session.queueBind(arg::queue="message_queue", arg::exchange="amq.fanout"); diff --git a/cpp/examples/examples/fanout/fanout_producer.cpp b/cpp/examples/examples/fanout/fanout_producer.cpp index a5904e6731..7521724920 100644 --- a/cpp/examples/examples/fanout/fanout_producer.cpp +++ b/cpp/examples/examples/fanout/fanout_producer.cpp @@ -21,22 +21,22 @@ /** - * direct_publisher.cpp: + * fanout_producer.cpp: * * This program is one of three programs designed to be used * together. These programs do not specify the exchange type - the * default exchange type is the direct exchange. * - * direct_config_queues.cpp: + * declare_queues.cpp: * * Creates a queue on a broker, binding a routing key to route * messages to that queue. * - * direct_publisher.cpp (this program): + * fanout_producer.cpp (this program): * * Publishes to a broker, specifying a routing key. * - * direct_listener.cpp + * listener.cpp * * Reads from a queue on the broker using a message listener. * diff --git a/cpp/examples/examples/fanout/listener.cpp b/cpp/examples/examples/fanout/listener.cpp index 3f94f73f48..91b5123c68 100644 --- a/cpp/examples/examples/fanout/listener.cpp +++ b/cpp/examples/examples/fanout/listener.cpp @@ -20,32 +20,15 @@ */ /** - * direct_listener.cpp: - * - * This program is one of three programs designed to be used - * together. These programs do not specify the exchange type - the - * default exchange type is the direct exchange. - * - * direct_config_queues.cpp: - * - * Creates a queue on a broker, binding a routing key to route - * messages to that queue. - * - * direct_publisher.cpp: - * - * Publishes to a broker, specifying a routing key. - * - * direct_listener.cpp (this program): - * - * Reads from a queue on the broker using a message listener. - * + * listener.cpp: This program reads messages fro a queue on + * the broker using a message listener. */ #include <qpid/client/Dispatcher.h> #include <qpid/client/Connection.h> #include <qpid/client/Session.h> #include <qpid/client/Message.h> -#include <qpid/client/MessageListener.h> +#include <qpid/client/SubscriptionManager.h> #include <unistd.h> #include <cstdlib> @@ -56,43 +39,25 @@ using namespace qpid::framing; class Listener : public MessageListener{ -private: - std::string destination_name; - Dispatcher dispatcher; -public: - Listener(Session& session, string destination_name): - destination_name(destination_name), - dispatcher(session) - {}; - - virtual void listen(); - virtual void received(Message& message); - ~Listener() { }; + private: + SubscriptionManager& subscriptions; + public: + Listener(SubscriptionManager& subscriptions); + virtual void received(Message& message); }; - -void Listener::listen() { - std::cout << "Activating listener for: " <<destination_name << std::endl; - dispatcher.listen(destination_name, this); - - // ### The following line gives up control - it should be possible - // ### to listen without giving up control! - - dispatcher.run(); -} - +Listener::Listener(SubscriptionManager& subs) : subscriptions(subs) +{} void Listener::received(Message& message) { std::cout << "Message: " << message.getData() << std::endl; - if (message.getData() == "That's all, folks!") { - std::cout << "Shutting down listener for " <<destination_name << std::endl; - dispatcher.stop(); + std::cout << "Shutting down listener for " << message.getDestination() + << std::endl; + subscriptions.cancel(message.getDestination()); } } - - int main(int argc, char** argv) { const char* host = argc>1 ? argv[1] : "127.0.0.1"; int port = argc>2 ? atoi(argv[2]) : 5672; @@ -104,24 +69,15 @@ int main(int argc, char** argv) { //--------- Main body of program -------------------------------------------- + SubscriptionManager subscriptions(session); + // Create a listener and subscribe it to the queue named "message_queue" + Listener listener(subscriptions); + subscriptions.subscribe(listener, "message_queue"); + // Deliver messages until the subscription is cancelled + // by Listener::received() + subscriptions.run(); - // Subscribe to the queue, route it to a client destination for - // the listener. (The destination name merely identifies the - // destination in the listener, you can use any name as long as - // you use the same name for the listener). - - session.messageSubscribe(arg::queue="message_queue", arg::destination="listener_destination"); - - session.messageFlow(arg::destination="listener_destination", arg::unit=0, arg::value=1);//messages ### Define a constant? - session.messageFlow(arg::destination="listener_destination", arg::unit=1, arg::value=0xFFFFFFFF);//bytes ###### Define a constant? - - // Tell the listener to listen to the destination we just - // created above. - - Listener listener(session, "listener_destination"); - listener.listen(); - - //----------------------------------------------------------------------------- + //--------------------------------------------------------------------------- connection.close(); return 0; diff --git a/cpp/examples/examples/fanout/verify.in b/cpp/examples/examples/fanout/verify.in index 9d1c1445e1..23d08f38dd 100644 --- a/cpp/examples/examples/fanout/verify.in +++ b/cpp/examples/examples/fanout/verify.in @@ -1,7 +1,6 @@ -==== ./declare_queues.out -==== ./fanout_producer.out -==== ./listener.out -Activating listener for: listener_destination +==== declare_queues.out +==== fanout_producer.out +==== listener.out Message: Message 0 Message: Message 1 Message: Message 2 @@ -13,4 +12,4 @@ Message: Message 7 Message: Message 8 Message: Message 9 Message: That's all, folks! -Shutting down listener for listener_destination +Shutting down listener for message_queue diff --git a/cpp/examples/examples/fanout/verify_cpp_python b/cpp/examples/examples/fanout/verify_cpp_python index 59fa63478c..f53784ef1c 100644 --- a/cpp/examples/examples/fanout/verify_cpp_python +++ b/cpp/examples/examples/fanout/verify_cpp_python @@ -1,5 +1,5 @@ # See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify -py=../../../../python/examples/fanout +py=$PYTHON_EXAMPLES/fanout clients ./declare_queues ./fanout_producer $py/fanout_consumer.py outputs ./declare_queues.out ./fanout_producer.out $py/fanout_consumer.py.out diff --git a/cpp/examples/examples/fanout/verify_cpp_python.in b/cpp/examples/examples/fanout/verify_cpp_python.in index 141e7c6a84..cb9e52cfcc 100644 --- a/cpp/examples/examples/fanout/verify_cpp_python.in +++ b/cpp/examples/examples/fanout/verify_cpp_python.in @@ -1,6 +1,6 @@ -==== ./declare_queues.out -==== ./fanout_producer.out -==== ../../../../python/examples/fanout/fanout_consumer.py.out +==== declare_queues.out +==== fanout_producer.out +==== fanout_consumer.py.out Message 0 Message 1 Message 2 diff --git a/cpp/examples/examples/fanout/verify_python_cpp b/cpp/examples/examples/fanout/verify_python_cpp index cef36bd287..00a0727352 100644 --- a/cpp/examples/examples/fanout/verify_python_cpp +++ b/cpp/examples/examples/fanout/verify_python_cpp @@ -1,5 +1,5 @@ # See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify -py=../../../../python/examples/fanout -clients $py/declare_queues.py $py/fanout_producer .py ./listener +py=$PYTHON_EXAMPLES/fanout +clients $py/declare_queues.py $py/fanout_producer.py ./listener outputs $py/declare_queues.py.out $py/fanout_producer.py.out ./listener.out diff --git a/cpp/examples/examples/fanout/verify_python_cpp.in b/cpp/examples/examples/fanout/verify_python_cpp.in new file mode 100644 index 0000000000..87a1694e6c --- /dev/null +++ b/cpp/examples/examples/fanout/verify_python_cpp.in @@ -0,0 +1,15 @@ +==== declare_queues.py.out +==== fanout_producer.py.out +==== listener.out +Message: message 0 +Message: message 1 +Message: message 2 +Message: message 3 +Message: message 4 +Message: message 5 +Message: message 6 +Message: message 7 +Message: message 8 +Message: message 9 +Message: That's all, folks! +Shutting down listener for message_queue diff --git a/cpp/examples/examples/pub-sub/verify.in b/cpp/examples/examples/pub-sub/verify.in index ac51038a1b..6413c5c788 100644 --- a/cpp/examples/examples/pub-sub/verify.in +++ b/cpp/examples/examples/pub-sub/verify.in @@ -1,4 +1,4 @@ -==== ./topic_publisher.out +==== topic_publisher.out ==== topic_listener.out | remove_uuid | sort Declaring queue: europe Declaring queue: news diff --git a/cpp/examples/examples/pub-sub/verify_cpp_python b/cpp/examples/examples/pub-sub/verify_cpp_python index ff711a310f..ecc573eed3 100644 --- a/cpp/examples/examples/pub-sub/verify_cpp_python +++ b/cpp/examples/examples/pub-sub/verify_cpp_python @@ -1,5 +1,5 @@ # See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify -py=../../../../python/examples/pubsub +py=$PYTHON_EXAMPLES/pubsub background "Queues created" $py/topic_subscriber.py clients ./topic_publisher outputs ./topic_publisher.out "$py/topic_subscriber.py.out | remove_uuid64 | sort" diff --git a/cpp/examples/examples/pub-sub/verify_cpp_python.in b/cpp/examples/examples/pub-sub/verify_cpp_python.in index 9e033dc25c..b3c9e750f5 100644 --- a/cpp/examples/examples/pub-sub/verify_cpp_python.in +++ b/cpp/examples/examples/pub-sub/verify_cpp_python.in @@ -1,5 +1,5 @@ -==== ./topic_publisher.out -==== ../../../../python/examples/pubsub/topic_subscriber.py.out | remove_uuid64 | sort +==== topic_publisher.out +==== topic_subscriber.py.out | remove_uuid64 | sort Message 0 Message 0 Message 0 diff --git a/cpp/examples/examples/pub-sub/verify_python_cpp b/cpp/examples/examples/pub-sub/verify_python_cpp index e9c72c94d7..2ddaad58c2 100644 --- a/cpp/examples/examples/pub-sub/verify_python_cpp +++ b/cpp/examples/examples/pub-sub/verify_python_cpp @@ -1,5 +1,5 @@ # See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify -py=../../../../python/examples/pubsub +py=$PYTHON_EXAMPLES/pubsub background "Listening" ./topic_listener clients $py/topic_publisher.py outputs $py/topic_publisher.py.out "topic_listener.out | remove_uuid | sort" diff --git a/cpp/examples/examples/pub-sub/verify_python_cpp.in b/cpp/examples/examples/pub-sub/verify_python_cpp.in index 6f92458792..97fccf0a32 100644 --- a/cpp/examples/examples/pub-sub/verify_python_cpp.in +++ b/cpp/examples/examples/pub-sub/verify_python_cpp.in @@ -1,4 +1,4 @@ -==== ../../../../python/examples/pubsub/topic_publisher.py.out +==== topic_publisher.py.out ==== topic_listener.out | remove_uuid | sort Declaring queue: europe Declaring queue: news diff --git a/cpp/examples/examples/request-response/verify b/cpp/examples/examples/request-response/verify index a8c942b5e6..76007ff8d2 100644 --- a/cpp/examples/examples/request-response/verify +++ b/cpp/examples/examples/request-response/verify @@ -2,4 +2,4 @@ background "Waiting" ./server clients ./client kill %% # Must kill the server. -outputs "./client.out | remove_uuid" " server.out | remove_uuid" +outputs "./client.out | remove_uuid" "server.out | remove_uuid" diff --git a/cpp/examples/examples/request-response/verify.in b/cpp/examples/examples/request-response/verify.in index 3767fb3f43..7925dc5671 100644 --- a/cpp/examples/examples/request-response/verify.in +++ b/cpp/examples/examples/request-response/verify.in @@ -1,4 +1,4 @@ -==== ./client.out | remove_uuid +==== client.out | remove_uuid Activating response queue listener for: client Request: Twas brillig, and the slithy toves Request: Did gire and gymble in the wabe. @@ -10,7 +10,7 @@ Response: DID GIRE AND GYMBLE IN THE WABE. Response: ALL MIMSY WERE THE BOROGROVES, Response: AND THE MOME RATHS OUTGRABE. Shutting down listener for client -==== server.out | remove_uuid +==== server.out | remove_uuid Activating request queue listener for: request Waiting for requests Request: Twas brillig, and the slithy toves (client) diff --git a/cpp/examples/examples/request-response/verify_cpp_python b/cpp/examples/examples/request-response/verify_cpp_python index 9470110bc2..9d71d51c37 100644 --- a/cpp/examples/examples/request-response/verify_cpp_python +++ b/cpp/examples/examples/request-response/verify_cpp_python @@ -1,6 +1,5 @@ # See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify -py=../../../../python/examples/request-response -background "Request server running" $py/server.py +background "Request server running" $PYTHON_EXAMPLES/request-response/server.py clients ./client kill %% # Must kill the server. -outputs "./client.out | remove_uuid" "$py/server.py.out | remove_uuid64" +outputs "./client.out | remove_uuid" "$PYTHON_EXAMPLES/request-response/server.py.out | remove_uuid64" diff --git a/cpp/examples/examples/request-response/verify_cpp_python.in b/cpp/examples/examples/request-response/verify_cpp_python.in index efffc32332..280484bd2a 100644 --- a/cpp/examples/examples/request-response/verify_cpp_python.in +++ b/cpp/examples/examples/request-response/verify_cpp_python.in @@ -1,4 +1,4 @@ -==== ./client.out | remove_uuid +==== client.out | remove_uuid Activating response queue listener for: client Request: Twas brillig, and the slithy toves Request: Did gire and gymble in the wabe. @@ -10,6 +10,6 @@ Response: DID GIRE AND GYMBLE IN THE WABE. Response: ALL MIMSY WERE THE BOROGROVES, Response: AND THE MOME RATHS OUTGRABE. Shutting down listener for client -==== ../../../../python/examples/request-response/server.py.out | remove_uuid64 +==== server.py.out | remove_uuid64 Request server running - run your client now. (Times out after 100 seconds ...) diff --git a/cpp/examples/examples/request-response/verify_python_cpp b/cpp/examples/examples/request-response/verify_python_cpp index 11f5c4cbc4..9f3f1caaf4 100644 --- a/cpp/examples/examples/request-response/verify_python_cpp +++ b/cpp/examples/examples/request-response/verify_python_cpp @@ -1,6 +1,5 @@ # See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify -py=../../../../python/examples/request-response -background "Request server running" ./server -clients $py/client.py +background "Waiting" ./server +clients $PYTHON_EXAMPLES/request-response/client.py kill %% # Must kill the server. -outputs "./client.py.out | remove_uuid64" " server.out | remove_uuid" +outputs "$PYTHON_EXAMPLES/request-response/client.py.out | remove_uuid64" "server.out | remove_uuid64" diff --git a/cpp/examples/examples/request-response/verify_python_cpp.in b/cpp/examples/examples/request-response/verify_python_cpp.in new file mode 100644 index 0000000000..7718d54973 --- /dev/null +++ b/cpp/examples/examples/request-response/verify_python_cpp.in @@ -0,0 +1,18 @@ +==== client.py.out | remove_uuid64 +Request: Twas brilling, and the slithy toves +Request: Did gyre and gimble in the wabe. +Request: All mimsy were the borogroves, +Request: And the mome raths outgrabe. +Messages queue: ReplyTo: +Response: TWAS BRILLING, AND THE SLITHY TOVES +Response: DID GYRE AND GIMBLE IN THE WABE. +Response: ALL MIMSY WERE THE BOROGROVES, +Response: AND THE MOME RATHS OUTGRABE. +No more messages! +==== server.out | remove_uuid64 +Activating request queue listener for: request +Waiting for requests +Request: Twas brilling, and the slithy toves (ReplyTo:) +Request: Did gyre and gimble in the wabe. (ReplyTo:) +Request: All mimsy were the borogroves, (ReplyTo:) +Request: And the mome raths outgrabe. (ReplyTo:) diff --git a/cpp/examples/verify b/cpp/examples/verify new file mode 100755 index 0000000000..844e99b765 --- /dev/null +++ b/cpp/examples/verify @@ -0,0 +1,81 @@ +#!/bin/sh +# Driver script to verify installed examples (also used for build tests.) +# +# Usage: verify example_dir [ example_dir ...] +# Where each example_dir must contain a verify sub-script to include. +# +# If $QPIDD is set, run a private QPIDD and use it. +# If $QPID_HOST or $QPID_PORT are set, use them to connect. +# + +export QPID_DATA_DIR= + +cleanup() { + test -n "$QPIDD" && $QPIDD -q # Private broker + kill %% > /dev/null 2>&1 # Leftover background jobs +} + +trap cleanup EXIT + +ARGS="${QPID_HOST:-localhost} $QPID_PORT" + +outfile() { echo $1.out; } + +fail() { test -n "$*" && echo $* 1>&2 ; FAIL=1; return 1; } + +client() { "$@" $ARGS > `outfile $*` || fail; } + +clients() { for cmd in "$@"; do client $cmd; done; } + +waitfor() { until grep -a -l "$2" $1 >/dev/null 2>&1 ; do sleep 1 ; done ; } + +background() { + pattern=$1; shift + out=`outfile $*` + eval "$* $ARGS > $out &" || { fail; return 1; } + waitfor $out "$pattern" +} + +name() { + for x in $*; do name="$name `basename $x`"; done + echo $name; +} + +outputs() { + wait 2> /dev/null # Wait for all backgroud processes to complete + rm -f $script.out + for f in "$@"; do + { echo "==== `name $f`"; eval "cat $f"; } >> $script.out || fail + done +} + +verify() { + FAIL= + if [ -d $1 ]; then dir=$1; script=verify; + else dir=`dirname $1`; script=`basename $1`; fi + cd $dir || return 1 + rm -f *.out + { source ./$script && diff -ac $script.out $script.in ; } || fail + test -z "$FAIL" && rm -f *.out + return $FAIL +} + +HEX="[a-fA-F0-9]" +remove_uuid() { + sed "s/$HEX\{8\}-$HEX\{4\}-$HEX\{4\}-$HEX\{4\}-$HEX\{12\}//g" $* +} +remove_uuid64() { + sed 's/[-A-Za-z0-9_]\{22\}==//g' $* +} + +# Start private broker if QPIDD is set. +if [ -n "$QPIDD" ] ; then + export QPID_PORT=`$QPIDD -dp0` || { echo "Cannot start $QPIDD" ; exit 1; } + trap "$QPIDD -q" EXIT +fi + +for example in "$@"; do + echo -n "$example : " + if ( verify $example; ) then echo "PASS"; else echo "FAIL"; RET=1; fi + done +exit $RET diff --git a/cpp/examples/verify_all b/cpp/examples/verify_all new file mode 100755 index 0000000000..db1d6de783 --- /dev/null +++ b/cpp/examples/verify_all @@ -0,0 +1,18 @@ +#!/bin/sh +# Verify all C++/python example combinations. +# +verify=$1; shift +qpidd=$1; shift +cpp=$1; shift + +trap "$qpidd -q" exit +export QPID_PORT=`$qpidd -dp0 --data-dir ""` +export PYTHON_EXAMPLES + +find="find $cpp" +test -d $PYTHON_EXAMPLES && find="$find $PYTHON_EXAMPLES" +find="$find -name verify" +test -d $PYTHON_EXAMPLES && \ + find="$find -o -name verify_cpp_python -o -name verify_python_cpp" +$verify `$find` + |