From 5be658a8817b8092a7b53b116f622412a5d0aef6 Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Wed, 8 Nov 2006 17:07:44 +0000 Subject: More reorg to separate APR/posix code, work in progress. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@472545 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/test/client/client_test.cpp | 12 +++---- cpp/test/client/topic_listener.cpp | 11 ++++--- cpp/test/client/topic_publisher.cpp | 52 +++++++++++++++---------------- cpp/test/unit/qpid/apr/APRBaseTest.cpp | 44 ++++++++++++++++++++++++++ cpp/test/unit/qpid/broker/MessageTest.cpp | 5 +-- cpp/test/unit/qpid/sys/APRBaseTest.cpp | 44 -------------------------- 6 files changed, 82 insertions(+), 86 deletions(-) create mode 100644 cpp/test/unit/qpid/apr/APRBaseTest.cpp delete mode 100644 cpp/test/unit/qpid/sys/APRBaseTest.cpp (limited to 'cpp/test') diff --git a/cpp/test/client/client_test.cpp b/cpp/test/client/client_test.cpp index 0e57babbef..8e9c58179a 100644 --- a/cpp/test/client/client_test.cpp +++ b/cpp/test/client/client_test.cpp @@ -36,9 +36,7 @@ public: inline virtual void received(Message& /*msg*/){ std::cout << "Received message " /**<< msg **/<< std::endl; - monitor->acquire(); monitor->notify(); - monitor->release(); } }; @@ -77,12 +75,12 @@ int main(int argc, char**) msg.setData(data); channel.publish(msg, exchange, "MyTopic"); std::cout << "Published message." << std::endl; - - monitor.acquire(); - monitor.wait(); - monitor.release(); - + { + Monitor::ScopedLock l(monitor); + monitor.wait(); + } + con.closeChannel(&channel); std::cout << "Closed channel." << std::endl; con.close(); diff --git a/cpp/test/client/topic_listener.cpp b/cpp/test/client/topic_listener.cpp index 0f383134b5..9aa93bc2b5 100644 --- a/cpp/test/client/topic_listener.cpp +++ b/cpp/test/client/topic_listener.cpp @@ -21,11 +21,12 @@ #include "qpid/client/Exchange.h" #include "qpid/client/MessageListener.h" #include "qpid/client/Queue.h" -#include +#include #include #include using namespace qpid::client; +using namespace qpid::sys; class Listener : public MessageListener{ Channel* const channel; @@ -33,7 +34,7 @@ class Listener : public MessageListener{ const bool transactional; bool init; int count; - apr_time_t start; + int64_t start; void shutdown(); void report(); @@ -101,7 +102,7 @@ Listener::Listener(Channel* _channel, const std::string& _responseq, bool tx) : void Listener::received(Message& message){ if(!init){ - start = apr_time_as_msec(apr_time_now()); + start = getTimeMsecs(); count = 0; init = true; } @@ -123,8 +124,8 @@ void Listener::shutdown(){ } void Listener::report(){ - apr_time_t finish = apr_time_as_msec(apr_time_now()); - apr_time_t time = finish - start; + int64_t finish = getTimeMsecs(); + int64_t time = finish - start; std::stringstream reportstr; reportstr << "Received " << count << " messages in " << time << " ms."; Message msg; diff --git a/cpp/test/client/topic_publisher.cpp b/cpp/test/client/topic_publisher.cpp index 119d275cfd..22c36ea9e3 100644 --- a/cpp/test/client/topic_publisher.cpp +++ b/cpp/test/client/topic_publisher.cpp @@ -23,7 +23,7 @@ #include "qpid/client/Queue.h" #include "qpid/sys/Monitor.h" #include "unistd.h" -#include +#include #include #include @@ -43,7 +43,7 @@ class Publisher : public MessageListener{ public: Publisher(Channel* channel, const std::string& controlTopic, bool tx); virtual void received(Message& msg); - apr_time_t publish(int msgs, int listeners, int size); + int64_t publish(int msgs, int listeners, int size); void terminate(); }; @@ -105,19 +105,19 @@ int main(int argc, char** argv){ channel.start(); int batchSize(args.getBatches()); - apr_time_t max(0); - apr_time_t min(0); - apr_time_t sum(0); + int64_t max(0); + int64_t min(0); + int64_t sum(0); for(int i = 0; i < batchSize; i++){ if(i > 0 && args.getDelay()) sleep(args.getDelay()); - apr_time_t time = publisher.publish(args.getMessages(), args.getSubscribers(), args.getSize()); + int64_t time = publisher.publish(args.getMessages(), args.getSubscribers(), args.getSize()); if(!max || time > max) max = time; if(!min || time < min) min = time; sum += time; - std::cout << "Completed " << (i+1) << " of " << batchSize << " in " << time << "ms" << std::endl; + std::cout << "Completed " << (i+1) << " of " << batchSize << " in " << nsecsToMsecs(time) << "ms" << std::endl; } publisher.terminate(); - apr_time_t avg = sum / batchSize; + int64_t avg = sum / batchSize; if(batchSize > 1){ std::cout << batchSize << " batches completed. avg=" << avg << ", max=" << max << ", min=" << min << std::endl; @@ -135,12 +135,11 @@ Publisher::Publisher(Channel* _channel, const std::string& _controlTopic, bool t void Publisher::received(Message& msg){ //count responses and when all are received end the current batch - monitor.acquire(); + Monitor::ScopedLock l(monitor); if(--count == 0){ monitor.notify(); } std::cout << "Received report: " << msg.getData() << " (" << count << " remaining)." << std::endl; - monitor.release(); } void Publisher::waitForCompletion(int msgs){ @@ -148,26 +147,27 @@ void Publisher::waitForCompletion(int msgs){ monitor.wait(); } -apr_time_t Publisher::publish(int msgs, int listeners, int size){ - monitor.acquire(); +int64_t Publisher::publish(int msgs, int listeners, int size){ Message msg; msg.setData(generateData(size)); - apr_time_t start(apr_time_as_msec(apr_time_now())); - for(int i = 0; i < msgs; i++){ - channel->publish(msg, Exchange::DEFAULT_TOPIC_EXCHANGE, controlTopic); - } - //send report request - Message reportRequest; - reportRequest.getHeaders().setString("TYPE", "REPORT_REQUEST"); - channel->publish(reportRequest, Exchange::DEFAULT_TOPIC_EXCHANGE, controlTopic); - if(transactional){ - channel->commit(); + int64_t start = getTimeMsecs(); + { + Monitor::ScopedLock l(monitor); + for(int i = 0; i < msgs; i++){ + channel->publish(msg, Exchange::DEFAULT_TOPIC_EXCHANGE, controlTopic); + } + //send report request + Message reportRequest; + reportRequest.getHeaders().setString("TYPE", "REPORT_REQUEST"); + channel->publish(reportRequest, Exchange::DEFAULT_TOPIC_EXCHANGE, controlTopic); + if(transactional){ + channel->commit(); + } + + waitForCompletion(listeners); } - waitForCompletion(listeners); - monitor.release(); - apr_time_t finish(apr_time_as_msec(apr_time_now())); - + int64_t finish(getTimeMsecs()); return finish - start; } diff --git a/cpp/test/unit/qpid/apr/APRBaseTest.cpp b/cpp/test/unit/qpid/apr/APRBaseTest.cpp new file mode 100644 index 0000000000..a0f88f78db --- /dev/null +++ b/cpp/test/unit/qpid/apr/APRBaseTest.cpp @@ -0,0 +1,44 @@ +/* + * + * Copyright (c) 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#include "qpid/apr/APRBase.h" +#include +#include + +using namespace qpid::sys; + +class APRBaseTest : public CppUnit::TestCase +{ + CPPUNIT_TEST_SUITE(APRBaseTest); + CPPUNIT_TEST(testMe); + CPPUNIT_TEST_SUITE_END(); + + public: + + void testMe() + { + APRBase::increment(); + APRBase::increment(); + APRBase::decrement(); + APRBase::decrement(); + } +}; + +// Make this test suite a plugin. +CPPUNIT_PLUGIN_IMPLEMENT(); +CPPUNIT_TEST_SUITE_REGISTRATION(APRBaseTest); + diff --git a/cpp/test/unit/qpid/broker/MessageTest.cpp b/cpp/test/unit/qpid/broker/MessageTest.cpp index 1dbbeda827..c0b9225483 100644 --- a/cpp/test/unit/qpid/broker/MessageTest.cpp +++ b/cpp/test/unit/qpid/broker/MessageTest.cpp @@ -15,14 +15,12 @@ * limitations under the License. * */ -#include "qpid/sys/APRBase.h" -#include "qpid/broker/Message.h" +#include #include #include using namespace qpid::broker; using namespace qpid::framing; -using namespace qpid::sys; class MessageTest : public CppUnit::TestCase { @@ -34,7 +32,6 @@ class MessageTest : public CppUnit::TestCase void testMe() { - APRBase::increment(); const int size(10); for(int i = 0; i < size; i++){ Message::shared_ptr msg = Message::shared_ptr(new Message(0, "A", "B", true, true)); diff --git a/cpp/test/unit/qpid/sys/APRBaseTest.cpp b/cpp/test/unit/qpid/sys/APRBaseTest.cpp deleted file mode 100644 index fc0c7dd9e1..0000000000 --- a/cpp/test/unit/qpid/sys/APRBaseTest.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - * - * Copyright (c) 2006 The Apache Software Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -#include "qpid/sys/APRBase.h" -#include -#include - -using namespace qpid::sys; - -class APRBaseTest : public CppUnit::TestCase -{ - CPPUNIT_TEST_SUITE(APRBaseTest); - CPPUNIT_TEST(testMe); - CPPUNIT_TEST_SUITE_END(); - - public: - - void testMe() - { - APRBase::increment(); - APRBase::increment(); - APRBase::decrement(); - APRBase::decrement(); - } -}; - -// Make this test suite a plugin. -CPPUNIT_PLUGIN_IMPLEMENT(); -CPPUNIT_TEST_SUITE_REGISTRATION(APRBaseTest); - -- cgit v1.2.1