summaryrefslogtreecommitdiff
path: root/cpp/tests
diff options
context:
space:
mode:
authorGordon Sim <gsim@apache.org>2007-05-15 07:38:48 +0000
committerGordon Sim <gsim@apache.org>2007-05-15 07:38:48 +0000
commitb20c9a463aa86f91e5c3f5d86c75c988591f8d74 (patch)
tree3bfa8e4badada05d663033c2289ad3df89d0654c /cpp/tests
parentad0c6952f75c86ad587602cfb14dab46efedd4f6 (diff)
downloadqpid-python-b20c9a463aa86f91e5c3f5d86c75c988591f8d74.tar.gz
Separated out implementation from interop test headers.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/branches/M2@538079 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/tests')
-rw-r--r--cpp/tests/BasicP2PTest.cpp66
-rw-r--r--cpp/tests/BasicP2PTest.h44
-rw-r--r--cpp/tests/BasicPubSubTest.cpp121
-rw-r--r--cpp/tests/BasicPubSubTest.h99
-rw-r--r--cpp/tests/Makefile.am11
-rw-r--r--cpp/tests/SimpleTestCaseBase.cpp87
-rw-r--r--cpp/tests/SimpleTestCaseBase.h71
7 files changed, 299 insertions, 200 deletions
diff --git a/cpp/tests/BasicP2PTest.cpp b/cpp/tests/BasicP2PTest.cpp
new file mode 100644
index 0000000000..b202f88ca6
--- /dev/null
+++ b/cpp/tests/BasicP2PTest.cpp
@@ -0,0 +1,66 @@
+/*
+ *
+ * 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 "BasicP2PTest.h"
+
+using namespace qpid;
+using namespace qpid::client;
+
+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)
+ : Worker(options, _messages), queue(_queue){}
+ void init()
+ {
+ Queue q(queue, true);
+ channel.declareQueue(q);
+ framing::FieldTable args;
+ channel.bind(Exchange::STANDARD_DIRECT_EXCHANGE, q, queue, args);
+ channel.consume(q, tag, this);
+ channel.start();
+ }
+
+ void start()
+ {
+ }
+
+ void received(Message&)
+ {
+ count++;
+ }
+};
+
+void BasicP2PTest::assign(const std::string& role, framing::FieldTable& params, TestOptions& options)
+{
+ std::string queue = params.getString("P2P_QUEUE_AND_KEY_NAME");
+ int messages = params.getInt("P2P_NUM_MESSAGES");
+ if (role == "SENDER") {
+ worker = std::auto_ptr<Worker>(new Sender(options, Exchange::STANDARD_DIRECT_EXCHANGE, queue, messages));
+ } else if(role == "RECEIVER"){
+ worker = std::auto_ptr<Worker>(new Receiver(options, queue, messages));
+ } else {
+ throw Exception("unrecognised role");
+ }
+ worker->init();
+}
diff --git a/cpp/tests/BasicP2PTest.h b/cpp/tests/BasicP2PTest.h
index 8b5d0e7a8c..3936f556a9 100644
--- a/cpp/tests/BasicP2PTest.h
+++ b/cpp/tests/BasicP2PTest.h
@@ -34,51 +34,11 @@
namespace qpid {
-using namespace qpid::client;
-
class BasicP2PTest : public SimpleTestCaseBase
{
-
- class Receiver : public Worker, public MessageListener
- {
- const std::string queue;
- std::string tag;
- public:
- Receiver(TestOptions& options, const std::string& _queue, const int _messages) : Worker(options, _messages), queue(_queue){}
-
- void init()
- {
- Queue q(queue, true);
- channel.declareQueue(q);
- framing::FieldTable args;
- channel.bind(Exchange::STANDARD_DIRECT_EXCHANGE, q, queue, args);
- channel.consume(q, tag, this);
- channel.start();
- }
-
- void start(){
- }
-
- void received(Message&)
- {
- count++;
- }
- };
-
+ class Receiver;
public:
- void assign(const std::string& role, framing::FieldTable& params, TestOptions& options)
- {
- std::string queue = params.getString("P2P_QUEUE_AND_KEY_NAME");
- int messages = params.getInt("P2P_NUM_MESSAGES");
- if (role == "SENDER") {
- worker = std::auto_ptr<Worker>(new Sender(options, Exchange::STANDARD_DIRECT_EXCHANGE, queue, messages));
- } else if(role == "RECEIVER"){
- worker = std::auto_ptr<Worker>(new Receiver(options, queue, messages));
- } else {
- throw Exception("unrecognised role");
- }
- worker->init();
- }
+ void assign(const std::string& role, framing::FieldTable& params, TestOptions& options);
};
}
diff --git a/cpp/tests/BasicPubSubTest.cpp b/cpp/tests/BasicPubSubTest.cpp
new file mode 100644
index 0000000000..623194d331
--- /dev/null
+++ b/cpp/tests/BasicPubSubTest.cpp
@@ -0,0 +1,121 @@
+/*
+ *
+ * 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 "BasicPubSubTest.h"
+
+using namespace qpid;
+
+class BasicPubSubTest::Receiver : public Worker, public MessageListener
+{
+ const Exchange& exchange;
+ const std::string queue;
+ 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)
+ : Worker(options, _messages), exchange(_exchange), queue(_queue), key(_key){}
+
+ void init()
+ {
+ Queue q(queue, true);
+ channel.declareQueue(q);
+ framing::FieldTable args;
+ channel.bind(exchange, q, key, args);
+ channel.consume(q, tag, this);
+ channel.start();
+ }
+
+ void start(){
+ }
+
+ void received(Message&)
+ {
+ count++;
+ }
+};
+
+class BasicPubSubTest::MultiReceiver : public Worker, public MessageListener
+{
+ typedef boost::ptr_vector<Receiver> ReceiverList;
+ ReceiverList receivers;
+
+public:
+ MultiReceiver(TestOptions& options, const Exchange& exchange, const std::string& key, const int _messages, int receiverCount)
+ : Worker(options, _messages)
+ {
+ for (int i = 0; i != receiverCount; i++) {
+ std::string queue = (boost::format("%1%_%2%") % options.clientid % i).str();
+ receivers.push_back(new Receiver(options, exchange, queue, key, _messages));
+ }
+ }
+
+ void init()
+ {
+ for (ReceiverList::size_type i = 0; i != receivers.size(); i++) {
+ receivers[i].init();
+ }
+ }
+
+ void start()
+ {
+ for (ReceiverList::size_type i = 0; i != receivers.size(); i++) {
+ receivers[i].start();
+ }
+ }
+
+ void received(Message& msg)
+ {
+ for (ReceiverList::size_type i = 0; i != receivers.size(); i++) {
+ receivers[i].received(msg);
+ }
+ }
+
+ virtual int getCount()
+ {
+ count = 0;
+ for (ReceiverList::size_type i = 0; i != receivers.size(); i++) {
+ count += receivers[i].getCount();
+ }
+ return count;
+ }
+ virtual void stop()
+ {
+ for (ReceiverList::size_type i = 0; i != receivers.size(); i++) {
+ receivers[i].stop();
+ }
+ }
+};
+
+void BasicPubSubTest::assign(const std::string& role, framing::FieldTable& params, TestOptions& options)
+{
+ std::string key = params.getString("PUBSUB_KEY");
+ int messages = params.getInt("PUBSUB_NUM_MESSAGES");
+ int receivers = params.getInt("PUBSUB_NUM_RECEIVERS");
+ if (role == "SENDER") {
+ worker = std::auto_ptr<Worker>(new Sender(options, Exchange::STANDARD_TOPIC_EXCHANGE, key, messages));
+ } else if(role == "RECEIVER"){
+ worker = std::auto_ptr<Worker>(new MultiReceiver(options, Exchange::STANDARD_TOPIC_EXCHANGE, key, messages, receivers));
+ } else {
+ throw Exception("unrecognised role");
+ }
+ worker->init();
+}
+
diff --git a/cpp/tests/BasicPubSubTest.h b/cpp/tests/BasicPubSubTest.h
index c86d85e81a..e757bd8020 100644
--- a/cpp/tests/BasicPubSubTest.h
+++ b/cpp/tests/BasicPubSubTest.h
@@ -40,103 +40,10 @@ using namespace qpid::client;
class BasicPubSubTest : public SimpleTestCaseBase
{
-
- class Receiver : public Worker, public MessageListener
- {
- const Exchange& exchange;
- const std::string queue;
- 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)
- : Worker(options, _messages), exchange(_exchange), queue(_queue), key(_key){}
-
- void init()
- {
- Queue q(queue, true);
- channel.declareQueue(q);
- framing::FieldTable args;
- channel.bind(exchange, q, key, args);
- channel.consume(q, tag, this);
- channel.start();
- }
-
- void start(){
- }
-
- void received(Message&)
- {
- count++;
- }
- };
-
- class MultiReceiver : public Worker, public MessageListener
- {
- typedef boost::ptr_vector<Receiver> ReceiverList;
- ReceiverList receivers;
-
- public:
- MultiReceiver(TestOptions& options, const Exchange& exchange, const std::string& key, const int _messages, int receiverCount)
- : Worker(options, _messages)
- {
- for (int i = 0; i != receiverCount; i++) {
- std::string queue = (boost::format("%1%_%2%") % options.clientid % i).str();
- receivers.push_back(new Receiver(options, exchange, queue, key, _messages));
- }
- }
-
- void init()
- {
- for (ReceiverList::size_type i = 0; i != receivers.size(); i++) {
- receivers[i].init();
- }
- }
-
- void start()
- {
- for (ReceiverList::size_type i = 0; i != receivers.size(); i++) {
- receivers[i].start();
- }
- }
-
- void received(Message& msg)
- {
- for (ReceiverList::size_type i = 0; i != receivers.size(); i++) {
- receivers[i].received(msg);
- }
- }
-
- virtual int getCount()
- {
- count = 0;
- for (ReceiverList::size_type i = 0; i != receivers.size(); i++) {
- count += receivers[i].getCount();
- }
- return count;
- }
- virtual void stop()
- {
- for (ReceiverList::size_type i = 0; i != receivers.size(); i++) {
- receivers[i].stop();
- }
- }
- };
-
+ class Receiver;
+ class MultiReceiver;
public:
- void assign(const std::string& role, framing::FieldTable& params, TestOptions& options)
- {
- std::string key = params.getString("PUBSUB_KEY");
- int messages = params.getInt("PUBSUB_NUM_MESSAGES");
- int receivers = params.getInt("PUBSUB_NUM_RECEIVERS");
- if (role == "SENDER") {
- worker = std::auto_ptr<Worker>(new Sender(options, Exchange::STANDARD_TOPIC_EXCHANGE, key, messages));
- } else if(role == "RECEIVER"){
- worker = std::auto_ptr<Worker>(new MultiReceiver(options, Exchange::STANDARD_TOPIC_EXCHANGE, key, messages, receivers));
- } else {
- throw Exception("unrecognised role");
- }
- worker->init();
- }
+ void assign(const std::string& role, framing::FieldTable& params, TestOptions& options);
};
}
diff --git a/cpp/tests/Makefile.am b/cpp/tests/Makefile.am
index 6e5208aca7..68935d057d 100644
--- a/cpp/tests/Makefile.am
+++ b/cpp/tests/Makefile.am
@@ -23,8 +23,7 @@ client_tests = \
client_test \
echo_service \
topic_listener \
- topic_publisher \
- interop_runner
+ topic_publisher
broker_tests = \
AccumulatedAckTest \
@@ -105,3 +104,11 @@ gen.mk: Makefile.am
) \
> $@-t
mv $@-t $@
+
+bin_PROGRAMS = interop_runner
+interop_runner_SOURCES = \
+ interop_runner.cpp \
+ SimpleTestCaseBase.cpp \
+ BasicP2PTest.cpp \
+ BasicPubSubTest.cpp
+interop_runner_LDADD = $(lib_client) $(lib_common) $(extra_libs)
diff --git a/cpp/tests/SimpleTestCaseBase.cpp b/cpp/tests/SimpleTestCaseBase.cpp
new file mode 100644
index 0000000000..691f2b0652
--- /dev/null
+++ b/cpp/tests/SimpleTestCaseBase.cpp
@@ -0,0 +1,87 @@
+/*
+ *
+ * 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 "SimpleTestCaseBase.h"
+
+using namespace qpid;
+
+void SimpleTestCaseBase::start()
+{
+ if (worker.get()) {
+ worker->start();
+ }
+}
+
+void SimpleTestCaseBase::stop()
+{
+ if (worker.get()) {
+ worker->stop();
+ }
+}
+
+void SimpleTestCaseBase::report(client::Message& report)
+{
+ if (worker.get()) {
+ report.getHeaders().setInt("MESSAGE_COUNT", worker->getCount());
+ //add number of messages sent or received
+ std::stringstream reportstr;
+ reportstr << worker->getCount();
+ report.setData(reportstr.str());
+ }
+}
+
+SimpleTestCaseBase::Sender::Sender(TestOptions& options,
+ const Exchange& _exchange,
+ const std::string& _key,
+ const int _messages)
+ : Worker(options, _messages), exchange(_exchange), key(_key) {}
+
+void SimpleTestCaseBase::Sender::init()
+{
+ channel.start();
+}
+
+void SimpleTestCaseBase::Sender::start(){
+ Message msg;
+ while (count < messages) {
+ channel.publish(msg, exchange, key);
+ count++;
+ }
+ stop();
+}
+
+SimpleTestCaseBase::Worker::Worker(TestOptions& options, const int _messages) :
+ connection(options.trace), messages(_messages), count(0)
+{
+ connection.open(options.broker, options.port);
+ connection.openChannel(&channel);
+}
+
+void SimpleTestCaseBase::Worker::stop()
+{
+ channel.close();
+ connection.close();
+}
+
+int SimpleTestCaseBase::Worker::getCount()
+{
+ return count;
+}
+
diff --git a/cpp/tests/SimpleTestCaseBase.h b/cpp/tests/SimpleTestCaseBase.h
index 7a2421af3b..818ab3b315 100644
--- a/cpp/tests/SimpleTestCaseBase.h
+++ b/cpp/tests/SimpleTestCaseBase.h
@@ -49,26 +49,11 @@ protected:
public:
- Worker(TestOptions& options, const int _messages) :
- connection(options.trace), messages(_messages), count(0)
- {
- connection.open(options.broker, options.port);
- connection.openChannel(&channel);
- }
-
+ Worker(TestOptions& options, const int messages);
virtual ~Worker(){}
- virtual void stop()
- {
- channel.close();
- connection.close();
- }
-
- virtual int getCount()
- {
- return count;
- }
-
+ virtual void stop();
+ virtual int getCount();
virtual void init() = 0;
virtual void start() = 0;
};
@@ -79,24 +64,11 @@ protected:
const std::string key;
public:
Sender(TestOptions& options,
- const Exchange& _exchange,
- const std::string& _key,
- const int _messages)
- : Worker(options, _messages), exchange(_exchange), key(_key) {}
-
- void init()
- {
- channel.start();
- }
-
- void start(){
- Message msg;
- while (count < messages) {
- channel.publish(msg, exchange, key);
- count++;
- }
- stop();
- }
+ const Exchange& exchange,
+ const std::string& key,
+ const int messages);
+ void init();
+ void start();
};
std::auto_ptr<Worker> worker;
@@ -106,30 +78,9 @@ public:
virtual ~SimpleTestCaseBase() {}
- void start()
- {
- if (worker.get()) {
- worker->start();
- }
- }
-
- void stop()
- {
- if (worker.get()) {
- worker->stop();
- }
- }
-
- void report(client::Message& report)
- {
- if (worker.get()) {
- report.getHeaders().setInt("MESSAGE_COUNT", worker->getCount());
- //add number of messages sent or received
- std::stringstream reportstr;
- reportstr << worker->getCount();
- report.setData(reportstr.str());
- }
- }
+ void start();
+ void stop();
+ void report(client::Message& report);
};
}