diff options
Diffstat (limited to 'qpid/cpp/src/tests')
90 files changed, 1828 insertions, 990 deletions
diff --git a/qpid/cpp/src/tests/AccumulatedAckTest.cpp b/qpid/cpp/src/tests/AccumulatedAckTest.cpp index 028ce71907..c736a519d2 100644 --- a/qpid/cpp/src/tests/AccumulatedAckTest.cpp +++ b/qpid/cpp/src/tests/AccumulatedAckTest.cpp @@ -8,9 +8,9 @@ * 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 @@ -28,6 +28,9 @@ using std::list; using namespace qpid::framing; +namespace qpid { +namespace tests { + bool covers(const AccumulatedAck& ack, int i) { return ack.covers(SequenceNumber(i)); @@ -97,7 +100,7 @@ QPID_AUTO_TEST_CASE(testUpdateFromCompletionData) ack.update(mark, ranges); - for(int i = 0; i <= 15; i++) { + for(int i = 0; i <= 15; i++) { BOOST_CHECK(covers(ack, i)); } BOOST_CHECK(!covers(ack, 16)); @@ -221,7 +224,7 @@ QPID_AUTO_TEST_CASE(testConsolidation4) ack.update(SequenceNumber(9), SequenceNumber(9)); ack.update(SequenceNumber(3), SequenceNumber(4)); - for(int i = 0; i <= 15; i++) { + for(int i = 0; i <= 15; i++) { BOOST_CHECK(covers(ack, i)); } BOOST_CHECK(!covers(ack, 16)); @@ -230,3 +233,5 @@ QPID_AUTO_TEST_CASE(testConsolidation4) QPID_AUTO_TEST_SUITE_END() + +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/Array.cpp b/qpid/cpp/src/tests/Array.cpp index c779cbe901..7622b89d15 100644 --- a/qpid/cpp/src/tests/Array.cpp +++ b/qpid/cpp/src/tests/Array.cpp @@ -7,9 +7,9 @@ * 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 @@ -25,6 +25,9 @@ #include "unit_test.h" +namespace qpid { +namespace tests { + QPID_AUTO_TEST_SUITE(ArrayTestSuite) using namespace qpid::framing; @@ -69,7 +72,7 @@ QPID_AUTO_TEST_CASE(testArrayAssignment) Array a(data); b = a; BOOST_CHECK_EQUAL(a, b); - } + } std::vector<std::string> data2; b.collect(data2); //BOOST_CHECK_EQUAL(data, data2); @@ -77,3 +80,5 @@ QPID_AUTO_TEST_CASE(testArrayAssignment) } QPID_AUTO_TEST_SUITE_END() + +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/AsyncCompletion.cpp b/qpid/cpp/src/tests/AsyncCompletion.cpp index 41423d8245..4492e6b6bc 100644 --- a/qpid/cpp/src/tests/AsyncCompletion.cpp +++ b/qpid/cpp/src/tests/AsyncCompletion.cpp @@ -49,10 +49,13 @@ using boost::intrusive_ptr; * message enqueues at the correct time. */ +namespace qpid { +namespace tests { + class AsyncCompletionMessageStore : public NullMessageStore { public: sys::BlockingQueue<boost::intrusive_ptr<PersistableMessage> > enqueued; - + AsyncCompletionMessageStore() : NullMessageStore() {} ~AsyncCompletionMessageStore(){} @@ -82,10 +85,10 @@ QPID_AUTO_TEST_CASE(testWaitTillComplete) { transfers[i] = s.messageTransfer(arg::content=msg); } - // Get hold of the broker-side messages. + // Get hold of the broker-side messages. typedef vector<intrusive_ptr<PersistableMessage> > BrokerMessages; BrokerMessages enqueued; - for (int j = 0; j < count; ++j) + for (int j = 0; j < count; ++j) enqueued.push_back(store->enqueued.pop(TIME_SEC)); // Send a sync, make sure it does not complete till all messages are complete. @@ -111,3 +114,5 @@ QPID_AUTO_TEST_CASE(testGetResult) { } QPID_AUTO_TEST_SUITE_END() + +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/AtomicValue.cpp b/qpid/cpp/src/tests/AtomicValue.cpp index 05083ad177..d855d993a7 100644 --- a/qpid/cpp/src/tests/AtomicValue.cpp +++ b/qpid/cpp/src/tests/AtomicValue.cpp @@ -21,6 +21,9 @@ #include "test_tools.h" #include "qpid/sys/AtomicValue.h" +namespace qpid { +namespace tests { + QPID_AUTO_TEST_SUITE(AtomicValueTestSuite) QPID_AUTO_TEST_CASE(test) { @@ -47,3 +50,5 @@ QPID_AUTO_TEST_CASE(test) { QPID_AUTO_TEST_SUITE_END() + +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/BrokerFixture.h b/qpid/cpp/src/tests/BrokerFixture.h index 397045d00b..bb985cf7e1 100644 --- a/qpid/cpp/src/tests/BrokerFixture.h +++ b/qpid/cpp/src/tests/BrokerFixture.h @@ -10,9 +10,9 @@ * 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 @@ -35,6 +35,9 @@ #include "qpid/sys/Thread.h" #include <boost/noncopyable.hpp> +namespace qpid { +namespace tests { + /** * A fixture with an in-process broker. */ @@ -55,7 +58,7 @@ struct BrokerFixture : private boost::noncopyable { } opts.port=0; // Management doesn't play well with multiple in-process brokers. - opts.enableMgmt=false; + opts.enableMgmt=false; opts.workerThreads=1; opts.dataDir=""; opts.auth=false; @@ -144,5 +147,6 @@ struct SessionFixtureT : BrokerFixture, ClientT<ConnectionType,SessionType> { typedef SessionFixtureT<LocalConnection> SessionFixture; typedef SessionFixtureT<ProxyConnection> ProxySessionFixture; +}} // namespace qpid::tests #endif /*!TESTS_BROKERFIXTURE_H*/ diff --git a/qpid/cpp/src/tests/ClientMessageTest.cpp b/qpid/cpp/src/tests/ClientMessageTest.cpp index bc0945674f..f925f1c234 100644 --- a/qpid/cpp/src/tests/ClientMessageTest.cpp +++ b/qpid/cpp/src/tests/ClientMessageTest.cpp @@ -24,6 +24,9 @@ using namespace qpid::client; +namespace qpid { +namespace tests { + QPID_AUTO_TEST_SUITE(ClientMessageTestSuite) QPID_AUTO_TEST_CASE(MessageCopyAssign) { @@ -33,7 +36,7 @@ QPID_AUTO_TEST_CASE(MessageCopyAssign) { Message c(m); BOOST_CHECK_EQUAL("foo", c.getData()); Message a; - BOOST_CHECK_EQUAL("", a.getData()); + BOOST_CHECK_EQUAL("", a.getData()); a = m; BOOST_CHECK_EQUAL("foo", a.getData()); a.setData("a"); @@ -44,3 +47,5 @@ QPID_AUTO_TEST_CASE(MessageCopyAssign) { } QPID_AUTO_TEST_SUITE_END() + +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/ClientSessionTest.cpp b/qpid/cpp/src/tests/ClientSessionTest.cpp index 3ed7491f7d..6ca0aa6d44 100644 --- a/qpid/cpp/src/tests/ClientSessionTest.cpp +++ b/qpid/cpp/src/tests/ClientSessionTest.cpp @@ -7,9 +7,9 @@ * 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 @@ -40,6 +40,9 @@ #include <vector> +namespace qpid { +namespace tests { + QPID_AUTO_TEST_SUITE(ClientSessionTest) using namespace qpid::client; @@ -122,12 +125,12 @@ QPID_AUTO_TEST_CASE(testDispatcher) ClientSessionFixture fix; fix.session =fix.connection.newSession(); size_t count = 100; - for (size_t i = 0; i < count; ++i) + for (size_t i = 0; i < count; ++i) fix.session.messageTransfer(arg::content=Message(boost::lexical_cast<string>(i), "my-queue")); DummyListener listener(fix.session, "my-queue", count); listener.run(); - BOOST_CHECK_EQUAL(count, listener.messages.size()); - for (size_t i = 0; i < count; ++i) + BOOST_CHECK_EQUAL(count, listener.messages.size()); + for (size_t i = 0; i < count; ++i) BOOST_CHECK_EQUAL(boost::lexical_cast<string>(i), listener.messages[i].getData()); } @@ -142,8 +145,8 @@ QPID_AUTO_TEST_CASE(testDispatcherThread) fix.session.messageTransfer(arg::content=Message(boost::lexical_cast<string>(i), "my-queue")); } t.join(); - BOOST_CHECK_EQUAL(count, listener.messages.size()); - for (size_t i = 0; i < count; ++i) + BOOST_CHECK_EQUAL(count, listener.messages.size()); + for (size_t i = 0; i < count; ++i) BOOST_CHECK_EQUAL(boost::lexical_cast<string>(i), listener.messages[i].getData()); } @@ -215,7 +218,7 @@ QPID_AUTO_TEST_CASE(testLocalQueue) { BOOST_CHECK_EQUAL("foo1", lq.pop().getData()); BOOST_CHECK(lq.empty()); // Credit exhausted. fix.subs.getSubscription("lq").setFlowControl(FlowControl::unlimited()); - BOOST_CHECK_EQUAL("foo2", lq.pop().getData()); + BOOST_CHECK_EQUAL("foo2", lq.pop().getData()); } struct DelayedTransfer : sys::Runnable @@ -246,7 +249,7 @@ QPID_AUTO_TEST_CASE(testGet) { Thread t(sender); //test timed get where message shows up after a short delay BOOST_CHECK(fix.subs.get(got, "getq", 5*TIME_SEC)); - BOOST_CHECK_EQUAL("foo2", got.getData()); + BOOST_CHECK_EQUAL("foo2", got.getData()); t.join(); } @@ -271,8 +274,8 @@ QPID_AUTO_TEST_CASE(testPeriodicExpiration) { ClientSessionFixture fix(opts); fix.session.queueDeclare(arg::queue="my-queue", arg::exclusive=true, arg::autoDelete=true); - for (uint i = 0; i < 10; i++) { - Message m((boost::format("Message_%1%") % (i+1)).str(), "my-queue"); + for (uint i = 0; i < 10; i++) { + Message m((boost::format("Message_%1%") % (i+1)).str(), "my-queue"); if (i % 2) m.getDeliveryProperties().setTtl(500); fix.session.messageTransfer(arg::content=m); } @@ -286,15 +289,15 @@ QPID_AUTO_TEST_CASE(testExpirationOnPop) { ClientSessionFixture fix; fix.session.queueDeclare(arg::queue="my-queue", arg::exclusive=true, arg::autoDelete=true); - for (uint i = 0; i < 10; i++) { - Message m((boost::format("Message_%1%") % (i+1)).str(), "my-queue"); + for (uint i = 0; i < 10; i++) { + Message m((boost::format("Message_%1%") % (i+1)).str(), "my-queue"); if (i % 2) m.getDeliveryProperties().setTtl(200); fix.session.messageTransfer(arg::content=m); } qpid::sys::usleep(300* 1000); - for (uint i = 0; i < 10; i++) { + for (uint i = 0; i < 10; i++) { if (i % 2) continue; Message m; BOOST_CHECK(fix.subs.get(m, "my-queue", TIME_SEC)); @@ -306,8 +309,8 @@ QPID_AUTO_TEST_CASE(testRelease) { ClientSessionFixture fix; const uint count=10; - for (uint i = 0; i < count; i++) { - Message m((boost::format("Message_%1%") % (i+1)).str(), "my-queue"); + for (uint i = 0; i < count; i++) { + Message m((boost::format("Message_%1%") % (i+1)).str(), "my-queue"); fix.session.messageTransfer(arg::content=m); } @@ -334,7 +337,7 @@ QPID_AUTO_TEST_CASE(testRelease) { for (uint i = 0; i < count; i++) { BOOST_CHECK_EQUAL((boost::format("Message_%1%") % (i+1)).str(), l2.messages[i].getData()); } - + fix.subs.stop(); fix.subs.wait(); fix.session.close(); @@ -344,8 +347,8 @@ QPID_AUTO_TEST_CASE(testCompleteOnAccept) { ClientSessionFixture fix; const uint count = 8; const uint chunk = 4; - for (uint i = 0; i < count; i++) { - Message m((boost::format("Message_%1%") % (i+1)).str(), "my-queue"); + for (uint i = 0; i < count; i++) { + Message m((boost::format("Message_%1%") % (i+1)).str(), "my-queue"); fix.session.messageTransfer(arg::content=m); } @@ -358,25 +361,25 @@ QPID_AUTO_TEST_CASE(testCompleteOnAccept) { Subscription s = fix.subs.subscribe(q, "my-queue", settings); fix.session.messageFlush(arg::destination=s.getName()); SequenceSet accepted; - for (uint i = 0; i < chunk; i++) { + for (uint i = 0; i < chunk; i++) { Message m; BOOST_CHECK(q.get(m)); BOOST_CHECK_EQUAL((boost::format("Message_%1%") % (i+1)).str(), m.getData()); accepted.add(m.getId()); - } + } Message m; BOOST_CHECK(!q.get(m)); - + s.accept(accepted); fix.session.messageFlush(arg::destination=s.getName()); accepted.clear(); - - for (uint i = chunk; i < count; i++) { + + for (uint i = chunk; i < count; i++) { Message m; BOOST_CHECK(q.get(m)); BOOST_CHECK_EQUAL((boost::format("Message_%1%") % (i+1)).str(), m.getData()); accepted.add(m.getId()); - } + } fix.session.messageAccept(accepted); } @@ -424,7 +427,7 @@ QPID_AUTO_TEST_CASE(testConcurrentSenders) connection.open(settings); AsyncSession session = connection.newSession(); Message message(string(512, 'X')); - + boost::ptr_vector<Publisher> publishers; for (size_t i = 0; i < 5; i++) { publishers.push_back(new Publisher(connection, message, 100)); @@ -447,7 +450,7 @@ QPID_AUTO_TEST_CASE(testExclusiveSubscribe) ScopedSuppressLogging sl; BOOST_CHECK_THROW(fix.subs.subscribe(q, "myq", "second"), ResourceLockedException); ; - + } QPID_AUTO_TEST_CASE(testExclusiveBinding) { @@ -478,7 +481,7 @@ QPID_AUTO_TEST_CASE(testResubscribeWithLocalQueue) { fix.subs.subscribe(p, "some-queue"); fix.subs.cancel("some-queue"); fix.subs.subscribe(q, "some-queue"); - + fix.session.messageTransfer(arg::content=Message("some-data", "some-queue")); fix.session.messageFlush(arg::destination="some-queue"); @@ -542,10 +545,10 @@ QPID_AUTO_TEST_CASE(testLVQVariedSize) { std::ostringstream data; size_t size = 100 - ((i % 10) * 10); data << std::string(size, 'x'); - + Message m(data.str(), queue); m.getHeaders().setString(key, "abc"); - fix.session.messageTransfer(arg::content=m); + fix.session.messageTransfer(arg::content=m); } } @@ -594,7 +597,7 @@ QPID_AUTO_TEST_CASE(testExpirationNotAltered) { ClientSessionFixture fix; fix.session.queueDeclare(arg::queue="my-queue", arg::exclusive=true, arg::autoDelete=true); - Message m("my-message", "my-queue"); + Message m("my-message", "my-queue"); m.getDeliveryProperties().setTtl(60000); m.getDeliveryProperties().setExpiration(12345); fix.session.messageTransfer(arg::content=m); @@ -606,4 +609,4 @@ QPID_AUTO_TEST_CASE(testExpirationNotAltered) { QPID_AUTO_TEST_SUITE_END() - +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/ClusterFailover.cpp b/qpid/cpp/src/tests/ClusterFailover.cpp index 9ce9c4a36b..c2fb1282b1 100644 --- a/qpid/cpp/src/tests/ClusterFailover.cpp +++ b/qpid/cpp/src/tests/ClusterFailover.cpp @@ -32,6 +32,9 @@ #include <boost/algorithm/string.hpp> #include <boost/bind.hpp> +namespace qpid { +namespace tests { + QPID_AUTO_TEST_SUITE(ClusterFailoverTestSuite) using namespace std; @@ -60,3 +63,5 @@ QPID_AUTO_TEST_CASE(testReconnectSameSessionName) { } QPID_AUTO_TEST_SUITE_END() + +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/ClusterFixture.cpp b/qpid/cpp/src/tests/ClusterFixture.cpp index e12106c464..7c357c3cd1 100644 --- a/qpid/cpp/src/tests/ClusterFixture.cpp +++ b/qpid/cpp/src/tests/ClusterFixture.cpp @@ -61,6 +61,9 @@ using boost::assign::list_of; #include "ClusterFixture.h" +namespace qpid { +namespace tests { + ClusterFixture::ClusterFixture(size_t n, const Args& args_, int localIndex_) : name(Uuid(true).str()), localIndex(localIndex_), userArgs(args_) { @@ -152,3 +155,5 @@ std::set<int> knownBrokerPorts(qpid::client::Connection& source, int n) { s.insert((*i)[0].get<qpid::TcpAddress>()->port); return s; } + +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/ClusterFixture.h b/qpid/cpp/src/tests/ClusterFixture.h index 08b314499e..5952cc1736 100644 --- a/qpid/cpp/src/tests/ClusterFixture.h +++ b/qpid/cpp/src/tests/ClusterFixture.h @@ -60,6 +60,9 @@ using qpid::broker::Broker; using boost::shared_ptr; using qpid::cluster::Cluster; +namespace qpid { +namespace tests { + /** Cluster fixture is a vector of ports for the replicas. * * At most one replica (by default replica 0) is in the current @@ -107,4 +110,6 @@ class ClusterFixture : public vector<uint16_t> { */ std::set<int> knownBrokerPorts(qpid::client::Connection& source, int n=-1); +}} // namespace qpid::tests + #endif /*!CLUSTER_FIXTURE_H*/ diff --git a/qpid/cpp/src/tests/ConnectionOptions.h b/qpid/cpp/src/tests/ConnectionOptions.h index cf86894235..6fd6c2c63f 100644 --- a/qpid/cpp/src/tests/ConnectionOptions.h +++ b/qpid/cpp/src/tests/ConnectionOptions.h @@ -10,9 +10,9 @@ * 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 @@ -25,6 +25,8 @@ #include "qpid/client/ConnectionSettings.h" #include "qpid/Options.h" +namespace qpid { + /** * Options parser for ConnectionOptions. */ @@ -35,9 +37,9 @@ struct ConnectionOptions : public qpid::Options, { using namespace qpid; addOptions() - ("broker,b", optValue(host, "HOST"), "Broker host to connect to") + ("broker,b", optValue(host, "HOST"), "Broker host to connect to") ("port,p", optValue(port, "PORT"), "Broker port to connect to") - ("protocol,P", optValue(protocol, "tcp|rdma"), "Protocol to use for broker connection") + ("protocol,P", optValue(protocol, "tcp|rdma"), "Protocol to use for broker connection") ("virtualhost,v", optValue(virtualhost, "VHOST"), "virtual host") ("username", optValue(username, "USER"), "user name for broker log in.") ("password", optValue(password, "PASSWORD"), "password for broker log in.") @@ -46,7 +48,7 @@ struct ConnectionOptions : public qpid::Options, ("max-channels", optValue(maxChannels, "N"), "the maximum number of channels the client requires.") ("heartbeat", optValue(heartbeat, "N"), "Desired heartbeat interval in seconds.") ("max-frame-size", optValue(maxFrameSize, "N"), "the maximum frame size to request.") - ("bounds-multiplier", optValue(bounds, "N"), + ("bounds-multiplier", optValue(bounds, "N"), "bound size of write queue (as a multiple of the max frame size).") ("tcp-nodelay", optValue(tcpNoDelay), "Turn on tcp-nodelay") ("service", optValue(service, "SERVICE-NAME"), "SASL service name.") @@ -55,4 +57,6 @@ struct ConnectionOptions : public qpid::Options, } }; +} // namespace qpid + #endif /*!QPID_CLIENT_CONNECTIONOPTIONS_H*/ diff --git a/qpid/cpp/src/tests/ConsoleTest.cpp b/qpid/cpp/src/tests/ConsoleTest.cpp index 1d55b13f3c..107472ed9e 100644 --- a/qpid/cpp/src/tests/ConsoleTest.cpp +++ b/qpid/cpp/src/tests/ConsoleTest.cpp @@ -7,9 +7,9 @@ * 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 @@ -23,6 +23,9 @@ #include "qpid/console/ClassKey.h" #include "unit_test.h" +namespace qpid { +namespace tests { + QPID_AUTO_TEST_SUITE(ConsoleTestSuite) using namespace qpid::framing; @@ -40,4 +43,4 @@ QPID_AUTO_TEST_CASE(testClassKey) { QPID_AUTO_TEST_SUITE_END() - +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/DeliveryRecordTest.cpp b/qpid/cpp/src/tests/DeliveryRecordTest.cpp index 8ff7ad3584..17f9a0d148 100644 --- a/qpid/cpp/src/tests/DeliveryRecordTest.cpp +++ b/qpid/cpp/src/tests/DeliveryRecordTest.cpp @@ -8,9 +8,9 @@ * 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 @@ -31,6 +31,9 @@ using namespace qpid::framing; using boost::dynamic_pointer_cast; using std::list; +namespace qpid { +namespace tests { + QPID_AUTO_TEST_SUITE(DeliveryRecordTestSuite) QPID_AUTO_TEST_CASE(testSort) @@ -60,3 +63,4 @@ QPID_AUTO_TEST_CASE(testSort) QPID_AUTO_TEST_SUITE_END() +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/DispatcherTest.cpp b/qpid/cpp/src/tests/DispatcherTest.cpp index c619a36438..17b3b4e3e6 100644 --- a/qpid/cpp/src/tests/DispatcherTest.cpp +++ b/qpid/cpp/src/tests/DispatcherTest.cpp @@ -7,9 +7,9 @@ * 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 @@ -39,6 +39,9 @@ using namespace std; using namespace qpid::sys; +namespace qpid { +namespace tests { + int writeALot(int fd, const string& s) { int bytesWritten = 0; do { @@ -46,7 +49,7 @@ int writeALot(int fd, const string& s) { int lastWrite = ::write(fd, s.c_str(), s.size()); if ( lastWrite >= 0) { bytesWritten += lastWrite; - } + } } while (errno != EAGAIN); return bytesWritten; } @@ -54,13 +57,13 @@ int writeALot(int fd, const string& s) { int readALot(int fd) { int bytesRead = 0; char buf[10240]; - + do { errno = 0; int lastRead = ::read(fd, buf, sizeof(buf)); if ( lastRead >= 0) { bytesRead += lastRead; - } + } } while (errno != EAGAIN); return bytesRead; } @@ -83,7 +86,7 @@ void rInterrupt(DispatchHandle&) { } void wInterrupt(DispatchHandle&) { - cerr << "W"; + cerr << "W"; } DispatchHandle::Callback rcb = rInterrupt; @@ -108,15 +111,19 @@ void timer_handler(int /*signo*/, siginfo_t* /*info*/, void* /*context*/) { wh->call(wcb); } else { phase1finished = true; - assert(::timer_delete(timer) == 0); + assert(::timer_delete(timer) == 0); } } +}} // namespace qpid::tests + +using namespace qpid::tests; + int main(int /*argc*/, char** /*argv*/) { // Create poller Poller::shared_ptr poller(new Poller); - + // Create dispatcher thread Dispatcher d(poller); Dispatcher d1(poller); @@ -131,14 +138,14 @@ int main(int /*argc*/, char** /*argv*/) int sv[2]; int rc = ::socketpair(AF_UNIX, SOCK_STREAM, 0, sv); assert(rc >= 0); - + // Set non-blocking rc = ::fcntl(sv[0], F_SETFL, O_NONBLOCK); assert(rc >= 0); rc = ::fcntl(sv[1], F_SETFL, O_NONBLOCK); assert(rc >= 0); - + // Make up a large string string testString = "This is only a test ... 1,2,3,4,5,6,7,8,9,10;"; for (int i = 0; i < 8; i++) @@ -148,19 +155,19 @@ int main(int /*argc*/, char** /*argv*/) PosixIOHandle f1(sv[1]); rh = new DispatchHandleRef(f0, boost::bind(reader, _1, sv[0]), 0, 0); - wh = new DispatchHandleRef(f1, 0, boost::bind(writer, _1, sv[1], testString), 0); + wh = new DispatchHandleRef(f1, 0, boost::bind(writer, _1, sv[1], testString), 0); rh->startWatch(poller); wh->startWatch(poller); // Set up a regular itimer interupt - + // Ignore signal in this thread ::sigset_t sm; ::sigemptyset(&sm); ::sigaddset(&sm, SIGRTMIN); ::pthread_sigmask(SIG_BLOCK, &sm, 0); - + // Signal handling struct ::sigaction sa; sa.sa_sigaction = timer_handler; @@ -168,18 +175,18 @@ int main(int /*argc*/, char** /*argv*/) ::sigemptyset(&sa.sa_mask); rc = ::sigaction(SIGRTMIN, &sa,0); assert(rc == 0); - + ::sigevent se; ::memset(&se, 0, sizeof(se)); // Clear to make valgrind happy (this *is* the neatest way to do this portably - sigh) se.sigev_notify = SIGEV_SIGNAL; se.sigev_signo = SIGRTMIN; rc = ::timer_create(CLOCK_REALTIME, &se, &timer); assert(rc == 0); - + itimerspec ts = { /*.it_value = */ {2, 0}, // s, ns /*.it_interval = */ {2, 0}}; // s, ns - + rc = ::timer_settime(timer, 0, &ts, 0); assert(rc == 0); @@ -200,11 +207,11 @@ int main(int /*argc*/, char** /*argv*/) sa.sa_sigaction = stop_handler; rc = ::sigaction(SIGRTMIN, &sa,0); assert(rc == 0); - + itimerspec nts = { /*.it_value = */ {30, 0}, // s, ns /*.it_interval = */ {30, 0}}; // s, ns - + rc = ::timer_create(CLOCK_REALTIME, &se, &timer); assert(rc == 0); rc = ::timer_settime(timer, 0, &nts, 0); @@ -228,7 +235,7 @@ int main(int /*argc*/, char** /*argv*/) rc = ::timer_delete(timer); assert(rc == 0); - + poller->shutdown(); dt.join(); dt1.join(); @@ -237,6 +244,6 @@ int main(int /*argc*/, char** /*argv*/) cout << "\nWrote: " << writtenBytes << "\n"; cout << "Read: " << readBytes << "\n"; - + return 0; } diff --git a/qpid/cpp/src/tests/DtxWorkRecordTest.cpp b/qpid/cpp/src/tests/DtxWorkRecordTest.cpp index c7c1b460ff..9d7666dca4 100644 --- a/qpid/cpp/src/tests/DtxWorkRecordTest.cpp +++ b/qpid/cpp/src/tests/DtxWorkRecordTest.cpp @@ -7,9 +7,9 @@ * 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 @@ -27,6 +27,9 @@ using namespace qpid::broker; using boost::static_pointer_cast; +namespace qpid { +namespace tests { + QPID_AUTO_TEST_SUITE(DtxWorkRecordTestSuite) QPID_AUTO_TEST_CASE(testOnePhaseCommit){ @@ -44,7 +47,7 @@ QPID_AUTO_TEST_CASE(testOnePhaseCommit){ DtxBuffer::shared_ptr bufferB(new DtxBuffer()); bufferB->enlist(static_pointer_cast<TxOp>(opB)); bufferB->markEnded(); - + DtxWorkRecord work("my-xid", &store); work.add(bufferA); work.add(bufferB); @@ -77,7 +80,7 @@ QPID_AUTO_TEST_CASE(testFailOnOnePhaseCommit){ DtxBuffer::shared_ptr bufferC(new DtxBuffer()); bufferC->enlist(static_pointer_cast<TxOp>(opC)); bufferC->markEnded(); - + DtxWorkRecord work("my-xid", &store); work.add(bufferA); work.add(bufferB); @@ -108,7 +111,7 @@ QPID_AUTO_TEST_CASE(testTwoPhaseCommit){ DtxBuffer::shared_ptr bufferB(new DtxBuffer()); bufferB->enlist(static_pointer_cast<TxOp>(opB)); bufferB->markEnded(); - + DtxWorkRecord work("my-xid", &store); work.add(bufferA); work.add(bufferB); @@ -142,7 +145,7 @@ QPID_AUTO_TEST_CASE(testFailOnTwoPhaseCommit){ DtxBuffer::shared_ptr bufferC(new DtxBuffer()); bufferC->enlist(static_pointer_cast<TxOp>(opC)); bufferC->markEnded(); - + DtxWorkRecord work("my-xid", &store); work.add(bufferA); work.add(bufferB); @@ -171,7 +174,7 @@ QPID_AUTO_TEST_CASE(testRollback){ DtxBuffer::shared_ptr bufferB(new DtxBuffer()); bufferB->enlist(static_pointer_cast<TxOp>(opB)); bufferB->markEnded(); - + DtxWorkRecord work("my-xid", &store); work.add(bufferA); work.add(bufferB); @@ -187,3 +190,4 @@ QPID_AUTO_TEST_CASE(testRollback){ QPID_AUTO_TEST_SUITE_END() +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/ExchangeTest.cpp b/qpid/cpp/src/tests/ExchangeTest.cpp index 2100fb5ed7..44835c6184 100644 --- a/qpid/cpp/src/tests/ExchangeTest.cpp +++ b/qpid/cpp/src/tests/ExchangeTest.cpp @@ -7,9 +7,9 @@ * 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 @@ -39,9 +39,12 @@ using namespace qpid::framing; using namespace qpid::sys; using namespace qpid; +namespace qpid { +namespace tests { + QPID_AUTO_TEST_SUITE(ExchangeTestSuite) -QPID_AUTO_TEST_CASE(testMe) +QPID_AUTO_TEST_CASE(testMe) { Queue::shared_ptr queue(new Queue("queue", true)); Queue::shared_ptr queue2(new Queue("queue2", true)); @@ -70,7 +73,7 @@ QPID_AUTO_TEST_CASE(testIsBound) Queue::shared_ptr b(new Queue("b", true)); Queue::shared_ptr c(new Queue("c", true)); Queue::shared_ptr d(new Queue("d", true)); - + string k1("abc"); string k2("def"); string k3("xyz"); @@ -139,7 +142,7 @@ QPID_AUTO_TEST_CASE(testIsBound) headers.bind(a, "", &args3); headers.bind(b, "", &args2); headers.bind(c, "", &args1); - + BOOST_CHECK(headers.isBound(a, 0, 0)); BOOST_CHECK(headers.isBound(a, 0, &args1)); BOOST_CHECK(headers.isBound(a, 0, &args3)); @@ -153,7 +156,7 @@ QPID_AUTO_TEST_CASE(testIsBound) BOOST_CHECK(!headers.isBound(d, 0, &args3)); } -QPID_AUTO_TEST_CASE(testDeleteGetAndRedeclare) +QPID_AUTO_TEST_CASE(testDeleteGetAndRedeclare) { ExchangeRegistry exchanges; exchanges.declare("my-exchange", "direct", false, FieldTable()); @@ -162,7 +165,7 @@ QPID_AUTO_TEST_CASE(testDeleteGetAndRedeclare) exchanges.get("my-exchange"); } catch (const NotFoundException&) {} std::pair<Exchange::shared_ptr, bool> response = exchanges.declare("my-exchange", "direct", false, FieldTable()); - BOOST_CHECK_EQUAL(string("direct"), response.first->getType()); + BOOST_CHECK_EQUAL(string("direct"), response.first->getType()); } intrusive_ptr<Message> cmessage(std::string exchange, std::string routingKey) { @@ -175,7 +178,7 @@ intrusive_ptr<Message> cmessage(std::string exchange, std::string routingKey) { return msg; } -QPID_AUTO_TEST_CASE(testSequenceOptions) +QPID_AUTO_TEST_CASE(testSequenceOptions) { FieldTable args; args.setInt("qpid.msg_sequence",1); @@ -225,22 +228,22 @@ QPID_AUTO_TEST_CASE(testSequenceOptions) direct.encode(buffer); } { - + ExchangeRegistry exchanges; buffer.reset(); DirectExchange::shared_ptr exch_dec = Exchange::decode(exchanges, buffer); - + intrusive_ptr<Message> msg1 = cmessage("e", "A"); DeliverableMessage dmsg1(msg1); exch_dec->route(dmsg1, "abc", 0); BOOST_CHECK_EQUAL(4, msg1->getApplicationHeaders()->getAsInt64("qpid.msg_sequence")); - + } delete [] buff; } -QPID_AUTO_TEST_CASE(testIVEOption) +QPID_AUTO_TEST_CASE(testIVEOption) { FieldTable args; args.setInt("qpid.ive",1); @@ -248,7 +251,7 @@ QPID_AUTO_TEST_CASE(testIVEOption) FanOutExchange fanout("fanout1", false, args); HeadersExchange header("headers1", false, args); TopicExchange topic ("topic1", false, args); - + intrusive_ptr<Message> msg1 = cmessage("direct1", "abc"); msg1->getProperties<MessageProperties>()->getApplicationHeaders().setString("a", "abc"); DeliverableMessage dmsg1(msg1); @@ -256,7 +259,7 @@ QPID_AUTO_TEST_CASE(testIVEOption) FieldTable args2; args2.setString("x-match", "any"); args2.setString("a", "abc"); - + direct.route(dmsg1, "abc", 0); fanout.route(dmsg1, "abc", 0); header.route(dmsg1, "abc", &args2); @@ -265,20 +268,22 @@ QPID_AUTO_TEST_CASE(testIVEOption) Queue::shared_ptr queue1(new Queue("queue1", true)); Queue::shared_ptr queue2(new Queue("queue2", true)); Queue::shared_ptr queue3(new Queue("queue3", true)); - + BOOST_CHECK(HeadersExchange::match(args2, msg1->getProperties<MessageProperties>()->getApplicationHeaders())); - + BOOST_CHECK(direct.bind(queue, "abc", 0)); BOOST_CHECK(fanout.bind(queue1, "abc", 0)); BOOST_CHECK(header.bind(queue2, "", &args2)); BOOST_CHECK(topic.bind(queue3, "abc", 0)); - + BOOST_CHECK_EQUAL(1u,queue->getMessageCount()); BOOST_CHECK_EQUAL(1u,queue1->getMessageCount()); BOOST_CHECK_EQUAL(1u,queue2->getMessageCount()); BOOST_CHECK_EQUAL(1u,queue3->getMessageCount()); - + } QPID_AUTO_TEST_SUITE_END() + +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/FieldTable.cpp b/qpid/cpp/src/tests/FieldTable.cpp index 5b43871f6d..fe2a14ec03 100644 --- a/qpid/cpp/src/tests/FieldTable.cpp +++ b/qpid/cpp/src/tests/FieldTable.cpp @@ -7,9 +7,9 @@ * 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 @@ -29,6 +29,9 @@ using namespace qpid::framing; +namespace qpid { +namespace tests { + QPID_AUTO_TEST_SUITE(FieldTableTestSuite) QPID_AUTO_TEST_CASE(testMe) @@ -57,7 +60,7 @@ QPID_AUTO_TEST_CASE(testAssignment) a.setInt("B", 1234); b = a; a.setString("A", "CCCC"); - + BOOST_CHECK(string("CCCC") == a.getAsString("A")); BOOST_CHECK(string("BBBB") == b.getAsString("A")); BOOST_CHECK_EQUAL(1234, a.getAsInt("B")); @@ -69,7 +72,7 @@ QPID_AUTO_TEST_CASE(testAssignment) { FieldTable c; c = a; - + char* buff = static_cast<char*>(::alloca(c.encodedSize())); Buffer wbuffer(buff, c.encodedSize()); wbuffer.put(c); @@ -102,7 +105,7 @@ QPID_AUTO_TEST_CASE(testNestedValues) list.push_back(List::ValuePtr(new Unsigned32Value(u))); list.push_back(List::ValuePtr(new Str8Value("yellow"))); list.push_back(List::ValuePtr(new DoubleValue(d))); - + a.setString("id", "A"); b.setString("id", "B"); a.setTable("B", b); @@ -192,7 +195,7 @@ QPID_AUTO_TEST_CASE(test64GetAndSetConverts) FieldTable args; args.setInt64("a",100); args.setInt64("b",-(int64_t) ((int64_t) 1<<34)); - + args.setUInt64("c",1u); args.setUInt64("d",(uint64_t) ((uint64_t) 1<<34)); BOOST_CHECK_EQUAL(1u, args.getAsUInt64("c")); @@ -204,5 +207,7 @@ QPID_AUTO_TEST_CASE(test64GetAndSetConverts) BOOST_CHECK_EQUAL((int64_t) ((int64_t) 1<<34), args.getAsInt64("d")); } - + QPID_AUTO_TEST_SUITE_END() + +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/FieldValue.cpp b/qpid/cpp/src/tests/FieldValue.cpp index 448f068107..0ebd0d7d44 100644 --- a/qpid/cpp/src/tests/FieldValue.cpp +++ b/qpid/cpp/src/tests/FieldValue.cpp @@ -6,9 +6,9 @@ * 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 @@ -20,6 +20,9 @@ #include "unit_test.h" +namespace qpid { +namespace tests { + QPID_AUTO_TEST_SUITE(FieldValueTestSuite) using namespace qpid::framing; @@ -32,7 +35,7 @@ IntegerValue i(42); QPID_AUTO_TEST_CASE(testStr16ValueEquals) { - + BOOST_CHECK(Str16Value("abc") == s); BOOST_CHECK(Str16Value("foo") != s); BOOST_CHECK(s != i); @@ -73,7 +76,7 @@ QPID_AUTO_TEST_CASE(testFieldTableValueEquals) BOOST_CHECK_EQUAL(std::string("FOO"), ft.getValue().getString("foo")); BOOST_CHECK_EQUAL(7, ft.getValue().getInt("magic")); - + FieldTableValue f2; BOOST_CHECK(ft != f2); f2.getValue().setString("foo", "FOO"); @@ -88,3 +91,5 @@ QPID_AUTO_TEST_CASE(testFieldTableValueEquals) #endif QPID_AUTO_TEST_SUITE_END() + +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/ForkedBroker.cpp b/qpid/cpp/src/tests/ForkedBroker.cpp index 30c346850c..e1a96c8e90 100644 --- a/qpid/cpp/src/tests/ForkedBroker.cpp +++ b/qpid/cpp/src/tests/ForkedBroker.cpp @@ -30,6 +30,16 @@ using namespace std; using qpid::ErrnoException; +namespace std { +static ostream& operator<<(ostream& o, const qpid::tests::ForkedBroker::Args& a) { +copy(a.begin(), a.end(), ostream_iterator<string>(o, " ")); +return o; +} +} + +namespace qpid { +namespace tests { + ForkedBroker::ForkedBroker(const Args& constArgs) { Args args(constArgs); Args::iterator i = find(args.begin(), args.end(), string("TMP_DATA_DIR")); @@ -71,12 +81,6 @@ void ForkedBroker::kill(int sig) { throw qpid::Exception(QPID_MSG("Forked broker exited with: " << WEXITSTATUS(status))); } -namespace std { -static ostream& operator<<(ostream& o, const ForkedBroker::Args& a) { - copy(a.begin(), a.end(), ostream_iterator<string>(o, " ")); - return o; -} - bool isLogOption(const std::string& s) { const char * log_enable = "--log-enable", * trace = "--trace"; @@ -85,8 +89,6 @@ bool isLogOption(const std::string& s) { ); } -} - void ForkedBroker::init(const Args& userArgs) { using qpid::ErrnoException; port = 0; @@ -125,3 +127,5 @@ void ForkedBroker::init(const Args& userArgs) { ::exit(1); } } + +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/ForkedBroker.h b/qpid/cpp/src/tests/ForkedBroker.h index 45b522068c..ddbad185d8 100644 --- a/qpid/cpp/src/tests/ForkedBroker.h +++ b/qpid/cpp/src/tests/ForkedBroker.h @@ -11,9 +11,9 @@ * 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 @@ -31,9 +31,12 @@ #include <stdio.h> #include <sys/wait.h> +namespace qpid { +namespace tests { + /** * 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. @@ -42,17 +45,17 @@ * 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: typedef std::vector<std::string> Args; // argv args are passed to broker. - // + // // Special value "TMP_DATA_DIR" is substituted with a temporary // data directory for the broker. - // + // ForkedBroker(const Args& argv); ~ForkedBroker(); @@ -70,4 +73,6 @@ class ForkedBroker { std::string dataDir; }; +}} // namespace qpid::tests + #endif /*!TESTS_FORKEDBROKER_H*/ diff --git a/qpid/cpp/src/tests/Frame.cpp b/qpid/cpp/src/tests/Frame.cpp index 11905911fa..1270eabba3 100644 --- a/qpid/cpp/src/tests/Frame.cpp +++ b/qpid/cpp/src/tests/Frame.cpp @@ -7,9 +7,9 @@ * 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 @@ -23,6 +23,9 @@ #include <boost/lexical_cast.hpp> #include "unit_test.h" +namespace qpid { +namespace tests { + QPID_AUTO_TEST_SUITE(FrameTestSuite) using namespace std; @@ -78,3 +81,5 @@ QPID_AUTO_TEST_CASE(testLoop) { } QPID_AUTO_TEST_SUITE_END() + +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/FrameDecoder.cpp b/qpid/cpp/src/tests/FrameDecoder.cpp index f5db66d5fe..9eeff2a41e 100644 --- a/qpid/cpp/src/tests/FrameDecoder.cpp +++ b/qpid/cpp/src/tests/FrameDecoder.cpp @@ -7,9 +7,9 @@ * 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 @@ -27,6 +27,9 @@ #include <string> +namespace qpid { +namespace tests { + QPID_AUTO_TEST_SUITE(FrameDecoderTest) using namespace std; @@ -69,5 +72,7 @@ QPID_AUTO_TEST_CASE(testByteFragments) { } - + QPID_AUTO_TEST_SUITE_END() + +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/FramingTest.cpp b/qpid/cpp/src/tests/FramingTest.cpp index e09ee19bc2..3d0fa0c0de 100644 --- a/qpid/cpp/src/tests/FramingTest.cpp +++ b/qpid/cpp/src/tests/FramingTest.cpp @@ -7,9 +7,9 @@ * 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 @@ -39,8 +39,11 @@ using namespace qpid; using namespace qpid::framing; using namespace std; +namespace qpid { +namespace tests { + template <class T> -std::string tostring(const T& x) +std::string tostring(const T& x) { std::ostringstream out; out << x; @@ -49,7 +52,7 @@ std::string tostring(const T& x) QPID_AUTO_TEST_SUITE(FramingTestSuite) -QPID_AUTO_TEST_CASE(testMessageTransferBody) +QPID_AUTO_TEST_CASE(testMessageTransferBody) { char buffer[1024]; ProtocolVersion version(highestProtocolVersion); @@ -62,8 +65,8 @@ QPID_AUTO_TEST_CASE(testMessageTransferBody) out.decode(rbuff); BOOST_CHECK_EQUAL(tostring(in), tostring(out)); } - -QPID_AUTO_TEST_CASE(testConnectionSecureBody) + +QPID_AUTO_TEST_CASE(testConnectionSecureBody) { char buffer[1024]; ProtocolVersion version(highestProtocolVersion); @@ -88,10 +91,10 @@ QPID_AUTO_TEST_CASE(testConnectionRedirectBody) Array hosts(0x95); hosts.add(boost::shared_ptr<FieldValue>(new Str16Value(a))); hosts.add(boost::shared_ptr<FieldValue>(new Str16Value(b))); - + ConnectionRedirectBody in(version, a, hosts); in.encode(wbuff); - + Buffer rbuff(buffer, sizeof(buffer)); ConnectionRedirectBody out(version); out.decode(rbuff); @@ -111,7 +114,7 @@ QPID_AUTO_TEST_CASE(testQueueDeclareBody) out.decode(rbuff); BOOST_CHECK_EQUAL(tostring(in), tostring(out)); } - + QPID_AUTO_TEST_CASE(testConnectionRedirectBodyFrame) { char buffer[1024]; @@ -122,7 +125,7 @@ QPID_AUTO_TEST_CASE(testConnectionRedirectBodyFrame) Array hosts(0x95); hosts.add(boost::shared_ptr<FieldValue>(new Str16Value(a))); hosts.add(boost::shared_ptr<FieldValue>(new Str16Value(b))); - + AMQFrame in((ConnectionRedirectBody(version, a, hosts))); in.setChannel(999); in.encode(wbuff); @@ -149,3 +152,5 @@ QPID_AUTO_TEST_CASE(testMessageCancelBodyFrame) } QPID_AUTO_TEST_SUITE_END() + +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/HeaderTest.cpp b/qpid/cpp/src/tests/HeaderTest.cpp index 01e7c22ee6..4b16f3c793 100644 --- a/qpid/cpp/src/tests/HeaderTest.cpp +++ b/qpid/cpp/src/tests/HeaderTest.cpp @@ -7,9 +7,9 @@ * 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 @@ -26,9 +26,12 @@ using namespace qpid::framing; using namespace std; +namespace qpid { +namespace tests { + QPID_AUTO_TEST_SUITE(HeaderTestSuite) -QPID_AUTO_TEST_CASE(testGenericProperties) +QPID_AUTO_TEST_CASE(testGenericProperties) { AMQHeaderBody body; body.get<MessageProperties>(true)->getApplicationHeaders().setString( @@ -47,10 +50,10 @@ QPID_AUTO_TEST_CASE(testGenericProperties) props->getApplicationHeaders().get("A")->get<string>()); } -QPID_AUTO_TEST_CASE(testMessageProperties) +QPID_AUTO_TEST_CASE(testMessageProperties) { AMQFrame out((AMQHeaderBody())); - MessageProperties* props1 = + MessageProperties* props1 = out.castBody<AMQHeaderBody>()->get<MessageProperties>(true); props1->setContentLength(42); @@ -82,10 +85,10 @@ QPID_AUTO_TEST_CASE(testMessageProperties) } -QPID_AUTO_TEST_CASE(testDeliveryProperies) +QPID_AUTO_TEST_CASE(testDeliveryProperies) { AMQFrame out((AMQHeaderBody())); - DeliveryProperties* props1 = + DeliveryProperties* props1 = out.castBody<AMQHeaderBody>()->get<DeliveryProperties>(true); props1->setDiscardUnroutable(true); @@ -108,3 +111,4 @@ QPID_AUTO_TEST_CASE(testDeliveryProperies) QPID_AUTO_TEST_SUITE_END() +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/HeadersExchangeTest.cpp b/qpid/cpp/src/tests/HeadersExchangeTest.cpp index 46933f955a..40deb59c86 100644 --- a/qpid/cpp/src/tests/HeadersExchangeTest.cpp +++ b/qpid/cpp/src/tests/HeadersExchangeTest.cpp @@ -7,9 +7,9 @@ * 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 @@ -28,9 +28,12 @@ using namespace qpid::broker; using namespace qpid::framing; +namespace qpid { +namespace tests { + QPID_AUTO_TEST_SUITE(HeadersExchangeTestSuite) - -QPID_AUTO_TEST_CASE(testMatchAll) + +QPID_AUTO_TEST_CASE(testMatchAll) { FieldTable b, m, n; b.setString("x-match", "all"); @@ -43,7 +46,7 @@ QPID_AUTO_TEST_CASE(testMatchAll) // Ignore extras. m.setString("extra", "x"); BOOST_CHECK(HeadersExchange::match(b, m)); - + // Fail mismatch, wrong value. m.setString("foo", "NotFoo"); BOOST_CHECK(!HeadersExchange::match(b, m)); @@ -54,7 +57,7 @@ QPID_AUTO_TEST_CASE(testMatchAll) BOOST_CHECK(!HeadersExchange::match(b, n)); } -QPID_AUTO_TEST_CASE(testMatchAny) +QPID_AUTO_TEST_CASE(testMatchAny) { FieldTable b, m, n; b.setString("x-match", "any"); @@ -67,7 +70,7 @@ QPID_AUTO_TEST_CASE(testMatchAny) BOOST_CHECK(HeadersExchange::match(b, m)); } -QPID_AUTO_TEST_CASE(testMatchEmptyValue) +QPID_AUTO_TEST_CASE(testMatchEmptyValue) { FieldTable b, m; b.setString("x-match", "all"); @@ -82,23 +85,23 @@ QPID_AUTO_TEST_CASE(testMatchEmptyArgs) { FieldTable b, m; m.setString("foo", "FOO"); - + b.setString("x-match", "all"); BOOST_CHECK(HeadersExchange::match(b, m)); b.setString("x-match", "any"); BOOST_CHECK(!HeadersExchange::match(b, m)); } - -QPID_AUTO_TEST_CASE(testMatchNoXMatch) + +QPID_AUTO_TEST_CASE(testMatchNoXMatch) { FieldTable b, m; b.setString("foo", "FOO"); m.setString("foo", "FOO"); BOOST_CHECK(!HeadersExchange::match(b, m)); } - -QPID_AUTO_TEST_CASE(testBindNoXMatch) + +QPID_AUTO_TEST_CASE(testBindNoXMatch) { HeadersExchange exchange("test"); Queue::shared_ptr queue; @@ -112,4 +115,6 @@ QPID_AUTO_TEST_CASE(testBindNoXMatch) } } -QPID_AUTO_TEST_SUITE_END() +QPID_AUTO_TEST_SUITE_END() + +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/IncompleteMessageList.cpp b/qpid/cpp/src/tests/IncompleteMessageList.cpp index e830df0e8b..303d83cd66 100644 --- a/qpid/cpp/src/tests/IncompleteMessageList.cpp +++ b/qpid/cpp/src/tests/IncompleteMessageList.cpp @@ -7,9 +7,9 @@ * 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 @@ -27,6 +27,9 @@ #include "unit_test.h" +namespace qpid { +namespace tests { + QPID_AUTO_TEST_SUITE(IncompleteMessageListTestSuite) using namespace qpid::broker; @@ -41,7 +44,7 @@ struct Checker Checker(uint start, uint end) { for (uint i = start; i <= end; i++) { ids.push_back(i); - } + } } Checker& expect(const SequenceNumber& id) { @@ -49,11 +52,11 @@ struct Checker return *this; } - void operator()(boost::intrusive_ptr<Message> msg) { + void operator()(boost::intrusive_ptr<Message> msg) { BOOST_CHECK(!ids.empty()); BOOST_CHECK_EQUAL(msg->getCommandId(), ids.front()); ids.pop_front(); - } + } }; QPID_AUTO_TEST_CASE(testProcessSimple) @@ -91,7 +94,7 @@ QPID_AUTO_TEST_CASE(testProcessWithIncomplete) list.process(Checker(1, 2), false); //mark message complete and re-process to get remaining messages sent to listener middle->enqueueComplete(); - list.process(Checker(3, 5), false); + list.process(Checker(3, 5), false); } @@ -127,3 +130,5 @@ QPID_AUTO_TEST_CASE(testSyncProcessWithIncomplete) } QPID_AUTO_TEST_SUITE_END() + +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/InlineAllocator.cpp b/qpid/cpp/src/tests/InlineAllocator.cpp index fe6eaefaf4..a4c4d64cea 100644 --- a/qpid/cpp/src/tests/InlineAllocator.cpp +++ b/qpid/cpp/src/tests/InlineAllocator.cpp @@ -7,9 +7,9 @@ * 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 @@ -22,6 +22,9 @@ #include "qpid/InlineAllocator.h" #include "unit_test.h" +namespace qpid { +namespace tests { + QPID_AUTO_TEST_SUITE(InlineAllocatorTestSuite) using namespace qpid; @@ -48,16 +51,18 @@ QPID_AUTO_TEST_CASE(testAllocateFull) { char* p = alloc.allocate(1); BOOST_CHECK(p == (char*)&alloc); - + char* q = alloc.allocate(1); BOOST_CHECK(q != (char*)&alloc); alloc.deallocate(p,1); p = alloc.allocate(1); BOOST_CHECK(p == (char*)&alloc); - + alloc.deallocate(p,1); alloc.deallocate(q,1); } QPID_AUTO_TEST_SUITE_END() + +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/InlineVector.cpp b/qpid/cpp/src/tests/InlineVector.cpp index 009f10af9d..ba5165886d 100644 --- a/qpid/cpp/src/tests/InlineVector.cpp +++ b/qpid/cpp/src/tests/InlineVector.cpp @@ -7,9 +7,9 @@ * 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 @@ -22,6 +22,9 @@ #include "qpid/InlineVector.h" #include "unit_test.h" +namespace qpid { +namespace tests { + QPID_AUTO_TEST_SUITE(InlineVectorTestSuite) using namespace qpid; @@ -117,7 +120,9 @@ QPID_AUTO_TEST_CASE(testAssign) { QPID_AUTO_TEST_CASE(testResize) { Vec v; v.resize(5); - BOOST_CHECK(!isInline(v)); + BOOST_CHECK(!isInline(v)); } QPID_AUTO_TEST_SUITE_END() + +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/ManagementTest.cpp b/qpid/cpp/src/tests/ManagementTest.cpp index e6f2e2e3fd..d05b4676ba 100644 --- a/qpid/cpp/src/tests/ManagementTest.cpp +++ b/qpid/cpp/src/tests/ManagementTest.cpp @@ -7,9 +7,9 @@ * 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 @@ -24,6 +24,9 @@ #include "qpid/console/ObjectId.h" #include "unit_test.h" +namespace qpid { +namespace tests { + QPID_AUTO_TEST_SUITE(ManagementTestSuite) using namespace qpid::framing; @@ -109,4 +112,4 @@ QPID_AUTO_TEST_CASE(testConsoleObjectId) { QPID_AUTO_TEST_SUITE_END() - +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/MessageBuilderTest.cpp b/qpid/cpp/src/tests/MessageBuilderTest.cpp index 1f3f830633..c2fb8ad32e 100644 --- a/qpid/cpp/src/tests/MessageBuilderTest.cpp +++ b/qpid/cpp/src/tests/MessageBuilderTest.cpp @@ -7,9 +7,9 @@ * 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 @@ -31,15 +31,18 @@ using namespace qpid::broker; using namespace qpid::framing; using namespace qpid::sys; +namespace qpid { +namespace tests { + class MockMessageStore : public NullMessageStore { enum Op {STAGE=1, APPEND=2}; uint64_t id; - boost::intrusive_ptr<PersistableMessage> expectedMsg; + boost::intrusive_ptr<PersistableMessage> expectedMsg; string expectedData; std::list<Op> ops; - + void checkExpectation(Op actual) { BOOST_CHECK_EQUAL(ops.front(), actual); @@ -49,17 +52,17 @@ class MockMessageStore : public NullMessageStore public: MockMessageStore() : id(0), expectedMsg(0) {} - void expectStage(PersistableMessage& msg) - { + void expectStage(PersistableMessage& msg) + { expectedMsg = &msg; - ops.push_back(STAGE); + ops.push_back(STAGE); } - void expectAppendContent(PersistableMessage& msg, const string& data) - { + void expectAppendContent(PersistableMessage& msg, const string& data) + { expectedMsg = &msg; expectedData = data; - ops.push_back(APPEND); + ops.push_back(APPEND); } void stage(const boost::intrusive_ptr<PersistableMessage>& msg) @@ -74,7 +77,7 @@ class MockMessageStore : public NullMessageStore { checkExpectation(APPEND); BOOST_CHECK_EQUAL(boost::static_pointer_cast<const PersistableMessage>(expectedMsg), msg); - BOOST_CHECK_EQUAL(expectedData, data); + BOOST_CHECK_EQUAL(expectedData, data); } bool expectationsMet() @@ -89,7 +92,7 @@ class MockMessageStore : public NullMessageStore } }; - + QPID_AUTO_TEST_SUITE(MessageBuilderTestSuite) QPID_AUTO_TEST_CASE(testHeaderOnly) @@ -103,7 +106,7 @@ QPID_AUTO_TEST_CASE(testHeaderOnly) AMQFrame method((MessageTransferBody(ProtocolVersion(), exchange, 0, 0))); AMQFrame header((AMQHeaderBody())); - header.castBody<AMQHeaderBody>()->get<MessageProperties>(true)->setContentLength(0); + header.castBody<AMQHeaderBody>()->get<MessageProperties>(true)->setContentLength(0); header.castBody<AMQHeaderBody>()->get<DeliveryProperties>(true)->setRoutingKey(key); builder.handle(method); @@ -132,7 +135,7 @@ QPID_AUTO_TEST_CASE(test1ContentFrame) header.setEof(false); content.setBof(false); - header.castBody<AMQHeaderBody>()->get<MessageProperties>(true)->setContentLength(data.size()); + header.castBody<AMQHeaderBody>()->get<MessageProperties>(true)->setContentLength(data.size()); header.castBody<AMQHeaderBody>()->get<DeliveryProperties>(true)->setRoutingKey(key); builder.handle(method); @@ -143,7 +146,7 @@ QPID_AUTO_TEST_CASE(test1ContentFrame) BOOST_CHECK(builder.getMessage()); BOOST_CHECK(!builder.getMessage()->getFrames().isComplete()); - builder.handle(content); + builder.handle(content); BOOST_CHECK(builder.getMessage()); BOOST_CHECK(builder.getMessage()->getFrames().isComplete()); } @@ -169,7 +172,7 @@ QPID_AUTO_TEST_CASE(test2ContentFrames) content1.setEof(false); content2.setBof(false); - header.castBody<AMQHeaderBody>()->get<MessageProperties>(true)->setContentLength(data1.size() + data2.size()); + header.castBody<AMQHeaderBody>()->get<MessageProperties>(true)->setContentLength(data1.size() + data2.size()); header.castBody<AMQHeaderBody>()->get<DeliveryProperties>(true)->setRoutingKey(key); builder.handle(method); @@ -188,7 +191,7 @@ QPID_AUTO_TEST_CASE(testStaging) MockMessageStore store; MessageBuilder builder(&store, 5); builder.start(SequenceNumber()); - + std::string data1("abcdefg"); std::string data2("hijklmn"); std::string exchange("builder-exchange"); @@ -199,7 +202,7 @@ QPID_AUTO_TEST_CASE(testStaging) AMQFrame content1((AMQContentBody(data1))); AMQFrame content2((AMQContentBody(data2))); - header.castBody<AMQHeaderBody>()->get<MessageProperties>(true)->setContentLength(data1.size() + data2.size()); + header.castBody<AMQHeaderBody>()->get<MessageProperties>(true)->setContentLength(data1.size() + data2.size()); header.castBody<AMQHeaderBody>()->get<DeliveryProperties>(true)->setRoutingKey(key); builder.handle(method); @@ -223,7 +226,7 @@ QPID_AUTO_TEST_CASE(testNoManagementStaging) MockMessageStore store; MessageBuilder builder(&store, 5); builder.start(SequenceNumber()); - + std::string data1("abcdefg"); std::string exchange("qpid.management"); std::string key("builder-exchange"); @@ -232,7 +235,7 @@ QPID_AUTO_TEST_CASE(testNoManagementStaging) AMQFrame header((AMQHeaderBody())); AMQFrame content1((AMQContentBody(data1))); - header.castBody<AMQHeaderBody>()->get<MessageProperties>(true)->setContentLength(data1.size()); + header.castBody<AMQHeaderBody>()->get<MessageProperties>(true)->setContentLength(data1.size()); header.castBody<AMQHeaderBody>()->get<DeliveryProperties>(true)->setRoutingKey(key); builder.handle(method); @@ -242,4 +245,7 @@ QPID_AUTO_TEST_CASE(testNoManagementStaging) BOOST_CHECK(store.expectationsMet()); BOOST_CHECK_EQUAL((uint64_t) 0, builder.getMessage()->getPersistenceId()); } + QPID_AUTO_TEST_SUITE_END() + +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/MessageReplayTracker.cpp b/qpid/cpp/src/tests/MessageReplayTracker.cpp index a5121cdeb7..3d79ee53c2 100644 --- a/qpid/cpp/src/tests/MessageReplayTracker.cpp +++ b/qpid/cpp/src/tests/MessageReplayTracker.cpp @@ -7,9 +7,9 @@ * 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 @@ -23,6 +23,9 @@ #include "qpid/client/MessageReplayTracker.h" #include "qpid/sys/Time.h" +namespace qpid { +namespace tests { + QPID_AUTO_TEST_SUITE(MessageReplayTrackerTests) using namespace qpid::client; @@ -53,8 +56,8 @@ QPID_AUTO_TEST_CASE(testReplay) MessageReplayTracker tracker(10); tracker.init(fix.session); - for (uint i = 0; i < 5; i++) { - Message message((boost::format("Message_%1%") % (i+1)).str(), "my-queue"); + for (uint i = 0; i < 5; i++) { + Message message((boost::format("Message_%1%") % (i+1)).str(), "my-queue"); tracker.send(message); } ReplayBufferChecker checker(1, 10); @@ -62,7 +65,7 @@ QPID_AUTO_TEST_CASE(testReplay) tracker.replay(fix.session); for (uint j = 0; j < 2; j++) {//each message should have been sent twice - for (uint i = 0; i < 5; i++) { + for (uint i = 0; i < 5; i++) { Message m; BOOST_CHECK(fix.subs.get(m, "my-queue", TIME_SEC)); BOOST_CHECK_EQUAL((boost::format("Message_%1%") % (i+1)).str(), m.getData()); @@ -79,15 +82,15 @@ QPID_AUTO_TEST_CASE(testCheckCompletion) MessageReplayTracker tracker(10); tracker.init(fix.session); - for (uint i = 0; i < 5; i++) { - Message message((boost::format("Message_%1%") % (i+1)).str(), "my-queue"); + for (uint i = 0; i < 5; i++) { + Message message((boost::format("Message_%1%") % (i+1)).str(), "my-queue"); tracker.send(message); } fix.session.sync();//ensures all messages are complete tracker.checkCompletion(); tracker.replay(fix.session); Message received; - for (uint i = 0; i < 5; i++) { + for (uint i = 0; i < 5; i++) { BOOST_CHECK(fix.subs.get(received, "my-queue")); BOOST_CHECK_EQUAL((boost::format("Message_%1%") % (i+1)).str(), received.getData()); } @@ -96,4 +99,4 @@ QPID_AUTO_TEST_CASE(testCheckCompletion) QPID_AUTO_TEST_SUITE_END() - +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/MessageTest.cpp b/qpid/cpp/src/tests/MessageTest.cpp index cd63f64a37..7d67c92b37 100644 --- a/qpid/cpp/src/tests/MessageTest.cpp +++ b/qpid/cpp/src/tests/MessageTest.cpp @@ -7,9 +7,9 @@ * 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 @@ -33,6 +33,9 @@ using namespace qpid::broker; using namespace qpid::framing; +namespace qpid { +namespace tests { + QPID_AUTO_TEST_SUITE(MessageTestSuite) QPID_AUTO_TEST_CASE(testEncodeDecode) @@ -56,7 +59,7 @@ QPID_AUTO_TEST_CASE(testEncodeDecode) msg->getFrames().append(content2); MessageProperties* mProps = msg->getFrames().getHeaders()->get<MessageProperties>(true); - mProps->setContentLength(data1.size() + data2.size()); + mProps->setContentLength(data1.size() + data2.size()); mProps->setMessageId(messageId); FieldTable applicationHeaders; applicationHeaders.setString("abc", "xyz"); @@ -69,7 +72,7 @@ QPID_AUTO_TEST_CASE(testEncodeDecode) char* buff = static_cast<char*>(::alloca(msg->encodedSize())); Buffer wbuffer(buff, msg->encodedSize()); msg->encode(wbuffer); - + Buffer rbuffer(buff, msg->encodedSize()); msg = new Message(); msg->decodeHeader(rbuffer); @@ -86,3 +89,4 @@ QPID_AUTO_TEST_CASE(testEncodeDecode) QPID_AUTO_TEST_SUITE_END() +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/MessageUtils.h b/qpid/cpp/src/tests/MessageUtils.h index 6a12c72007..dae74cce7d 100644 --- a/qpid/cpp/src/tests/MessageUtils.h +++ b/qpid/cpp/src/tests/MessageUtils.h @@ -7,9 +7,9 @@ * 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 @@ -28,9 +28,12 @@ using namespace qpid; using namespace broker; using namespace framing; +namespace qpid { +namespace tests { + struct MessageUtils { - static boost::intrusive_ptr<Message> createMessage(const string& exchange="", const string& routingKey="", + static boost::intrusive_ptr<Message> createMessage(const string& exchange="", const string& routingKey="", const Uuid& messageId=Uuid(true), uint64_t contentSize = 0) { boost::intrusive_ptr<broker::Message> msg(new broker::Message()); @@ -41,7 +44,7 @@ struct MessageUtils msg->getFrames().append(method); msg->getFrames().append(header); MessageProperties* props = msg->getFrames().getHeaders()->get<MessageProperties>(true); - props->setContentLength(contentSize); + props->setContentLength(contentSize); props->setMessageId(messageId); msg->getFrames().getHeaders()->get<DeliveryProperties>(true)->setRoutingKey(routingKey); return msg; @@ -53,3 +56,5 @@ struct MessageUtils msg->getFrames().append(content); } }; + +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/MessagingSessionTests.cpp b/qpid/cpp/src/tests/MessagingSessionTests.cpp index 4ee27f0764..f5a5420d3a 100644 --- a/qpid/cpp/src/tests/MessagingSessionTests.cpp +++ b/qpid/cpp/src/tests/MessagingSessionTests.cpp @@ -7,9 +7,9 @@ * 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 @@ -36,6 +36,9 @@ #include <string> #include <vector> +namespace qpid { +namespace tests { + QPID_AUTO_TEST_SUITE(MessagingSessionTests) using namespace qpid::messaging; @@ -86,7 +89,7 @@ struct MessagingFixture : public BrokerFixture Session session; BrokerAdmin admin; - MessagingFixture(Broker::Options opts = Broker::Options()) : + MessagingFixture(Broker::Options opts = Broker::Options()) : BrokerFixture(opts), connection(Connection::open((boost::format("amqp:tcp:localhost:%1%") % (broker->getPort(Broker::TCP_TRANSPORT))).str())), session(connection.newSession()), @@ -133,7 +136,7 @@ struct TopicFixture : MessagingFixture struct MultiQueueFixture : MessagingFixture { - typedef std::vector<std::string>::const_iterator const_iterator; + typedef std::vector<std::string>::const_iterator const_iterator; std::vector<std::string> queues; MultiQueueFixture(const std::vector<std::string>& names = boost::assign::list_of<std::string>("q1")("q2")("q3")) : queues(names) @@ -161,7 +164,7 @@ struct MessageDataCollector : MessageListener } }; -std::vector<std::string> fetch(Receiver& receiver, int count, qpid::sys::Duration timeout=qpid::sys::TIME_SEC*5) +std::vector<std::string> fetch(Receiver& receiver, int count, qpid::sys::Duration timeout=qpid::sys::TIME_SEC*5) { std::vector<std::string> data; Message message; @@ -189,13 +192,12 @@ QPID_AUTO_TEST_CASE(testSendReceiveHeaders) Sender sender = fix.session.createSender(fix.queue); Message out("test-message"); for (uint i = 0; i < 10; ++i) { - out.getHeaders()["a"] = i; + out.getHeaders()["a"] = i; sender.send(out); } Receiver receiver = fix.session.createReceiver(fix.queue); Message in; for (uint i = 0; i < 10; ++i) { - //Message in = receiver.fetch(5 * qpid::sys::TIME_SEC); BOOST_CHECK(receiver.fetch(in, 5 * qpid::sys::TIME_SEC)); BOOST_CHECK_EQUAL(in.getBytes(), out.getBytes()); BOOST_CHECK_EQUAL(in.getHeaders()["a"].asUint32(), i); @@ -249,14 +251,14 @@ QPID_AUTO_TEST_CASE(testSimpleTopic) Message in; BOOST_CHECK(!sub2.fetch(in, 0));//TODO: or should this raise an error? - + //TODO: check pending messages... } QPID_AUTO_TEST_CASE(testSessionFetch) { MultiQueueFixture fix; - + for (uint i = 0; i < fix.queues.size(); i++) { Receiver r = fix.session.createReceiver(fix.queues[i]); r.setCapacity(10u); @@ -267,8 +269,8 @@ QPID_AUTO_TEST_CASE(testSessionFetch) Sender s = fix.session.createSender(fix.queues[i]); Message msg((boost::format("Message_%1%") % (i+1)).str()); s.send(msg); - } - + } + for (uint i = 0; i < fix.queues.size(); i++) { Message msg; BOOST_CHECK(fix.session.fetch(msg, qpid::sys::TIME_SEC)); @@ -279,7 +281,7 @@ QPID_AUTO_TEST_CASE(testSessionFetch) QPID_AUTO_TEST_CASE(testSessionDispatch) { MultiQueueFixture fix; - + MessageDataCollector collector; for (uint i = 0; i < fix.queues.size(); i++) { Receiver r = fix.session.createReceiver(fix.queues[i]); @@ -292,10 +294,10 @@ QPID_AUTO_TEST_CASE(testSessionDispatch) Sender s = fix.session.createSender(fix.queues[i]); Message msg((boost::format("Message_%1%") % (i+1)).str()); s.send(msg); - } + } while (fix.session.dispatch(qpid::sys::TIME_SEC)) ; - + BOOST_CHECK_EQUAL(collector.messageData, boost::assign::list_of<std::string>("Message_1")("Message_2")("Message_3")); } @@ -309,7 +311,7 @@ QPID_AUTO_TEST_CASE(testMapMessage) out.getContent().asMap()["pi"] = 3.14f; sender.send(out); Receiver receiver = fix.session.createReceiver(fix.queue); - Message in = receiver.fetch(5 * qpid::sys::TIME_SEC); + Message in = receiver.fetch(5 * qpid::sys::TIME_SEC); BOOST_CHECK_EQUAL(in.getContent().asMap()["abc"].asString(), "def"); BOOST_CHECK_EQUAL(in.getContent().asMap()["pi"].asFloat(), 3.14f); fix.session.acknowledge(); @@ -324,11 +326,11 @@ QPID_AUTO_TEST_CASE(testListMessage) out.getContent() << "abc"; out.getContent() << 1234; out.getContent() << "def"; - out.getContent() << 56.789; + out.getContent() << 56.789; sender.send(out); Receiver receiver = fix.session.createReceiver(fix.queue); - Message in = receiver.fetch(5 * qpid::sys::TIME_SEC); - Variant::List& list = in.getContent().asList(); + Message in = receiver.fetch(5 * qpid::sys::TIME_SEC); + Variant::List& list = in.getContent().asList(); BOOST_CHECK_EQUAL(list.size(), out.getContent().asList().size()); BOOST_CHECK_EQUAL(list.front().asString(), "abc"); list.pop_front(); @@ -354,7 +356,86 @@ QPID_AUTO_TEST_CASE(testReject) fix.session.reject(in); in = receiver.fetch(5 * qpid::sys::TIME_SEC); BOOST_CHECK_EQUAL(in.getBytes(), m2.getBytes()); - fix.session.acknowledge(); + fix.session.acknowledge(); +} + +QPID_AUTO_TEST_CASE(testAvailable) +{ + MultiQueueFixture fix; + + Receiver r1 = fix.session.createReceiver(fix.queues[0]); + r1.setCapacity(100); + r1.start(); + + Receiver r2 = fix.session.createReceiver(fix.queues[1]); + r2.setCapacity(100); + r2.start(); + + Sender s1 = fix.session.createSender(fix.queues[0]); + Sender s2 = fix.session.createSender(fix.queues[1]); + + for (uint i = 0; i < 10; ++i) { + s1.send(Message((boost::format("A_%1%") % (i+1)).str())); + } + for (uint i = 0; i < 5; ++i) { + s2.send(Message((boost::format("B_%1%") % (i+1)).str())); + } + qpid::sys::sleep(1);//is there any avoid an arbitrary sleep while waiting for messages to be dispatched? + for (uint i = 0; i < 5; ++i) { + BOOST_CHECK_EQUAL(fix.session.available(), 15u - 2*i); + BOOST_CHECK_EQUAL(r1.available(), 10u - i); + BOOST_CHECK_EQUAL(r1.fetch().getBytes(), (boost::format("A_%1%") % (i+1)).str()); + BOOST_CHECK_EQUAL(r2.available(), 5u - i); + BOOST_CHECK_EQUAL(r2.fetch().getBytes(), (boost::format("B_%1%") % (i+1)).str()); + fix.session.acknowledge(); + } + for (uint i = 5; i < 10; ++i) { + BOOST_CHECK_EQUAL(fix.session.available(), 10u - i); + BOOST_CHECK_EQUAL(r1.available(), 10u - i); + BOOST_CHECK_EQUAL(r1.fetch().getBytes(), (boost::format("A_%1%") % (i+1)).str()); + } +} + +QPID_AUTO_TEST_CASE(testPendingAck) +{ + QueueFixture fix; + Sender sender = fix.session.createSender(fix.queue); + for (uint i = 0; i < 10; ++i) { + sender.send(Message((boost::format("Message_%1%") % (i+1)).str())); + } + Receiver receiver = fix.session.createReceiver(fix.queue); + for (uint i = 0; i < 10; ++i) { + BOOST_CHECK_EQUAL(receiver.fetch().getBytes(), (boost::format("Message_%1%") % (i+1)).str()); + } + BOOST_CHECK_EQUAL(fix.session.pendingAck(), 0u); + fix.session.acknowledge(); + BOOST_CHECK_EQUAL(fix.session.pendingAck(), 10u); + fix.session.sync(); + BOOST_CHECK_EQUAL(fix.session.pendingAck(), 0u); +} + +QPID_AUTO_TEST_CASE(testPendingSend) +{ + QueueFixture fix; + Sender sender = fix.session.createSender(fix.queue); + for (uint i = 0; i < 10; ++i) { + sender.send(Message((boost::format("Message_%1%") % (i+1)).str())); + } + //Note: this test relies on 'inside knowledge' of the sender + //implementation and the fact that the simple test case makes it + //possible to predict when completion information will be sent to + //the client. TODO: is there a better way of testing this? + BOOST_CHECK_EQUAL(sender.pending(), 10u); + fix.session.sync(); + BOOST_CHECK_EQUAL(sender.pending(), 0u); + + Receiver receiver = fix.session.createReceiver(fix.queue); + for (uint i = 0; i < 10; ++i) { + BOOST_CHECK_EQUAL(receiver.fetch().getBytes(), (boost::format("Message_%1%") % (i+1)).str()); + } + fix.session.acknowledge(); } QPID_AUTO_TEST_SUITE_END() + +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/PartialFailure.cpp b/qpid/cpp/src/tests/PartialFailure.cpp index f77a1401f8..8d9970f909 100644 --- a/qpid/cpp/src/tests/PartialFailure.cpp +++ b/qpid/cpp/src/tests/PartialFailure.cpp @@ -31,6 +31,9 @@ #include <boost/algorithm/string.hpp> #include <boost/bind.hpp> +namespace qpid { +namespace tests { + QPID_AUTO_TEST_SUITE(PartialFailureTestSuite) using namespace std; @@ -257,3 +260,5 @@ QPID_AUTO_TEST_CASE(testPartialFailureMemberLeaves) { #endif #endif // FIXME aconway 2009-07-30: QPID_AUTO_TEST_SUITE_END() + +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/PollableCondition.cpp b/qpid/cpp/src/tests/PollableCondition.cpp index b5cf1b4cd2..f9b3c25c93 100644 --- a/qpid/cpp/src/tests/PollableCondition.cpp +++ b/qpid/cpp/src/tests/PollableCondition.cpp @@ -7,9 +7,9 @@ * 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 @@ -28,6 +28,8 @@ #include "qpid/sys/Thread.h" #include <boost/bind.hpp> +namespace qpid { +namespace tests { QPID_AUTO_TEST_SUITE(PollableConditionTest) @@ -37,7 +39,7 @@ const Duration SHORT = TIME_SEC/100; const Duration LONG = TIME_SEC/10; class Callback { - public: + public: enum Action { NONE, CLEAR }; Callback() : count(), action(NONE) {} @@ -46,7 +48,7 @@ class Callback { Mutex::ScopedLock l(lock); ++count; switch(action) { - case NONE: break; + case NONE: break; case CLEAR: pc.clear(); break; } action = NONE; @@ -62,9 +64,9 @@ class Callback { action = a; return wait(LONG); } - + private: - bool wait(Duration timeout) { + bool wait(Duration timeout) { int n = count; AbsTime deadline(now(), timeout); while (n == count && lock.wait(deadline)) @@ -83,7 +85,7 @@ QPID_AUTO_TEST_CASE(testPollableCondition) { PollableCondition pc(boost::bind(&Callback::call, &callback, _1), poller); Thread runner = Thread(*poller); - + BOOST_CHECK(callback.isNotCalling()); // condition is not set. pc.set(); @@ -104,4 +106,4 @@ QPID_AUTO_TEST_CASE(testPollableCondition) { QPID_AUTO_TEST_SUITE_END() - +}} //namespace qpid::tests diff --git a/qpid/cpp/src/tests/ProxyTest.cpp b/qpid/cpp/src/tests/ProxyTest.cpp index 4ea10f7be9..a926b28395 100644 --- a/qpid/cpp/src/tests/ProxyTest.cpp +++ b/qpid/cpp/src/tests/ProxyTest.cpp @@ -7,9 +7,9 @@ * 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 @@ -28,6 +28,9 @@ using namespace qpid::framing; +namespace qpid { +namespace tests { + QPID_AUTO_TEST_SUITE(ProxyTestSuite) @@ -47,5 +50,7 @@ QPID_AUTO_TEST_CASE(testScopedSync) Proxy::ScopedSync s(p); p.send(ExecutionSyncBody(p.getVersion())); } - + QPID_AUTO_TEST_SUITE_END() + +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/QueueEvents.cpp b/qpid/cpp/src/tests/QueueEvents.cpp index cd9439355e..bd18fa45fb 100644 --- a/qpid/cpp/src/tests/QueueEvents.cpp +++ b/qpid/cpp/src/tests/QueueEvents.cpp @@ -7,9 +7,9 @@ * 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 @@ -31,6 +31,9 @@ #include <boost/bind.hpp> #include <boost/format.hpp> +namespace qpid { +namespace tests { + QPID_AUTO_TEST_SUITE(QueueEventsSuite) using namespace qpid::client; @@ -156,7 +159,7 @@ QPID_AUTO_TEST_CASE(testSystemLevelEventProcessing) fixture.session.queueDeclare(arg::queue=q, arg::arguments=options); //send and consume some messages LocalQueue incoming; - Subscription sub = fixture.subs.subscribe(incoming, q); + Subscription sub = fixture.subs.subscribe(incoming, q); for (int i = 0; i < 5; i++) { fixture.session.messageTransfer(arg::content=client::Message((boost::format("%1%_%2%") % "Message" % (i+1)).str(), q)); } @@ -177,7 +180,7 @@ QPID_AUTO_TEST_CASE(testSystemLevelEventProcessing) SequenceNumber dequeueId(1); for (int i = 0; i < 5; i++) { listener.checkEnqueue(q, (boost::format("%1%_%2%") % "Message" % (i+1)).str(), enqueueId++); - } + } for (int i = 0; i < 3; i++) { listener.checkDequeue(q, (boost::format("%1%_%2%") % "Message" % (i+1)).str(), dequeueId++); } @@ -203,7 +206,7 @@ QPID_AUTO_TEST_CASE(testSystemLevelEventProcessing_enqueuesOnly) fixture.session.queueDeclare(arg::queue=q, arg::arguments=options); //send and consume some messages LocalQueue incoming; - Subscription sub = fixture.subs.subscribe(incoming, q); + Subscription sub = fixture.subs.subscribe(incoming, q); for (int i = 0; i < 5; i++) { fixture.session.messageTransfer(arg::content=client::Message((boost::format("%1%_%2%") % "Message" % (i+1)).str(), q)); } @@ -224,7 +227,7 @@ QPID_AUTO_TEST_CASE(testSystemLevelEventProcessing_enqueuesOnly) SequenceNumber dequeueId(1); for (int i = 0; i < 5; i++) { listener.checkEnqueue(q, (boost::format("%1%_%2%") % "Message" % (i+1)).str(), enqueueId++); - } + } for (int i = 5; i < 10; i++) { listener.checkEnqueue(q, (boost::format("%1%_%2%") % "Message" % (i+1)).str(), enqueueId++); } @@ -232,4 +235,4 @@ QPID_AUTO_TEST_CASE(testSystemLevelEventProcessing_enqueuesOnly) QPID_AUTO_TEST_SUITE_END() - +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/QueueOptionsTest.cpp b/qpid/cpp/src/tests/QueueOptionsTest.cpp index 93d1961caa..f2fbaba2c1 100644 --- a/qpid/cpp/src/tests/QueueOptionsTest.cpp +++ b/qpid/cpp/src/tests/QueueOptionsTest.cpp @@ -7,9 +7,9 @@ * 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 @@ -27,14 +27,17 @@ using namespace qpid::client; +namespace qpid { +namespace tests { + QPID_AUTO_TEST_SUITE(QueueOptionsTestSuite) QPID_AUTO_TEST_CASE(testSizePolicy) { QueueOptions ft; - + ft.setSizePolicy(REJECT,1,2); - + BOOST_CHECK(QueueOptions::strREJECT == ft.getAsString(QueueOptions::strTypeKey)); BOOST_CHECK(1 == ft.getAsInt(QueueOptions::strMaxSizeKey)); BOOST_CHECK(2 == ft.getAsInt(QueueOptions::strMaxCountKey)); @@ -49,7 +52,7 @@ QPID_AUTO_TEST_CASE(testSizePolicy) ft.setSizePolicy(RING_STRICT,1,0); BOOST_CHECK(QueueOptions::strRING_STRICT == ft.getAsString(QueueOptions::strTypeKey)); - + ft.clearSizePolicy(); BOOST_CHECK(!ft.isSet(QueueOptions::strTypeKey)); BOOST_CHECK(!ft.isSet(QueueOptions::strMaxSizeKey)); @@ -59,13 +62,13 @@ QPID_AUTO_TEST_CASE(testSizePolicy) QPID_AUTO_TEST_CASE(testFlags) { QueueOptions ft; - + ft.setPersistLastNode(); ft.setOrdering(LVQ); - + BOOST_CHECK(1 == ft.getAsInt(QueueOptions::strPersistLastNode)); BOOST_CHECK(1 == ft.getAsInt(QueueOptions::strLastValueQueue)); - + ft.clearPersistLastNode(); ft.setOrdering(FIFO); @@ -78,8 +81,8 @@ QPID_AUTO_TEST_CASE(testSetOrdering) { //ensure setOrdering(FIFO) works even if not preceded by a call to //setOrdering(LVQ) - QueueOptions ft; - ft.setOrdering(FIFO); + QueueOptions ft; + ft.setOrdering(FIFO); BOOST_CHECK(!ft.isSet(QueueOptions::strLastValueQueue)); } @@ -88,10 +91,12 @@ QPID_AUTO_TEST_CASE(testClearPersistLastNode) { //ensure clear works even if not preceded by the setting on the //option - QueueOptions ft; + QueueOptions ft; ft.clearPersistLastNode(); BOOST_CHECK(!ft.isSet(QueueOptions::strPersistLastNode)); } QPID_AUTO_TEST_SUITE_END() + +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/QueuePolicyTest.cpp b/qpid/cpp/src/tests/QueuePolicyTest.cpp index 7c7f8b7a10..f40d30b588 100644 --- a/qpid/cpp/src/tests/QueuePolicyTest.cpp +++ b/qpid/cpp/src/tests/QueuePolicyTest.cpp @@ -7,9 +7,9 @@ * 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 @@ -32,6 +32,9 @@ using namespace qpid::broker; using namespace qpid::client; using namespace qpid::framing; +namespace qpid { +namespace tests { + QPID_AUTO_TEST_SUITE(QueuePolicyTestSuite) QueuedMessage createMessage(uint32_t size) @@ -50,11 +53,11 @@ QPID_AUTO_TEST_CASE(testCount) BOOST_CHECK_EQUAL((uint32_t) 5, policy->getMaxCount()); QueuedMessage msg = createMessage(10); - for (size_t i = 0; i < 5; i++) { + for (size_t i = 0; i < 5; i++) { policy->tryEnqueue(msg); } try { - policy->tryEnqueue(msg); + policy->tryEnqueue(msg); BOOST_FAIL("Policy did not fail on enqueuing sixth message"); } catch (const ResourceLimitExceededException&) {} @@ -62,7 +65,7 @@ QPID_AUTO_TEST_CASE(testCount) policy->tryEnqueue(msg); try { - policy->tryEnqueue(msg); + policy->tryEnqueue(msg); BOOST_FAIL("Policy did not fail on enqueuing sixth message (after dequeue)"); } catch (const ResourceLimitExceededException&) {} } @@ -71,12 +74,12 @@ QPID_AUTO_TEST_CASE(testSize) { std::auto_ptr<QueuePolicy> policy(QueuePolicy::createQueuePolicy(0, 50)); QueuedMessage msg = createMessage(10); - - for (size_t i = 0; i < 5; i++) { + + for (size_t i = 0; i < 5; i++) { policy->tryEnqueue(msg); } try { - policy->tryEnqueue(msg); + policy->tryEnqueue(msg); BOOST_FAIL("Policy did not fail on aggregate size exceeding 50. " << *policy); } catch (const ResourceLimitExceededException&) {} @@ -84,7 +87,7 @@ QPID_AUTO_TEST_CASE(testSize) policy->tryEnqueue(msg); try { - policy->tryEnqueue(msg); + policy->tryEnqueue(msg); BOOST_FAIL("Policy did not fail on aggregate size exceeding 50 (after dequeue). " << *policy); } catch (const ResourceLimitExceededException&) {} } @@ -104,7 +107,7 @@ QPID_AUTO_TEST_CASE(testBoth) messages.push_back(createMessage(11)); messages.push_back(createMessage(2)); messages.push_back(createMessage(7)); - for (size_t i = 0; i < messages.size(); i++) { + for (size_t i = 0; i < messages.size(); i++) { policy->tryEnqueue(messages[i]); } //size = 45 at this point, count = 5 @@ -140,7 +143,7 @@ QPID_AUTO_TEST_CASE(testSettings) BOOST_CHECK_EQUAL(a->getMaxSize(), b->getMaxSize()); } -QPID_AUTO_TEST_CASE(testRingPolicy) +QPID_AUTO_TEST_CASE(testRingPolicy) { FieldTable args; std::auto_ptr<QueuePolicy> policy = QueuePolicy::createQueuePolicy(5, 0, QueuePolicy::RING); @@ -169,7 +172,7 @@ QPID_AUTO_TEST_CASE(testRingPolicy) BOOST_CHECK(!f.subs.get(msg, q)); } -QPID_AUTO_TEST_CASE(testStrictRingPolicy) +QPID_AUTO_TEST_CASE(testStrictRingPolicy) { FieldTable args; std::auto_ptr<QueuePolicy> policy = QueuePolicy::createQueuePolicy(5, 0, QueuePolicy::RING_STRICT); @@ -181,7 +184,7 @@ QPID_AUTO_TEST_CASE(testStrictRingPolicy) LocalQueue incoming; SubscriptionSettings settings(FlowControl::unlimited()); settings.autoAck = 0; // no auto ack. - Subscription sub = f.subs.subscribe(incoming, q, settings); + Subscription sub = f.subs.subscribe(incoming, q, settings); for (int i = 0; i < 5; i++) { f.session.messageTransfer(arg::content=client::Message((boost::format("%1%_%2%") % "Message" % (i+1)).str(), q)); } @@ -192,10 +195,10 @@ QPID_AUTO_TEST_CASE(testStrictRingPolicy) ScopedSuppressLogging sl; // Suppress messages for expected errors. f.session.messageTransfer(arg::content=client::Message("Message_6", q)); BOOST_FAIL("expecting ResourceLimitExceededException."); - } catch (const ResourceLimitExceededException&) {} + } catch (const ResourceLimitExceededException&) {} } -QPID_AUTO_TEST_CASE(testPolicyWithDtx) +QPID_AUTO_TEST_CASE(testPolicyWithDtx) { FieldTable args; std::auto_ptr<QueuePolicy> policy = QueuePolicy::createQueuePolicy(5, 0, QueuePolicy::REJECT); @@ -207,7 +210,7 @@ QPID_AUTO_TEST_CASE(testPolicyWithDtx) LocalQueue incoming; SubscriptionSettings settings(FlowControl::unlimited()); settings.autoAck = 0; // no auto ack. - Subscription sub = f.subs.subscribe(incoming, q, settings); + Subscription sub = f.subs.subscribe(incoming, q, settings); f.session.dtxSelect(); Xid tx1(1, "test-dtx-mgr", "tx1"); f.session.dtxStart(arg::xid=tx1); @@ -244,7 +247,7 @@ QPID_AUTO_TEST_CASE(testPolicyWithDtx) ScopedSuppressLogging sl; // Suppress messages for expected errors. other.messageTransfer(arg::content=client::Message("Message_6", q)); BOOST_FAIL("expecting ResourceLimitExceededException."); - } catch (const ResourceLimitExceededException&) {} + } catch (const ResourceLimitExceededException&) {} f.session.dtxCommit(arg::xid=tx3); //now retry and this time should succeed @@ -252,7 +255,7 @@ QPID_AUTO_TEST_CASE(testPolicyWithDtx) other.messageTransfer(arg::content=client::Message("Message_6", q)); } -QPID_AUTO_TEST_CASE(testFlowToDiskWithNoStore) +QPID_AUTO_TEST_CASE(testFlowToDiskWithNoStore) { //Ensure that with no store loaded, we don't flow to disk but //fallback to rejecting messages @@ -265,7 +268,7 @@ QPID_AUTO_TEST_CASE(testFlowToDiskWithNoStore) LocalQueue incoming; SubscriptionSettings settings(FlowControl::unlimited()); settings.autoAck = 0; // no auto ack. - Subscription sub = f.subs.subscribe(incoming, q, settings); + Subscription sub = f.subs.subscribe(incoming, q, settings); for (int i = 0; i < 5; i++) { f.session.messageTransfer(arg::content=client::Message((boost::format("%1%_%2%") % "Message" % (i+1)).str(), q)); } @@ -276,8 +279,10 @@ QPID_AUTO_TEST_CASE(testFlowToDiskWithNoStore) ScopedSuppressLogging sl; // Suppress messages for expected errors. f.session.messageTransfer(arg::content=client::Message("Message_6", q)); BOOST_FAIL("expecting ResourceLimitExceededException."); - } catch (const ResourceLimitExceededException&) {} + } catch (const ResourceLimitExceededException&) {} } QPID_AUTO_TEST_SUITE_END() + +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/QueueRegistryTest.cpp b/qpid/cpp/src/tests/QueueRegistryTest.cpp index 7ad4e0b89d..712cb568c3 100644 --- a/qpid/cpp/src/tests/QueueRegistryTest.cpp +++ b/qpid/cpp/src/tests/QueueRegistryTest.cpp @@ -6,9 +6,9 @@ * 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 @@ -23,6 +23,9 @@ using namespace qpid::broker; +namespace qpid { +namespace tests { + QPID_AUTO_TEST_SUITE(QueueRegistryTest) QPID_AUTO_TEST_CASE(testDeclare) @@ -49,7 +52,7 @@ QPID_AUTO_TEST_CASE(testDeclare) BOOST_CHECK_EQUAL(bar, q->getName()); } -QPID_AUTO_TEST_CASE(testDeclareTmp) +QPID_AUTO_TEST_CASE(testDeclareTmp) { QueueRegistry reg; std::pair<Queue::shared_ptr, bool> qc; @@ -58,8 +61,8 @@ QPID_AUTO_TEST_CASE(testDeclareTmp) BOOST_CHECK(qc.second); BOOST_CHECK_EQUAL(std::string("tmp_1"), qc.first->getName()); } - -QPID_AUTO_TEST_CASE(testFind) + +QPID_AUTO_TEST_CASE(testFind) { std::string foo("foo"); std::string bar("bar"); @@ -75,7 +78,7 @@ QPID_AUTO_TEST_CASE(testFind) BOOST_CHECK_EQUAL(bar, q->getName()); } -QPID_AUTO_TEST_CASE(testDestroy) +QPID_AUTO_TEST_CASE(testDestroy) { std::string foo("foo"); QueueRegistry reg; @@ -92,3 +95,5 @@ QPID_AUTO_TEST_CASE(testDestroy) } QPID_AUTO_TEST_SUITE_END() + +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/QueueTest.cpp b/qpid/cpp/src/tests/QueueTest.cpp index b70afa52a7..841a19f7c1 100644 --- a/qpid/cpp/src/tests/QueueTest.cpp +++ b/qpid/cpp/src/tests/QueueTest.cpp @@ -7,9 +7,9 @@ * 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 @@ -39,9 +39,12 @@ using namespace qpid::broker; using namespace qpid::framing; using namespace qpid::sys; +namespace qpid { +namespace tests { + class TestConsumer : public virtual Consumer{ public: - typedef boost::shared_ptr<TestConsumer> shared_ptr; + typedef boost::shared_ptr<TestConsumer> shared_ptr; intrusive_ptr<Message> last; bool received; @@ -82,68 +85,68 @@ QPID_AUTO_TEST_SUITE(QueueTestSuite) QPID_AUTO_TEST_CASE(testAsyncMessage) { Queue::shared_ptr queue(new Queue("my_test_queue", true)); intrusive_ptr<Message> received; - + TestConsumer::shared_ptr c1(new TestConsumer()); queue->consume(c1); - - + + //Test basic delivery: intrusive_ptr<Message> msg1 = create_message("e", "A"); msg1->enqueueAsync(queue, 0);//this is done on enqueue which is not called from process queue->process(msg1); sleep(2); - + BOOST_CHECK(!c1->received); msg1->enqueueComplete(); - + received = queue->get().payload; - BOOST_CHECK_EQUAL(msg1.get(), received.get()); + BOOST_CHECK_EQUAL(msg1.get(), received.get()); } - - + + QPID_AUTO_TEST_CASE(testAsyncMessageCount){ Queue::shared_ptr queue(new Queue("my_test_queue", true)); intrusive_ptr<Message> msg1 = create_message("e", "A"); msg1->enqueueAsync(queue, 0);//this is done on enqueue which is not called from process - + queue->process(msg1); sleep(2); uint32_t compval=0; BOOST_CHECK_EQUAL(compval, queue->getMessageCount()); msg1->enqueueComplete(); compval=1; - BOOST_CHECK_EQUAL(compval, queue->getMessageCount()); + BOOST_CHECK_EQUAL(compval, queue->getMessageCount()); } QPID_AUTO_TEST_CASE(testConsumers){ Queue::shared_ptr queue(new Queue("my_queue", true)); - + //Test adding consumers: TestConsumer::shared_ptr c1(new TestConsumer()); TestConsumer::shared_ptr c2(new TestConsumer()); queue->consume(c1); queue->consume(c2); - + BOOST_CHECK_EQUAL(uint32_t(2), queue->getConsumerCount()); - + //Test basic delivery: intrusive_ptr<Message> msg1 = create_message("e", "A"); intrusive_ptr<Message> msg2 = create_message("e", "B"); intrusive_ptr<Message> msg3 = create_message("e", "C"); - + queue->deliver(msg1); BOOST_CHECK(queue->dispatch(c1)); BOOST_CHECK_EQUAL(msg1.get(), c1->last.get()); - + queue->deliver(msg2); BOOST_CHECK(queue->dispatch(c2)); BOOST_CHECK_EQUAL(msg2.get(), c2->last.get()); - + c1->received = false; queue->deliver(msg3); BOOST_CHECK(queue->dispatch(c1)); - BOOST_CHECK_EQUAL(msg3.get(), c1->last.get()); - + BOOST_CHECK_EQUAL(msg3.get(), c1->last.get()); + //Test cancellation: queue->cancel(c1); BOOST_CHECK_EQUAL(uint32_t(1), queue->getConsumerCount()); @@ -157,15 +160,15 @@ QPID_AUTO_TEST_CASE(testRegistry){ registry.declare("queue1", true, true); registry.declare("queue2", true, true); registry.declare("queue3", true, true); - + BOOST_CHECK(registry.find("queue1")); BOOST_CHECK(registry.find("queue2")); BOOST_CHECK(registry.find("queue3")); - + registry.destroy("queue1"); registry.destroy("queue2"); registry.destroy("queue3"); - + BOOST_CHECK(!registry.find("queue1")); BOOST_CHECK(!registry.find("queue2")); BOOST_CHECK(!registry.find("queue3")); @@ -177,13 +180,13 @@ QPID_AUTO_TEST_CASE(testDequeue){ intrusive_ptr<Message> msg2 = create_message("e", "B"); intrusive_ptr<Message> msg3 = create_message("e", "C"); intrusive_ptr<Message> received; - + queue->deliver(msg1); queue->deliver(msg2); queue->deliver(msg3); - + BOOST_CHECK_EQUAL(uint32_t(3), queue->getMessageCount()); - + received = queue->get().payload; BOOST_CHECK_EQUAL(msg1.get(), received.get()); BOOST_CHECK_EQUAL(uint32_t(2), queue->getMessageCount()); @@ -204,7 +207,7 @@ QPID_AUTO_TEST_CASE(testDequeue){ received = queue->get().payload; BOOST_CHECK(!received); BOOST_CHECK_EQUAL(uint32_t(0), queue->getMessageCount()); - + } QPID_AUTO_TEST_CASE(testBound) @@ -236,7 +239,7 @@ QPID_AUTO_TEST_CASE(testBound) queue->unbind(exchanges, queue); //ensure the remaining exchanges don't still have the queue bound to them: - FailOnDeliver deliverable; + FailOnDeliver deliverable; exchange1->route(deliverable, key, &args); exchange3->route(deliverable, key, &args); } @@ -245,10 +248,10 @@ QPID_AUTO_TEST_CASE(testPersistLastNodeStanding){ client::QueueOptions args; args.setPersistLastNode(); - + Queue::shared_ptr queue(new Queue("my-queue", true)); queue->configure(args); - + intrusive_ptr<Message> msg1 = create_message("e", "A"); intrusive_ptr<Message> msg2 = create_message("e", "B"); intrusive_ptr<Message> msg3 = create_message("e", "C"); @@ -256,13 +259,13 @@ QPID_AUTO_TEST_CASE(testPersistLastNodeStanding){ //enqueue 2 messages queue->deliver(msg1); queue->deliver(msg2); - + //change mode queue->setLastNodeFailure(); - + //enqueue 1 message queue->deliver(msg3); - + //check all have persistent ids. BOOST_CHECK(msg1->isPersistent()); BOOST_CHECK(msg2->isPersistent()); @@ -277,7 +280,7 @@ class TestMessageStoreOC : public NullMessageStore uint enqCnt; uint deqCnt; bool error; - + virtual void dequeue(TransactionContext*, const boost::intrusive_ptr<PersistableMessage>& /*msg*/, const PersistableQueue& /*queue*/) @@ -298,7 +301,7 @@ class TestMessageStoreOC : public NullMessageStore { error=true; } - + TestMessageStoreOC() : NullMessageStore(),enqCnt(0),deqCnt(0),error(false) {} ~TestMessageStoreOC(){} }; @@ -312,7 +315,7 @@ QPID_AUTO_TEST_CASE(testLVQOrdering){ Queue::shared_ptr queue(new Queue("my-queue", true )); queue->configure(args); - + intrusive_ptr<Message> msg1 = create_message("e", "A"); intrusive_ptr<Message> msg2 = create_message("e", "B"); intrusive_ptr<Message> msg3 = create_message("e", "C"); @@ -324,27 +327,27 @@ QPID_AUTO_TEST_CASE(testLVQOrdering){ string key; args.getLVQKey(key); BOOST_CHECK_EQUAL(key, "qpid.LVQ_key"); - + msg1->getProperties<MessageProperties>()->getApplicationHeaders().setString(key,"a"); msg2->getProperties<MessageProperties>()->getApplicationHeaders().setString(key,"b"); msg3->getProperties<MessageProperties>()->getApplicationHeaders().setString(key,"c"); msg4->getProperties<MessageProperties>()->getApplicationHeaders().setString(key,"a"); - + //enqueue 4 message queue->deliver(msg1); queue->deliver(msg2); queue->deliver(msg3); queue->deliver(msg4); - + BOOST_CHECK_EQUAL(queue->getMessageCount(), 3u); - + received = queue->get().payload; BOOST_CHECK_EQUAL(msg4.get(), received.get()); received = queue->get().payload; BOOST_CHECK_EQUAL(msg2.get(), received.get()); - + received = queue->get().payload; BOOST_CHECK_EQUAL(msg3.get(), received.get()); @@ -357,18 +360,18 @@ QPID_AUTO_TEST_CASE(testLVQOrdering){ queue->deliver(msg5); queue->deliver(msg6); queue->deliver(msg7); - + BOOST_CHECK_EQUAL(queue->getMessageCount(), 3u); - + received = queue->get().payload; BOOST_CHECK_EQUAL(msg5.get(), received.get()); received = queue->get().payload; BOOST_CHECK_EQUAL(msg6.get(), received.get()); - + received = queue->get().payload; BOOST_CHECK_EQUAL(msg7.get(), received.get()); - + } QPID_AUTO_TEST_CASE(testLVQEmptyKey){ @@ -379,20 +382,20 @@ QPID_AUTO_TEST_CASE(testLVQEmptyKey){ Queue::shared_ptr queue(new Queue("my-queue", true )); queue->configure(args); - + intrusive_ptr<Message> msg1 = create_message("e", "A"); intrusive_ptr<Message> msg2 = create_message("e", "B"); string key; args.getLVQKey(key); BOOST_CHECK_EQUAL(key, "qpid.LVQ_key"); - + msg1->getProperties<MessageProperties>()->getApplicationHeaders().setString(key,"a"); queue->deliver(msg1); queue->deliver(msg2); BOOST_CHECK_EQUAL(queue->getMessageCount(), 2u); - + } QPID_AUTO_TEST_CASE(testLVQAcquire){ @@ -403,7 +406,7 @@ QPID_AUTO_TEST_CASE(testLVQAcquire){ Queue::shared_ptr queue(new Queue("my-queue", true )); queue->configure(args); - + intrusive_ptr<Message> msg1 = create_message("e", "A"); intrusive_ptr<Message> msg2 = create_message("e", "B"); intrusive_ptr<Message> msg3 = create_message("e", "C"); @@ -416,7 +419,7 @@ QPID_AUTO_TEST_CASE(testLVQAcquire){ string key; args.getLVQKey(key); BOOST_CHECK_EQUAL(key, "qpid.LVQ_key"); - + msg1->getProperties<MessageProperties>()->getApplicationHeaders().setString(key,"a"); msg2->getProperties<MessageProperties>()->getApplicationHeaders().setString(key,"b"); @@ -424,13 +427,13 @@ QPID_AUTO_TEST_CASE(testLVQAcquire){ msg4->getProperties<MessageProperties>()->getApplicationHeaders().setString(key,"a"); msg5->getProperties<MessageProperties>()->getApplicationHeaders().setString(key,"b"); msg6->getProperties<MessageProperties>()->getApplicationHeaders().setString(key,"c"); - + //enqueue 4 message queue->deliver(msg1); queue->deliver(msg2); queue->deliver(msg3); queue->deliver(msg4); - + BOOST_CHECK_EQUAL(queue->getMessageCount(), 3u); framing::SequenceNumber sequence(1); @@ -439,9 +442,9 @@ QPID_AUTO_TEST_CASE(testLVQAcquire){ BOOST_CHECK(!queue->acquire(qmsg)); BOOST_CHECK(queue->acquire(qmsg2)); - + BOOST_CHECK_EQUAL(queue->getMessageCount(), 2u); - + queue->deliver(msg5); BOOST_CHECK_EQUAL(queue->getMessageCount(), 3u); @@ -449,11 +452,11 @@ QPID_AUTO_TEST_CASE(testLVQAcquire){ args.setOrdering(client::LVQ_NO_BROWSE); queue->configure(args); TestConsumer::shared_ptr c1(new TestConsumer(false)); - + queue->dispatch(c1); queue->dispatch(c1); queue->dispatch(c1); - + queue->deliver(msg6); BOOST_CHECK_EQUAL(queue->getMessageCount(), 3u); @@ -474,7 +477,7 @@ QPID_AUTO_TEST_CASE(testLVQMultiQueue){ intrusive_ptr<Message> received; queue1->configure(args); queue2->configure(args); - + intrusive_ptr<Message> msg1 = create_message("e", "A"); intrusive_ptr<Message> msg2 = create_message("e", "A"); @@ -484,17 +487,17 @@ QPID_AUTO_TEST_CASE(testLVQMultiQueue){ msg1->getProperties<MessageProperties>()->getApplicationHeaders().setString(key,"a"); msg2->getProperties<MessageProperties>()->getApplicationHeaders().setString(key,"a"); - + queue1->deliver(msg1); queue2->deliver(msg1); queue1->deliver(msg2); - + received = queue1->get().payload; BOOST_CHECK_EQUAL(msg2.get(), received.get()); received = queue2->get().payload; BOOST_CHECK_EQUAL(msg1.get(), received.get()); - + } QPID_AUTO_TEST_CASE(testLVQRecover){ @@ -518,7 +521,7 @@ QPID_AUTO_TEST_CASE(testLVQRecover){ Queue::shared_ptr queue1(new Queue("my-queue", true, &testStore)); intrusive_ptr<Message> received; queue1->configure(args); - + intrusive_ptr<Message> msg1 = create_message("e", "A"); intrusive_ptr<Message> msg2 = create_message("e", "A"); // 2 @@ -544,7 +547,7 @@ QPID_AUTO_TEST_CASE(testLVQRecover){ BOOST_CHECK_EQUAL(testStore.deqCnt, 1u); } -void addMessagesToQueue(uint count, Queue& queue, uint oddTtl = 200, uint evenTtl = 0) +void addMessagesToQueue(uint count, Queue& queue, uint oddTtl = 200, uint evenTtl = 0) { for (uint i = 0; i < count; i++) { intrusive_ptr<Message> m = create_message("exchange", "key"); @@ -592,7 +595,7 @@ QPID_AUTO_TEST_CASE(testMultiQueueLastNode){ queue1->configure(args); Queue::shared_ptr queue2(new Queue("queue2", true, &testStore )); queue2->configure(args); - + intrusive_ptr<Message> msg1 = create_message("e", "A"); queue1->deliver(msg1); @@ -623,7 +626,7 @@ QPID_AUTO_TEST_CASE(testMultiQueueLastNode){ // check no failure messages are stored queue1->clearLastNodeFailure(); queue2->clearLastNodeFailure(); - + intrusive_ptr<Message> msg3 = create_message("e", "B"); queue1->deliver(msg3); queue2->deliver(msg3); @@ -631,7 +634,7 @@ QPID_AUTO_TEST_CASE(testMultiQueueLastNode){ queue1->setLastNodeFailure(); queue2->setLastNodeFailure(); BOOST_CHECK_EQUAL(testStore.enqCnt, 6u); - + // check requeue 1 intrusive_ptr<Message> msg4 = create_message("e", "C"); intrusive_ptr<Message> msg5 = create_message("e", "D"); @@ -639,17 +642,17 @@ QPID_AUTO_TEST_CASE(testMultiQueueLastNode){ framing::SequenceNumber sequence(1); QueuedMessage qmsg1(queue1.get(), msg4, sequence); QueuedMessage qmsg2(queue2.get(), msg5, ++sequence); - + queue1->requeue(qmsg1); BOOST_CHECK_EQUAL(testStore.enqCnt, 7u); - + // check requeue 2 queue2->clearLastNodeFailure(); queue2->requeue(qmsg2); BOOST_CHECK_EQUAL(testStore.enqCnt, 7u); queue2->setLastNodeFailure(); BOOST_CHECK_EQUAL(testStore.enqCnt, 8u); - + queue2->clearLastNodeFailure(); queue2->setLastNodeFailure(); BOOST_CHECK_EQUAL(testStore.enqCnt, 8u); @@ -664,8 +667,8 @@ simulate this: 4. stop and recover remaining node 5. add another node 6. kill that new node again -make sure that an attempt to re-enqueue a message does not happen which will -result in the last man standing exiting with an error. +make sure that an attempt to re-enqueue a message does not happen which will +result in the last man standing exiting with an error. we need to make sure that recover is safe, i.e. messages are not requeued to the store. @@ -678,7 +681,7 @@ not requeued to the store. Queue::shared_ptr queue1(new Queue("my-queue", true, &testStore)); intrusive_ptr<Message> received; queue1->configure(args); - + // check requeue 1 intrusive_ptr<Message> msg1 = create_message("e", "C"); intrusive_ptr<Message> msg2 = create_message("e", "D"); @@ -711,17 +714,29 @@ simulate store excption going into last node standing Queue::shared_ptr queue1(new Queue("my-queue", true, &testStore)); intrusive_ptr<Message> received; queue1->configure(args); - + // check requeue 1 intrusive_ptr<Message> msg1 = create_message("e", "C"); queue1->deliver(msg1); testStore.createError(); - + ScopedSuppressLogging sl; // Suppress messages for expected errors. queue1->setLastNodeFailure(); BOOST_CHECK_EQUAL(testStore.enqCnt, 0u); -}QPID_AUTO_TEST_SUITE_END() +} + +intrusive_ptr<Message> mkMsg(std::string exchange, std::string routingKey) { + intrusive_ptr<Message> msg(new Message()); + AMQFrame method((MessageTransferBody(ProtocolVersion(), exchange, 0, 0))); + AMQFrame header((AMQHeaderBody())); + msg->getFrames().append(method); + msg->getFrames().append(header); + msg->getFrames().getHeaders()->get<DeliveryProperties>(true)->setRoutingKey(routingKey); + return msg; +} +QPID_AUTO_TEST_SUITE_END() +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/RangeSet.cpp b/qpid/cpp/src/tests/RangeSet.cpp index 9c602de78d..db3a964086 100644 --- a/qpid/cpp/src/tests/RangeSet.cpp +++ b/qpid/cpp/src/tests/RangeSet.cpp @@ -24,6 +24,9 @@ using namespace std; using namespace qpid; +namespace qpid { +namespace tests { + QPID_AUTO_TEST_SUITE(RangeSetTestSuite) typedef qpid::Range<int> TestRange; @@ -44,8 +47,8 @@ QPID_AUTO_TEST_CASE(testRangeSetAddPoint) { BOOST_CHECK_MESSAGE(r.contains(TestRange(3,4)), r); BOOST_CHECK(!r.empty()); r += 5; - BOOST_CHECK_MESSAGE(r.contains(5), r); - BOOST_CHECK_MESSAGE(r.contains(TestRange(5,6)), r); + BOOST_CHECK_MESSAGE(r.contains(5), r); + BOOST_CHECK_MESSAGE(r.contains(TestRange(5,6)), r); BOOST_CHECK_MESSAGE(!r.contains(TestRange(3,6)), r); r += 4; BOOST_CHECK_MESSAGE(r.contains(TestRange(3,6)), r); @@ -139,3 +142,5 @@ QPID_AUTO_TEST_CASE(testRangeContaining) { } QPID_AUTO_TEST_SUITE_END() + +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/RateFlowcontrolTest.cpp b/qpid/cpp/src/tests/RateFlowcontrolTest.cpp index b8fda09f61..80ad06af8c 100644 --- a/qpid/cpp/src/tests/RateFlowcontrolTest.cpp +++ b/qpid/cpp/src/tests/RateFlowcontrolTest.cpp @@ -7,9 +7,9 @@ * 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 @@ -27,25 +27,28 @@ using namespace qpid::broker; using namespace qpid::sys; +namespace qpid { +namespace tests { + QPID_AUTO_TEST_SUITE(RateFlowcontrolTestSuite) QPID_AUTO_TEST_CASE(RateFlowcontrolTest) { // BOOST_CHECK(predicate); // BOOST_CHECK_EQUAL(a, b); - + RateFlowcontrol fc(100); AbsTime n=AbsTime::now(); - + BOOST_CHECK_EQUAL( fc.receivedMessage(n, 0), 0U ); - + fc.sentCredit(n, 0); - + BOOST_CHECK_EQUAL( fc.receivedMessage(n, 0), 0U ); fc.sentCredit(n, 50); Duration d=250*TIME_MSEC; - + n = AbsTime(n,d); BOOST_CHECK_EQUAL( fc.receivedMessage(n, 25), 0U ); BOOST_CHECK_EQUAL( fc.availableCredit(n), 25U ); @@ -64,3 +67,5 @@ QPID_AUTO_TEST_CASE(RateFlowcontrolTest) } QPID_AUTO_TEST_SUITE_END() + +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/RefCounted.cpp b/qpid/cpp/src/tests/RefCounted.cpp index 8c679a3d2e..e4c1da5696 100644 --- a/qpid/cpp/src/tests/RefCounted.cpp +++ b/qpid/cpp/src/tests/RefCounted.cpp @@ -27,6 +27,9 @@ using boost::intrusive_ptr; using namespace std; using namespace qpid; +namespace qpid { +namespace tests { + struct CountMe : public RefCounted { static int instances; CountMe() { ++instances; } @@ -48,3 +51,5 @@ QPID_AUTO_TEST_CASE(testRefCounted) { } QPID_AUTO_TEST_SUITE_END() + +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/ReplicationTest.cpp b/qpid/cpp/src/tests/ReplicationTest.cpp index 38dc1a9e52..ed768f1306 100644 --- a/qpid/cpp/src/tests/ReplicationTest.cpp +++ b/qpid/cpp/src/tests/ReplicationTest.cpp @@ -7,9 +7,9 @@ * 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 @@ -42,6 +42,9 @@ using namespace qpid::framing; using namespace qpid::replication::constants; using boost::assign::list_of; +namespace qpid { +namespace tests { + QPID_AUTO_TEST_SUITE(ReplicationTestSuite) // The CMake-based build passes in the module suffix; if it's not there, this @@ -63,7 +66,7 @@ qpid::broker::Broker::Options getBrokerOpts(const std::vector<std::string>& args return opts; } -QPID_AUTO_TEST_CASE(testReplicationExchange) +QPID_AUTO_TEST_CASE(testReplicationExchange) { qpid::broker::Broker::Options brokerOpts(getBrokerOpts(list_of<string>("qpidd") ("--replication-exchange-name=qpid.replication"))); @@ -79,7 +82,7 @@ QPID_AUTO_TEST_CASE(testReplicationExchange) f.session.queueDeclare(arg::queue=eventQ, arg::exclusive=true, arg::autoDelete=true, arg::arguments=eventQopts); f.session.exchangeBind(arg::exchange="qpid.replication", arg::queue=eventQ, arg::bindingKey=dataQ); - + f.session.queueDeclare(arg::queue=eventQ2, arg::exclusive=true, arg::autoDelete=true, arg::arguments=eventQopts); f.session.exchangeBind(arg::exchange="qpid.replication", arg::queue=eventQ2, arg::bindingKey=dataQ2); @@ -133,3 +136,5 @@ QPID_AUTO_TEST_CASE(testReplicationExchange) QPID_AUTO_TEST_SUITE_END() + +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/RetryList.cpp b/qpid/cpp/src/tests/RetryList.cpp index 80f59bf15f..d1d22348a3 100644 --- a/qpid/cpp/src/tests/RetryList.cpp +++ b/qpid/cpp/src/tests/RetryList.cpp @@ -24,6 +24,9 @@ using namespace qpid; using namespace qpid::broker; +namespace qpid { +namespace tests { + QPID_AUTO_TEST_SUITE(RetryListTestSuite) struct RetryListFixture @@ -36,7 +39,7 @@ struct RetryListFixture { urls.push_back(Url(s)); } - + void addExpectation(const std::string& host, uint16_t port) { expected.push_back(TcpAddress(host, port)); @@ -57,7 +60,7 @@ struct RetryListFixture } }; -QPID_AUTO_TEST_CASE(testWithSingleAddress) +QPID_AUTO_TEST_CASE(testWithSingleAddress) { RetryListFixture test; test.addUrl("amqp:host:5673"); @@ -65,7 +68,7 @@ QPID_AUTO_TEST_CASE(testWithSingleAddress) test.check(); } -QPID_AUTO_TEST_CASE(testWithSingleUrlOfMultipleAddresses) +QPID_AUTO_TEST_CASE(testWithSingleUrlOfMultipleAddresses) { RetryListFixture test; test.addUrl("amqp:host1,host2:2222,tcp:host3:5673,host4:1"); @@ -78,7 +81,7 @@ QPID_AUTO_TEST_CASE(testWithSingleUrlOfMultipleAddresses) test.check(); } -QPID_AUTO_TEST_CASE(testWithMultipleUrlsOfMultipleAddresses) +QPID_AUTO_TEST_CASE(testWithMultipleUrlsOfMultipleAddresses) { RetryListFixture test; test.addUrl("amqp:my-host"); @@ -97,10 +100,12 @@ QPID_AUTO_TEST_CASE(testWithMultipleUrlsOfMultipleAddresses) test.check(); } -QPID_AUTO_TEST_CASE(testEmptyList) +QPID_AUTO_TEST_CASE(testEmptyList) { RetryListFixture test; test.check(); } QPID_AUTO_TEST_SUITE_END() + +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/SequenceNumberTest.cpp b/qpid/cpp/src/tests/SequenceNumberTest.cpp index e4c6d066ef..f3c934e3ca 100644 --- a/qpid/cpp/src/tests/SequenceNumberTest.cpp +++ b/qpid/cpp/src/tests/SequenceNumberTest.cpp @@ -7,9 +7,9 @@ * 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 @@ -26,6 +26,8 @@ using namespace qpid::framing; +namespace qpid { +namespace tests { void checkDifference(SequenceNumber& a, SequenceNumber& b, int gap) { @@ -54,7 +56,7 @@ void checkComparison(SequenceNumber& a, SequenceNumber& b, int gap) BOOST_CHECK(++a < ++b);//test prefix } //keep incrementing until a also wraps around - for (int i = 0; i < (gap + 2); i++) { + for (int i = 0; i < (gap + 2); i++) { BOOST_CHECK(a++ < b++);//test postfix } //let a 'catch up' @@ -91,7 +93,7 @@ QPID_AUTO_TEST_CASE(testIncrementPostfix) BOOST_CHECK(b != c); } -QPID_AUTO_TEST_CASE(testIncrementPrefix) +QPID_AUTO_TEST_CASE(testIncrementPrefix) { SequenceNumber a; SequenceNumber b; @@ -203,3 +205,5 @@ QPID_AUTO_TEST_CASE(testDifferenceWithWrapAround2) } QPID_AUTO_TEST_SUITE_END() + +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/SequenceSet.cpp b/qpid/cpp/src/tests/SequenceSet.cpp index ba2f1391a1..aaeb68e3c5 100644 --- a/qpid/cpp/src/tests/SequenceSet.cpp +++ b/qpid/cpp/src/tests/SequenceSet.cpp @@ -20,6 +20,9 @@ #include "unit_test.h" #include <list> +namespace qpid { +namespace tests { + QPID_AUTO_TEST_SUITE(SequenceSetTestSuite) using namespace qpid::framing; @@ -72,7 +75,7 @@ QPID_AUTO_TEST_CASE(testAdd) { BOOST_CHECK(!s.contains(i)); RangeExpectations().expect(2, 5).expect(8, 8).check(s); - + SequenceSet t; t.add(6, 10); t.add(s); @@ -90,7 +93,7 @@ QPID_AUTO_TEST_CASE(testAdd2) { SequenceSet s; s.add(7,6); s.add(4,4); - s.add(3,10); + s.add(3,10); s.add(2); RangeExpectations().expect(2, 10).check(s); } @@ -137,4 +140,4 @@ QPID_AUTO_TEST_CASE(testRemove) { QPID_AUTO_TEST_SUITE_END() - +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/SessionState.cpp b/qpid/cpp/src/tests/SessionState.cpp index 5e21ff2b70..157cabfb63 100644 --- a/qpid/cpp/src/tests/SessionState.cpp +++ b/qpid/cpp/src/tests/SessionState.cpp @@ -28,6 +28,9 @@ #include <functional> #include <numeric> +namespace qpid { +namespace tests { + QPID_AUTO_TEST_SUITE(SessionStateTestSuite) using namespace std; @@ -94,7 +97,7 @@ size_t transfer1(qpid::SessionState& s, string content) { size_t transfer1Char(qpid::SessionState& s, char content) { return transfer1(s, string(1,content)); } - + // Send transfer frame with multiple single-byte content frames. size_t transferN(qpid::SessionState& s, string content) { size_t size=send(s, transferFrame(!content.empty())); @@ -134,7 +137,7 @@ QPID_AUTO_TEST_CASE(testSendGetReplyList) { BOOST_CHECK_EQUAL(str(s.senderExpected(SessionPoint(0,0))),"CabcCdCeCfCxyz"); // Ignore controls. s.senderRecord(AMQFrame(new SessionFlushBody())); - BOOST_CHECK_EQUAL(str(s.senderExpected(SessionPoint(2,0))),"CeCfCxyz"); + BOOST_CHECK_EQUAL(str(s.senderExpected(SessionPoint(2,0))),"CeCfCxyz"); } QPID_AUTO_TEST_CASE(testNeedFlush) { @@ -185,7 +188,7 @@ QPID_AUTO_TEST_CASE(testPeerConfirmed) { s.senderConfirmed(SessionPoint(5)); BOOST_CHECK_EQUAL(str(s.senderExpected(SessionPoint(5,0))), "CxCy"); BOOST_CHECK(s.senderNeedFlush()); - + s.senderConfirmed(SessionPoint(6)); BOOST_CHECK_EQUAL(str(s.senderExpected(SessionPoint(6,0))), "Cy"); BOOST_CHECK(!s.senderNeedFlush()); @@ -195,7 +198,7 @@ QPID_AUTO_TEST_CASE(testPeerCompleted) { qpid::SessionState s; s.setTimeout(1); s.senderGetCommandPoint(); - // Completion implies confirmation + // Completion implies confirmation transfers(s, "abc"); BOOST_CHECK_EQUAL(str(s.senderExpected(SessionPoint(0,0))), "CaCbCc"); SequenceSet set(SequenceSet() + 0 + 1); @@ -205,7 +208,7 @@ QPID_AUTO_TEST_CASE(testPeerCompleted) { transfers(s, "def"); // We dont do out-of-order confirmation, so this will only confirm up to 3: set = SequenceSet(SequenceSet() + 2 + 3 + 5); - s.senderCompleted(set); + s.senderCompleted(set); BOOST_CHECK_EQUAL(str(s.senderExpected(SessionPoint(4,0))), "CeCf"); } @@ -215,11 +218,11 @@ QPID_AUTO_TEST_CASE(testReceive) { s.receiverSetCommandPoint(SessionPoint()); BOOST_CHECK_EQUAL(s.receiverGetExpected(), SessionPoint(0)); BOOST_CHECK_EQUAL(s.receiverGetReceived(), SessionPoint(0)); - + BOOST_CHECK(s.receiverRecord(transferFrame(false))); BOOST_CHECK_EQUAL(s.receiverGetExpected(), SessionPoint(1)); BOOST_CHECK_EQUAL(s.receiverGetReceived(), SessionPoint(1)); - + BOOST_CHECK(s.receiverRecord(transferFrame(true))); SessionPoint point = SessionPoint(1, transferFrameSize()); BOOST_CHECK_EQUAL(s.receiverGetExpected(), point); @@ -297,3 +300,5 @@ QPID_AUTO_TEST_CASE(testNeedKnownCompleted) { QPID_AUTO_TEST_SUITE_END() + +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/Shlib.cpp b/qpid/cpp/src/tests/Shlib.cpp index 7d2f2456c7..692cfcdff9 100644 --- a/qpid/cpp/src/tests/Shlib.cpp +++ b/qpid/cpp/src/tests/Shlib.cpp @@ -24,6 +24,9 @@ #include "unit_test.h" +namespace qpid { +namespace tests { + QPID_AUTO_TEST_SUITE(ShlibTestSuite) using namespace qpid::sys; @@ -51,7 +54,7 @@ QPID_AUTO_TEST_CASE(testShlib) { } catch (const qpid::Exception&) {} } - + QPID_AUTO_TEST_CASE(testAutoShlib) { int unloaded = 0; { @@ -66,6 +69,8 @@ QPID_AUTO_TEST_CASE(testAutoShlib) { } BOOST_CHECK_EQUAL(42, unloaded); } - + QPID_AUTO_TEST_SUITE_END() + +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/SocketProxy.h b/qpid/cpp/src/tests/SocketProxy.h index ccce3c8842..9df32a1336 100644 --- a/qpid/cpp/src/tests/SocketProxy.h +++ b/qpid/cpp/src/tests/SocketProxy.h @@ -35,8 +35,11 @@ #include "qpid/sys/Mutex.h" #include "qpid/log/Statement.h" +namespace qpid { +namespace tests { + /** - * A simple socket proxy that forwards to another socket. + * A simple socket proxy that forwards to another socket. * Used between client & local broker to simulate network failures. */ class SocketProxy : private qpid::sys::Runnable @@ -59,7 +62,7 @@ class SocketProxy : private qpid::sys::Runnable joined = false; thread = qpid::sys::Thread(static_cast<qpid::sys::Runnable*>(this)); } - + ~SocketProxy() { close(); if (!joined) thread.join(); } /** Simulate a network disconnect. */ @@ -88,7 +91,7 @@ class SocketProxy : private qpid::sys::Runnable } uint16_t getPort() const { return port; } - + private: static void throwErrno(const std::string& msg) { throw qpid::Exception(msg+":"+qpid::sys::strError(errno)); @@ -153,7 +156,7 @@ class SocketProxy : private qpid::sys::Runnable } try { if (server.get()) server->close(); - close(); + close(); } catch (const std::exception& e) { QPID_LOG(debug, "SocketProxy::run exception in client/server close()" << e.what()); @@ -169,4 +172,6 @@ class SocketProxy : private qpid::sys::Runnable bool dropClient, dropServer; }; +}} // namespace qpid::tests + #endif diff --git a/qpid/cpp/src/tests/TestMessageStore.h b/qpid/cpp/src/tests/TestMessageStore.h index be1ed57349..20e0b755b2 100644 --- a/qpid/cpp/src/tests/TestMessageStore.h +++ b/qpid/cpp/src/tests/TestMessageStore.h @@ -10,9 +10,9 @@ * 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 @@ -28,6 +28,9 @@ using namespace qpid; using namespace qpid::broker; using namespace qpid::framing; +namespace qpid { +namespace tests { + typedef std::pair<string, boost::intrusive_ptr<PersistableMessage> > msg_queue_pair; class TestMessageStore : public NullMessageStore @@ -35,7 +38,7 @@ class TestMessageStore : public NullMessageStore public: std::vector<boost::intrusive_ptr<PersistableMessage> > dequeued; std::vector<msg_queue_pair> enqueued; - + void dequeue(TransactionContext*, const boost::intrusive_ptr<PersistableMessage>& msg, const PersistableQueue& /*queue*/) @@ -47,7 +50,7 @@ class TestMessageStore : public NullMessageStore const boost::intrusive_ptr<PersistableMessage>& msg, const PersistableQueue& queue) { - msg->enqueueComplete(); + msg->enqueueComplete(); enqueued.push_back(msg_queue_pair(queue.getName(), msg)); } @@ -55,4 +58,6 @@ class TestMessageStore : public NullMessageStore ~TestMessageStore(){} }; +}} // namespace qpid::tests + #endif diff --git a/qpid/cpp/src/tests/TestOptions.h b/qpid/cpp/src/tests/TestOptions.h index a400fe5ecb..f8da0f59cf 100644 --- a/qpid/cpp/src/tests/TestOptions.h +++ b/qpid/cpp/src/tests/TestOptions.h @@ -9,9 +9,9 @@ * 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 @@ -67,7 +67,7 @@ struct TestOptions : public qpid::Options connection.open(con); } - + bool help; ConnectionOptions con; qpid::log::Options log; diff --git a/qpid/cpp/src/tests/TimerTest.cpp b/qpid/cpp/src/tests/TimerTest.cpp index 2642c980ba..1552421ba0 100644 --- a/qpid/cpp/src/tests/TimerTest.cpp +++ b/qpid/cpp/src/tests/TimerTest.cpp @@ -8,9 +8,9 @@ * 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 @@ -32,6 +32,9 @@ using namespace qpid::sys; using boost::intrusive_ptr; using boost::dynamic_pointer_cast; +namespace qpid { +namespace tests { + class Counter { Mutex lock; @@ -44,7 +47,7 @@ class Counter return ++counter; } }; - + class TestTask : public TimerTask { const AbsTime start; @@ -56,7 +59,7 @@ class TestTask : public TimerTask Counter& counter; public: - TestTask(Duration timeout, Counter& _counter) + TestTask(Duration timeout, Counter& _counter) : TimerTask(timeout), start(now()), expected(timeout), end(start), fired(false), counter(_counter) {} void fire() @@ -106,14 +109,14 @@ QPID_AUTO_TEST_CASE(testGeneral) intrusive_ptr<TestTask> task2(new TestTask(Duration(1 * TIME_SEC), counter)); intrusive_ptr<TestTask> task3(new TestTask(Duration(4 * TIME_SEC), counter)); intrusive_ptr<TestTask> task4(new TestTask(Duration(2 * TIME_SEC), counter)); - + timer.add(task1); timer.add(task2); timer.add(task3); timer.add(task4); - + dynamic_pointer_cast<TestTask>(task3)->wait(Duration(6 * TIME_SEC)); - + dynamic_pointer_cast<TestTask>(task1)->check(3); dynamic_pointer_cast<TestTask>(task2)->check(1); dynamic_pointer_cast<TestTask>(task3)->check(4); @@ -121,3 +124,5 @@ QPID_AUTO_TEST_CASE(testGeneral) } QPID_AUTO_TEST_SUITE_END() + +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/TopicExchangeTest.cpp b/qpid/cpp/src/tests/TopicExchangeTest.cpp index d707066534..c103620dbf 100644 --- a/qpid/cpp/src/tests/TopicExchangeTest.cpp +++ b/qpid/cpp/src/tests/TopicExchangeTest.cpp @@ -6,9 +6,9 @@ * 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 @@ -22,11 +22,15 @@ using namespace qpid::broker; using namespace std; + +namespace qpid { +namespace tests { + QPID_AUTO_TEST_SUITE(TopicExchangeTestSuite) #define CHECK_NORMALIZED(expect, pattern) BOOST_CHECK_EQUAL(expect, TopicExchange::normalize(pattern)); -QPID_AUTO_TEST_CASE(testNormalize) +QPID_AUTO_TEST_CASE(testNormalize) { CHECK_NORMALIZED("", ""); CHECK_NORMALIZED("a.b.c", "a.b.c"); @@ -38,8 +42,8 @@ QPID_AUTO_TEST_CASE(testNormalize) CHECK_NORMALIZED("a.*.*.*.#", "a.*.#.*.#.*"); CHECK_NORMALIZED("*.*.*.#", "*.#.#.*.*.#"); } - -QPID_AUTO_TEST_CASE(testPlain) + +QPID_AUTO_TEST_CASE(testPlain) { string pattern("ab.cd.e"); BOOST_CHECK(TopicExchange::match(pattern, "ab.cd.e")); @@ -57,7 +61,7 @@ QPID_AUTO_TEST_CASE(testPlain) } -QPID_AUTO_TEST_CASE(testStar) +QPID_AUTO_TEST_CASE(testStar) { string pattern("a.*.b"); BOOST_CHECK(TopicExchange::match(pattern, "a.xx.b")); @@ -75,7 +79,7 @@ QPID_AUTO_TEST_CASE(testStar) BOOST_CHECK(!TopicExchange::match(pattern, "q.x.y")); } -QPID_AUTO_TEST_CASE(testHash) +QPID_AUTO_TEST_CASE(testHash) { string pattern("a.#.b"); BOOST_CHECK(TopicExchange::match(pattern, "a.b")); @@ -99,7 +103,7 @@ QPID_AUTO_TEST_CASE(testHash) BOOST_CHECK(TopicExchange::match(pattern, "a.x.x.b.y.y.c")); } -QPID_AUTO_TEST_CASE(testMixed) +QPID_AUTO_TEST_CASE(testMixed) { string pattern("*.x.#.y"); BOOST_CHECK(TopicExchange::match(pattern, "a.x.y")); @@ -119,3 +123,5 @@ QPID_AUTO_TEST_CASE(testMixed) } QPID_AUTO_TEST_SUITE_END() + +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/TxBufferTest.cpp b/qpid/cpp/src/tests/TxBufferTest.cpp index 3d6a12cacc..4807026ab7 100644 --- a/qpid/cpp/src/tests/TxBufferTest.cpp +++ b/qpid/cpp/src/tests/TxBufferTest.cpp @@ -7,9 +7,9 @@ * 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 @@ -27,6 +27,9 @@ using namespace qpid::broker; using boost::static_pointer_cast; +namespace qpid { +namespace tests { + QPID_AUTO_TEST_SUITE(TxBufferTestSuite) QPID_AUTO_TEST_CASE(testCommitLocal) @@ -174,3 +177,5 @@ QPID_AUTO_TEST_CASE(testBufferIsClearedAfterCommit) } QPID_AUTO_TEST_SUITE_END() + +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/TxMocks.h b/qpid/cpp/src/tests/TxMocks.h index fe103c5fe5..a34d864bae 100644 --- a/qpid/cpp/src/tests/TxMocks.h +++ b/qpid/cpp/src/tests/TxMocks.h @@ -7,9 +7,9 @@ * 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 @@ -32,6 +32,9 @@ using namespace qpid::broker; using boost::static_pointer_cast; using std::string; +namespace qpid { +namespace tests { + template <class T> void assertEqualVector(std::vector<T>& expected, std::vector<T>& actual){ unsigned int i = 0; while(i < expected.size() && i < actual.size()){ @@ -62,15 +65,15 @@ class MockTxOp : public TxOp, public TxOpConstants{ string debugName; public: typedef boost::shared_ptr<MockTxOp> shared_ptr; - + MockTxOp() : failOnPrepare(false) {} MockTxOp(bool _failOnPrepare) : failOnPrepare(_failOnPrepare) {} - + void setDebugName(string name){ debugName = name; } - void printExpected(){ + void printExpected(){ std::cout << std::endl << "MockTxOp[" << debugName << "] expects: "; for (std::vector<string>::iterator i = expected.begin(); i < expected.end(); i++) { if(i != expected.begin()) std::cout << ", "; @@ -79,7 +82,7 @@ public: std::cout << std::endl; } - void printActual(){ + void printActual(){ std::cout << std::endl << "MockTxOp[" << debugName << "] actual: "; for (std::vector<string>::iterator i = actual.begin(); i < actual.end(); i++) { if(i != actual.begin()) std::cout << ", "; @@ -87,7 +90,7 @@ public: } std::cout << std::endl; } - + bool prepare(TransactionContext*) throw(){ actual.push_back(PREPARE); return !failOnPrepare; @@ -116,8 +119,8 @@ public: } void accept(TxOpConstVisitor&) const {} - - ~MockTxOp(){} + + ~MockTxOp(){} }; class MockTransactionalStore : public TransactionalStore{ @@ -128,10 +131,10 @@ class MockTransactionalStore : public TransactionalStore{ const string ABORT; std::vector<string> expected; std::vector<string> actual; - + enum states {OPEN = 1, PREPARED = 2, COMMITTED = 3, ABORTED = 4}; int state; - + class TestTransactionContext : public TPCTransactionContext{ MockTransactionalStore* store; public: @@ -145,29 +148,29 @@ class MockTransactionalStore : public TransactionalStore{ if(!store->isOpen() && !store->isPrepared()) throw "txn already completed"; store->state = COMMITTED; } - + void abort(){ if(!store->isOpen() && !store->isPrepared()) throw "txn already completed"; store->state = ABORTED; } ~TestTransactionContext(){} }; - + public: MockTransactionalStore() : BEGIN("BEGIN"), BEGIN2PC("BEGIN2PC"), PREPARE("PREPARE"), COMMIT("COMMIT"), ABORT("ABORT"), state(OPEN){} void collectPreparedXids(std::set<std::string>&) { - throw "Operation not supported"; + throw "Operation not supported"; } - - std::auto_ptr<TPCTransactionContext> begin(const std::string&){ + + std::auto_ptr<TPCTransactionContext> begin(const std::string&){ actual.push_back(BEGIN2PC); std::auto_ptr<TPCTransactionContext> txn(new TestTransactionContext(this)); return txn; } - std::auto_ptr<TransactionContext> begin(){ + std::auto_ptr<TransactionContext> begin(){ actual.push_back(BEGIN); std::auto_ptr<TransactionContext> txn(new TestTransactionContext(this)); return txn; @@ -183,7 +186,7 @@ public: void abort(TransactionContext& ctxt){ actual.push_back(ABORT); dynamic_cast<TestTransactionContext&>(ctxt).abort(); - } + } MockTransactionalStore& expectBegin(){ expected.push_back(BEGIN); return *this; @@ -207,23 +210,25 @@ public: void check(){ assertEqualVector(expected, actual); } - + bool isPrepared(){ return state == PREPARED; } - + bool isCommitted(){ return state == COMMITTED; } - + bool isAborted(){ return state == ABORTED; } - + bool isOpen() const{ return state == OPEN; } ~MockTransactionalStore(){} }; +}} // namespace qpid::tests + #endif diff --git a/qpid/cpp/src/tests/TxPublishTest.cpp b/qpid/cpp/src/tests/TxPublishTest.cpp index 63dbf99266..fabb01b864 100644 --- a/qpid/cpp/src/tests/TxPublishTest.cpp +++ b/qpid/cpp/src/tests/TxPublishTest.cpp @@ -7,9 +7,9 @@ * 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 @@ -35,30 +35,33 @@ using boost::intrusive_ptr; using namespace qpid::broker; using namespace qpid::framing; +namespace qpid { +namespace tests { + struct TxPublishTest { - + TestMessageStore store; Queue::shared_ptr queue1; Queue::shared_ptr queue2; intrusive_ptr<Message> msg; TxPublish op; - + TxPublishTest() : - queue1(new Queue("queue1", false, &store, 0)), - queue2(new Queue("queue2", false, &store, 0)), + queue1(new Queue("queue1", false, &store, 0)), + queue2(new Queue("queue2", false, &store, 0)), msg(MessageUtils::createMessage("exchange", "routing_key", "id")), op(msg) { msg->getProperties<DeliveryProperties>()->setDeliveryMode(PERSISTENT); op.deliverTo(queue1); op.deliverTo(queue2); - } + } }; QPID_AUTO_TEST_SUITE(TxPublishTestSuite) - + QPID_AUTO_TEST_CASE(testPrepare) { TxPublishTest t; @@ -88,7 +91,9 @@ QPID_AUTO_TEST_CASE(testCommit) BOOST_CHECK_EQUAL(t.msg, msg_dequeue); BOOST_CHECK_EQUAL((uint32_t) 1, t.queue2->getMessageCount()); - BOOST_CHECK_EQUAL(t.msg, t.queue2->get().payload); + BOOST_CHECK_EQUAL(t.msg, t.queue2->get().payload); } QPID_AUTO_TEST_SUITE_END() + +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/Url.cpp b/qpid/cpp/src/tests/Url.cpp index f3b42a7208..343186eb1f 100644 --- a/qpid/cpp/src/tests/Url.cpp +++ b/qpid/cpp/src/tests/Url.cpp @@ -26,6 +26,9 @@ using namespace std; using namespace qpid; using namespace boost::assign; +namespace qpid { +namespace tests { + QPID_AUTO_TEST_SUITE(UrlTestSuite) #define URL_CHECK_STR(STR) BOOST_CHECK_EQUAL(Url(STR).str(), STR) @@ -65,3 +68,5 @@ QPID_AUTO_TEST_CASE(TestInvalidAddress) { } QPID_AUTO_TEST_SUITE_END() + +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/Uuid.cpp b/qpid/cpp/src/tests/Uuid.cpp index ea2e80b63b..a6ddb9b5a5 100644 --- a/qpid/cpp/src/tests/Uuid.cpp +++ b/qpid/cpp/src/tests/Uuid.cpp @@ -24,6 +24,9 @@ #include <set> +namespace qpid { +namespace tests { + QPID_AUTO_TEST_SUITE(UuidTestSuite) using namespace std; @@ -77,3 +80,5 @@ QPID_AUTO_TEST_CASE(testUuidEncodeDecode) { } QPID_AUTO_TEST_SUITE_END() + +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/Variant.cpp b/qpid/cpp/src/tests/Variant.cpp index b7ce776827..2d68bb842c 100644 --- a/qpid/cpp/src/tests/Variant.cpp +++ b/qpid/cpp/src/tests/Variant.cpp @@ -7,9 +7,9 @@ * 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 @@ -25,6 +25,9 @@ using namespace qpid::messaging; +namespace qpid { +namespace tests { + QPID_AUTO_TEST_SUITE(VariantSuite) QPID_AUTO_TEST_CASE(testConversions) @@ -94,11 +97,11 @@ QPID_AUTO_TEST_CASE(testAssignment) const uint32_t i(1000); value = i; BOOST_CHECK_EQUAL(VAR_UINT32, value.getType()); - BOOST_CHECK_EQUAL(VAR_STRING, other.getType()); + BOOST_CHECK_EQUAL(VAR_STRING, other.getType()); } QPID_AUTO_TEST_CASE(testList) -{ +{ const std::string s("abc"); const float f(9.876f); const int16_t x(1000); @@ -108,7 +111,7 @@ QPID_AUTO_TEST_CASE(testList) value.asList().push_back(Variant(f)); value.asList().push_back(Variant(x)); BOOST_CHECK_EQUAL(3u, value.asList().size()); - Variant::List::const_iterator i = value.asList().begin(); + Variant::List::const_iterator i = value.asList().begin(); BOOST_CHECK(i != value.asList().end()); BOOST_CHECK_EQUAL(VAR_STRING, i->getType()); @@ -129,7 +132,7 @@ QPID_AUTO_TEST_CASE(testList) } QPID_AUTO_TEST_CASE(testMap) -{ +{ const std::string red("red"); const float pi(3.14f); const int16_t x(1000); @@ -145,7 +148,7 @@ QPID_AUTO_TEST_CASE(testMap) BOOST_CHECK_EQUAL(VAR_FLOAT, value.asMap()["pi"].getType()); BOOST_CHECK_EQUAL(pi, value.asMap()["pi"].asFloat()); - + BOOST_CHECK_EQUAL(VAR_INT16, value.asMap()["my-key"].getType()); BOOST_CHECK_EQUAL(x, value.asMap()["my-key"].asInt16()); @@ -153,5 +156,7 @@ QPID_AUTO_TEST_CASE(testMap) BOOST_CHECK_EQUAL(VAR_STRING, value.asMap()["my-key"].getType()); BOOST_CHECK_EQUAL(std::string("now it's a string"), value.asMap()["my-key"].asString()); } - + QPID_AUTO_TEST_SUITE_END() + +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/XmlClientSessionTest.cpp b/qpid/cpp/src/tests/XmlClientSessionTest.cpp index b6b8520bd8..46a4c826a3 100644 --- a/qpid/cpp/src/tests/XmlClientSessionTest.cpp +++ b/qpid/cpp/src/tests/XmlClientSessionTest.cpp @@ -7,9 +7,9 @@ * 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 @@ -39,6 +39,9 @@ #include <vector> +namespace qpid { +namespace tests { + QPID_AUTO_TEST_SUITE(XmlClientSessionTest) using namespace qpid::client; @@ -118,10 +121,10 @@ QPID_AUTO_TEST_CASE(testXmlBinding) { FieldTable binding; binding.setString("xquery", "declare variable $color external;" "(./message/id mod 2 = 1) and ($color = 'blue')"); - f.session.exchangeBind(qpid::client::arg::exchange="xml", qpid::client::arg::queue="odd_blue", qpid::client::arg::bindingKey="query_name", qpid::client::arg::arguments=binding); + f.session.exchangeBind(qpid::client::arg::exchange="xml", qpid::client::arg::queue="odd_blue", qpid::client::arg::bindingKey="query_name", qpid::client::arg::arguments=binding); Message message; - message.getDeliveryProperties().setRoutingKey("query_name"); + message.getDeliveryProperties().setRoutingKey("query_name"); message.getHeaders().setString("color", "blue"); string m = "<message><id>1</id></message>"; @@ -130,7 +133,7 @@ QPID_AUTO_TEST_CASE(testXmlBinding) { f.session.messageTransfer(qpid::client::arg::content=message, qpid::client::arg::destination="xml"); Message m2 = localQueue.get(); - BOOST_CHECK_EQUAL(m, m2.getData()); + BOOST_CHECK_EQUAL(m, m2.getData()); } /** @@ -146,10 +149,10 @@ QPID_AUTO_TEST_CASE(testXMLBindMultipleQueues) { FieldTable blue; blue.setString("xquery", "./colour = 'blue'"); - f.session.exchangeBind(arg::exchange="xml", arg::queue="blue", arg::bindingKey="by-colour", arg::arguments=blue); + f.session.exchangeBind(arg::exchange="xml", arg::queue="blue", arg::bindingKey="by-colour", arg::arguments=blue); FieldTable red; red.setString("xquery", "./colour = 'red'"); - f.session.exchangeBind(arg::exchange="xml", arg::queue="red", arg::bindingKey="by-colour", arg::arguments=red); + f.session.exchangeBind(arg::exchange="xml", arg::queue="red", arg::bindingKey="by-colour", arg::arguments=red); Message sent1("<colour>blue</colour>", "by-colour"); f.session.messageTransfer(arg::content=sent1, arg::destination="xml"); @@ -223,3 +226,4 @@ olour", arg::arguments=blue); QPID_AUTO_TEST_SUITE_END() +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/acl.py b/qpid/cpp/src/tests/acl.py index b62288a769..fc53d2ce8b 100755 --- a/qpid/cpp/src/tests/acl.py +++ b/qpid/cpp/src/tests/acl.py @@ -61,7 +61,7 @@ class ACLTests(TestBase010): # ACL general tests #===================================== - def test_deny_all(self): + def test_deny_mode(self): """ Test the deny all mode """ @@ -71,7 +71,9 @@ class ACLTests(TestBase010): aclf.write('acl deny all all') aclf.close() - self.reload_acl() + result = self.reload_acl() + if (result.text.find("format error",0,len(result.text)) != -1): + self.fail(result) session = self.get_session('bob','bob') try: @@ -87,7 +89,7 @@ class ACLTests(TestBase010): except qpid.session.SessionException, e: self.assertEqual(530,e.args[0].error_code) - def test_allow_all(self): + def test_allow_mode(self): """ Test the allow all mode """ @@ -96,7 +98,9 @@ class ACLTests(TestBase010): aclf.write('acl allow all all') aclf.close() - self.reload_acl() + result = self.reload_acl() + if (result.text.find("format error",0,len(result.text)) != -1): + self.fail(result) session = self.get_session('bob','bob') try: @@ -124,7 +128,9 @@ class ACLTests(TestBase010): aclf.write('acl allow all all') aclf.close() - self.reload_acl() + result = self.reload_acl() + if (result.text.find("format error",0,len(result.text)) != -1): + self.fail(result) session = self.get_session('bob','bob') try: @@ -208,9 +214,9 @@ class ACLTests(TestBase010): # ACL queue tests #===================================== - def test_queue_acl(self): + def test_queue_allow_mode(self): """ - Test various modes for queue acl + Test cases for queue acl in allow mode """ aclf = ACLFile() aclf.write('acl deny bob@QPID create queue name=q1 durable=true passive=true\n') @@ -221,27 +227,35 @@ class ACLTests(TestBase010): aclf.write('acl allow all all') aclf.close() - self.reload_acl() + result = self.reload_acl() + if (result.text.find("format error",0,len(result.text)) != -1): + self.fail(result) session = self.get_session('bob','bob') try: - session.queue_declare(queue="q1", durable='true', passive='true') + session.queue_declare(queue="q1", durable=True, passive=True) self.fail("ACL should deny queue create request with name=q1 durable=true passive=true"); except qpid.session.SessionException, e: self.assertEqual(530,e.args[0].error_code) session = self.get_session('bob','bob') try: - session.queue_declare(queue="q2", exclusive='true') + session.queue_declare(queue="q2", exclusive=True) self.fail("ACL should deny queue create request with name=q2 exclusive=true"); except qpid.session.SessionException, e: self.assertEqual(530,e.args[0].error_code) session = self.get_session('bob','bob') try: - session.queue_declare(queue="q3", exclusive='true') - session.queue_declare(queue="q4", durable='true') + session.queue_declare(queue="q2", durable=True) + except qpid.session.SessionException, e: + if (530 == e.args[0].error_code): + self.fail("ACL should allow queue create request for q2 with any parameter other than exclusive=true"); + + try: + session.queue_declare(queue="q3", exclusive=True) + session.queue_declare(queue="q4", durable=True) except qpid.session.SessionException, e: if (530 == e.args[0].error_code): self.fail("ACL should allow queue create request for q3 and q4 with any parameter"); @@ -279,57 +293,185 @@ class ACLTests(TestBase010): if (530 == e.args[0].error_code): self.fail("ACL should allow queue delete request for q3"); + + def test_queue_deny_mode(self): + """ + Test cases for queue acl in deny mode + """ + aclf = ACLFile() + aclf.write('acl allow bob@QPID create queue name=q1 durable=true passive=true\n') + aclf.write('acl allow bob@QPID create queue name=q2 exclusive=true\n') + aclf.write('acl allow bob@QPID access queue name=q3\n') + aclf.write('acl allow bob@QPID purge queue name=q3\n') + aclf.write('acl allow bob@QPID create queue name=q3\n') + aclf.write('acl allow bob@QPID create queue name=q4\n') + aclf.write('acl allow bob@QPID delete queue name=q4\n') + aclf.write('acl allow guest@QPID all all\n') + aclf.write('acl deny all all') + aclf.close() + + result = self.reload_acl() + if (result.text.find("format error",0,len(result.text)) != -1): + self.fail(result) + + session = self.get_session('bob','bob') + + try: + session.queue_declare(queue="q1", durable=True, passive=True) + except qpid.session.SessionException, e: + if (530 == e.args[0].error_code): + self.fail("ACL should allow queue create request with name=q1 durable=true passive=true"); + + try: + session.queue_declare(queue="q1", durable=False, passive=False) + self.fail("ACL should deny queue create request with name=q1 durable=true passive=false"); + except qpid.session.SessionException, e: + self.assertEqual(530,e.args[0].error_code) + session = self.get_session('bob','bob') + + try: + session.queue_declare(queue="q2", exclusive=False) + self.fail("ACL should deny queue create request with name=q2 exclusive=false"); + except qpid.session.SessionException, e: + self.assertEqual(530,e.args[0].error_code) + session = self.get_session('bob','bob') + + try: + session.queue_declare(queue="q2", exclusive=True) + except qpid.session.SessionException, e: + if (530 == e.args[0].error_code): + self.fail("ACL should allow queue create request for q2 with exclusive=true"); + + try: + session.queue_declare(queue="q3") + session.queue_declare(queue="q4") + except qpid.session.SessionException, e: + if (530 == e.args[0].error_code): + self.fail("ACL should allow queue create request for q3 and q4"); + + try: + session.queue_query(queue="q4") + self.fail("ACL should deny queue query request for q4"); + except qpid.session.SessionException, e: + self.assertEqual(530,e.args[0].error_code) + session = self.get_session('bob','bob') + + try: + session.queue_purge(queue="q4") + self.fail("ACL should deny queue purge request for q4"); + except qpid.session.SessionException, e: + self.assertEqual(530,e.args[0].error_code) + session = self.get_session('bob','bob') + + try: + session.queue_purge(queue="q3") + except qpid.session.SessionException, e: + if (530 == e.args[0].error_code): + self.fail("ACL should allow queue purge request for q3"); + + try: + session.queue_query(queue="q3") + except qpid.session.SessionException, e: + if (530 == e.args[0].error_code): + self.fail("ACL should allow queue query request for q3"); + + try: + session.queue_delete(queue="q3") + self.fail("ACL should deny queue delete request for q3"); + except qpid.session.SessionException, e: + self.assertEqual(530,e.args[0].error_code) + session = self.get_session('bob','bob') + + try: + session.queue_delete(queue="q4") + except qpid.session.SessionException, e: + if (530 == e.args[0].error_code): + self.fail("ACL should allow queue delete request for q4"); + #===================================== # ACL exchange tests #===================================== - def test_exchange_acl(self): + def test_exchange_acl_allow_mode(self): + session = self.get_session('bob','bob') + session.queue_declare(queue="baz") + """ - Test various modes for exchange acl + Test cases for exchange acl in allow mode """ aclf = ACLFile() aclf.write('acl deny bob@QPID create exchange name=testEx durable=true passive=true\n') aclf.write('acl deny bob@QPID create exchange name=ex1 type=direct\n') - aclf.write('acl deny bob@QPID access exchange name=myEx\n') + aclf.write('acl deny bob@QPID access exchange name=myEx queuename=q1 routingkey=rk1.*\n') aclf.write('acl deny bob@QPID bind exchange name=myEx queuename=q1 routingkey=rk1\n') aclf.write('acl deny bob@QPID unbind exchange name=myEx queuename=q1 routingkey=rk1\n') - aclf.write('acl deny bob@QPID delete exchange name=myEx\n') + aclf.write('acl deny bob@QPID delete exchange name=myEx\n') aclf.write('acl allow all all') aclf.close() - self.reload_acl() + result = self.reload_acl() + if (result.text.find("format error",0,len(result.text)) != -1): + self.fail(result) session = self.get_session('bob','bob') - + session.queue_declare(queue='q1') + session.queue_declare(queue='q2') + session.exchange_declare(exchange='myEx', type='direct') + try: - session.exchange_declare(exchange='testEx', durable='true', passive='true') + session.exchange_declare(exchange='testEx', durable=True, passive=True) self.fail("ACL should deny exchange create request with name=testEx durable=true passive=true"); except qpid.session.SessionException, e: self.assertEqual(530,e.args[0].error_code) session = self.get_session('bob','bob') try: + session.exchange_declare(exchange='testEx', type='direct', durable=True, passive=False) + except qpid.session.SessionException, e: + print e + if (530 == e.args[0].error_code): + self.fail("ACL should allow exchange create request for testEx with any parameter other than durable=true and passive=true"); + + try: session.exchange_declare(exchange='ex1', type='direct') self.fail("ACL should deny exchange create request with name=ex1 type=direct"); - except qpid.session.SessionException, e: + except qpid.session.SessionException, e: self.assertEqual(530,e.args[0].error_code) session = self.get_session('bob','bob') try: session.exchange_declare(exchange='myXml', type='direct') - session.queue_declare(queue='q1') except qpid.session.SessionException, e: if (530 == e.args[0].error_code): self.fail("ACL should allow exchange create request for myXml with any parameter"); try: session.exchange_query(name='myEx') - self.fail("ACL should deny queue query request for q3"); + self.fail("ACL should deny exchange query request for myEx"); except qpid.session.SessionException, e: self.assertEqual(530,e.args[0].error_code) session = self.get_session('bob','bob') + + try: + session.exchange_bound(exchange='myEx', queue='q1', binding_key='rk1.*') + self.fail("ACL should deny exchange bound request for myEx with queuename=q1 and routing_key='rk1.*' "); + except qpid.session.SessionException, e: + self.assertEqual(530,e.args[0].error_code) + session = self.get_session('bob','bob') + + try: + session.exchange_query(name='amq.topic') + except qpid.session.SessionException, e: + if (530 == e.args[0].error_code): + self.fail("ACL should allow exchange query request for exchange='amq.topic'"); try: + session.exchange_bound(exchange='myEx', queue='q1', binding_key='rk2.*') + except qpid.session.SessionException, e: + if (530 == e.args[0].error_code): + self.fail("ACL should allow exchange bound request for myEx with queuename=q1 and binding_key='rk2.*'"); + + try: session.exchange_bind(exchange='myEx', queue='q1', binding_key='rk1') self.fail("ACL should deny exchange bind request with exchange='myEx' queuename='q1' bindingkey='rk1'"); except qpid.session.SessionException, e: @@ -337,10 +479,17 @@ class ACLTests(TestBase010): session = self.get_session('bob','bob') try: - session.exchange_bind(exchange='myXml', queue='q1', binding_key='x') + session.exchange_bind(exchange='myEx', queue='q1', binding_key='x') + except qpid.session.SessionException, e: + if (530 == e.args[0].error_code): + self.fail("ACL should allow exchange bind request for exchange='myEx', queue='q1', binding_key='x'"); + + try: + session.exchange_bind(exchange='myEx', queue='q2', binding_key='rk1') except qpid.session.SessionException, e: if (530 == e.args[0].error_code): - self.fail("ACL should allow exchange bind request for exchange='myXml', queue='q1', binding_key='x'"); + self.fail("ACL should allow exchange bind request for exchange='myEx', queue='q2', binding_key='rk1'"); + try: session.exchange_unbind(exchange='myEx', queue='q1', binding_key='rk1') self.fail("ACL should deny exchange unbind request with exchange='myEx' queuename='q1' bindingkey='rk1'"); @@ -349,10 +498,16 @@ class ACLTests(TestBase010): session = self.get_session('bob','bob') try: - session.exchange_unbind(exchange='myXml', queue='q1', binding_key='x') + session.exchange_unbind(exchange='myEx', queue='q1', binding_key='x') + except qpid.session.SessionException, e: + if (530 == e.args[0].error_code): + self.fail("ACL should allow exchange unbind request for exchange='myEx', queue='q1', binding_key='x'"); + + try: + session.exchange_unbind(exchange='myEx', queue='q2', binding_key='rk1') except qpid.session.SessionException, e: if (530 == e.args[0].error_code): - self.fail("ACL should allow exchange unbind request for exchange='myXml', queue='q1', binding_key='x'"); + self.fail("ACL should allow exchange unbind request for exchange='myEx', queue='q2', binding_key='rk1'"); try: session.exchange_delete(exchange='myEx') @@ -366,45 +521,161 @@ class ACLTests(TestBase010): except qpid.session.SessionException, e: if (530 == e.args[0].error_code): self.fail("ACL should allow exchange delete request for myXml"); - + + + def test_exchange_acl_deny_mode(self): + session = self.get_session('bob','bob') + session.queue_declare(queue='bar') + + """ + Test cases for exchange acl in deny mode + """ + aclf = ACLFile() + aclf.write('acl allow bob@QPID create exchange name=myEx durable=true passive=false\n') + aclf.write('acl allow bob@QPID bind exchange name=amq.topic queuename=bar routingkey=foo.*\n') + aclf.write('acl allow bob@QPID unbind exchange name=amq.topic queuename=bar routingkey=foo.*\n') + aclf.write('acl allow bob@QPID access exchange name=myEx queuename=q1 routingkey=rk1.*\n') + aclf.write('acl allow bob@QPID delete exchange name=myEx\n') + aclf.write('acl allow guest@QPID all all\n') + aclf.write('acl deny all all') + aclf.close() + + result = self.reload_acl() + if (result.text.find("format error",0,len(result.text)) != -1): + self.fail(result) + + session = self.get_session('bob','bob') + + try: + session.exchange_declare(exchange='myEx', type='direct', durable=True, passive=False) + except qpid.session.SessionException, e: + if (530 == e.args[0].error_code): + self.fail("ACL should allow exchange create request for myEx with durable=true and passive=false"); + try: + session.exchange_declare(exchange='myEx', type='direct', durable=False) + self.fail("ACL should deny exchange create request with name=myEx durable=false"); + except qpid.session.SessionException, e: + self.assertEqual(530,e.args[0].error_code) + session = self.get_session('bob','bob') + + try: + session.exchange_bind(exchange='amq.topic', queue='bar', binding_key='foo.bar') + except qpid.session.SessionException, e: + if (530 == e.args[0].error_code): + self.fail("ACL should allow exchange bind request for exchange='amq.topic', queue='bar', binding_key='foor.bar'"); + + try: + session.exchange_bind(exchange='amq.topic', queue='baz', binding_key='foo.bar') + self.fail("ACL should deny exchange bind request for exchange='amq.topic', queue='baz', binding_key='foo.bar'"); + except qpid.session.SessionException, e: + self.assertEqual(530,e.args[0].error_code) + session = self.get_session('bob','bob') + + try: + session.exchange_bind(exchange='amq.topic', queue='bar', binding_key='fooz.bar') + self.fail("ACL should deny exchange bind request for exchange='amq.topic', queue='bar', binding_key='fooz.bar'"); + except qpid.session.SessionException, e: + self.assertEqual(530,e.args[0].error_code) + session = self.get_session('bob','bob') + + try: + session.exchange_unbind(exchange='amq.topic', queue='bar', binding_key='foo.bar') + except qpid.session.SessionException, e: + if (530 == e.args[0].error_code): + self.fail("ACL should allow exchange unbind request for exchange='amq.topic', queue='bar', binding_key='foor.bar'"); + try: + session.exchange_unbind(exchange='amq.topic', queue='baz', binding_key='foo.bar') + self.fail("ACL should deny exchange unbind request for exchange='amq.topic', queue='baz', binding_key='foo.bar'"); + except qpid.session.SessionException, e: + self.assertEqual(530,e.args[0].error_code) + session = self.get_session('bob','bob') + + try: + session.exchange_unbind(exchange='amq.topic', queue='bar', binding_key='fooz.bar') + self.fail("ACL should deny exchange unbind request for exchange='amq.topic', queue='bar', binding_key='fooz.bar'"); + except qpid.session.SessionException, e: + self.assertEqual(530,e.args[0].error_code) + session = self.get_session('bob','bob') + + try: + session.exchange_query(name='amq.topic') + self.fail("ACL should deny exchange query request for amq.topic"); + except qpid.session.SessionException, e: + self.assertEqual(530,e.args[0].error_code) + session = self.get_session('bob','bob') + + try: + session.exchange_bound(exchange='myEx', queue='q1', binding_key='rk2.*') + self.fail("ACL should deny exchange bound request for amq.topic with queuename=q1 and routing_key='rk2.*' "); + except qpid.session.SessionException, e: + self.assertEqual(530,e.args[0].error_code) + session = self.get_session('bob','bob') + + try: + session.exchange_query(name='myEx') + except qpid.session.SessionException, e: + if (530 == e.args[0].error_code): + self.fail("ACL should allow exchange query request for exchange='myEx'"); + + try: + session.exchange_bound(exchange='myEx', queue='q1', binding_key='rk1.*') + except qpid.session.SessionException, e: + if (530 == e.args[0].error_code): + self.fail("ACL should allow exchange bound request for myEx with queuename=q1 and binding_key='rk1.*'"); + + try: + session.exchange_delete(exchange='myXml') + self.fail("ACL should deny exchange delete request for myXml"); + except qpid.session.SessionException, e: + self.assertEqual(530,e.args[0].error_code) + session = self.get_session('bob','bob') + + try: + session.exchange_delete(exchange='myEx') + except qpid.session.SessionException, e: + if (530 == e.args[0].error_code): + self.fail("ACL should allow exchange delete request for myEx"); + #===================================== # ACL consume tests #===================================== - def test_consume_acl(self): + def test_consume_allow_mode(self): """ - Test various consume acl + Test cases for consume in allow mode """ aclf = ACLFile() - aclf.write('acl deny bob@QPID consume queue name=q1 durable=true\n') - aclf.write('acl deny bob@QPID consume queue name=q2 exclusive=true\n') + aclf.write('acl deny bob@QPID consume queue name=q1\n') + aclf.write('acl deny bob@QPID consume queue name=q2\n') aclf.write('acl allow all all') aclf.close() - self.reload_acl() + result = self.reload_acl() + if (result.text.find("format error",0,len(result.text)) != -1): + self.fail(result) session = self.get_session('bob','bob') try: - session.queue_declare(queue='q1', durable='true') - session.queue_declare(queue='q2', exclusive='true') - session.queue_declare(queue='q3', durable='true') + session.queue_declare(queue='q1') + session.queue_declare(queue='q2') + session.queue_declare(queue='q3') except qpid.session.SessionException, e: if (530 == e.args[0].error_code): self.fail("ACL should allow create queue request"); try: session.message_subscribe(queue='q1', destination='myq1') - self.fail("ACL should deny message subscriber request for queue='q1'"); + self.fail("ACL should deny subscription for queue='q1'"); except qpid.session.SessionException, e: self.assertEqual(530,e.args[0].error_code) session = self.get_session('bob','bob') try: session.message_subscribe(queue='q2', destination='myq1') - self.fail("ACL should deny message subscriber request for queue='q2'"); + self.fail("ACL should deny subscription for queue='q2'"); except qpid.session.SessionException, e: self.assertEqual(530,e.args[0].error_code) session = self.get_session('bob','bob') @@ -413,9 +684,51 @@ class ACLTests(TestBase010): session.message_subscribe(queue='q3', destination='myq1') except qpid.session.SessionException, e: if (530 == e.args[0].error_code): - self.fail("ACL should allow create message subscribe"); + self.fail("ACL should allow subscription for q3"); + def test_consume_deny_mode(self): + """ + Test cases for consume in allow mode + """ + aclf = ACLFile() + aclf.write('acl allow bob@QPID consume queue name=q1\n') + aclf.write('acl allow bob@QPID consume queue name=q2\n') + aclf.write('acl allow bob@QPID create queue\n') + aclf.write('acl allow guest@QPID all\n') + aclf.write('acl deny all all') + aclf.close() + + result = self.reload_acl() + if (result.text.find("format error",0,len(result.text)) != -1): + self.fail(result) + + session = self.get_session('bob','bob') + + + try: + session.queue_declare(queue='q1') + session.queue_declare(queue='q2') + session.queue_declare(queue='q3') + except qpid.session.SessionException, e: + if (530 == e.args[0].error_code): + self.fail("ACL should allow create queue request"); + + try: + session.message_subscribe(queue='q1', destination='myq1') + session.message_subscribe(queue='q2', destination='myq2') + except qpid.session.SessionException, e: + if (530 == e.args[0].error_code): + self.fail("ACL should allow subscription for q1 and q2"); + + try: + session.message_subscribe(queue='q3', destination='myq3') + self.fail("ACL should deny subscription for queue='q3'"); + except qpid.session.SessionException, e: + self.assertEqual(530,e.args[0].error_code) + session = self.get_session('bob','bob') + + #===================================== # ACL publish tests #===================================== @@ -431,15 +744,11 @@ class ACLTests(TestBase010): aclf.write('acl allow all all') aclf.close() - self.reload_acl() + result = self.reload_acl() + if (result.text.find("format error",0,len(result.text)) != -1): + self.fail(result) session = self.get_session('bob','bob') - - try: - session.exchange_declare(exchange='myEx', type='topic') - except qpid.session.SessionException, e: - if (530 == e.args[0].error_code): - self.fail("ACL should allow exchange create request for myEx with any parameter"); props = session.delivery_properties(routing_key="rk1") @@ -458,6 +767,7 @@ class ACLTests(TestBase010): session = self.get_session('bob','bob') try: + session.exchange_declare(exchange='myEx', type='direct', durable=False) session.message_transfer(destination="myEx", message=Message(props,"Test")) except qpid.session.SessionException, e: if (530 == e.args[0].error_code): diff --git a/qpid/cpp/src/tests/client_test.cpp b/qpid/cpp/src/tests/client_test.cpp index 05b42f620c..2f5e8e5afe 100644 --- a/qpid/cpp/src/tests/client_test.cpp +++ b/qpid/cpp/src/tests/client_test.cpp @@ -7,9 +7,9 @@ * 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 @@ -40,13 +40,16 @@ using namespace qpid::client; using namespace qpid::framing; using std::string; +namespace qpid { +namespace tests { + struct Args : public TestOptions { uint msgSize; bool verbose; Args() : TestOptions("Simple test of Qpid c++ client; sends and receives a single message."), msgSize(26) { - addOptions() + addOptions() ("size", optValue(msgSize, "N"), "message size") ("verbose", optValue(verbose), "print out some status messages"); } @@ -58,7 +61,7 @@ std::string generateData(uint size) { if (size < chars.length()) { return chars.substr(0, size); - } + } std::string data; for (uint i = 0; i < (size / chars.length()); i++) { data += chars; @@ -78,6 +81,10 @@ void print(const std::string& text, const Message& msg) std::cout << std::endl; } +}} // namespace qpid::tests + +using namespace qpid::tests; + int main(int argc, char** argv) { try { @@ -92,7 +99,7 @@ int main(int argc, char** argv) //Create and open a session on the connection through which //most functionality is exposed: Session session = connection.newSession(); - if (opts.verbose) 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 @@ -116,13 +123,13 @@ int main(int argc, char** argv) // Using the SubscriptionManager, get the message from the queue. SubscriptionManager subs(session); Message msgIn = subs.get("MyQueue"); - if (msgIn.getData() == msgOut.getData()) + if (msgIn.getData() == msgOut.getData()) if (opts.verbose) std::cout << "Received the exepected message." << std::endl; //close the session & connection session.close(); if (opts.verbose) std::cout << "Closed session." << std::endl; - connection.close(); + connection.close(); if (opts.verbose) std::cout << "Closed connection." << std::endl; return 0; } catch(const std::exception& e) { diff --git a/qpid/cpp/src/tests/cluster_test.cpp b/qpid/cpp/src/tests/cluster_test.cpp index 50ca241b5d..28fcdd13ad 100644 --- a/qpid/cpp/src/tests/cluster_test.cpp +++ b/qpid/cpp/src/tests/cluster_test.cpp @@ -59,8 +59,6 @@ template <class T> ostream& operator<<(ostream& o, const std::set<T>& s) { return seqPrint(o, s); } } -QPID_AUTO_TEST_SUITE(cluster_test) - using namespace std; using namespace qpid; using namespace qpid::cluster; @@ -70,6 +68,11 @@ using namespace boost::assign; using broker::Broker; using boost::shared_ptr; +namespace qpid { +namespace tests { + +QPID_AUTO_TEST_SUITE(cluster_test) + bool durableFlag = std::getenv("STORE_LIB") != 0; void prepareArgs(ClusterFixture::Args& args, const bool durableFlag = false) { @@ -1098,3 +1101,5 @@ QPID_AUTO_TEST_CASE(testRelease) { } QPID_AUTO_TEST_SUITE_END() + +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/consume.cpp b/qpid/cpp/src/tests/consume.cpp index 3aacf8b3da..69110d151f 100644 --- a/qpid/cpp/src/tests/consume.cpp +++ b/qpid/cpp/src/tests/consume.cpp @@ -7,9 +7,9 @@ * 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 @@ -36,6 +36,9 @@ using namespace qpid::client; using namespace qpid::sys; using namespace std; +namespace qpid { +namespace tests { + typedef vector<string> StringSet; struct Args : public qpid::TestOptions { @@ -46,7 +49,7 @@ struct Args : public qpid::TestOptions { bool summary; bool print; bool durable; - + Args() : count(1000), ack(0), queue("publish-consume"), declare(false), summary(false), print(false) { @@ -63,12 +66,12 @@ struct Args : public qpid::TestOptions { Args opts; -struct Client +struct Client { Connection connection; Session session; - Client() + Client() { opts.open(connection); session = connection.newSession(); @@ -85,7 +88,7 @@ struct Client settings.flowControl = FlowControl(opts.count, SubscriptionManager::UNLIMITED,false); Subscription sub = subs.subscribe(lq, opts.queue, settings); Message msg; - AbsTime begin=now(); + AbsTime begin=now(); for (size_t i = 0; i < opts.count; ++i) { msg=lq.pop(); QPID_LOG(info, "Received: " << msg.getMessageProperties().getCorrelationId()); @@ -99,7 +102,7 @@ struct Client else cout << "Time: " << secs << "s Rate: " << opts.count/secs << endl; } - ~Client() + ~Client() { try{ session.close(); @@ -110,6 +113,10 @@ struct Client } }; +}} // namespace qpid::tests + +using namespace qpid::tests; + int main(int argc, char** argv) { try { diff --git a/qpid/cpp/src/tests/datagen.cpp b/qpid/cpp/src/tests/datagen.cpp index 175f14cc57..acbc07d63c 100644 --- a/qpid/cpp/src/tests/datagen.cpp +++ b/qpid/cpp/src/tests/datagen.cpp @@ -7,9 +7,9 @@ * 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 @@ -25,7 +25,10 @@ #include <time.h> #include "qpid/Options.h" -struct Args : public qpid::Options +namespace qpid { +namespace tests { + +struct Args : public qpid::Options { uint count; uint minSize; @@ -34,12 +37,12 @@ struct Args : public qpid::Options uint maxChar; bool help; - Args() : qpid::Options("Random data generator"), - count(1), minSize(8), maxSize(4096), + Args() : qpid::Options("Random data generator"), + count(1), minSize(8), maxSize(4096), minChar(32), maxChar(126),//safely printable ascii chars help(false) { - addOptions() + addOptions() ("count", qpid::optValue(count, "N"), "number of data strings to generate") ("min-size", qpid::optValue(minSize, "N"), "minimum size of data string") ("max-size", qpid::optValue(maxSize, "N"), "maximum size of data string") @@ -81,6 +84,10 @@ std::string generateData(uint size, uint min, uint max) return data; } +}} // namespace qpid::tests + +using namespace qpid::tests; + int main(int argc, char** argv) { Args opts; diff --git a/qpid/cpp/src/tests/echotest.cpp b/qpid/cpp/src/tests/echotest.cpp index 98590e35ff..ab26dcf3fd 100644 --- a/qpid/cpp/src/tests/echotest.cpp +++ b/qpid/cpp/src/tests/echotest.cpp @@ -7,9 +7,9 @@ * 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 @@ -33,6 +33,9 @@ using namespace qpid::framing; using namespace qpid::sys; using namespace std; +namespace qpid { +namespace tests { + struct Args : public qpid::Options, public qpid::client::ConnectionSettings { @@ -48,7 +51,7 @@ struct Args : public qpid::Options, ("help", optValue(help), "Print this usage statement") ("count", optValue(count, "N"), "Number of messages to send") ("size", optValue(count, "N"), "Size of messages") - ("broker,b", optValue(host, "HOST"), "Broker host to connect to") + ("broker,b", optValue(host, "HOST"), "Broker host to connect to") ("port,p", optValue(port, "PORT"), "Broker port to connect to") ("username", optValue(username, "USER"), "user name for broker log in.") ("password", optValue(password, "PASSWORD"), "password for broker log in.") @@ -75,7 +78,7 @@ class Listener : public MessageListener Message request; double total, min, max; bool summary; - + public: Listener(Session& session, uint limit, bool summary); void start(uint size); @@ -92,7 +95,7 @@ void Listener::start(uint size) { session.queueDeclare(arg::queue=queue, arg::exclusive=true, arg::autoDelete=true); request.getDeliveryProperties().setRoutingKey(queue); - subscriptions.subscribe(*this, queue, SubscriptionSettings(FlowControl::unlimited(), ACCEPT_MODE_NONE)); + subscriptions.subscribe(*this, queue, SubscriptionSettings(FlowControl::unlimited(), ACCEPT_MODE_NONE)); request.getDeliveryProperties().setTimestamp(current_time()); if (size) request.setData(std::string(size, 'X')); @@ -100,7 +103,7 @@ void Listener::start(uint size) subscriptions.run(); } -void Listener::received(Message& response) +void Listener::received(Message& response) { //extract timestamp and compute latency: uint64_t sentAt = response.getDeliveryProperties().getTimestamp(); @@ -122,7 +125,11 @@ void Listener::received(Message& response) } } -int main(int argc, char** argv) +}} // namespace qpid::tests + +using namespace qpid::tests; + +int main(int argc, char** argv) { Args opts; opts.parse(argc, argv); diff --git a/qpid/cpp/src/tests/exception_test.cpp b/qpid/cpp/src/tests/exception_test.cpp index 379e957ef1..0e9a948f00 100644 --- a/qpid/cpp/src/tests/exception_test.cpp +++ b/qpid/cpp/src/tests/exception_test.cpp @@ -7,9 +7,9 @@ * 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 @@ -28,6 +28,9 @@ #include "qpid/sys/Thread.h" #include "qpid/framing/reply_exceptions.h" +namespace qpid { +namespace tests { + QPID_AUTO_TEST_SUITE(exception_test) // FIXME aconway 2008-06-12: need to update our exception handling to @@ -49,12 +52,12 @@ struct Catcher : public Runnable { function<void ()> f; bool caught; Thread thread; - + Catcher(function<void ()> f_) : f(f_), caught(false), thread(this) {} ~Catcher() { join(); } - + void run() { - try { + try { ScopedSuppressLogging sl; // Suppress messages for expected errors. f(); } @@ -110,7 +113,7 @@ QPID_AUTO_TEST_CASE(DisconnectedListen) { Catcher<TransportFailure> runner(bind(&SubscriptionManager::run, boost::ref(fix.subs))); fix.connection.proxy.close(); runner.join(); - BOOST_CHECK_THROW(fix.session.close(), TransportFailure); + BOOST_CHECK_THROW(fix.session.close(), TransportFailure); } QPID_AUTO_TEST_CASE(NoSuchQueueTest) { @@ -120,3 +123,5 @@ QPID_AUTO_TEST_CASE(NoSuchQueueTest) { } QPID_AUTO_TEST_SUITE_END() + +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/failover_soak.cpp b/qpid/cpp/src/tests/failover_soak.cpp index 08691912aa..39d72e258a 100644 --- a/qpid/cpp/src/tests/failover_soak.cpp +++ b/qpid/cpp/src/tests/failover_soak.cpp @@ -7,9 +7,9 @@ * 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 @@ -51,7 +51,8 @@ using namespace qpid::framing; using namespace qpid::client; - +namespace qpid { +namespace tests { typedef vector<ForkedBroker *> brokerVector; @@ -90,9 +91,9 @@ ostream& operator<< ( ostream& os, const childType& ct ) { struct child { - child ( string & name, pid_t pid, childType type ) + child ( string & name, pid_t pid, childType type ) : name(name), pid(pid), retval(-999), status(RUNNING), type(type) - { + { gettimeofday ( & startTime, 0 ); } @@ -107,7 +108,7 @@ struct child void - setType ( childType t ) + setType ( childType t ) { type = t; } @@ -126,7 +127,7 @@ struct child struct children : public vector<child *> -{ +{ void add ( string & name, pid_t pid, childType type ) @@ -135,7 +136,7 @@ struct children : public vector<child *> } - child * + child * get ( pid_t pid ) { vector<child *>::iterator i; @@ -155,7 +156,7 @@ struct children : public vector<child *> { if ( verbosity > 1 ) { - cerr << "children::exited warning: Can't find child with pid " + cerr << "children::exited warning: Can't find child with pid " << pid << endl; } @@ -192,7 +193,7 @@ struct children : public vector<child *> << endl; return (*i)->retval; } - + return 0; } @@ -226,11 +227,11 @@ struct children : public vector<child *> children allMyChildren; -void -childExit ( int ) +void +childExit ( int ) { - int childReturnCode; - pid_t pid = waitpid ( 0, & childReturnCode, WNOHANG); + int childReturnCode; + pid_t pid = waitpid ( 0, & childReturnCode, WNOHANG); if ( pid > 0 ) allMyChildren.exited ( pid, childReturnCode ); @@ -270,10 +271,10 @@ printBrokers ( brokerVector & brokers ) { cout << "Broker List ------------ size: " << brokers.size() << "\n"; for ( brokerVector::iterator i = brokers.begin(); i != brokers.end(); ++ i) { - cout << "pid: " - << (*i)->getPID() - << " port: " - << (*i)->getPort() + cout << "pid: " + << (*i)->getPID() + << " port: " + << (*i)->getPort() << endl; } cout << "end Broker List ------------\n"; @@ -293,7 +294,7 @@ wait_for_newbie ( ) if ( ! newbie ) return true; - try + try { Connection connection; connection.open ( "127.0.0.1", newbie_port ); @@ -303,8 +304,8 @@ wait_for_newbie ( ) } catch ( const std::exception& error ) { - std::cerr << "wait_for_newbie error: " - << error.what() + std::cerr << "wait_for_newbie error: " + << error.what() << endl; return false; } @@ -320,7 +321,7 @@ startNewBroker ( brokerVector & brokers, char const * moduleOrDir, string const clusterName, int verbosity, - int durable ) + int durable ) { static int brokerId = 0; stringstream path, prefix; @@ -353,8 +354,8 @@ startNewBroker ( brokerVector & brokers, ForkedBroker * broker = newbie; if ( verbosity > 0 ) - std::cerr << "new broker created: pid == " - << broker->getPID() + std::cerr << "new broker created: pid == " + << broker->getPID() << " log-prefix == " << "soak-" << brokerId << endl; @@ -381,8 +382,8 @@ killFrontBroker ( brokerVector & brokers, int verbosity ) catch ( const exception& error ) { if ( verbosity > 0 ) { - cout << "error killing broker: " - << error.what() + cout << "error killing broker: " + << error.what() << endl; } @@ -398,14 +399,14 @@ killFrontBroker ( brokerVector & brokers, int verbosity ) /* - * The optional delay is to avoid killing newbie brokers that have just + * The optional delay is to avoid killing newbie brokers that have just * been added and are still in the process of updating. This causes * spurious, test-generated errors that scare everybody. */ void killAllBrokers ( brokerVector & brokers, int delay ) { - if ( delay > 0 ) + if ( delay > 0 ) { std::cerr << "Killing all brokers after delay of " << delay << endl; sleep ( delay ); @@ -413,8 +414,8 @@ killAllBrokers ( brokerVector & brokers, int delay ) for ( uint i = 0; i < brokers.size(); ++ i ) try { brokers[i]->kill(9); } - catch ( const exception& error ) - { + catch ( const exception& error ) + { std::cerr << "killAllBrokers Warning: exception during kill on broker " << i << " " @@ -428,21 +429,21 @@ killAllBrokers ( brokerVector & brokers, int delay ) pid_t -runDeclareQueuesClient ( brokerVector brokers, +runDeclareQueuesClient ( brokerVector brokers, char const * host, char const * path, int verbosity, int durable - ) + ) { string name("declareQueues"); int port = brokers[0]->getPort ( ); if ( verbosity > 1 ) - cout << "startDeclareQueuesClient: host: " - << host - << " port: " - << port + cout << "startDeclareQueuesClient: host: " + << host + << " port: " + << port << endl; stringstream portSs; portSs << port; @@ -473,12 +474,12 @@ runDeclareQueuesClient ( brokerVector brokers, pid_t -startReceivingClient ( brokerVector brokers, +startReceivingClient ( brokerVector brokers, char const * host, char const * receiverPath, char const * reportFrequency, int verbosity - ) + ) { string name("receiver"); int port = brokers[0]->getPort ( ); @@ -520,14 +521,14 @@ startReceivingClient ( brokerVector brokers, pid_t -startSendingClient ( brokerVector brokers, +startSendingClient ( brokerVector brokers, char const * host, char const * senderPath, char const * nMessages, char const * reportFrequency, int verbosity, int durability - ) + ) { string name("sender"); int port = brokers[0]->getPort ( ); @@ -580,13 +581,14 @@ startSendingClient ( brokerVector brokers, #define HANGING 7 #define ERROR_KILLING_BROKER 8 +}} // namespace qpid::tests -// If you want durability, use the "dir" option of "moduleOrDir" . - +using namespace qpid::tests; +// If you want durability, use the "dir" option of "moduleOrDir" . int -main ( int argc, char const ** argv ) -{ +main ( int argc, char const ** argv ) +{ if ( argc != 9 ) { cerr << "Usage: " << argv[0] @@ -626,10 +628,10 @@ main ( int argc, char const ** argv ) int nBrokers = 3; for ( int i = 0; i < nBrokers; ++ i ) { startNewBroker ( brokers, - moduleOrDir, + moduleOrDir, clusterName, verbosity, - durable ); + durable ); } @@ -638,7 +640,7 @@ main ( int argc, char const ** argv ) // Run the declareQueues child. int childStatus; - pid_t dqClientPid = + pid_t dqClientPid = runDeclareQueuesClient ( brokers, host, declareQueuesPath, verbosity, durable ); if ( -1 == dqClientPid ) { cerr << "END_OF_TEST ERROR_START_DECLARE_1\n"; @@ -657,8 +659,8 @@ main ( int argc, char const ** argv ) // Start the receiving client. pid_t receivingClientPid = - startReceivingClient ( brokers, - host, + startReceivingClient ( brokers, + host, receiverPath, reportFrequency, verbosity ); @@ -669,10 +671,10 @@ main ( int argc, char const ** argv ) // Start the sending client. - pid_t sendingClientPid = - startSendingClient ( brokers, - host, - senderPath, + pid_t sendingClientPid = + startSendingClient ( brokers, + host, + senderPath, nMessages, reportFrequency, verbosity, @@ -687,10 +689,10 @@ main ( int argc, char const ** argv ) maxSleep = 4; - for ( int totalBrokers = 3; - totalBrokers < maxBrokers; - ++ totalBrokers - ) + for ( int totalBrokers = 3; + totalBrokers < maxBrokers; + ++ totalBrokers + ) { if ( verbosity > 0 ) cout << totalBrokers << " brokers have been added to the cluster.\n\n\n"; @@ -721,14 +723,14 @@ main ( int argc, char const ** argv ) cout << "Starting new broker.\n\n"; startNewBroker ( brokers, - moduleOrDir, + moduleOrDir, clusterName, verbosity, - durable ); - + durable ); + if ( verbosity > 1 ) printBrokers ( brokers ); - + // If all children have exited, quit. int unfinished = allMyChildren.unfinished(); if ( ! unfinished ) { diff --git a/qpid/cpp/src/tests/latencytest.cpp b/qpid/cpp/src/tests/latencytest.cpp index e1c47eab05..a205ef6c7c 100644 --- a/qpid/cpp/src/tests/latencytest.cpp +++ b/qpid/cpp/src/tests/latencytest.cpp @@ -7,9 +7,9 @@ * 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 @@ -40,6 +40,9 @@ using namespace qpid::client; using namespace qpid::sys; using std::string; +namespace qpid { +namespace tests { + typedef std::vector<std::string> StringSet; struct Args : public qpid::TestOptions { @@ -64,7 +67,7 @@ struct Args : public qpid::TestOptions { durable(false), base("latency-test"), singleConnect(false) { - addOptions() + addOptions() ("size", optValue(size, "N"), "message size") ("concurrentTests", optValue(concurrentConnections, "N"), "number of concurrent test setups, will create another publisher,\ @@ -73,9 +76,9 @@ struct Args : public qpid::TestOptions { ("count", optValue(count, "N"), "number of messages to send") ("rate", optValue(rate, "N"), "target message rate (causes count to be ignored)") ("sync", optValue(sync), "send messages synchronously") - ("report-frequency", optValue(reportFrequency, "N"), + ("report-frequency", optValue(reportFrequency, "N"), "number of milliseconds to wait between reports (ignored unless rate specified)") - ("time-limit", optValue(timeLimit, "N"), + ("time-limit", optValue(timeLimit, "N"), "test duration, in seconds") ("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)") @@ -98,7 +101,7 @@ uint64_t current_time() return t; } -struct Stats +struct Stats { Mutex lock; uint count; @@ -132,7 +135,7 @@ public: }; class Receiver : public Client, public MessageListener -{ +{ SubscriptionManager mgr; uint count; Stats& stats; @@ -168,7 +171,7 @@ class Test Receiver receiver; Sender sender; AbsTime begin; - + public: Test(const string& q) : queue(q), receiver(queue, stats), sender(queue, receiver), begin(now()) {} void start(); @@ -186,7 +189,7 @@ Client::Client(const string& q) : queue(q) connection = &localConnection; opts.open(localConnection); } - session = connection->newSession(); + session = connection->newSession(); } void Client::start() @@ -235,7 +238,7 @@ Receiver::Receiver(const string& q, Stats& s) : Client(q), mgr(session), count(0 settings.acceptMode = ACCEPT_MODE_NONE; settings.flowControl = FlowControl::unlimited(); } - mgr.subscribe(*this, queue, settings); + mgr.subscribe(*this, queue, settings); } void Receiver::test() @@ -283,7 +286,7 @@ void Stats::print() if (!opts.csv) { if (count) { std::cout << "Latency(ms): min=" << minLatency << ", max=" << - maxLatency << ", avg=" << aux_avg; + maxLatency << ", avg=" << aux_avg; } else { std::cout << "Stalled: no samples for interval"; } @@ -368,7 +371,7 @@ void Sender::sendByRate() Duration delay(sentAt, waitTill); if (delay < 0) ++missedRate; - else + else sys::usleep(delay / TIME_USEC); if (timeLimit != 0 && Duration(start, now()) > timeLimit) { session.sync(); @@ -382,7 +385,7 @@ string Sender::generateData(uint size) { if (size < chars.length()) { return chars.substr(0, size); - } + } std::string data; for (uint i = 0; i < (size / chars.length()); i++) { data += chars; @@ -392,35 +395,39 @@ string Sender::generateData(uint size) } -void Test::start() -{ - receiver.start(); +void Test::start() +{ + receiver.start(); begin = AbsTime(now()); - sender.start(); + sender.start(); } -void Test::join() -{ - sender.join(); - receiver.join(); +void Test::join() +{ + sender.join(); + receiver.join(); AbsTime end = now(); Duration time(begin, end); double msecs(time / TIME_MSEC); if (!opts.csv) { - std::cout << "Sent " << receiver.getCount() << " msgs through " << queue + std::cout << "Sent " << receiver.getCount() << " msgs through " << queue << " in " << msecs << "ms (" << (receiver.getCount() * 1000 / msecs) << " msgs/s) "; } stats.print(); std::cout << std::endl; } -void Test::report() -{ +void Test::report() +{ stats.print(); std::cout << std::endl; stats.reset(); } +}} // namespace qpid::tests + +using namespace qpid::tests; + int main(int argc, char** argv) { try { diff --git a/qpid/cpp/src/tests/logging.cpp b/qpid/cpp/src/tests/logging.cpp index 00e1d7de85..5cb563c7d3 100644 --- a/qpid/cpp/src/tests/logging.cpp +++ b/qpid/cpp/src/tests/logging.cpp @@ -37,6 +37,9 @@ #include <time.h> +namespace qpid { +namespace tests { + QPID_AUTO_TEST_SUITE(loggingTestSuite) using namespace std; @@ -106,7 +109,7 @@ struct TestOutput : public Logger::Output { TestOutput(Logger& l) { l.output(std::auto_ptr<Logger::Output>(this)); } - + void log(const Statement& s, const string& m) { msg.push_back(m); stmt.push_back(s); @@ -117,7 +120,7 @@ struct TestOutput : public Logger::Output { using boost::assign::list_of; QPID_AUTO_TEST_CASE(testLoggerOutput) { - Logger l; + Logger l; l.clear(); l.select(Selector(debug)); Statement s=QPID_LOG_STATEMENT_INIT(debug); @@ -174,7 +177,7 @@ QPID_AUTO_TEST_CASE(testLoggerFormat) { l.format(Logger::FUNCTION); QPID_LOG(critical, "foo"); BOOST_CHECK_EQUAL(string(BOOST_CURRENT_FUNCTION) + ": foo\n", out->last()); - + l.format(Logger::LEVEL); QPID_LOG(critical, "foo"); BOOST_CHECK_EQUAL("critical foo\n", out->last()); @@ -228,12 +231,12 @@ clock_t timeLoop(int times, int (*fp)()) { // Overhead test disabled because it consumes a ton of CPU and takes // forever under valgrind. Not friendly for regular test runs. -// +// #if 0 QPID_AUTO_TEST_CASE(testOverhead) { // Ensure that the ratio of CPU time for an incrementing loop // with and without disabled log statements is in acceptable limits. - // + // int times=100000000; clock_t noLog=timeLoop(times, count); clock_t withLog=timeLoop(times, loggedCount); @@ -242,9 +245,9 @@ QPID_AUTO_TEST_CASE(testOverhead) { // NB: in initial tests the ratio was consistently below 1.5, // 2.5 is reasonable and should avoid spurios failures // due to machine load. - // - BOOST_CHECK_SMALL(ratio, 2.5); -} + // + BOOST_CHECK_SMALL(ratio, 2.5); +} #endif // 0 Statement statement( @@ -290,7 +293,7 @@ QPID_AUTO_TEST_CASE(testOptionsParse) { } QPID_AUTO_TEST_CASE(testOptionsDefault) { - Options opts(""); + qpid::log::Options opts(""); #ifdef _WIN32 qpid::log::windows::SinkOptions sinks("test"); #else @@ -328,10 +331,10 @@ QPID_AUTO_TEST_CASE(testSelectorFromOptions) { QPID_AUTO_TEST_CASE(testLoggerStateure) { Logger& l=Logger::instance(); ScopedSuppressLogging ls(l); - Options opts("test"); + qpid::log::Options opts("test"); const char* argv[]={ 0, - "--log-time", "no", + "--log-time", "no", "--log-source", "yes", "--log-to-stderr", "no", "--log-to-file", "logging.tmp", @@ -352,7 +355,7 @@ QPID_AUTO_TEST_CASE(testLoggerStateure) { QPID_AUTO_TEST_CASE(testQuoteNonPrintable) { Logger& l=Logger::instance(); ScopedSuppressLogging ls(l); - Options opts("test"); + qpid::log::Options opts("test"); opts.time=false; #ifdef _WIN32 qpid::log::windows::SinkOptions *sinks = @@ -367,7 +370,7 @@ QPID_AUTO_TEST_CASE(testQuoteNonPrintable) { char s[] = "null\0tab\tspace newline\nret\r\x80\x99\xff"; string str(s, sizeof(s)); - QPID_LOG(critical, str); + QPID_LOG(critical, str); ifstream log("logging.tmp"); string line; getline(log, line, '\0'); @@ -378,3 +381,5 @@ QPID_AUTO_TEST_CASE(testQuoteNonPrintable) { } QPID_AUTO_TEST_SUITE_END() + +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/perftest.cpp b/qpid/cpp/src/tests/perftest.cpp index d383e0eb80..88d9fd15cb 100644 --- a/qpid/cpp/src/tests/perftest.cpp +++ b/qpid/cpp/src/tests/perftest.cpp @@ -7,9 +7,9 @@ * 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 @@ -49,6 +49,9 @@ using namespace sys; using boost::lexical_cast; using boost::bind; +namespace qpid { +namespace tests { + enum Mode { SHARED, FANOUT, TOPIC }; const char* modeNames[] = { "shared", "fanout", "topic" }; @@ -105,9 +108,9 @@ struct Opts : public TestOptions { bool commitAsync; static const std::string helpText; - + Opts() : - TestOptions(helpText), + TestOptions(helpText), setup(false), control(false), publish(false), subscribe(false), baseName("perftest"), pubs(1), count(500000), size(1024), confirm(true), durable(false), uniqueData(false), syncPub(false), subs(1), ack(0), @@ -136,16 +139,16 @@ struct Opts : public TestOptions { ("nsubs", optValue(subs, "N"), "Create N subscribers.") ("sub-ack", optValue(ack, "N"), "N>0: Subscriber acks batches of N.\n" "N==0: Subscriber uses unconfirmed mode") - + ("qt", optValue(qt, "N"), "Create N queues or topics.") ("single-connection", optValue(singleConnect, "yes|no"), "Use one connection for multiple sessions.") - + ("iterations", optValue(iterations, "N"), "Desired number of iterations of the test.") ("summary,s", optValue(summary), "Summary output: pubs/sec subs/sec transfers/sec Mbytes/sec") ("queue-max-count", optValue(queueMaxCount, "N"), "queue policy: count to trigger 'flow to disk'") ("queue-max-size", optValue(queueMaxSize, "N"), "queue policy: accumulated size to trigger 'flow to disk'") - ("base-name", optValue(baseName, "NAME"), "base name used for queues or topics") + ("base-name", optValue(baseName, "NAME"), "base name used for queues or topics") ("queue-durable", optValue(queueDurable, "N"), "Make queue durable (implied if durable set)") ("interval_sub", optValue(intervalSub, "ms"), ">=0 delay between msg consume") @@ -171,7 +174,7 @@ struct Opts : public TestOptions { count += subs - (count % subs); cout << "WARNING: Adjusted --count to " << count << " the nearest multiple of --nsubs" << endl; - } + } totalPubs = pubs*qt; totalSubs = subs*qt; subQuota = (pubs*count)/subs; @@ -258,7 +261,7 @@ struct Client : public Runnable { }; struct Setup : public Client { - + void queueInit(string name, bool durable=false, const framing::FieldTable& settings=framing::FieldTable()) { session.queueDeclare(arg::queue=name, arg::durable=durable, arg::arguments=settings); session.queuePurge(arg::queue=name); @@ -278,7 +281,7 @@ struct Setup : public Client { for (size_t i = 0; i < opts.qt; ++i) { ostringstream qname; qname << opts.baseName << i; - queueInit(qname.str(), opts.durable || opts.queueDurable, settings); + queueInit(qname.str(), opts.durable || opts.queueDurable, settings); } } } @@ -303,7 +306,7 @@ class Stats { public: Stats() : sum(0) {} - + // Functor to collect rates. void operator()(const string& data) { try { @@ -314,7 +317,7 @@ class Stats { throw Exception("Bad report: "+data); } } - + double mean() const { return sum/values.size(); } @@ -331,7 +334,7 @@ class Stats { } return sqrt(ssq/(values.size()-1)); } - + ostream& print(ostream& out) { ostream_iterator<double> o(out, "\n"); copy(values.begin(), values.end(), o); @@ -341,11 +344,11 @@ class Stats { return out << endl; } }; - + // Manage control queues, collect and print reports. struct Controller : public Client { - + SubscriptionManager subs; Controller() : subs(session) {} @@ -354,7 +357,7 @@ struct Controller : public Client { void process(size_t n, string queue, boost::function<void (const string&)> msgFn) { - if (!opts.summary) + if (!opts.summary) cout << "Processing " << n << " messages from " << queue << " " << flush; LocalQueue lq; @@ -370,8 +373,8 @@ struct Controller : public Client { void process(size_t n, LocalQueue lq, string queue, boost::function<void (const string&)> msgFn) { - session.messageFlow(queue, 0, n); - if (!opts.summary) + session.messageFlow(queue, 0, n); + if (!opts.summary) cout << "Processing " << n << " messages from " << queue << " " << flush; for (size_t i = 0; i < n; ++i) { @@ -386,7 +389,7 @@ struct Controller : public Client { cout << "Sending " << data << " " << n << " times to " << queue << endl; Message msg(data, queue); - for (size_t i = 0; i < n; ++i) + for (size_t i = 0; i < n; ++i) session.messageTransfer(arg::content=msg, arg::acceptMode=1); } @@ -419,7 +422,7 @@ struct Controller : public Client { process(opts.totalPubs, pubDone, fqn("pub_done"), boost::ref(pubRates)); process(opts.totalSubs, subDone, fqn("sub_done"), boost::ref(subRates)); - AbsTime end=now(); + AbsTime end=now(); double time=secs(start, end); double txrate=opts.transfers/time; @@ -469,12 +472,12 @@ struct PublishThread : public Client { string routingKey; PublishThread() {}; - + PublishThread(string key, string dest=string()) { destination=dest; routingKey=key; } - + void run() { // Publisher try { string data; @@ -492,7 +495,7 @@ struct PublishThread : public Client { } } else { size_t msgSize=max(opts.size, sizeof(size_t)); - data = string(msgSize, 'X'); + data = string(msgSize, 'X'); } Message msg(data, routingKey); @@ -500,21 +503,21 @@ struct PublishThread : public Client { msg.getDeliveryProperties().setDeliveryMode(framing::PERSISTENT); - if (opts.txPub){ + if (opts.txPub){ session.txSelect(); } SubscriptionManager subs(session); LocalQueue lq; - subs.setFlowControl(1, SubscriptionManager::UNLIMITED, true); - subs.subscribe(lq, fqn("pub_start")); - + subs.setFlowControl(1, SubscriptionManager::UNLIMITED, true); + subs.subscribe(lq, fqn("pub_start")); + for (size_t j = 0; j < opts.iterations; ++j) { expect(lq.pop().getData(), "start"); AbsTime start=now(); for (size_t i=0; i<opts.count; i++) { // Stamp the iteration into the message data, avoid // any heap allocation. - const_cast<std::string&>(msg.getData()).replace(offset, sizeof(size_t), + const_cast<std::string&>(msg.getData()).replace(offset, sizeof(size_t), reinterpret_cast<const char*>(&i), sizeof(size_t)); if (opts.syncPub) { sync(session).messageTransfer( @@ -540,7 +543,7 @@ struct PublishThread : public Client { if (opts.confirm) session.sync(); AbsTime end=now(); double time=secs(start,end); - + // Send result to controller. Message report(lexical_cast<string>(opts.count/time), fqn("pub_done")); session.messageTransfer(arg::content=report, arg::acceptMode=1); @@ -561,7 +564,7 @@ struct SubscribeThread : public Client { string queue; SubscribeThread() {} - + SubscribeThread(string q) { queue = q; } SubscribeThread(string key, string ex) { @@ -586,7 +589,7 @@ struct SubscribeThread : public Client { } void run() { // Subscribe - try { + try { if (opts.txSub) sync(session).txSelect(); SubscriptionManager subs(session); SubscriptionSettings settings; @@ -606,15 +609,15 @@ struct SubscribeThread : public Client { if (opts.iterations > 1) { subs.subscribe(iterationControl, fqn("sub_iteration"), SubscriptionSettings(FlowControl::messageCredit(0))); } - + for (size_t j = 0; j < opts.iterations; ++j) { if (j > 0) { //need to wait here until all subs are done - session.messageFlow(fqn("sub_iteration"), 0, 1); + session.messageFlow(fqn("sub_iteration"), 0, 1); iterationControl.pop(); //need to allocate some more credit for subscription - session.messageFlow(queue, 0, opts.subQuota); + session.messageFlow(queue, 0, opts.subQuota); } Message msg; AbsTime start=now(); @@ -627,7 +630,7 @@ struct SubscribeThread : public Client { } if (opts.intervalSub) qpid::sys::usleep(opts.intervalSub*1000); - // TODO aconway 2007-11-23: check message order for. + // TODO aconway 2007-11-23: check message order for. // multiple publishers. Need an array of counters, // one per publisher and a publisher ID in the // message. Careful not to introduce a lot of overhead @@ -664,6 +667,10 @@ struct SubscribeThread : public Client { } }; +}} // namespace qpid::tests + +using namespace qpid::tests; + int main(int argc, char** argv) { int exitCode = 0; boost::ptr_vector<Client> subs(opts.subs); diff --git a/qpid/cpp/src/tests/publish.cpp b/qpid/cpp/src/tests/publish.cpp index 34c2b8fefc..3f456e7588 100644 --- a/qpid/cpp/src/tests/publish.cpp +++ b/qpid/cpp/src/tests/publish.cpp @@ -7,9 +7,9 @@ * 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 @@ -36,6 +36,9 @@ using namespace qpid::client; using namespace qpid::sys; using namespace std; +namespace qpid { +namespace tests { + typedef vector<string> StringSet; struct Args : public qpid::TestOptions { @@ -61,12 +64,12 @@ struct Args : public qpid::TestOptions { Args opts; -struct Client +struct Client { Connection connection; AsyncSession session; - Client() + Client() { opts.open(connection); session = connection.newSession(); @@ -75,7 +78,7 @@ struct Client // Cheap hex calculation, avoid expensive ostrstream and string // creation to generate correlation ids in message loop. char hex(char i) { return i<10 ? '0'+i : 'A'+i-10; } - void hex(char i, string& s) { + void hex(char i, string& s) { s[0]=hex(i>>24); s[1]=hex(i>>16); s[2]=hex(i>>8); s[3]=i; } @@ -86,7 +89,7 @@ struct Client string correlationId = "0000"; if (opts.durable) msg.getDeliveryProperties().setDeliveryMode(framing::PERSISTENT); - + for (uint i = 0; i < opts.count; i++) { if (opts.id) { hex(i+1, correlationId); @@ -103,7 +106,7 @@ struct Client else cout << "Time: " << secs << "s Rate: " << opts.count/secs << endl; } - ~Client() + ~Client() { try{ session.close(); @@ -114,6 +117,10 @@ struct Client } }; +}} // namespace qpid::tests + +using namespace qpid::tests; + int main(int argc, char** argv) { try { diff --git a/qpid/cpp/src/tests/qpid_ping.cpp b/qpid/cpp/src/tests/qpid_ping.cpp index cc07ade7bb..b046fdf54b 100644 --- a/qpid/cpp/src/tests/qpid_ping.cpp +++ b/qpid/cpp/src/tests/qpid_ping.cpp @@ -7,9 +7,9 @@ * 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 @@ -38,6 +38,9 @@ using namespace qpid::framing; using namespace qpid::client; using namespace qpid; +namespace qpid { +namespace tests { + struct PingOptions : public qpid::TestOptions { int timeout; // Timeout in seconds. bool quiet; // No output @@ -58,7 +61,7 @@ class Ping : public Runnable { public: Ping() : status(WAITING) {} - + void run() { try { opts.open(connection); @@ -100,6 +103,9 @@ class Ping : public Runnable { } }; +}} // namespace qpid::tests + +using namespace qpid::tests; int main(int argc, char** argv) { try { diff --git a/qpid/cpp/src/tests/qrsh.cpp b/qpid/cpp/src/tests/qrsh.cpp index 2d71b600d5..0cb52b6b05 100644 --- a/qpid/cpp/src/tests/qrsh.cpp +++ b/qpid/cpp/src/tests/qrsh.cpp @@ -7,9 +7,9 @@ * 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 @@ -37,11 +37,13 @@ using namespace qpid::framing; using namespace std; +namespace qpid { +namespace tests { class ResponseListener : public MessageListener { public : - + int exitCode; ResponseListener ( SubscriptionManager & subscriptions ) @@ -50,7 +52,7 @@ class ResponseListener : public MessageListener { } - virtual void + virtual void received ( Message & message ) { char first_word[1000]; @@ -66,9 +68,9 @@ class ResponseListener : public MessageListener if ( ! strcmp ( first_word, "get_response" ) ) { // The remainder of the message is the file we requested. - fprintf ( stdout, - "%s", - message.getData().c_str() + strlen("get_response" ) + fprintf ( stdout, + "%s", + message.getData().c_str() + strlen("get_response" ) ); subscriptions.cancel(message.getDestination()); } @@ -76,12 +78,13 @@ class ResponseListener : public MessageListener private : - + SubscriptionManager & subscriptions; }; +}} // namespace qpid::tests - +using namespace qpid::tests; /* * argv[1] host @@ -90,8 +93,8 @@ class ResponseListener : public MessageListener * argv[4] command name * argv[5..N] args to the command */ -int -main ( int argc, char ** argv ) +int +main ( int argc, char ** argv ) { const char* host = argv[1]; int port = atoi(argv[2]); @@ -99,14 +102,14 @@ main ( int argc, char ** argv ) Connection connection; - try + try { connection.open ( host, port ); Session session = connection.newSession ( ); // Make a queue and bind it to fanout. string myQueue = session.getId().getName(); - + session.queueDeclare ( arg::queue=myQueue, arg::exclusive=true, arg::autoDelete=true @@ -136,7 +139,7 @@ main ( int argc, char ** argv ) response_command = true; // Send the payload message. - // Skip "qrsh host_name port" + // Skip "qrsh host_name port" Message message; stringstream ss; for ( int i = 3; i < argc; ++ i ) @@ -144,7 +147,7 @@ main ( int argc, char ** argv ) message.setData ( ss.str() ); - session.messageTransfer(arg::content=message, + session.messageTransfer(arg::content=message, arg::destination="amq.fanout"); if ( response_command ) @@ -153,8 +156,8 @@ main ( int argc, char ** argv ) session.close(); connection.close(); return responseListener.exitCode; - } - catch ( exception const & e) + } + catch ( exception const & e) { cerr << e.what() << endl; } diff --git a/qpid/cpp/src/tests/qrsh_server.cpp b/qpid/cpp/src/tests/qrsh_server.cpp index 4b80212eae..f1163ba479 100644 --- a/qpid/cpp/src/tests/qrsh_server.cpp +++ b/qpid/cpp/src/tests/qrsh_server.cpp @@ -7,9 +7,9 @@ * 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 @@ -43,7 +43,8 @@ using namespace qpid::framing; using namespace std; - +namespace qpid { +namespace tests { int mrand ( int max_desired_val ) @@ -54,7 +55,7 @@ mrand ( int max_desired_val ) -char * +char * file2str ( char const * file_name ) { FILE * fp = fopen ( file_name, "r" ); @@ -71,9 +72,9 @@ file2str ( char const * file_name ) if ( ! content ) { - fprintf ( stderr, - "file2str error: can't malloc %d bytes.\n", - (int)file_len + fprintf ( stderr, + "file2str error: can't malloc %d bytes.\n", + (int)file_len ); return 0; } @@ -123,9 +124,9 @@ class QrshServer : public MessageListener bool myMessage ( Message const & message ); /* ---------------------------------------------- - * Special Commands + * Special Commands * These are commands that the qrsh_server executes - * directly, rather than through a child process + * directly, rather than through a child process * instance of qrsh_run. */ void runCommand ( Message const & message ); @@ -157,9 +158,9 @@ class QrshServer : public MessageListener char const * skipWord ( char const * s ); - void string_replaceAll ( string & str, - string & target, - string & replacement + void string_replaceAll ( string & str, + string & target, + string & replacement ); @@ -186,12 +187,12 @@ class QrshServer : public MessageListener -QrshServer::QrshServer ( SubscriptionManager & subs, +QrshServer::QrshServer ( SubscriptionManager & subs, char const * name, char const * qrsh_run_path, char const * host, int port - ) + ) : subscriptions ( subs ), name ( name ), qrsh_run_path ( qrsh_run_path ), @@ -202,11 +203,11 @@ QrshServer::QrshServer ( SubscriptionManager & subs, { data_dir << "/tmp/qrsh_" << getpid(); - + if(mkdir ( data_dir.str().c_str(), 0777 ) ) { - fprintf ( stderr, - "QrshServer::QrshServer error: can't mkdir |%s|\n", + fprintf ( stderr, + "QrshServer::QrshServer error: can't mkdir |%s|\n", data_dir.str().c_str() ); exit ( 1 ); @@ -239,21 +240,21 @@ QrshServer::start ( ) << name; send ( announcement_data.str() ); - + saidHello = true; } -void +void QrshServer::send ( string const & content ) { try { Message message; message.setData ( content ); - + Connection connection; connection.open ( host, port ); Session session = connection.newSession ( ); @@ -289,7 +290,7 @@ QrshServer::sayHello ( ) -void +void QrshServer::sayName ( ) { fprintf ( stderr, "My name is: |%s|\n", name.c_str() ); @@ -343,7 +344,7 @@ QrshServer::getStraw ( Message const & message ) break; } } - + if ( i_win && (ties <= 0) ) { myStraw = 0; @@ -364,10 +365,10 @@ QrshServer::getStraw ( Message const & message ) /* * "APB" command (all-points-bullitens (commands that are not addressed * specifically to any server)) are handled directly, here. - * Because if I return simply "true", the normal command processing code + * Because if I return simply "true", the normal command processing code * will misinterpret the command. */ -bool +bool QrshServer::myMessage ( Message const & message ) { int const maxlen = 100; @@ -414,7 +415,7 @@ QrshServer::myMessage ( Message const & message ) { return true; } - else + else if ( ! strcmp ( first_word, "any" ) ) { straws.clear(); @@ -443,7 +444,7 @@ QrshServer::rememberIntroduction ( Message const & message ) -void +void QrshServer::addAlias ( Message const & message ) { char alias[1000]; @@ -463,8 +464,8 @@ QrshServer::getNames ( ) if ( ! dir ) { - fprintf ( stderr, - "QrshServer::getNames error: could not open dir |%s|.\n", + fprintf ( stderr, + "QrshServer::getNames error: could not open dir |%s|.\n", data_dir.str().c_str() ); return; @@ -491,8 +492,8 @@ QrshServer::getNames ( ) } else { - /* - * Fail silently. The non-existence of this file + /* + * Fail silently. The non-existence of this file * is not necessarily an error. */ } @@ -504,9 +505,9 @@ QrshServer::getNames ( ) void -QrshServer::string_replaceAll ( string & str, - string & target, - string & replacement +QrshServer::string_replaceAll ( string & str, + string & target, + string & replacement ) { int target_size = target.size(); @@ -519,7 +520,7 @@ QrshServer::string_replaceAll ( string & str, -bool +bool QrshServer::isProcessName ( char const * str ) { getNames(); @@ -537,12 +538,12 @@ QrshServer::isProcessName ( char const * str ) -int +int QrshServer::string_countWords ( char const * s1 ) { int count = 0; char const * s2 = s1 + 1; - + if ( ! isspace(* s1) ) { ++ count; @@ -603,7 +604,7 @@ QrshServer::get ( Message const & request_message ) */ char file_or_process_name[1000]; sscanf ( request_message.getData().c_str(), "%*s%*s%s", file_or_process_name ); - + if ( isProcessName ( file_or_process_name ) ) { stringstream desired_file_name; @@ -612,13 +613,13 @@ QrshServer::get ( Message const & request_message ) << file_or_process_name << '/'; char requested_output_stream[1000]; - if(1 != sscanf ( request_message.getData().c_str(), - "%*s%*s%*s%s", - requested_output_stream + if(1 != sscanf ( request_message.getData().c_str(), + "%*s%*s%*s%s", + requested_output_stream ) ) { - fprintf ( stderr, + fprintf ( stderr, "QrshServer::get error: Can't read requested data file name from this message: |%s|\n", request_message.getData().c_str() ); @@ -674,7 +675,7 @@ QrshServer::exited ( Message const & message ) if ( truncated_command ) { stringstream ss; - ss << qrsh_run_path + ss << qrsh_run_path << ' ' << data_dir.str() << ' ' @@ -706,9 +707,9 @@ QrshServer::exited ( Message const & message ) fprintf ( stderr, "qrsh_server error awaiting child!\n" ); exit ( 1 ); } - + exit_code >>= 8; - + stringstream data; data << "wait_response " << exit_code; @@ -731,7 +732,7 @@ QrshServer::wait ( Message const & message ) // The second word is "exec_wait". // The third word is the symbolic name of the command to wait for. // The fact that there are exactly three words means that this - // must be a command that has already been named and started -- + // must be a command that has already been named and started -- // we just need to find its pid and wait on it. pre_existing = true; } @@ -762,7 +763,7 @@ QrshServer::wait ( Message const & message ) if ( truncated_command ) { stringstream ss; - ss << qrsh_run_path + ss << qrsh_run_path << ' ' << data_dir.str() << ' ' @@ -795,7 +796,7 @@ QrshServer::wait ( Message const & message ) exit ( 1 ); } } - + exit_code >>= 8; stringstream data; @@ -810,7 +811,7 @@ QrshServer::wait ( Message const & message ) -char const * +char const * QrshServer::skipWord ( char const * s ) { if(! (s && *s) ) @@ -884,7 +885,7 @@ QrshServer::getArgs ( char const * str ) arg_len = 0; } - done: + done: if ( arg_len > 0 ) lengths.push_back ( arg_len ); @@ -896,8 +897,8 @@ QrshServer::getArgs ( char const * str ) for ( int i = 0; i < n_args; ++ i ) { argv[i] = ( char *) malloc ( lengths[i] + 1 ); - strncpy ( argv[i], - str + start_positions[i], + strncpy ( argv[i], + str + start_positions[i], lengths[i] ); argv[i][lengths[i]] = 0; @@ -971,12 +972,12 @@ QrshServer::runCommand ( Message const & message ) * qrsh_run, which will save all its data in the qrsh dir. */ stringstream ss; - ss << qrsh_run_path + ss << qrsh_run_path << ' ' << data_dir.str() << ' ' << s; - + if ( ! fork() ) { char ** argv = getArgs ( ss.str().c_str() ); @@ -988,8 +989,8 @@ QrshServer::runCommand ( Message const & message ) -void -QrshServer::received ( Message & message ) +void +QrshServer::received ( Message & message ) { if ( myMessage ( message ) ) runCommand ( message ); @@ -997,7 +998,9 @@ QrshServer::received ( Message & message ) +}} // namespace qpid::tests +using namespace qpid::tests; /* * fixme mick Mon Aug 3 10:29:26 EDT 2009 @@ -1024,23 +1027,23 @@ main ( int /*argc*/, char** argv ) // Declare queues. string myQueue = session.getId().getName(); - session.queueDeclare ( arg::queue=myQueue, + session.queueDeclare ( arg::queue=myQueue, arg::exclusive=true, arg::autoDelete=true); - session.exchangeBind ( arg::exchange="amq.fanout", - arg::queue=myQueue, + session.exchangeBind ( arg::exchange="amq.fanout", + arg::queue=myQueue, arg::bindingKey="my-key"); - + // Create a server and subscribe it to my queue. SubscriptionManager subscriptions ( session ); - QrshServer server ( subscriptions, + QrshServer server ( subscriptions, argv[1], // server name argv[2], // qrsh exe path host, port ); - subscriptions.subscribe ( server, myQueue ); + subscriptions.subscribe ( server, myQueue ); // Receive messages until the subscription is cancelled // by QrshServer::received() @@ -1048,7 +1051,7 @@ main ( int /*argc*/, char** argv ) connection.close(); } - catch(const exception& error) + catch(const exception& error) { cout << error.what() << endl; return 1; diff --git a/qpid/cpp/src/tests/receiver.cpp b/qpid/cpp/src/tests/receiver.cpp index 49f7ff0338..e01954e31a 100644 --- a/qpid/cpp/src/tests/receiver.cpp +++ b/qpid/cpp/src/tests/receiver.cpp @@ -7,9 +7,9 @@ * 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 @@ -36,7 +36,10 @@ using namespace qpid::framing; using namespace std; -struct Args : public qpid::TestOptions +namespace qpid { +namespace tests { + +struct Args : public qpid::TestOptions { string queue; uint messages; @@ -47,7 +50,7 @@ struct Args : public qpid::TestOptions Args() : queue("test-queue"), messages(0), ignoreDuplicates(false), creditWindow(0), ackFrequency(1), browse(false) { - addOptions() + addOptions() ("queue", qpid::optValue(queue, "QUEUE NAME"), "Queue from which to request messages") ("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)") @@ -77,15 +80,15 @@ class Receiver : public MessageListener, public FailoverManager::Command bool isDuplicate(Message& message); }; -Receiver::Receiver(const string& q, uint messages, bool ignoreDuplicates, uint creditWindow, uint ackFrequency, bool browse) : - queue(q), count(messages), skipDups(ignoreDuplicates), processed(0), lastSn(0) +Receiver::Receiver(const string& q, uint messages, bool ignoreDuplicates, uint creditWindow, uint ackFrequency, bool browse) : + queue(q), count(messages), skipDups(ignoreDuplicates), processed(0), lastSn(0) { if (browse) settings.acquireMode = ACQUIRE_MODE_NOT_ACQUIRED; if (creditWindow) settings.flowControl = FlowControl::messageWindow(creditWindow); settings.autoAck = ackFrequency; } -void Receiver::received(Message& message) +void Receiver::received(Message& message) { if (!(skipDups && isDuplicate(message))) { bool eos = message.getData() == EOS; @@ -94,7 +97,7 @@ void Receiver::received(Message& message) } } -bool Receiver::isDuplicate(Message& message) +bool Receiver::isDuplicate(Message& message) { uint sn = message.getHeaders().getAsInt("sn"); if (lastSn < sn) { @@ -115,6 +118,10 @@ void Receiver::execute(AsyncSession& session, bool /*isRetry*/) } } +}} // namespace qpid::tests + +using namespace qpid::tests; + int main(int argc, char ** argv) { Args opts; @@ -130,6 +137,3 @@ int main(int argc, char ** argv) } return 1; } - - - diff --git a/qpid/cpp/src/tests/replaying_sender.cpp b/qpid/cpp/src/tests/replaying_sender.cpp index 3ee69eec14..bfb4b042b6 100644 --- a/qpid/cpp/src/tests/replaying_sender.cpp +++ b/qpid/cpp/src/tests/replaying_sender.cpp @@ -7,9 +7,9 @@ * 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 @@ -35,12 +35,15 @@ using namespace qpid::framing; using namespace std; +namespace qpid { +namespace tests { + class Sender : public FailoverManager::Command { public: Sender(const std::string& queue, uint count, uint reportFreq); void execute(AsyncSession& session, bool isRetry); - uint getSent(); + uint getSent(); void setVerbosity ( int v ) { verbosity = v; } void setPersistence ( int p ) { persistence = p; } @@ -51,7 +54,7 @@ class Sender : public FailoverManager::Command uint sent; const uint reportFrequency; Message message; - + int verbosity; int persistence; }; @@ -93,7 +96,11 @@ uint Sender::getSent() return sent; } -int main(int argc, char ** argv) +}} // namespace qpid::tests + +using namespace qpid::tests; + +int main(int argc, char ** argv) { ConnectionSettings settings; @@ -118,23 +125,23 @@ int main(int argc, char ** argv) connection.execute ( sender ); if ( verbosity > 0 ) { - std::cout << "Sender finished. Sent " - << sender.getSent() - << " messages." + std::cout << "Sender finished. Sent " + << sender.getSent() + << " messages." << endl; } connection.close(); - return 0; - } - catch(const std::exception& error) + return 0; + } + catch(const std::exception& error) { - cerr << "Sender (host: " - << settings.host - << " port: " + cerr << "Sender (host: " + << settings.host + << " port: " << settings.port << " ) " - << " Failed: " - << error.what() + << " Failed: " + << error.what() << std::endl; } return 1; diff --git a/qpid/cpp/src/tests/resuming_receiver.cpp b/qpid/cpp/src/tests/resuming_receiver.cpp index ef559a009d..807bd83bee 100644 --- a/qpid/cpp/src/tests/resuming_receiver.cpp +++ b/qpid/cpp/src/tests/resuming_receiver.cpp @@ -7,9 +7,9 @@ * 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 @@ -35,8 +35,11 @@ using namespace qpid::framing; using namespace std; -class Listener : public MessageListener, - public FailoverManager::Command, +namespace qpid { +namespace tests { + +class Listener : public MessageListener, + public FailoverManager::Command, public FailoverManager::ReconnectionStrategy { public: @@ -57,32 +60,32 @@ class Listener : public MessageListener, }; -Listener::Listener(int freq, int verbosity) - : count(0), - received_twice(0), - lastSn(0), - gaps(false), +Listener::Listener(int freq, int verbosity) + : count(0), + received_twice(0), + lastSn(0), + gaps(false), reportFrequency(freq), verbosity(verbosity), done(false) {} -void Listener::received(Message & message) +void Listener::received(Message & message) { - if (message.getData() == "That's all, folks!") + if (message.getData() == "That's all, folks!") { done = true; if(verbosity > 0 ) { - std::cout << "Shutting down listener for " + std::cout << "Shutting down listener for " << message.getDestination() << std::endl; - std::cout << "Listener received " - << count - << " messages (" - << received_twice - << " received_twice)" + std::cout << "Listener received " + << count + << " messages (" + << received_twice + << " received_twice)" << endl; } subscription.cancel(); @@ -99,8 +102,8 @@ void Listener::received(Message & message) ++count; if ( ! ( count % reportFrequency ) ) { if ( verbosity > 0 ) - std::cout << "Listener has received " - << count + std::cout << "Listener has received " + << count << " messages.\n"; } } else { @@ -133,6 +136,10 @@ void Listener::editUrlList(std::vector<Url>& urls) if (urls.size() > 1) std::rotate(urls.begin(), urls.begin() + 1, urls.end()); } +}} // namespace qpid::tests + +using namespace qpid::tests; + int main(int argc, char ** argv) { ConnectionSettings settings; diff --git a/qpid/cpp/src/tests/sender.cpp b/qpid/cpp/src/tests/sender.cpp index 311de2e5f8..4e845c42b4 100644 --- a/qpid/cpp/src/tests/sender.cpp +++ b/qpid/cpp/src/tests/sender.cpp @@ -7,9 +7,9 @@ * 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 @@ -37,22 +37,27 @@ using namespace qpid::framing; using namespace std; -struct Args : public qpid::TestOptions +namespace qpid { +namespace tests { + +struct Args : public qpid::TestOptions { string destination; string key; uint sendEos; bool durable; + uint ttl; string lvqMatchValue; string lvqMatchFile; - Args() : key("test-queue"), sendEos(0), durable(false) + Args() : key("test-queue"), sendEos(0), durable(false), ttl(0) { addOptions() ("exchange", qpid::optValue(destination, "EXCHANGE"), "Exchange to send messages to") ("routing-key", qpid::optValue(key, "KEY"), "Routing key to add to messages") ("send-eos", qpid::optValue(sendEos, "N"), "Send N EOS messages to mark end of input") ("durable", qpid::optValue(durable, "true|false"), "Mark messages as durable.") + ("ttl", qpid::optValue(ttl, "msecs"), "Time-to-live for messages, in milliseconds") ("lvq-match-value", qpid::optValue(lvqMatchValue, "KEY"), "The value to set for the LVQ match key property") ("lvq-match-file", qpid::optValue(lvqMatchFile, "FILE"), "A file containing values to set for the LVQ match key property"); } @@ -63,26 +68,29 @@ const string EOS("eos"); class Sender : public FailoverManager::Command { public: - Sender(const std::string& destination, const std::string& key, uint sendEos, bool durable, + Sender(const std::string& destination, const std::string& key, uint sendEos, bool durable, uint ttl, const std::string& lvqMatchValue, const std::string& lvqMatchFile); void execute(AsyncSession& session, bool isRetry); private: const std::string destination; MessageReplayTracker sender; - Message message; + Message message; const uint sendEos; uint sent; std::ifstream lvqMatchValues; }; -Sender::Sender(const std::string& dest, const std::string& key, uint eos, bool durable, - const std::string& lvqMatchValue, const std::string& lvqMatchFile) : +Sender::Sender(const std::string& dest, const std::string& key, uint eos, bool durable, uint ttl, const std::string& lvqMatchValue, const std::string& lvqMatchFile) : destination(dest), sender(10), message("", key), sendEos(eos), sent(0) , lvqMatchValues(lvqMatchFile.c_str()) { if (durable){ message.getDeliveryProperties().setDeliveryMode(framing::PERSISTENT); } + if (ttl) { + message.getDeliveryProperties().setTtl(ttl); + } + if (!lvqMatchValue.empty()) { message.getHeaders().setString(QueueOptions::strLVQMatchProperty, lvqMatchValue); } @@ -108,16 +116,20 @@ void Sender::execute(AsyncSession& session, bool isRetry) } } -int main(int argc, char ** argv) +}} // namespace qpid::tests + +using namespace qpid::tests; + +int main(int argc, char ** argv) { Args opts; try { opts.parse(argc, argv); FailoverManager connection(opts.con); - Sender sender(opts.destination, opts.key, opts.sendEos, opts.durable, opts.lvqMatchValue, opts.lvqMatchFile); + Sender sender(opts.destination, opts.key, opts.sendEos, opts.durable, opts.ttl, opts.lvqMatchValue, opts.lvqMatchFile); connection.execute(sender); connection.close(); - return 0; + return 0; } catch(const std::exception& error) { std::cout << "Failed: " << error.what() << std::endl; } diff --git a/qpid/cpp/src/tests/shlibtest.cpp b/qpid/cpp/src/tests/shlibtest.cpp index e485cc9397..5655eb7e64 100644 --- a/qpid/cpp/src/tests/shlibtest.cpp +++ b/qpid/cpp/src/tests/shlibtest.cpp @@ -18,6 +18,9 @@ * */ +namespace qpid { +namespace tests { + int* loaderData = 0; extern "C" #ifdef WIN32 @@ -28,5 +31,4 @@ void callMe(int *i) { loaderData=i; } struct OnUnload { ~OnUnload() { *loaderData=42; } }; OnUnload unloader; // For destructor. - - +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/test_store.cpp b/qpid/cpp/src/tests/test_store.cpp index 90503818ed..64a96bf71a 100644 --- a/qpid/cpp/src/tests/test_store.cpp +++ b/qpid/cpp/src/tests/test_store.cpp @@ -7,9 +7,9 @@ * 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 @@ -22,7 +22,7 @@ /**@file * Plug-in message store for tests. - * + * * Add functionality as required, build up a comprehensive set of * features to support persistent behavior tests. * @@ -46,6 +46,9 @@ using namespace std; using namespace boost; using namespace qpid::sys; +namespace qpid { +namespace tests { + struct TestStoreOptions : public Options { string name; @@ -66,7 +69,7 @@ struct Completer : public Runnable { delete this; } }; - + class TestStore : public NullMessageStore { public: TestStore(const string& name_, Broker& broker_) : name(name_), broker(broker_) {} @@ -83,7 +86,7 @@ class TestStore : public NullMessageStore { // Check the message for special instructions. size_t i = string::npos; - size_t j = string::npos; + size_t j = string::npos; if (strncmp(data.c_str(), TEST_STORE_DO.c_str(), strlen(TEST_STORE_DO.c_str())) == 0 && (i = data.find(name+"[")) != string::npos && (j = data.find("]", i)) != string::npos) @@ -144,3 +147,5 @@ struct TestStorePlugin : public Plugin { }; static TestStorePlugin pluginInstance; + +}} // namespace qpid::tests diff --git a/qpid/cpp/src/tests/test_tools.h b/qpid/cpp/src/tests/test_tools.h index 54837d3e5b..832c04af04 100644 --- a/qpid/cpp/src/tests/test_tools.h +++ b/qpid/cpp/src/tests/test_tools.h @@ -34,7 +34,7 @@ template <class T> std::ostream& seqPrint(std::ostream& o, const T& seq) { return o; } -// Compare sequences +// Compare sequences template <class T, class U> bool seqEqual(const T& a, const U& b) { typename T::const_iterator i = a.begin(); @@ -60,6 +60,9 @@ template <class T> bool operator == (const boost::assign_detail::generic_list<T>& b, const vector<T>& a) { return seqEqual(a, b); } } +namespace qpid { +namespace tests { + /** NB: order of parameters is regex first, in line with * CHECK(expected, actual) convention. */ @@ -98,6 +101,7 @@ inline std::string getLibPath(const char* envName, const char* defaultPath = 0) return defaultPath; } +}} // namespace qpid::tests #endif /*!TEST_TOOLS_H*/ diff --git a/qpid/cpp/src/tests/topic_listener.cpp b/qpid/cpp/src/tests/topic_listener.cpp index 44070cd4c9..aa8c19df99 100644 --- a/qpid/cpp/src/tests/topic_listener.cpp +++ b/qpid/cpp/src/tests/topic_listener.cpp @@ -7,9 +7,9 @@ * 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 @@ -23,7 +23,7 @@ * This file provides one half of a test and example of a pub-sub * style of interaction. See topic_publisher.cpp for the other half, * in which the logic for publishing is defined. - * + * * This file contains the listener logic. A listener will subscribe to * a logical 'topic'. It will count the number of messages it receives * and the time elapsed between the first one and the last one. It @@ -50,11 +50,14 @@ using namespace qpid::sys; using namespace qpid::framing; using namespace std; +namespace qpid { +namespace tests { + /** * A message listener implementation in which the runtime logic is * defined. */ -class Listener : public MessageListener{ +class Listener : public MessageListener{ Session session; SubscriptionManager& mgr; const string responseQueue; @@ -62,7 +65,7 @@ class Listener : public MessageListener{ bool init; int count; AbsTime start; - + void shutdown(); void report(); public: @@ -91,6 +94,52 @@ struct Args : public qpid::TestOptions { } }; +Listener::Listener(const Session& s, SubscriptionManager& m, const string& _responseq, bool tx) : + session(s), mgr(m), responseQueue(_responseq), transactional(tx), init(false), count(0){} + +void Listener::received(Message& message){ + if(!init){ + start = now(); + count = 0; + init = true; + cout << "Batch started." << endl; + } + string type = message.getHeaders().getAsString("TYPE"); + + if(string("TERMINATION_REQUEST") == type){ + shutdown(); + }else if(string("REPORT_REQUEST") == type){ + subscription.accept(subscription.getUnaccepted()); // Accept everything upto this point + cout <<"Batch ended, sending report." << endl; + //send a report: + report(); + init = false; + }else if (++count % 1000 == 0){ + cout <<"Received " << count << " messages." << endl; + } +} + +void Listener::shutdown(){ + mgr.stop(); +} + +void Listener::report(){ + AbsTime finish = now(); + Duration time(start, finish); + stringstream reportstr; + reportstr << "Received " << count << " messages in " + << time/TIME_MSEC << " ms."; + Message msg(reportstr.str(), responseQueue); + msg.getHeaders().setString("TYPE", "REPORT"); + session.messageTransfer(arg::destination="amq.direct", arg::content=msg, arg::acceptMode=1); + if(transactional){ + sync(session).txCommit(); + } +} + +}} // namespace qpid::tests + +using namespace qpid::tests; /** * The main routine creates a Listener instance and sets it up to @@ -142,7 +191,7 @@ int main(int argc, char** argv){ if (args.transactional) { session.txSelect(); } - + cout << "topic_listener: listening..." << endl; mgr.run(); if (args.durable) { @@ -158,47 +207,3 @@ int main(int argc, char** argv){ } return 1; } - -Listener::Listener(const Session& s, SubscriptionManager& m, const string& _responseq, bool tx) : - session(s), mgr(m), responseQueue(_responseq), transactional(tx), init(false), count(0){} - -void Listener::received(Message& message){ - if(!init){ - start = now(); - count = 0; - init = true; - cout << "Batch started." << endl; - } - string type = message.getHeaders().getAsString("TYPE"); - - if(string("TERMINATION_REQUEST") == type){ - shutdown(); - }else if(string("REPORT_REQUEST") == type){ - subscription.accept(subscription.getUnaccepted()); // Accept everything upto this point - cout <<"Batch ended, sending report." << endl; - //send a report: - report(); - init = false; - }else if (++count % 1000 == 0){ - cout <<"Received " << count << " messages." << endl; - } -} - -void Listener::shutdown(){ - mgr.stop(); -} - -void Listener::report(){ - AbsTime finish = now(); - Duration time(start, finish); - stringstream reportstr; - reportstr << "Received " << count << " messages in " - << time/TIME_MSEC << " ms."; - Message msg(reportstr.str(), responseQueue); - msg.getHeaders().setString("TYPE", "REPORT"); - session.messageTransfer(arg::destination="amq.direct", arg::content=msg, arg::acceptMode=1); - if(transactional){ - sync(session).txCommit(); - } -} - diff --git a/qpid/cpp/src/tests/topic_publisher.cpp b/qpid/cpp/src/tests/topic_publisher.cpp index 40055bbfa0..3381132b1a 100644 --- a/qpid/cpp/src/tests/topic_publisher.cpp +++ b/qpid/cpp/src/tests/topic_publisher.cpp @@ -7,9 +7,9 @@ * 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 @@ -23,7 +23,7 @@ * This file provides one half of a test and example of a pub-sub * style of interaction. See topic_listener.cpp for the other half, in * which the logic for subscribers is defined. - * + * * This file contains the publisher logic. The publisher will send a * number of messages to the exchange with the appropriate routing key * for the logical 'topic'. Once it has done this it will then send a @@ -49,19 +49,22 @@ using namespace qpid::client; using namespace qpid::sys; using namespace std; +namespace qpid { +namespace tests { + /** * The publishing logic is defined in this class. It implements * message listener and can therfore be used to receive messages sent * back by the subscribers. */ -class Publisher { +class Publisher { AsyncSession session; SubscriptionManager mgr; LocalQueue queue; const string controlTopic; const bool transactional; const bool durable; - + string generateData(int size); public: @@ -99,6 +102,64 @@ struct Args : public TestOptions { } }; +Publisher::Publisher(const AsyncSession& _session, const string& _controlTopic, bool tx, bool d) : + session(_session), mgr(session), controlTopic(_controlTopic), transactional(tx), durable(d) +{ + mgr.subscribe(queue, "response"); +} + +int64_t Publisher::publish(int msgs, int listeners, int size){ + Message msg(generateData(size), controlTopic); + if (durable) { + msg.getDeliveryProperties().setDeliveryMode(framing::PERSISTENT); + } + AbsTime start = now(); + + for(int i = 0; i < msgs; i++){ + session.messageTransfer(arg::content=msg, arg::destination="amq.topic", arg::acceptMode=1); + } + //send report request + Message reportRequest("", controlTopic); + reportRequest.getHeaders().setString("TYPE", "REPORT_REQUEST"); + session.messageTransfer(arg::content=reportRequest, arg::destination="amq.topic", arg::acceptMode=1); + if(transactional){ + sync(session).txCommit(); + } + //wait for a response from each listener (TODO, could log these) + for (int i = 0; i < listeners; i++) { + Message report = queue.pop(); + } + + if(transactional){ + sync(session).txCommit(); + } + + AbsTime finish = now(); + return Duration(start, finish); +} + +string Publisher::generateData(int size){ + string data; + for(int i = 0; i < size; i++){ + data += ('A' + (i / 26)); + } + return data; +} + +void Publisher::terminate(){ + //send termination request + Message terminationRequest("", controlTopic); + terminationRequest.getHeaders().setString("TYPE", "TERMINATION_REQUEST"); + session.messageTransfer(arg::content=terminationRequest, arg::destination="amq.topic", arg::acceptMode=1); + if(transactional){ + session.txCommit(); + } +} + +}} // namespace qpid::tests + +using namespace qpid::tests; + int main(int argc, char** argv) { try{ Args args; @@ -120,11 +181,11 @@ int main(int argc, char** argv) { Message m = statusQ.get(); if( m.getData().find("topic_listener: ", 0) == 0 ) { cout << "Listener " << (i+1) << " of " << args.subscribers - << " is ready (pid " << m.getData().substr(16, m.getData().length() - 16) - << ")" << endl; + << " is ready (pid " << m.getData().substr(16, m.getData().length() - 16) + << ")" << endl; } else { throw Exception(QPID_MSG("Unexpected message received on status queue: " << m.getData())); - } + } } } @@ -150,12 +211,12 @@ int main(int argc, char** argv) { if(!min || msecs < min) min = msecs; sum += msecs; cout << "Completed " << (i+1) << " of " << batchSize - << " in " << msecs << "ms" << endl; + << " in " << msecs << "ms" << endl; } publisher.terminate(); int64_t avg = sum / batchSize; if(batchSize > 1){ - cout << batchSize << " batches completed. avg=" << avg << + cout << batchSize << " batches completed. avg=" << avg << ", max=" << max << ", min=" << min << endl; } session.close(); @@ -167,57 +228,3 @@ int main(int argc, char** argv) { } return 1; } - -Publisher::Publisher(const AsyncSession& _session, const string& _controlTopic, bool tx, bool d) : - session(_session), mgr(session), controlTopic(_controlTopic), transactional(tx), durable(d) -{ - mgr.subscribe(queue, "response"); -} - -int64_t Publisher::publish(int msgs, int listeners, int size){ - Message msg(generateData(size), controlTopic); - if (durable) { - msg.getDeliveryProperties().setDeliveryMode(framing::PERSISTENT); - } - AbsTime start = now(); - - for(int i = 0; i < msgs; i++){ - session.messageTransfer(arg::content=msg, arg::destination="amq.topic", arg::acceptMode=1); - } - //send report request - Message reportRequest("", controlTopic); - reportRequest.getHeaders().setString("TYPE", "REPORT_REQUEST"); - session.messageTransfer(arg::content=reportRequest, arg::destination="amq.topic", arg::acceptMode=1); - if(transactional){ - sync(session).txCommit(); - } - //wait for a response from each listener (TODO, could log these) - for (int i = 0; i < listeners; i++) { - Message report = queue.pop(); - } - - if(transactional){ - sync(session).txCommit(); - } - - AbsTime finish = now(); - return Duration(start, finish); -} - -string Publisher::generateData(int size){ - string data; - for(int i = 0; i < size; i++){ - data += ('A' + (i / 26)); - } - return data; -} - -void Publisher::terminate(){ - //send termination request - Message terminationRequest("", controlTopic); - terminationRequest.getHeaders().setString("TYPE", "TERMINATION_REQUEST"); - session.messageTransfer(arg::content=terminationRequest, arg::destination="amq.topic", arg::acceptMode=1); - if(transactional){ - session.txCommit(); - } -} diff --git a/qpid/cpp/src/tests/txjob.cpp b/qpid/cpp/src/tests/txjob.cpp index 94db96a666..a7a905c1b7 100644 --- a/qpid/cpp/src/tests/txjob.cpp +++ b/qpid/cpp/src/tests/txjob.cpp @@ -7,9 +7,9 @@ * 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 @@ -33,7 +33,10 @@ using namespace qpid::client; using namespace qpid::sys; -struct Args : public qpid::TestOptions +namespace qpid { +namespace tests { + +struct Args : public qpid::TestOptions { string workQueue; string source; @@ -43,10 +46,10 @@ struct Args : public qpid::TestOptions bool quit; bool declareQueues; - Args() : workQueue("txshift-control"), source("txshift-1"), dest("txshift-2"), messages(0), jobs(0), + Args() : workQueue("txshift-control"), source("txshift-1"), dest("txshift-2"), messages(0), jobs(0), quit(false), declareQueues(false) { - addOptions() + addOptions() ("messages", qpid::optValue(messages, "N"), "Number of messages to shift") ("jobs", qpid::optValue(jobs, "N"), "Number of shift jobs to request") ("source", qpid::optValue(source, "QUEUE NAME"), "source queue from which messages will be shifted") @@ -57,6 +60,10 @@ struct Args : public qpid::TestOptions } }; +}} // namespace qpid::tests + +using namespace qpid::tests; + //TODO: might be nice to make this capable of failover as well at some //point; for now its just for the setup phase. int main(int argc, char** argv) diff --git a/qpid/cpp/src/tests/txshift.cpp b/qpid/cpp/src/tests/txshift.cpp index 97135c9829..882d3716d8 100644 --- a/qpid/cpp/src/tests/txshift.cpp +++ b/qpid/cpp/src/tests/txshift.cpp @@ -7,9 +7,9 @@ * 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 @@ -34,14 +34,17 @@ using namespace qpid::client; using namespace qpid::sys; -struct Args : public qpid::TestOptions +namespace qpid { +namespace tests { + +struct Args : public qpid::TestOptions { string workQueue; size_t workers; Args() : workQueue("txshift-control"), workers(1) { - addOptions() + addOptions() ("workers", qpid::optValue(workers, "N"), "Number of separate worker sessions to start") ("work-queue", qpid::optValue(workQueue, "NAME"), "work queue from which to take instructions"); } @@ -61,7 +64,7 @@ struct Transfer : MessageListener Transfer(const std::string control_) : control(control_), expected(0), transfered(0) {} - void subscribeToSource(SubscriptionManager manager) + void subscribeToSource(SubscriptionManager manager) { sourceSettings.autoAck = 0;//will accept once at the end of the batch sourceSettings.flowControl = FlowControl::messageCredit(expected); @@ -69,7 +72,7 @@ struct Transfer : MessageListener QPID_LOG(info, "Subscribed to source: " << source << " expecting: " << expected); } - void subscribeToControl(SubscriptionManager manager) + void subscribeToControl(SubscriptionManager manager) { controlSettings.flowControl = FlowControl::messageCredit(1); controlSubscription = manager.subscribe(*this, control, controlSettings); @@ -94,7 +97,7 @@ struct Transfer : MessageListener message.getDeliveryProperties().setRoutingKey(destination); async(sourceSubscription.getSession()).messageTransfer(arg::content=message); if (++transfered == expected) { - QPID_LOG(info, "completed job: " << transfered << " messages shifted from " << + QPID_LOG(info, "completed job: " << transfered << " messages shifted from " << source << " to " << destination); sourceSubscription.accept(sourceSubscription.getUnaccepted()); sourceSubscription.getSession().txCommit(); @@ -111,7 +114,7 @@ struct Transfer : MessageListener destination = message.getHeaders().getAsString("dest"); expected = message.getHeaders().getAsInt("count"); transfered = 0; - QPID_LOG(info, "received transfer request: " << expected << " messages to be shifted from " << + QPID_LOG(info, "received transfer request: " << expected << " messages to be shifted from " << source << " to " << destination); subscribeToSource(controlSubscription.getSubscriptionManager()); } else if (message.getData() == "quit") { @@ -133,7 +136,7 @@ struct Worker : FailoverManager::Command, Runnable Worker(FailoverManager& c, const std::string& controlQueue) : connection(c), transfer(controlQueue) {} - void run() + void run() { connection.execute(*this); } @@ -148,7 +151,7 @@ struct Worker : FailoverManager::Command, Runnable runner.join(); } - void execute(AsyncSession& session, bool isRetry) + void execute(AsyncSession& session, bool isRetry) { if (isRetry) QPID_LOG(info, "Retrying..."); session.txSelect(); @@ -159,6 +162,10 @@ struct Worker : FailoverManager::Command, Runnable } }; +}} // namespace qpid::tests + +using namespace qpid::tests; + int main(int argc, char** argv) { Args opts; diff --git a/qpid/cpp/src/tests/txtest.cpp b/qpid/cpp/src/tests/txtest.cpp index f604df7e21..d0ba2f1245 100644 --- a/qpid/cpp/src/tests/txtest.cpp +++ b/qpid/cpp/src/tests/txtest.cpp @@ -7,9 +7,9 @@ * 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 @@ -41,6 +41,9 @@ using namespace qpid::client; using namespace qpid::sys; using std::string; +namespace qpid { +namespace tests { + typedef std::vector<std::string> StringSet; struct Args : public qpid::TestOptions { @@ -55,12 +58,12 @@ struct Args : public qpid::TestOptions { bool dtx; bool quiet; - Args() : init(true), transfer(true), check(true), - size(256), durable(true), queues(2), + Args() : init(true), transfer(true), check(true), + size(256), durable(true), queues(2), base("tx-test"), msgsPerTx(1), txCount(1), totalMsgCount(10), dtx(false), quiet(false) { - addOptions() + addOptions() ("init", optValue(init, "yes|no"), "Declare queues and populate one with the initial set of messages.") ("transfer", optValue(transfer, "yes|no"), "'Move' messages from one queue to another using transactions to ensure no message loss.") @@ -83,7 +86,7 @@ std::string generateData(uint size) { if (size < chars.length()) { return chars.substr(0, size); - } + } std::string data; for (uint i = 0; i < (size / chars.length()); i++) { data += chars; @@ -103,18 +106,18 @@ void generateSet(const std::string& base, uint count, StringSet& collection) Args opts; -struct Client +struct Client { Connection connection; AsyncSession session; - Client() + Client() { opts.open(connection); session = connection.newSession(); } - ~Client() + ~Client() { try{ session.close(); @@ -134,19 +137,19 @@ struct Transfer : public Client, public Runnable Transfer(const std::string& to, const std::string& from) : src(to), dest(from), xid(0x4c414e47, "", from) {} - void run() + void run() { try { - + if (opts.dtx) session.dtxSelect(); else session.txSelect(); SubscriptionManager subs(session); - + LocalQueue lq; SubscriptionSettings settings(FlowControl::messageWindow(opts.msgsPerTx)); settings.autoAck = 0; // Disabled Subscription sub = subs.subscribe(lq, src, settings); - + for (uint t = 0; t < opts.txCount; t++) { Message in; Message out("", dest); @@ -187,7 +190,7 @@ struct Transfer : public Client, public Runnable } }; -struct Controller : public Client +struct Controller : public Client { StringSet ids; StringSet queues; @@ -198,7 +201,7 @@ struct Controller : public Client generateSet("msg", opts.totalMsgCount, ids); } - void init() + void init() { //declare queues for (StringSet::iterator i = queues.begin(); i != queues.end(); i++) { @@ -236,7 +239,7 @@ struct Controller : public Client } } - int check() + int check() { SubscriptionManager subs(session); @@ -291,10 +294,10 @@ struct Controller : public Client //check that drained == ids StringSet missing; - set_difference(ids.begin(), ids.end(), drained.begin(), drained.end(), back_inserter(missing)); + set_difference(ids.begin(), ids.end(), drained.begin(), drained.end(), back_inserter(missing)); StringSet extra; - set_difference(drained.begin(), drained.end(), ids.begin(), ids.end(), back_inserter(extra)); + set_difference(drained.begin(), drained.end(), ids.begin(), ids.end(), back_inserter(extra)); if (missing.empty() && extra.empty()) { std::cout << "All expected messages were retrieved." << std::endl; @@ -303,26 +306,30 @@ struct Controller : public Client if (!missing.empty()) { std::cout << "The following ids were missing:" << std::endl; for (StringSet::iterator i = missing.begin(); i != missing.end(); i++) { - std::cout << " '" << *i << "'" << std::endl; - } + std::cout << " '" << *i << "'" << std::endl; + } } if (!extra.empty()) { std::cout << "The following extra ids were encountered:" << std::endl; for (StringSet::iterator i = extra.begin(); i != extra.end(); i++) { - std::cout << " '" << *i << "'" << std::endl; - } + std::cout << " '" << *i << "'" << std::endl; + } } return 1; } } }; +}} // namespace qpid::tests + +using namespace qpid::tests; + int main(int argc, char** argv) { try { opts.parse(argc, argv); Controller controller; - if (opts.init) controller.init(); + if (opts.init) controller.init(); if (opts.transfer) controller.transfer(); if (opts.check) return controller.check(); return 0; |