From 325d0b37fdfa8f90a5a3a1b5689b96a838d30e75 Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Thu, 8 Apr 2010 16:24:08 +0000 Subject: Renamed qpid_recv to qpid_receive. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@931991 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/tests/CMakeLists.txt | 8 +- cpp/src/tests/Makefile.am | 8 +- cpp/src/tests/qpid_receive.cpp | 229 +++++++++++++++++++++++++++++++++++++++++ cpp/src/tests/qpid_recv.cpp | 229 ----------------------------------------- 4 files changed, 236 insertions(+), 238 deletions(-) create mode 100644 cpp/src/tests/qpid_receive.cpp delete mode 100644 cpp/src/tests/qpid_recv.cpp (limited to 'cpp/src') diff --git a/cpp/src/tests/CMakeLists.txt b/cpp/src/tests/CMakeLists.txt index dad8cf0e4c..605c96c3e4 100644 --- a/cpp/src/tests/CMakeLists.txt +++ b/cpp/src/tests/CMakeLists.txt @@ -264,14 +264,12 @@ target_link_libraries (sender qpidclient) #sender_SOURCES=sender.cpp TestOptions.h ConnectionOptions.h remember_location(sender) -add_executable (qpid_recv qpid_recv.cpp Statistics.cpp ${platform_test_additions}) -target_link_libraries (qpid_recv qpidclient) -#qpid_recv_SOURCES=qpid_recv.cpp TestOptions.h ConnectionOptions.h -remember_location(qpid_recv) +add_executable (qpid_receive qpid_receive.cpp Statistics.cpp ${platform_test_additions}) +target_link_libraries (qpid_receive qpidclient) +remember_location(qpid_receive) add_executable (qpid_send qpid_send.cpp Statistics.cpp ${platform_test_additions}) target_link_libraries (qpid_send qpidclient) -#qpid_send_SOURCES=qpid_send.cpp TestOptions.h ConnectionOptions.h remember_location(qpid_send) if (CMAKE_SYSTEM_NAME STREQUAL Windows) diff --git a/cpp/src/tests/Makefile.am b/cpp/src/tests/Makefile.am index b9406c5ee3..776430b710 100644 --- a/cpp/src/tests/Makefile.am +++ b/cpp/src/tests/Makefile.am @@ -162,14 +162,14 @@ sender_SOURCES = \ ConnectionOptions.h sender_LDADD = $(lib_client) -qpidtest_PROGRAMS += qpid_recv -qpid_recv_SOURCES = \ - qpid_recv.cpp \ +qpidtest_PROGRAMS += qpid_receive +qpid_receive_SOURCES = \ + qpid_receive.cpp \ TestOptions.h \ ConnectionOptions.h \ Statistics.h \ Statistics.cpp -qpid_recv_LDADD = $(lib_client) +qpid_receive_LDADD = $(lib_client) qpidtest_PROGRAMS += qpid_send qpid_send_SOURCES = \ diff --git a/cpp/src/tests/qpid_receive.cpp b/cpp/src/tests/qpid_receive.cpp new file mode 100644 index 0000000000..77e9cd180a --- /dev/null +++ b/cpp/src/tests/qpid_receive.cpp @@ -0,0 +1,229 @@ +/* + * + * Licensed to the Apache 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include "TestOptions.h" +#include "Statistics.h" + +#include +#include + +using namespace qpid::messaging; +using namespace qpid::types; +using qpid::client::amqp0_10::FailoverUpdates; + +using namespace std; + +namespace qpid { +namespace tests { + +struct Options : public qpid::Options +{ + bool help; + std::string url; + std::string address; + std::string connectionOptions; + int64_t timeout; + bool forever; + uint messages; + bool ignoreDuplicates; + uint capacity; + uint ackFrequency; + uint tx; + uint rollbackFrequency; + bool printContent; + bool printHeaders; + bool failoverUpdates; + qpid::log::Options log; + bool reportTotal; + uint reportEvery; + + Options(const std::string& argv0=std::string()) + : qpid::Options("Options"), + help(false), + url("amqp:tcp:127.0.0.1"), + timeout(0), + forever(false), + messages(0), + ignoreDuplicates(false), + capacity(1000), + ackFrequency(100), + tx(0), + rollbackFrequency(0), + printContent(true), + printHeaders(false), + failoverUpdates(false), + log(argv0), + reportTotal(false), + reportEvery(0) + { + addOptions() + ("broker,b", qpid::optValue(url, "URL"), "url of broker to connect to") + ("address,a", qpid::optValue(address, "ADDRESS"), "address to receive from") + ("connection-options", qpid::optValue(connectionOptions, "OPTIONS"), "options for the connection") + ("timeout,t", qpid::optValue(timeout, "TIMEOUT"), "timeout in seconds to wait before exiting") + ("forever,f", qpid::optValue(forever), "ignore timeout and wait forever") + ("messages", qpid::optValue(messages, "N"), "Number of messages to receive; 0 means receive indefinitely") + ("ignore-duplicates", qpid::optValue(ignoreDuplicates), "Detect and ignore duplicates (by checking 'sn' header)") + ("capacity", qpid::optValue(capacity, "N"), "Pre-fetch window (0 implies no pre-fetch)") + ("ack-frequency", qpid::optValue(ackFrequency, "N"), "Ack frequency (0 implies none of the messages will get accepted)") + ("tx", qpid::optValue(tx, "N"), "batch size for transactions (0 implies transaction are not used)") + ("rollback-frequency", qpid::optValue(rollbackFrequency, "N"), "rollback frequency (0 implies no transaction will be rolledback)") + ("print-content", qpid::optValue(printContent, "yes|no"), "print out message content") + ("print-headers", qpid::optValue(printHeaders, "yes|no"), "print out message headers") + ("failover-updates", qpid::optValue(failoverUpdates), "Listen for membership updates distributed via amq.failover") + ("report-total", qpid::optValue(reportTotal), "Report total throughput and latency statistics") + ("report-every", qpid::optValue(reportEvery,"N"), "Report throughput and latency statistics every N messages.") + ("help", qpid::optValue(help), "print this usage statement"); + add(log); + } + + Duration getTimeout() + { + if (forever) return Duration::FOREVER; + else return Duration::SECOND*timeout; + + } + bool parse(int argc, char** argv) + { + try { + qpid::Options::parse(argc, argv); + if (address.empty()) throw qpid::Exception("Address must be specified!"); + qpid::log::Logger::instance().configure(log); + if (help) { + std::ostringstream msg; + std::cout << msg << *this << std::endl << std::endl + << "Drains messages from the specified address" << std::endl; + return false; + } else { + return true; + } + } catch (const std::exception& e) { + std::cerr << *this << std::endl << std::endl << e.what() << std::endl; + return false; + } + } +}; + +const string EOS("eos"); + +class SequenceTracker +{ + uint lastSn; + public: + SequenceTracker() : lastSn(0) {} + + bool isDuplicate(Message& message) + { + uint sn = message.getProperties()["sn"]; + if (lastSn < sn) { + lastSn = sn; + return false; + } else { + return true; + } + } +}; + +}} // namespace qpid::tests + +using namespace qpid::tests; + +int main(int argc, char ** argv) +{ + Options opts; + if (opts.parse(argc, argv)) { + Connection connection(opts.url, opts.connectionOptions); + try { + connection.connect(); + std::auto_ptr updates(opts.failoverUpdates ? new FailoverUpdates(connection) : 0); + Session session = opts.tx ? connection.createTransactionalSession() : connection.createSession(); + Receiver receiver = session.createReceiver(opts.address); + receiver.setCapacity(opts.capacity); + Message msg; + uint count = 0; + uint txCount = 0; + SequenceTracker sequenceTracker; + Duration timeout = opts.getTimeout(); + bool done = false; + Reporter reporter(std::cout, opts.reportEvery); + while (!done && receiver.fetch(msg, timeout)) { + reporter.message(msg); + if (!opts.ignoreDuplicates || !sequenceTracker.isDuplicate(msg)) { + if (msg.getContent() == EOS) { + done = true; + } else { + ++count; + if (opts.printHeaders) { + if (msg.getSubject().size()) std::cout << "Subject: " << msg.getSubject() << std::endl; + if (msg.getReplyTo()) std::cout << "ReplyTo: " << msg.getReplyTo() << std::endl; + if (msg.getCorrelationId().size()) std::cout << "CorrelationId: " << msg.getCorrelationId() << std::endl; + if (msg.getUserId().size()) std::cout << "UserId: " << msg.getUserId() << std::endl; + if (msg.getTtl().getMilliseconds()) std::cout << "TTL: " << msg.getTtl().getMilliseconds() << std::endl; + if (msg.getDurable()) std::cout << "Durable: true" << std::endl; + if (msg.getRedelivered()) std::cout << "Redelivered: true" << std::endl; + std::cout << "Properties: " << msg.getProperties() << std::endl; + std::cout << std::endl; + } + if (opts.printContent) + std::cout << msg.getContent() << std::endl;//TODO: handle map or list messages + if (opts.messages && count >= opts.messages) done = true; + } + } + if (opts.tx && (count % opts.tx == 0)) { + if (opts.rollbackFrequency && (++txCount % opts.rollbackFrequency == 0)) { + session.rollback(); + } else { + session.commit(); + } + } else if (opts.ackFrequency && (count % opts.ackFrequency == 0)) { + session.acknowledge(); + } + //opts.rejectFrequency?? + } + if (opts.reportTotal) reporter.report(); + if (opts.tx) { + if (opts.rollbackFrequency && (++txCount % opts.rollbackFrequency == 0)) { + session.rollback(); + } else { + session.commit(); + } + } else { + session.acknowledge(); + } + session.close(); + connection.close(); + return 0; + } catch(const std::exception& error) { + std::cerr << "Failure: " << error.what() << std::endl; + connection.close(); + } + } + return 1; +} diff --git a/cpp/src/tests/qpid_recv.cpp b/cpp/src/tests/qpid_recv.cpp deleted file mode 100644 index 77e9cd180a..0000000000 --- a/cpp/src/tests/qpid_recv.cpp +++ /dev/null @@ -1,229 +0,0 @@ -/* - * - * Licensed to the Apache 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include "TestOptions.h" -#include "Statistics.h" - -#include -#include - -using namespace qpid::messaging; -using namespace qpid::types; -using qpid::client::amqp0_10::FailoverUpdates; - -using namespace std; - -namespace qpid { -namespace tests { - -struct Options : public qpid::Options -{ - bool help; - std::string url; - std::string address; - std::string connectionOptions; - int64_t timeout; - bool forever; - uint messages; - bool ignoreDuplicates; - uint capacity; - uint ackFrequency; - uint tx; - uint rollbackFrequency; - bool printContent; - bool printHeaders; - bool failoverUpdates; - qpid::log::Options log; - bool reportTotal; - uint reportEvery; - - Options(const std::string& argv0=std::string()) - : qpid::Options("Options"), - help(false), - url("amqp:tcp:127.0.0.1"), - timeout(0), - forever(false), - messages(0), - ignoreDuplicates(false), - capacity(1000), - ackFrequency(100), - tx(0), - rollbackFrequency(0), - printContent(true), - printHeaders(false), - failoverUpdates(false), - log(argv0), - reportTotal(false), - reportEvery(0) - { - addOptions() - ("broker,b", qpid::optValue(url, "URL"), "url of broker to connect to") - ("address,a", qpid::optValue(address, "ADDRESS"), "address to receive from") - ("connection-options", qpid::optValue(connectionOptions, "OPTIONS"), "options for the connection") - ("timeout,t", qpid::optValue(timeout, "TIMEOUT"), "timeout in seconds to wait before exiting") - ("forever,f", qpid::optValue(forever), "ignore timeout and wait forever") - ("messages", qpid::optValue(messages, "N"), "Number of messages to receive; 0 means receive indefinitely") - ("ignore-duplicates", qpid::optValue(ignoreDuplicates), "Detect and ignore duplicates (by checking 'sn' header)") - ("capacity", qpid::optValue(capacity, "N"), "Pre-fetch window (0 implies no pre-fetch)") - ("ack-frequency", qpid::optValue(ackFrequency, "N"), "Ack frequency (0 implies none of the messages will get accepted)") - ("tx", qpid::optValue(tx, "N"), "batch size for transactions (0 implies transaction are not used)") - ("rollback-frequency", qpid::optValue(rollbackFrequency, "N"), "rollback frequency (0 implies no transaction will be rolledback)") - ("print-content", qpid::optValue(printContent, "yes|no"), "print out message content") - ("print-headers", qpid::optValue(printHeaders, "yes|no"), "print out message headers") - ("failover-updates", qpid::optValue(failoverUpdates), "Listen for membership updates distributed via amq.failover") - ("report-total", qpid::optValue(reportTotal), "Report total throughput and latency statistics") - ("report-every", qpid::optValue(reportEvery,"N"), "Report throughput and latency statistics every N messages.") - ("help", qpid::optValue(help), "print this usage statement"); - add(log); - } - - Duration getTimeout() - { - if (forever) return Duration::FOREVER; - else return Duration::SECOND*timeout; - - } - bool parse(int argc, char** argv) - { - try { - qpid::Options::parse(argc, argv); - if (address.empty()) throw qpid::Exception("Address must be specified!"); - qpid::log::Logger::instance().configure(log); - if (help) { - std::ostringstream msg; - std::cout << msg << *this << std::endl << std::endl - << "Drains messages from the specified address" << std::endl; - return false; - } else { - return true; - } - } catch (const std::exception& e) { - std::cerr << *this << std::endl << std::endl << e.what() << std::endl; - return false; - } - } -}; - -const string EOS("eos"); - -class SequenceTracker -{ - uint lastSn; - public: - SequenceTracker() : lastSn(0) {} - - bool isDuplicate(Message& message) - { - uint sn = message.getProperties()["sn"]; - if (lastSn < sn) { - lastSn = sn; - return false; - } else { - return true; - } - } -}; - -}} // namespace qpid::tests - -using namespace qpid::tests; - -int main(int argc, char ** argv) -{ - Options opts; - if (opts.parse(argc, argv)) { - Connection connection(opts.url, opts.connectionOptions); - try { - connection.connect(); - std::auto_ptr updates(opts.failoverUpdates ? new FailoverUpdates(connection) : 0); - Session session = opts.tx ? connection.createTransactionalSession() : connection.createSession(); - Receiver receiver = session.createReceiver(opts.address); - receiver.setCapacity(opts.capacity); - Message msg; - uint count = 0; - uint txCount = 0; - SequenceTracker sequenceTracker; - Duration timeout = opts.getTimeout(); - bool done = false; - Reporter reporter(std::cout, opts.reportEvery); - while (!done && receiver.fetch(msg, timeout)) { - reporter.message(msg); - if (!opts.ignoreDuplicates || !sequenceTracker.isDuplicate(msg)) { - if (msg.getContent() == EOS) { - done = true; - } else { - ++count; - if (opts.printHeaders) { - if (msg.getSubject().size()) std::cout << "Subject: " << msg.getSubject() << std::endl; - if (msg.getReplyTo()) std::cout << "ReplyTo: " << msg.getReplyTo() << std::endl; - if (msg.getCorrelationId().size()) std::cout << "CorrelationId: " << msg.getCorrelationId() << std::endl; - if (msg.getUserId().size()) std::cout << "UserId: " << msg.getUserId() << std::endl; - if (msg.getTtl().getMilliseconds()) std::cout << "TTL: " << msg.getTtl().getMilliseconds() << std::endl; - if (msg.getDurable()) std::cout << "Durable: true" << std::endl; - if (msg.getRedelivered()) std::cout << "Redelivered: true" << std::endl; - std::cout << "Properties: " << msg.getProperties() << std::endl; - std::cout << std::endl; - } - if (opts.printContent) - std::cout << msg.getContent() << std::endl;//TODO: handle map or list messages - if (opts.messages && count >= opts.messages) done = true; - } - } - if (opts.tx && (count % opts.tx == 0)) { - if (opts.rollbackFrequency && (++txCount % opts.rollbackFrequency == 0)) { - session.rollback(); - } else { - session.commit(); - } - } else if (opts.ackFrequency && (count % opts.ackFrequency == 0)) { - session.acknowledge(); - } - //opts.rejectFrequency?? - } - if (opts.reportTotal) reporter.report(); - if (opts.tx) { - if (opts.rollbackFrequency && (++txCount % opts.rollbackFrequency == 0)) { - session.rollback(); - } else { - session.commit(); - } - } else { - session.acknowledge(); - } - session.close(); - connection.close(); - return 0; - } catch(const std::exception& error) { - std::cerr << "Failure: " << error.what() << std::endl; - connection.close(); - } - } - return 1; -} -- cgit v1.2.1