diff options
Diffstat (limited to 'cpp/src/tests')
-rw-r--r-- | cpp/src/tests/.valgrind.supp | 7 | ||||
-rw-r--r-- | cpp/src/tests/BrokerFixture.h | 7 | ||||
-rw-r--r-- | cpp/src/tests/ForkedBroker.h | 91 | ||||
-rw-r--r-- | cpp/src/tests/Makefile.am | 3 | ||||
-rw-r--r-- | cpp/src/tests/cluster_test.cpp | 91 | ||||
-rw-r--r-- | cpp/src/tests/logging.cpp | 4 |
6 files changed, 141 insertions, 62 deletions
diff --git a/cpp/src/tests/.valgrind.supp b/cpp/src/tests/.valgrind.supp index bffde9d815..dd8f7536a1 100644 --- a/cpp/src/tests/.valgrind.supp +++ b/cpp/src/tests/.valgrind.supp @@ -192,3 +192,10 @@ fun:_ZN4qpid7Options5parseEiPPcRKSsb } +{ + CPG related errors - seem benign but should invesgitate. + Memcheck:Param + socketcall.sendmsg(msg.msg_iov[i]) + fun:sendmsg + obj:/usr/lib/openais/libcpg.so.2.0.0 +} diff --git a/cpp/src/tests/BrokerFixture.h b/cpp/src/tests/BrokerFixture.h index b6837f6553..b28dfe9c0c 100644 --- a/cpp/src/tests/BrokerFixture.h +++ b/cpp/src/tests/BrokerFixture.h @@ -86,16 +86,13 @@ struct ProxyConnection : public qpid::client::Connection { /** Convenience class to create and open a connection and session * and some related useful objects. */ -template <class ConnectionType=ProxyConnection, class SessionType=qpid::client::Session> +template <class ConnectionType=LocalConnection, class SessionType=qpid::client::Session> struct ClientT { ConnectionType connection; SessionType session; qpid::client::SubscriptionManager subs; qpid::client::LocalQueue lq; - ClientT(uint16_t port) : connection(port), - session(connection.newSession("Client")), - subs(session) - {} + ClientT(uint16_t port) : connection(port), session(connection.newSession()), subs(session) {} ~ClientT() { connection.close(); } }; diff --git a/cpp/src/tests/ForkedBroker.h b/cpp/src/tests/ForkedBroker.h new file mode 100644 index 0000000000..843c9ab8e2 --- /dev/null +++ b/cpp/src/tests/ForkedBroker.h @@ -0,0 +1,91 @@ +#ifndef TESTS_FORKEDBROKER_H +#define TESTS_FORKEDBROKER_H + +/* + * + * 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 "qpid/sys/Fork.h" +#include "qpid/log/Logger.h" +#include "qpid/broker/Broker.h" +#include "qpid/broker/SignalHandler.h" + +#include <boost/lexical_cast.hpp> + +#include <string> + +#include <signal.h> +#include <sys/wait.h> + +/** + * Class to fork a broker child process. + * + * For most tests a BrokerFixture may be more convenient as it starts + * a broker in the same process which allows you to easily debug into + * the broker. + * + * This useful for tests that need to start multiple brokers where + * those brokers can't coexist in the same process (e.g. for cluster + * tests where CPG doesn't allow multiple group members in a single + * process.) + * + */ +class ForkedBroker : public qpid::sys::ForkWithMessage { + pid_t childPid; + uint16_t port; + qpid::broker::Broker::Options opts; + std::string prefix; + + public: + ForkedBroker(const qpid::broker::Broker::Options& opts_, const std::string& prefix_=std::string()) + : childPid(0), port(0), opts(opts_), prefix(prefix_) { fork(); } + + ~ForkedBroker() { stop(); } + + void stop() { + if (childPid > 0) { + ::kill(childPid, SIGINT); + //FIXME aconway 2008-07-04: ::waitpid(childPid, 0, 0); + } + } + + void parent(pid_t pid) { + childPid = pid; + qpid::log::Logger::instance().setPrefix("parent"); + std::string portStr = wait(2); + port = boost::lexical_cast<uint16_t>(portStr); + } + + void child() { + prefix += boost::lexical_cast<std::string>(long(getpid())); + qpid::log::Logger::instance().setPrefix(prefix); + opts.port = 0; + boost::shared_ptr<qpid::broker::Broker> broker(new qpid::broker::Broker(opts)); + qpid::broker::SignalHandler::setBroker(broker); + QPID_LOG(info, "ForkedBroker started on " << broker->getPort()); + ready(boost::lexical_cast<std::string>(broker->getPort())); // Notify parent. + broker->run(); + QPID_LOG(notice, "ForkedBroker exiting."); + } + + uint16_t getPort() { return port; } +}; + +#endif /*!TESTS_FORKEDBROKER_H*/ diff --git a/cpp/src/tests/Makefile.am b/cpp/src/tests/Makefile.am index c34bf03553..f72264d69a 100644 --- a/cpp/src/tests/Makefile.am +++ b/cpp/src/tests/Makefile.am @@ -62,7 +62,8 @@ unit_test_SOURCES= unit_test.cpp unit_test.h \ TxBufferTest.cpp \ TxPublishTest.cpp \ MessageBuilderTest.cpp \ - ConnectionOptions.h + ConnectionOptions.h \ + ForkedBroker.h if HAVE_XML unit_test_SOURCES+= XmlClientSessionTest.cpp diff --git a/cpp/src/tests/cluster_test.cpp b/cpp/src/tests/cluster_test.cpp index 63e3b257b3..2fa7cd325d 100644 --- a/cpp/src/tests/cluster_test.cpp +++ b/cpp/src/tests/cluster_test.cpp @@ -19,10 +19,14 @@ #include "test_tools.h" #include "unit_test.h" +#include "ForkedBroker.h" #include "BrokerFixture.h" #include "qpid/cluster/Cpg.h" #include "qpid/framing/AMQBody.h" +#include "qpid/client/Connection.h" +#include "qpid/client/Session.h" +#include "qpid/framing/Uuid.h" #include <boost/bind.hpp> #include <boost/ptr_container/ptr_vector.hpp> @@ -33,15 +37,41 @@ #include <vector> #include <algorithm> +#include <signal.h> + QPID_AUTO_TEST_SUITE(CpgTestSuite) using namespace std; +using namespace qpid; using namespace qpid::cluster; using namespace qpid::framing; using namespace qpid::client; +using qpid::broker::Broker; using boost::ptr_vector; +struct ClusterFixture : public ptr_vector<ForkedBroker> { + string name; + + ClusterFixture(size_t n=0) : name(Uuid(true).str()) { add(n); } + void add(size_t n) { for (size_t i=0; i < n; ++i) add(); } + void add(); +}; + +void ClusterFixture::add() { + broker::Broker::Options opts; + Plugin::Factory::addOptions(opts); // For cluster options. + const char* argv[] = { + "", "--cluster-name", name.c_str(), "--auth=no", "--no-data-dir" + }; + opts.parse(sizeof(argv)/sizeof(*argv), const_cast<char**>(argv)); + ostringstream prefix; + prefix << "b" << size() << "-"; + QPID_LOG(info, "ClusterFixture adding broker " << prefix.str()); + push_back(new ForkedBroker(opts, prefix.str())); + QPID_LOG(info, "ClusterFixture added broker " << prefix.str()); +} + // For debugging: op << for CPG types. ostream& operator<<(ostream& o, const cpg_name* n) { @@ -117,56 +147,8 @@ QPID_AUTO_TEST_CASE(CpgBasic) { } -QPID_AUTO_TEST_CASE(CpgMulti) { - // Verify using multiple handles in one process. - // - Cpg::Name group("CpgMulti"); - Callback cb1(group.str()); - Cpg cpg1(cb1); - - Callback cb2(group.str()); - Cpg cpg2(cb2); - - cpg1.join(group); - cpg2.join(group); - iovec iov1 = { (void*)"Hello1", 6 }; - iovec iov2 = { (void*)"Hello2", 6 }; - cpg1.mcast(group, &iov1, 1); - cpg2.mcast(group, &iov2, 1); - cpg1.leave(group); - cpg2.leave(group); - - cpg1.dispatchSome(); - BOOST_REQUIRE_EQUAL(2u, cb1.delivered.size()); - BOOST_CHECK_EQUAL("Hello1", cb1.delivered[0]); - BOOST_CHECK_EQUAL("Hello2", cb1.delivered[1]); - - cpg2.dispatchSome(); - BOOST_REQUIRE_EQUAL(2u, cb1.delivered.size()); - BOOST_CHECK_EQUAL("Hello1", cb1.delivered[0]); - BOOST_CHECK_EQUAL("Hello2", cb1.delivered[1]); -} - -// Test cluster of BrokerFixtures. -struct ClusterFixture : public ptr_vector<BrokerFixture> { - ClusterFixture(size_t n=0) { add(n); } - void add(size_t n) { for (size_t i=0; i < n; ++i) add(); } - void add(); -}; - -void ClusterFixture::add() { - qpid::broker::Broker::Options opts; - // Assumes the cluster plugin is loaded. - qpid::Plugin::Factory::addOptions(opts); - const char* argv[] = { "--cluster-name", ::getenv("USERNAME") }; - // FIXME aconway 2008-06-26: fix parse() signature, should not need cast. - opts.parse(sizeof(argv)/sizeof(*argv), const_cast<char**>(argv)); - push_back(new BrokerFixture(opts)); -} - -#if 0 QPID_AUTO_TEST_CASE(testWiringReplication) { - ClusterFixture cluster(3); + ClusterFixture cluster(2); // FIXME aconway 2008-07-02: 3 brokers Client c0(cluster[0].getPort()); BOOST_CHECK(c0.session.queueQuery("q").getQueue().empty()); BOOST_CHECK(c0.session.exchangeQuery("ex").getType().empty()); @@ -187,16 +169,17 @@ QPID_AUTO_TEST_CASE(testMessageReplication) { ClusterFixture cluster(2); Client c0(cluster[0].getPort()); c0.session.queueDeclare("q"); - c0.session.messageTransfer(arg::content=TransferContent("data", "q")); + c0.session.messageTransfer(arg::content=TransferContent("foo", "q")); + c0.session.messageTransfer(arg::content=TransferContent("bar", "q")); c0.session.close(); Client c1(cluster[1].getPort()); Message msg; BOOST_CHECK(c1.subs.get(msg, "q", qpid::sys::TIME_SEC)); - BOOST_CHECK_EQUAL(string("data"), msg.getData()); + BOOST_CHECK_EQUAL(string("foo"), msg.getData()); + BOOST_CHECK(c1.subs.get(msg, "q", qpid::sys::TIME_SEC)); + BOOST_CHECK_EQUAL(string("bar"), msg.getData()); } -// TODO aconway 2008-06-25: dequeue replication, exactly once delivery, failover. - -#endif +// TODO aconway 2008-06-25: dequeue replication, failover. QPID_AUTO_TEST_SUITE_END() diff --git a/cpp/src/tests/logging.cpp b/cpp/src/tests/logging.cpp index 6b0315da04..97bfed2436 100644 --- a/cpp/src/tests/logging.cpp +++ b/cpp/src/tests/logging.cpp @@ -374,8 +374,8 @@ QPID_AUTO_TEST_CASE(testQuoteNonPrintable) { QPID_LOG(critical, str); ifstream log("logging.tmp"); string line; - getline(log, line); - string expect="critical null\\00tab\\09space newline\\0Aret\\0D\\80\\99\\FF\\00"; + getline(log, line, '\0'); + string expect="critical null\\x00tab\tspace newline\nret\r\\x80\\x99\\xFF\\x00\n"; BOOST_CHECK_EQUAL(expect, line); log.close(); unlink("logging.tmp"); |