summaryrefslogtreecommitdiff
path: root/cpp/src/tests
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/tests')
-rw-r--r--cpp/src/tests/BasicP2PTest.cpp4
-rw-r--r--cpp/src/tests/BasicP2PTest.h2
-rw-r--r--cpp/src/tests/BasicPubSubTest.cpp6
-rw-r--r--cpp/src/tests/BasicPubSubTest.h2
-rw-r--r--cpp/src/tests/SimpleTestCaseBase.cpp6
-rw-r--r--cpp/src/tests/SimpleTestCaseBase.h7
-rw-r--r--cpp/src/tests/TestCase.h4
-rw-r--r--cpp/src/tests/TestOptions.h30
-rw-r--r--cpp/src/tests/client_test.cpp31
-rw-r--r--cpp/src/tests/interop_runner.cpp49
-rw-r--r--cpp/src/tests/latencytest.cpp3
-rw-r--r--cpp/src/tests/topic_listener.cpp2
-rw-r--r--cpp/src/tests/topic_publisher.cpp2
13 files changed, 72 insertions, 76 deletions
diff --git a/cpp/src/tests/BasicP2PTest.cpp b/cpp/src/tests/BasicP2PTest.cpp
index b202f88ca6..9f5f1acccb 100644
--- a/cpp/src/tests/BasicP2PTest.cpp
+++ b/cpp/src/tests/BasicP2PTest.cpp
@@ -29,7 +29,7 @@ class BasicP2PTest::Receiver : public Worker, public MessageListener
const std::string queue;
std::string tag;
public:
- Receiver(TestOptions& options, const std::string& _queue, const int _messages)
+ Receiver(ConnectionSettings& options, const std::string& _queue, const int _messages)
: Worker(options, _messages), queue(_queue){}
void init()
{
@@ -51,7 +51,7 @@ public:
}
};
-void BasicP2PTest::assign(const std::string& role, framing::FieldTable& params, TestOptions& options)
+void BasicP2PTest::assign(const std::string& role, framing::FieldTable& params, ConnectionSettings& options)
{
std::string queue = params.getString("P2P_QUEUE_AND_KEY_NAME");
int messages = params.getInt("P2P_NUM_MESSAGES");
diff --git a/cpp/src/tests/BasicP2PTest.h b/cpp/src/tests/BasicP2PTest.h
index 3f0a3704f5..8f957187b0 100644
--- a/cpp/src/tests/BasicP2PTest.h
+++ b/cpp/src/tests/BasicP2PTest.h
@@ -38,7 +38,7 @@ class BasicP2PTest : public SimpleTestCaseBase
{
class Receiver;
public:
- void assign(const std::string& role, framing::FieldTable& params, TestOptions& options);
+ void assign(const std::string& role, framing::FieldTable& params, ConnectionSettings& options);
};
}
diff --git a/cpp/src/tests/BasicPubSubTest.cpp b/cpp/src/tests/BasicPubSubTest.cpp
index 623194d331..aed47b419c 100644
--- a/cpp/src/tests/BasicPubSubTest.cpp
+++ b/cpp/src/tests/BasicPubSubTest.cpp
@@ -30,7 +30,7 @@ class BasicPubSubTest::Receiver : public Worker, public MessageListener
const std::string key;
std::string tag;
public:
- Receiver(TestOptions& options, const Exchange& _exchange, const std::string& _queue, const std::string& _key, const int _messages)
+ Receiver(ConnectionSettings& options, const Exchange& _exchange, const std::string& _queue, const std::string& _key, const int _messages)
: Worker(options, _messages), exchange(_exchange), queue(_queue), key(_key){}
void init()
@@ -58,7 +58,7 @@ class BasicPubSubTest::MultiReceiver : public Worker, public MessageListener
ReceiverList receivers;
public:
- MultiReceiver(TestOptions& options, const Exchange& exchange, const std::string& key, const int _messages, int receiverCount)
+ MultiReceiver(ConnectionSettings& options, const Exchange& exchange, const std::string& key, const int _messages, int receiverCount)
: Worker(options, _messages)
{
for (int i = 0; i != receiverCount; i++) {
@@ -104,7 +104,7 @@ public:
}
};
-void BasicPubSubTest::assign(const std::string& role, framing::FieldTable& params, TestOptions& options)
+void BasicPubSubTest::assign(const std::string& role, framing::FieldTable& params, ConnectionSettings& options)
{
std::string key = params.getString("PUBSUB_KEY");
int messages = params.getInt("PUBSUB_NUM_MESSAGES");
diff --git a/cpp/src/tests/BasicPubSubTest.h b/cpp/src/tests/BasicPubSubTest.h
index c3f8020b3a..a6d794c5b6 100644
--- a/cpp/src/tests/BasicPubSubTest.h
+++ b/cpp/src/tests/BasicPubSubTest.h
@@ -43,7 +43,7 @@ class BasicPubSubTest : public SimpleTestCaseBase
class Receiver;
class MultiReceiver;
public:
- void assign(const std::string& role, framing::FieldTable& params, TestOptions& options);
+ void assign(const std::string& role, framing::FieldTable& params, ConnectionSettings& options);
};
}
diff --git a/cpp/src/tests/SimpleTestCaseBase.cpp b/cpp/src/tests/SimpleTestCaseBase.cpp
index 4f071cd02b..0111e030fb 100644
--- a/cpp/src/tests/SimpleTestCaseBase.cpp
+++ b/cpp/src/tests/SimpleTestCaseBase.cpp
@@ -47,7 +47,7 @@ void SimpleTestCaseBase::report(client::Message& report)
}
}
-SimpleTestCaseBase::Sender::Sender(TestOptions& options,
+SimpleTestCaseBase::Sender::Sender(ConnectionSettings& options,
const Exchange& _exchange,
const std::string& _key,
const int _messages)
@@ -67,8 +67,8 @@ void SimpleTestCaseBase::Sender::start(){
stop();
}
-SimpleTestCaseBase::Worker::Worker(TestOptions& options, const int _messages) :
- connection(options.trace), messages(_messages), count(0)
+SimpleTestCaseBase::Worker::Worker(ConnectionSettings& options, const int _messages) :
+ messages(_messages), count(0)
{
connection.open(options.host, options.port);
connection.openChannel(channel);
diff --git a/cpp/src/tests/SimpleTestCaseBase.h b/cpp/src/tests/SimpleTestCaseBase.h
index 7f94fa7e1c..e2c328437e 100644
--- a/cpp/src/tests/SimpleTestCaseBase.h
+++ b/cpp/src/tests/SimpleTestCaseBase.h
@@ -28,6 +28,7 @@
#include "qpid/client/Channel.h"
#include "qpid/client/Message.h"
#include "qpid/client/Connection.h"
+#include "qpid/client/ConnectionSettings.h"
#include "qpid/client/MessageListener.h"
#include "TestCase.h"
@@ -49,7 +50,7 @@ protected:
public:
- Worker(TestOptions& options, const int messages);
+ Worker(ConnectionSettings& options, const int messages);
virtual ~Worker(){}
virtual void stop();
@@ -63,7 +64,7 @@ protected:
const Exchange& exchange;
const std::string key;
public:
- Sender(TestOptions& options,
+ Sender(ConnectionSettings& options,
const Exchange& exchange,
const std::string& key,
const int messages);
@@ -74,7 +75,7 @@ protected:
std::auto_ptr<Worker> worker;
public:
- virtual void assign(const std::string& role, framing::FieldTable& params, TestOptions& options) = 0;
+ virtual void assign(const std::string& role, framing::FieldTable& params, ConnectionSettings& options) = 0;
virtual ~SimpleTestCaseBase() {}
diff --git a/cpp/src/tests/TestCase.h b/cpp/src/tests/TestCase.h
index 07bdd68933..7926c4fe1d 100644
--- a/cpp/src/tests/TestCase.h
+++ b/cpp/src/tests/TestCase.h
@@ -21,8 +21,8 @@
*
*/
+#include "qpid/client/ConnectionSettings.h"
#include "qpid/client/Message.h"
-#include "TestOptions.h"
namespace qpid {
@@ -39,7 +39,7 @@ public:
* may be 'activated' at this stage others may require an explicit
* start request.
*/
- virtual void assign(const std::string& role, framing::FieldTable& params, TestOptions& options) = 0;
+ virtual void assign(const std::string& role, framing::FieldTable& params, client::ConnectionSettings& options) = 0;
/**
* Each test will be started on its own thread, which should block
* until the test completes (this may or may not require an
diff --git a/cpp/src/tests/TestOptions.h b/cpp/src/tests/TestOptions.h
index 87710964d6..b34acaec4e 100644
--- a/cpp/src/tests/TestOptions.h
+++ b/cpp/src/tests/TestOptions.h
@@ -26,6 +26,7 @@
#include "qpid/Url.h"
#include "qpid/log/Logger.h"
#include "qpid/client/Connection.h"
+#include "qpid/client/ConnectionSettings.h"
#include <iostream>
#include <exception>
@@ -35,22 +36,11 @@ namespace qpid {
struct TestOptions : public qpid::Options
{
TestOptions(const std::string& helpText_=std::string()) :
- Options("Test Options"),
- host("localhost"), port(TcpAddress::DEFAULT_PORT),
- clientid("cpp"), username("guest"), password("guest"),
- help(false), helpText(helpText_)
+ Options("Test Options"), help(false), helpText(helpText_)
{
addOptions()
- ("host,h", optValue(host, "HOST"), "Broker host to connect to")
- // TODO aconway 2007-06-26: broker is synonym for host. Drop broker?
- ("broker,b", optValue(host, "HOST"), "Broker host to connect to")
- ("port,p", optValue(port, "PORT"), "Broker port to connect to")
- ("virtualhost,v", optValue(virtualhost, "VHOST"), "virtual host")
- ("clientname,n", optValue(clientid, "ID"), "unique client identifier")
- ("username", optValue(username, "USER"), "user name for broker log in.")
- ("password", optValue(password, "USER"), "password for broker log in.")
("help", optValue(help), "print this usage statement");
- add(log);
+ add(con);
}
/** As well as parsing, throw help message if requested. */
@@ -62,8 +52,7 @@ struct TestOptions : public qpid::Options
msg << *this << std::endl << std::endl << e.what() << std::endl;
throw qpid::Options::Exception(msg.str());
}
- trace = log.trace;
- qpid::log::Logger::instance().configure(log, argv[0]);
+ qpid::log::Logger::instance().configure(con.log, argv[0]);
if (help) {
std::ostringstream msg;
msg << *this << std::endl << std::endl << helpText << std::endl;
@@ -73,19 +62,12 @@ struct TestOptions : public qpid::Options
/** Open a connection using option values */
void open(qpid::client::Connection& connection) {
- connection.open(host, port, username, password, virtualhost);
+ connection.open(con);
}
- std::string host;
- uint16_t port;
- std::string virtualhost;
- std::string clientid;
- std::string username;
- std::string password;
- bool trace;
bool help;
- log::Options log;
+ client::ConnectionSettings con;
std::string helpText;
};
diff --git a/cpp/src/tests/client_test.cpp b/cpp/src/tests/client_test.cpp
index d0da2ec8ca..20e8b21a3a 100644
--- a/cpp/src/tests/client_test.cpp
+++ b/cpp/src/tests/client_test.cpp
@@ -30,6 +30,7 @@
#include "TestOptions.h"
#include "qpid/client/Connection.h"
+#include "qpid/client/ConnectionSettings.h"
#include "qpid/client/Message.h"
#include "qpid/client/Session.h"
#include "qpid/framing/FrameSet.h"
@@ -40,15 +41,15 @@ using namespace qpid::client;
using namespace qpid::framing;
using std::string;
-struct Args : public qpid::TestOptions {
+struct Args : public TestOptions {
uint msgSize;
- uint maxFrameSize;
+ bool verbose;
- Args() : msgSize(26), maxFrameSize(65535)
+ Args() : TestOptions("Simple test of Qpid c++ client; sends and receives a single message."), msgSize(26)
{
addOptions()
("size", optValue(msgSize, "N"), "message size")
- ("max-frame-size", optValue(maxFrameSize, "N"), "max frame size");
+ ("verbose", optValue(verbose), "print out some status messages");
}
};
@@ -85,33 +86,33 @@ int main(int argc, char** argv)
opts.parse(argc, argv);
//Connect to the broker:
- Connection connection(opts.trace, opts.maxFrameSize);
+ Connection connection;
opts.open(connection);
- if (opts.trace) std::cout << "Opened connection." << std::endl;
+ if (opts.verbose) std::cout << "Opened connection." << std::endl;
//Create and open a session on the connection through which
//most functionality is exposed:
Session session = connection.newSession(ASYNC);
- if (opts.trace) std::cout << "Opened session." << std::endl;
+ if (opts.verbose) std::cout << "Opened session." << std::endl;
//'declare' the exchange and the queue, which will create them
//as they don't exist
session.exchangeDeclare(arg::exchange="MyExchange", arg::type="direct");
- if (opts.trace) std::cout << "Declared exchange." << std::endl;
+ if (opts.verbose) std::cout << "Declared exchange." << std::endl;
session.queueDeclare(arg::queue="MyQueue", arg::autoDelete=true, arg::exclusive=true);
- if (opts.trace) std::cout << "Declared queue." << std::endl;
+ if (opts.verbose) std::cout << "Declared queue." << std::endl;
//now bind the queue to the exchange
session.exchangeBind(arg::exchange="MyExchange", arg::queue="MyQueue", arg::bindingKey="MyKey");
- if (opts.trace) std::cout << "Bound queue to exchange." << std::endl;
+ if (opts.verbose) std::cout << "Bound queue to exchange." << std::endl;
//create and send a message to the exchange using the routing
//key we bound our queue with:
Message msgOut(generateData(opts.msgSize));
msgOut.getDeliveryProperties().setRoutingKey("MyKey");
session.messageTransfer(arg::destination="MyExchange", arg::content=msgOut, arg::acceptMode=1);
- if (opts.trace) print("Published message: ", msgOut);
+ if (opts.verbose) print("Published message: ", msgOut);
//subscribe to the queue, add sufficient credit and then get
//incoming 'frameset', check that its a message transfer and
@@ -121,12 +122,12 @@ int main(int argc, char** argv)
session.messageSubscribe(arg::queue="MyQueue", arg::destination="MyId");
session.messageFlow(arg::destination="MyId", arg::unit=0, arg::value=1); //credit for one message
session.messageFlow(arg::destination="MyId", arg::unit=1, arg::value=0xFFFFFFFF); //credit for infinite bytes
- if (opts.trace) std::cout << "Subscribed to queue." << std::endl;
+ if (opts.verbose) std::cout << "Subscribed to queue." << std::endl;
FrameSet::shared_ptr incoming = session.get();
if (incoming->isA<MessageTransferBody>()) {
Message msgIn(*incoming);
if (msgIn.getData() == msgOut.getData()) {
- if (opts.trace) std::cout << "Received the exepected message." << std::endl;
+ if (opts.verbose) std::cout << "Received the exepected message." << std::endl;
session.messageAccept(SequenceSet(msgIn.getId()));
session.markCompleted(msgIn.getId(), true, true);
} else {
@@ -138,9 +139,9 @@ int main(int argc, char** argv)
//close the session & connection
session.close();
- if (opts.trace) std::cout << "Closed session." << std::endl;
+ if (opts.verbose) std::cout << "Closed session." << std::endl;
connection.close();
- if (opts.trace) std::cout << "Closed connection." << std::endl;
+ if (opts.verbose) std::cout << "Closed connection." << std::endl;
return 0;
} catch(const std::exception& e) {
std::cout << e.what() << std::endl;
diff --git a/cpp/src/tests/interop_runner.cpp b/cpp/src/tests/interop_runner.cpp
index 51dd2cb924..9435b8169f 100644
--- a/cpp/src/tests/interop_runner.cpp
+++ b/cpp/src/tests/interop_runner.cpp
@@ -24,6 +24,7 @@
#include "qpid/Exception.h"
#include "qpid/client/Channel.h"
#include "qpid/client/Connection.h"
+#include "qpid/client/ConnectionSettings.h"
#include "qpid/client/Exchange.h"
#include "qpid/client/MessageListener.h"
#include "qpid/client/Queue.h"
@@ -45,7 +46,6 @@
using namespace qpid::client;
using namespace qpid::sys;
using qpid::TestCase;
-using qpid::TestOptions;
using qpid::framing::FieldTable;
using qpid::framing::ReplyTo;
using namespace std;
@@ -54,7 +54,7 @@ class DummyRun : public TestCase
{
public:
DummyRun() {}
- void assign(const string&, FieldTable&, TestOptions&) {}
+ void assign(const string&, FieldTable&, ConnectionSettings&) {}
void start() {}
void stop() {}
void report(qpid::client::Message&) {}
@@ -68,7 +68,7 @@ class Listener : public MessageListener, private Runnable{
typedef boost::ptr_map<string, TestCase> TestMap;
Channel& channel;
- TestOptions& options;
+ ConnectionSettings& options;
TestMap tests;
const string name;
const string topic;
@@ -86,41 +86,52 @@ class Listener : public MessageListener, private Runnable{
void sendSimpleResponse(const string& type, Message& request);
void sendReport();
public:
- Listener(Channel& channel, TestOptions& options);
+ Listener(Channel& channel, ConnectionSettings& options);
void received(Message& msg);
void bindAndConsume();
void registerTest(string name, TestCase* test);
};
+struct TestSettings : ConnectionSettings
+{
+ bool help;
+
+ TestSettings() : help(false)
+ {
+ addOptions()
+ ("help", qpid::optValue(help), "print this usage statement");
+ }
+};
+
int main(int argc, char** argv) {
try {
- TestOptions options;
+ TestSettings options;
options.parse(argc, argv);
- if (options.help)
+ if (options.help) {
cout << options;
- else {
- Connection connection(options.trace);
+ } else {
+ Connection connection;
connection.open(options.host, options.port, "guest", "guest", options.virtualhost);
- Channel channel;
- connection.openChannel(channel);
+ Channel channel;
+ connection.openChannel(channel);
- Listener listener(channel, options);
- listener.registerTest("TC1_DummyRun", new DummyRun());
- listener.registerTest("TC2_BasicP2P", new qpid::BasicP2PTest());
- listener.registerTest("TC3_BasicPubSub", new qpid::BasicPubSubTest());
-
- listener.bindAndConsume();
+ Listener listener(channel, options);
+ listener.registerTest("TC1_DummyRun", new DummyRun());
+ listener.registerTest("TC2_BasicP2P", new qpid::BasicP2PTest());
+ listener.registerTest("TC3_BasicPubSub", new qpid::BasicPubSubTest());
+
+ listener.bindAndConsume();
- channel.run();
- connection.close();
+ channel.run();
+ connection.close();
}
} catch(const exception& error) {
cout << error.what() << endl << "Type " << argv[0] << " --help for help" << endl;
}
}
-Listener::Listener(Channel& _channel, TestOptions& _options) : channel(_channel), options(_options), name(options.clientid), topic("iop.control." + name)
+Listener::Listener(Channel& _channel, ConnectionSettings& _options) : channel(_channel), options(_options), name(options.clientid), topic("iop.control." + name)
{}
void Listener::registerTest(string name, TestCase* test)
diff --git a/cpp/src/tests/latencytest.cpp b/cpp/src/tests/latencytest.cpp
index a61a4b2e42..0b343d0243 100644
--- a/cpp/src/tests/latencytest.cpp
+++ b/cpp/src/tests/latencytest.cpp
@@ -66,7 +66,8 @@ struct Args : public qpid::TestOptions {
("prefetch", optValue(prefetch, "N"), "prefetch count (0 implies no flow control, and no acking)")
("ack", optValue(ack, "N"), "Ack frequency in messages (defaults to half the prefetch value)")
("durable", optValue(durable, "yes|no"), "use durable messages")
- ("queue-base-name", optValue(base, "<name>"), "base name for queues");
+ ("queue-base-name", optValue(base, "<name>"), "base name for queues")
+ ("tcp-nodelay", optValue(con.tcpNoDelay), "Turn on tcp-nodelay");
}
};
diff --git a/cpp/src/tests/topic_listener.cpp b/cpp/src/tests/topic_listener.cpp
index f1007ee4c2..ba6cd5f267 100644
--- a/cpp/src/tests/topic_listener.cpp
+++ b/cpp/src/tests/topic_listener.cpp
@@ -99,7 +99,7 @@ int main(int argc, char** argv){
if(args.help)
cout << args << endl;
else {
- Connection connection(args.trace);
+ Connection connection;
args.open(connection);
Session session = connection.newSession(ASYNC);
if (args.transactional) {
diff --git a/cpp/src/tests/topic_publisher.cpp b/cpp/src/tests/topic_publisher.cpp
index 8242530db1..a4d0dd9382 100644
--- a/cpp/src/tests/topic_publisher.cpp
+++ b/cpp/src/tests/topic_publisher.cpp
@@ -105,7 +105,7 @@ int main(int argc, char** argv) {
if(args.help)
cout << args << endl;
else {
- Connection connection(args.trace);
+ Connection connection;
args.open(connection);
Session session = connection.newSession(ASYNC);
if (args.transactional) {