diff options
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/lib/broker/SessionHandlerImpl.cpp | 2 | ||||
-rw-r--r-- | cpp/lib/client/ClientChannel.cpp | 6 | ||||
-rw-r--r-- | cpp/lib/common/Makefile.am | 1 | ||||
-rw-r--r-- | cpp/lib/common/sys/apr/APRSocket.cpp | 1 | ||||
-rw-r--r-- | cpp/lib/common/sys/apr/LFSessionContext.cpp | 2 | ||||
-rw-r--r-- | cpp/tests/Makefile.am | 8 | ||||
-rw-r--r-- | cpp/tests/P2PMessageSizeTest.cpp | 114 | ||||
-rw-r--r-- | cpp/tests/P2PMessageSizeTest.h | 58 | ||||
-rw-r--r-- | cpp/tests/PubSubMessageSizeTest.cpp | 125 | ||||
-rw-r--r-- | cpp/tests/PubSubMessageSizeTest.h | 51 | ||||
-rw-r--r-- | cpp/tests/SimpleTestCaseBase.cpp | 68 | ||||
-rw-r--r-- | cpp/tests/SimpleTestCaseBase.h | 117 | ||||
-rw-r--r-- | cpp/tests/TestCase.h | 21 | ||||
-rw-r--r-- | cpp/tests/TestUtils.cpp | 53 | ||||
-rw-r--r-- | cpp/tests/TestUtils.h | 32 | ||||
-rw-r--r-- | cpp/tests/interop_runner.cpp | 9 |
16 files changed, 636 insertions, 32 deletions
diff --git a/cpp/lib/broker/SessionHandlerImpl.cpp b/cpp/lib/broker/SessionHandlerImpl.cpp index 0bea721175..b23432e29d 100644 --- a/cpp/lib/broker/SessionHandlerImpl.cpp +++ b/cpp/lib/broker/SessionHandlerImpl.cpp @@ -138,8 +138,6 @@ void SessionHandlerImpl::initiated(qpid::framing::ProtocolInitiation* header){ client = new qpid::framing::AMQP_ClientProxy(context, header->getMajor(), header->getMinor()); - std::cout << "---------------" << this << std::endl; - //send connection start FieldTable properties; string mechanisms("PLAIN"); diff --git a/cpp/lib/client/ClientChannel.cpp b/cpp/lib/client/ClientChannel.cpp index 4ec0d87eeb..a97d79dcf9 100644 --- a/cpp/lib/client/ClientChannel.cpp +++ b/cpp/lib/client/ClientChannel.cpp @@ -258,9 +258,7 @@ void Channel::rollback(){ void Channel::handleMethod(AMQMethodBody::shared_ptr body){ //channel.flow, channel.close, basic.deliver, basic.return or a response to a synchronous request - if(responses.isWaiting()){ - responses.signalResponse(body); - }else if(method_bodies.basic_deliver.match(body.get())){ + if(method_bodies.basic_deliver.match(body.get())){ if(incoming != 0){ std::cout << "Existing message not complete [deliveryTag=" << incoming->getDeliveryTag() << "]" << std::endl; THROW_QPID_ERROR(PROTOCOL_ERROR + 504, "Existing message not complete"); @@ -280,6 +278,8 @@ void Channel::handleMethod(AMQMethodBody::shared_ptr body){ }else if(method_bodies.channel_flow.match(body.get())){ + } else if(responses.isWaiting()){ + responses.signalResponse(body); }else{ //signal error std::cout << "Unhandled method: " << *body << std::endl; diff --git a/cpp/lib/common/Makefile.am b/cpp/lib/common/Makefile.am index 3700b640a0..b2e2de2cf1 100644 --- a/cpp/lib/common/Makefile.am +++ b/cpp/lib/common/Makefile.am @@ -125,6 +125,7 @@ nobase_pkginclude_HEADERS = \ $(framing)/Value.h \ $(framing)/amqp_framing.h \ $(framing)/amqp_types.h \ + $(posix_hdr) \ Exception.h \ ExceptionHolder.h \ QpidError.h \ diff --git a/cpp/lib/common/sys/apr/APRSocket.cpp b/cpp/lib/common/sys/apr/APRSocket.cpp index 4917803370..f68d51d8e4 100644 --- a/cpp/lib/common/sys/apr/APRSocket.cpp +++ b/cpp/lib/common/sys/apr/APRSocket.cpp @@ -53,7 +53,6 @@ void APRSocket::write(qpid::framing::Buffer& buffer){ void APRSocket::close(){ if(!closed){ - std::cout << "Closing socket " << socket << "@" << this << std::endl; CHECK_APR_SUCCESS(apr_socket_close(socket)); closed = true; } diff --git a/cpp/lib/common/sys/apr/LFSessionContext.cpp b/cpp/lib/common/sys/apr/LFSessionContext.cpp index a06b7537ee..8a7ce18136 100644 --- a/cpp/lib/common/sys/apr/LFSessionContext.cpp +++ b/cpp/lib/common/sys/apr/LFSessionContext.cpp @@ -158,7 +158,7 @@ void LFSessionContext::close(){ void LFSessionContext::handleClose(){ handler->closed(); APRPool::free(fd.p); - std::cout << "Session closed [" << &socket << "]" << std::endl; + if (debug) std::cout << "Session closed [" << &socket << "]" << std::endl; delete handler; delete this; } diff --git a/cpp/tests/Makefile.am b/cpp/tests/Makefile.am index 09ccda8686..256e68058d 100644 --- a/cpp/tests/Makefile.am +++ b/cpp/tests/Makefile.am @@ -126,12 +126,18 @@ gen.mk: Makefile.am check_PROGRAMS = interop_runner interop_runner_SOURCES = \ interop_runner.cpp \ + TestUtils.cpp \ SimpleTestCaseBase.cpp \ BasicP2PTest.cpp \ BasicPubSubTest.cpp \ + P2PMessageSizeTest.cpp \ + PubSubMessageSizeTest.cpp \ + TestUtils.h \ SimpleTestCaseBase.h \ BasicP2PTest.h \ BasicPubSubTest.h \ + P2PMessageSizeTest.h \ + PubSubMessageSizeTest.h \ TestCase.h \ - TestOptions.h + TestOptions.h interop_runner_LDADD = $(lib_client) $(lib_common) $(extra_libs) diff --git a/cpp/tests/P2PMessageSizeTest.cpp b/cpp/tests/P2PMessageSizeTest.cpp new file mode 100644 index 0000000000..20ddb6e2aa --- /dev/null +++ b/cpp/tests/P2PMessageSizeTest.cpp @@ -0,0 +1,114 @@ +/* + * + * 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 "P2PMessageSizeTest.h" + +using namespace qpid; +using namespace qpid::client; + +/** + * P2PMessageSizeTest::Receiver is a Worker to play the receiving role in P2P test. + * + * TODO: This code is identical to the receiver in BasicP2PTest so should share implementation with that. + */ +class P2PMessageSizeTest::Receiver : public Worker, public MessageListener +{ + /** Holds the name of the queue to send the test message on. */ + const std::string queue; + + /** Used for ? */ + std::string tag; + +public: + + /** + * Creates a new Worker from given the TestOptions. The namd of the queue, to consume from is also specified. + * + * @param options The test options to configure the worker with. + * @param _queue The name of the queue to consume from on the default direct exchange. + * @param _mesages The expected number of messages to consume. Ignored. + */ + Receiver(TestOptions& options, const std::string& _queue, const int _messages) + : Worker(options, _messages), queue(_queue) + {} + + /** + * Binds this receivers queue to the standard exchange, and starts the dispatcher thread on its channel. + */ + 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(); + } + + /** + * Does nothing. + */ + void start() + { + } + + /** + * Increments the message count, on every message received. + * + * @param message The test message. Ignored. + */ + void received(Message& ) + { + count++; + } +}; + +/** + * Assigns the role to be played by this test case. The test parameters are fully specified in the + * assignment messages filed table. If the role is "SENDER" a Sender worker is created to delegate + * the test functionality to, if the role is "RECEIVER" a Receiver is used. + * + * @param role The role to be played; sender or receiver. + * @param assignRoleMessage The role assingment messages field table, contains the full test parameters. + * @param options Additional test options. + */ +void P2PMessageSizeTest::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"); + int messageSize = params.getInt("messageSize"); + + if (role == "SENDER") + { + worker = std::auto_ptr<Worker>(new Sender(options, Exchange::STANDARD_DIRECT_EXCHANGE, queue, messages, messageSize)); + } + 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/P2PMessageSizeTest.h b/cpp/tests/P2PMessageSizeTest.h new file mode 100644 index 0000000000..c434e74f4d --- /dev/null +++ b/cpp/tests/P2PMessageSizeTest.h @@ -0,0 +1,58 @@ +#ifndef _P2PMessageSizeTest_ +#define _P2PMessageSizeTest_ +/* + * + * 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 <memory> +#include <sstream> + +#include <ClientChannel.h> +#include <ClientMessage.h> +#include <Connection.h> +#include <Exception.h> +#include <MessageListener.h> +#include "SimpleTestCaseBase.h" + +namespace qpid { + +/** + * P2PMessageSizeTest implements test case 4, P2P messages with message size. Sends/received a specified number of messages to a + * specified route on the default exchange, of a specified size. Produces reports on the actual number of messages sent/received. + */ +class P2PMessageSizeTest : public SimpleTestCaseBase +{ + class Receiver; + +public: + + /** + * Assigns the role to be played by this test case. The test parameters are fully specified in the + * assignment messages filed table. + * + * @param role The role to be played; sender or receiver. + * @param assignRoleMessage The role assingment messages field table, contains the full test parameters. + * @param options Additional test options. + */ + void assign(const std::string& role, framing::FieldTable& params, TestOptions& options); +}; +} + +#endif diff --git a/cpp/tests/PubSubMessageSizeTest.cpp b/cpp/tests/PubSubMessageSizeTest.cpp new file mode 100644 index 0000000000..e75334d989 --- /dev/null +++ b/cpp/tests/PubSubMessageSizeTest.cpp @@ -0,0 +1,125 @@ +/* + * + * 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 "PubSubMessageSizeTest.h" + +using namespace qpid; + +class PubSubMessageSizeTest::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 PubSubMessageSizeTest::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 PubSubMessageSizeTest::assign(const std::string& role, framing::FieldTable& params, TestOptions& options) +{ + //std::cout << "void PubSubMessageSizeTest::assign(const std::string& role, framing::FieldTable& params, TestOptions& options): called"; + + std::string key = params.getString("PUBSUB_KEY"); + int messages = params.getInt("PUBSUB_NUM_MESSAGES"); + int receivers = params.getInt("PUBSUB_NUM_RECEIVERS"); + int messageSize = params.getInt("messageSize"); + + if (role == "SENDER") { + worker = std::auto_ptr<Worker>(new Sender(options, Exchange::STANDARD_TOPIC_EXCHANGE, key, messages, messageSize)); + } 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/PubSubMessageSizeTest.h b/cpp/tests/PubSubMessageSizeTest.h new file mode 100644 index 0000000000..c17f81fc1e --- /dev/null +++ b/cpp/tests/PubSubMessageSizeTest.h @@ -0,0 +1,51 @@ +#ifndef _PubSubMessageSizeTest_ +#define _PubSubMessageSizeTest_ +/* + * + * 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 <memory> +#include <sstream> + +#include <ClientChannel.h> +#include <ClientMessage.h> +#include <Connection.h> +#include <Exception.h> +#include <MessageListener.h> +#include "SimpleTestCaseBase.h" +#include <boost/ptr_container/ptr_vector.hpp> +#include <boost/format.hpp> + + +namespace qpid { + +using namespace qpid::client; + +class PubSubMessageSizeTest : public SimpleTestCaseBase +{ + class Receiver; + class MultiReceiver; +public: + void assign(const std::string& role, framing::FieldTable& params, TestOptions& options); +}; + +} + +#endif diff --git a/cpp/tests/SimpleTestCaseBase.cpp b/cpp/tests/SimpleTestCaseBase.cpp index 691f2b0652..3603df3af3 100644 --- a/cpp/tests/SimpleTestCaseBase.cpp +++ b/cpp/tests/SimpleTestCaseBase.cpp @@ -21,49 +21,98 @@ #include "SimpleTestCaseBase.h" using namespace qpid; +using namespace qpid::client; +/** + * Starts the test cases worker. + */ void SimpleTestCaseBase::start() { - if (worker.get()) { + if (worker.get()) + { worker->start(); } } +/** + * Stops the test cases worker. + */ void SimpleTestCaseBase::stop() { - if (worker.get()) { + if (worker.get()) + { worker->stop(); } } +/** + * Adds the test report to the specified message. This consists of writing the count of messages received into + * a header on the message. + * + * @param report The report message to add the test report to. + */ void SimpleTestCaseBase::report(client::Message& report) { - if (worker.get()) { + if (worker.get()) + { report.getHeaders().setInt("MESSAGE_COUNT", worker->getCount()); - //add number of messages sent or received + + // Add number of messages sent or received in the message body. + /* std::stringstream reportstr; reportstr << worker->getCount(); report.setData(reportstr.str()); + */ } } +/** + * Creates a sender using the specified options, for the given expected message count, exchange and routing key. + * This sets up the sender with the default message size for interop tests. + * + * @param options The creation options. + * @param exchange The exchange to send the messages over. + * @param key The routing key for the messages. + * @param messages The number of messages expected to be sent or received. + */ SimpleTestCaseBase::Sender::Sender(TestOptions& options, const Exchange& _exchange, const std::string& _key, const int _messages) - : Worker(options, _messages), exchange(_exchange), key(_key) {} + : Worker(options, _messages), exchange(_exchange), key(_key), messageSize(DEFAULT_INTEROP_MESSAGE_SIZE) {} + +/** + * Creates a sender using the specified options, for the given expected message count, exchange and routing key. + * + * @param options The creation options. + * @param exchange The exchange to send the messages over. + * @param key The routing key for the messages. + * @param messages The number of messages expected to be sent or received. + * @param messageSize The size of test messages to send. + */ +SimpleTestCaseBase::Sender::Sender(TestOptions& options, + const Exchange& _exchange, + const std::string& _key, + const int _messages, + const int _messageSize) + : Worker(options, _messages), exchange(_exchange), key(_key), messageSize(_messageSize) {} void SimpleTestCaseBase::Sender::init() { channel.start(); } -void SimpleTestCaseBase::Sender::start(){ - Message msg; - while (count < messages) { - channel.publish(msg, exchange, key); +void SimpleTestCaseBase::Sender::start() +{ + Message message; + qpid::createTestMessageOfSize(message, messageSize); + + while (count < messages) + { + channel.publish(message, exchange, key); count++; } + stop(); } @@ -84,4 +133,3 @@ int SimpleTestCaseBase::Worker::getCount() { return count; } - diff --git a/cpp/tests/SimpleTestCaseBase.h b/cpp/tests/SimpleTestCaseBase.h index 818ab3b315..66f87ae42a 100644 --- a/cpp/tests/SimpleTestCaseBase.h +++ b/cpp/tests/SimpleTestCaseBase.h @@ -30,59 +30,158 @@ #include <Exception.h> #include <MessageListener.h> #include "TestCase.h" +#include "TestUtils.h" +#define DEFAULT_INTEROP_MESSAGE_SIZE 256 namespace qpid { using namespace qpid::client; +/** + * SimpleTestCaseBase defines a base implementation of TestCase class. It provides the ability, to wrap a 'Worker' that + * the work of running a test case is delegated too. There are two kinds of workers provided, a base worker, which is abstract + * and may be extended to provide the tests behaviour, and a 'Sender' worker, that provides the ability to send a number + * of messages. + * + * <p/>A worker encapsulates a connection, a channel, an expected number of messages to be sent or received, and a count of the + * number actually sent or received. + */ class SimpleTestCaseBase : public TestCase { protected: + + /** + * A worker encapsulates a connection, channel, an expected number of messages to be sent or received, and a count of the + * number actually sent or received. + * + * <p/>Worker is an abstract class, extend it to do something usefull on the init() and start() methods. + * + * <p/>A worker is created from a set of TestOptions, which captures a number of configuration parameters, such as the + * broker to connect to. + * + * TODO: Extend TestOptions to capture the full set of creation properties for distributed tests. + */ class Worker { protected: + /** Holds the connection for the worker to send/receive over. */ client::Connection connection; + + /** Holds the channel for the worker to send/receive over. */ client::Channel channel; + + /** Holds the expected number of messages for the worker to send or received. */ const int messages; + + /** Holds a count of the number of messages actually sent or received. */ int count; public: + /** + * Creates a worker using the specified options, for the given expected message count. + * + * @param options The creation options. + * @param messages The number of messages expected to be sent or received. + */ Worker(TestOptions& options, const int messages); virtual ~Worker(){} + + /** Should be called ahead of start() to configure the worker. */ + virtual void init() = 0; + + /** Starts the workers test activity. */ + virtual void start() = 0; + /** Terminates the workers test activity. */ virtual void stop(); + + /** Gets the count of messages actually sent or received by the worker. */ virtual int getCount(); - virtual void init() = 0; - virtual void start() = 0; }; + /** + * Sender is a worker that sends the expected number of messages to be sent, over the configured exchange, using a + * specified routing key. + */ class Sender : public Worker { + /** Holds the exchange to send message to. */ const Exchange& exchange; + + /** Holds the routing key for the messages. */ const std::string key; + + /** Holds the message size parameter for all test messages. */ + const int messageSize; + public: - Sender(TestOptions& options, - const Exchange& exchange, - const std::string& key, - const int messages); + + /** + * Creates a sender using the specified options, for the given expected message count, exchange and routing key. + * + * @param options The creation options. + * @param exchange The exchange to send the messages over. + * @param key The routing key for the messages. + * @param messages The number of messages expected to be sent or received. + */ + Sender(TestOptions& options, const Exchange& exchange, const std::string& key, const int messages); + + /** + * Creates a sender using the specified options, for the given expected message count, exchange and routing key. + * + * @param options The creation options. + * @param exchange The exchange to send the messages over. + * @param key The routing key for the messages. + * @param messages The number of messages expected to be sent or received. + * @param messageSize The size of test messages to send. + */ + Sender(TestOptions& options, const Exchange& exchange, const std::string& key, const int messages, const int messageSize); + + /** + * Starts the underlying channel. + */ void init(); + + /** + * Sends the specified number of messages over the connection, channel and exchange using the configured routing key. + */ void start(); }; + /** Holds a pointer to the encapsulated worker. */ std::auto_ptr<Worker> worker; public: - virtual void assign(const std::string& role, framing::FieldTable& params, TestOptions& options) = 0; - + virtual ~SimpleTestCaseBase() {} + /** + * Assigns the role to be played by this test case. The test parameters are fully specified in the + * assignment messages filed table. + * + * @param role The role to be played; sender or receiver. + * @param assignRoleMessage The role assingment messages field table, contains the full test parameters. + * @param options Additional test options. + */ + virtual void assign(const std::string& role, framing::FieldTable& params, TestOptions& options) = 0; + + /** + * Starts the worker. + */ void start(); + + /** + * Stops the worker. + */ void stop(); + + /** + * Reports the number of messages sent or received. + */ void report(client::Message& report); }; - } #endif diff --git a/cpp/tests/TestCase.h b/cpp/tests/TestCase.h index a88b76bc1d..ec151a6d84 100644 --- a/cpp/tests/TestCase.h +++ b/cpp/tests/TestCase.h @@ -28,28 +28,39 @@ namespace qpid { /** - * Interface to be implemented by test cases for use with the test - * runner. + * TestCase provides an interface that classes implementing tests to be run using a distributed test client + * must implement. The interop test spec, defines a life-cycle for interop tests. This consists of, inviting + * a test to participate in a test, assigning a role, starting the test, and extracting a report on the + * outcome of the test. + * + * TODO: There is not method to process the test invitation. Add one. */ class TestCase { public: + /** - * Directs the test case to act in a particular role. Some roles - * may be 'activated' at this stage others may require an explicit - * start request. + * Assigns the role to be played by this test case. The test parameters are fully specified in the + * assignment messages filed table. + * + * @param role The role to be played; sender or receiver. + * @param assignRoleMessage The role assingment messages field table, contains the full test parameters. + * @param options Additional test options. */ virtual void assign(const std::string& role, framing::FieldTable& params, TestOptions& 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 * explicit stop() request). */ virtual void start() = 0; + /** * Requests that the test be stopped if still running. */ virtual void stop() = 0; + /** * Allows the test to fill in details on the final report * message. Will be called only after start has returned. diff --git a/cpp/tests/TestUtils.cpp b/cpp/tests/TestUtils.cpp new file mode 100644 index 0000000000..0b517a4339 --- /dev/null +++ b/cpp/tests/TestUtils.cpp @@ -0,0 +1,53 @@ +/* + * + * 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 "TestUtils.h" +#include <string> + +using namespace qpid; + +/** + * Creates a test message of the specified size. The message is filled with dummy (non-zero) data. + * + * @param size The size of the message to create. + */ +void qpid::createTestMessageOfSize(qpid::client::Message& message, int size) +{ + std::string MESSAGE_DATA("-- Test Message -- Test Message -- Test Message -- Test Message -- Test Message -- Test Message -- Test Message "); + std::string data; + + if (size > 0) + { + int div = MESSAGE_DATA.length() / size; + int mod = MESSAGE_DATA.length() % size; + + for (int i = 0; i < div; i++) + { + data += MESSAGE_DATA; + } + + if (mod != 0) + { + data += MESSAGE_DATA.substr(0, mod); + } + } + + message.setData(data); +} diff --git a/cpp/tests/TestUtils.h b/cpp/tests/TestUtils.h new file mode 100644 index 0000000000..1178a4e06f --- /dev/null +++ b/cpp/tests/TestUtils.h @@ -0,0 +1,32 @@ +#ifndef _TestUtils_ +#define _TestUtils_ +/* + * + * 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 <ClientMessage.h> + +namespace qpid { + +void createTestMessageOfSize(qpid::client::Message& message, int size); + +} + +#endif diff --git a/cpp/tests/interop_runner.cpp b/cpp/tests/interop_runner.cpp index 3dd87a0735..7cb9f1ead5 100644 --- a/cpp/tests/interop_runner.cpp +++ b/cpp/tests/interop_runner.cpp @@ -33,6 +33,8 @@ #include <memory> #include "BasicP2PTest.h" #include "BasicPubSubTest.h" +#include "P2PMessageSizeTest.h" +#include "PubSubMessageSizeTest.h" #include "TestCase.h" #include <boost/ptr_container/ptr_map.hpp> @@ -92,6 +94,7 @@ public: }; /** + * TODO: Add clock synching. CLOCK_SYNCH command is currently ignored. */ int main(int argc, char** argv){ TestOptions options; @@ -111,6 +114,8 @@ int main(int argc, char** argv){ listener.registerTest("TC1_DummyRun", new DummyRun()); listener.registerTest("TC2_BasicP2P", new qpid::BasicP2PTest()); listener.registerTest("TC3_BasicPubSub", new qpid::BasicPubSubTest()); + listener.registerTest("TC4_P2PMessageSize", new qpid::P2PMessageSizeTest()); + listener.registerTest("TC5_PubSubMessageSize", new qpid::PubSubMessageSizeTest()); listener.bindAndConsume(); @@ -184,10 +189,12 @@ void Listener::received(Message& message) std::string name(message.getHeaders().getString("TEST_NAME")); if (name.empty() || invite(name)) { sendSimpleResponse("ENLIST", message); + //std::cout << "Enlisting in test '" << name << "'" << std::endl; } else { std::cout << "Can't take part in '" << name << "'" << std::endl; } } else if (type == "ASSIGN_ROLE") { + //std::cout << "Got role assignment request for '" << name << "'" << std::endl; test->assign(message.getHeaders().getString("ROLE"), message.getHeaders(), options); sendSimpleResponse("ACCEPT_ROLE", message); } else if (type == "START") { @@ -202,6 +209,8 @@ void Listener::received(Message& message) } else if (type == "TERMINATE") { if (test != tests.end()) test->stop(); shutdown(); + } else if (type == "CLOCK_SYNCH") { + // Just ignore for now. } else { std::cerr <<"ERROR!: Received unknown control message: " << type << std::endl; shutdown(); |