From 1a14b81c86c49d562486ab2c55a75c564144fa71 Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Thu, 22 Jan 2009 20:29:12 +0000 Subject: Removed BodyHolder: minor performance improvement, opens the way for more efficient memory management. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@736783 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/tests/Blob.cpp | 128 ----------------------------------- cpp/src/tests/ExchangeTest.cpp | 4 +- cpp/src/tests/FramingTest.cpp | 4 +- cpp/src/tests/HeaderTest.cpp | 4 +- cpp/src/tests/Makefile.am | 2 +- cpp/src/tests/MessageBuilderTest.cpp | 29 ++++---- cpp/src/tests/MessageTest.cpp | 9 ++- cpp/src/tests/MessageUtils.h | 6 +- cpp/src/tests/QueueTest.cpp | 4 +- cpp/src/tests/SessionState.cpp | 13 ++-- cpp/src/tests/ssl_test | 2 +- 11 files changed, 36 insertions(+), 169 deletions(-) (limited to 'cpp/src/tests') diff --git a/cpp/src/tests/Blob.cpp b/cpp/src/tests/Blob.cpp index c40e43b96e..e69de29bb2 100644 --- a/cpp/src/tests/Blob.cpp +++ b/cpp/src/tests/Blob.cpp @@ -1,128 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -#include "qpid/framing/Blob.h" - -#include "unit_test.h" - -QPID_AUTO_TEST_SUITE(BlobTestSuite) - -using namespace std; -using namespace qpid::framing; - -struct Base { - int id; - int magic; - - Base(int n) : id(n), magic(42) {} - Base(const Base& c) : id(c.id), magic(42) {} - ~Base() { BOOST_CHECK_EQUAL(42, magic); } // Detect random data. -}; - -template struct Count : public Base { - static int instances; - bool destroyed; - - Count(int n) : Base(n), destroyed(false) { ++instances; } - Count(const Count& c) : Base(c), destroyed(false) { ++instances; } - ~Count() { - BOOST_CHECK(!destroyed); // Detect double-destructor - destroyed=true; - BOOST_CHECK(--instances >= 0); - } -}; - -template int Count::instances = 0; - -struct Foo : public Count { Foo(int n) : Count(n) {}; }; -struct Bar : public Count { Bar(int n) : Count(n) {}; }; - -typedef Blob TestBlob ; - -QPID_AUTO_TEST_CASE(testBlobCtor) { - { - TestBlob empty; - BOOST_CHECK(empty.empty()); - BOOST_CHECK(empty.get() == 0); - - TestBlob empty2(empty); - BOOST_CHECK(empty2.empty()); - - TestBlob foo(in_place(1)); - BOOST_CHECK(!foo.empty()); - BOOST_CHECK_EQUAL(1, foo.get()->id); - BOOST_CHECK_EQUAL(1, Foo::instances); - - TestBlob foo2(foo); - BOOST_CHECK(!foo2.empty()); - BOOST_CHECK_EQUAL(1, foo2.get()->id); - BOOST_CHECK_EQUAL(2, Foo::instances); - } - - BOOST_CHECK_EQUAL(0, Foo::instances); - BOOST_CHECK_EQUAL(0, Bar::instances); -} - - -QPID_AUTO_TEST_CASE(testAssign) { - { - TestBlob b; - b = Foo(2); - BOOST_CHECK_EQUAL(2, b.get()->id); - BOOST_CHECK_EQUAL(1, Foo::instances); - - TestBlob b2(b); - BOOST_CHECK_EQUAL(2, b.get()->id); - BOOST_CHECK_EQUAL(2, Foo::instances); - - b2 = Bar(3); - BOOST_CHECK_EQUAL(3, b2.get()->id); - BOOST_CHECK_EQUAL(1, Foo::instances); - BOOST_CHECK_EQUAL(1, Bar::instances); - - b2 = in_place(4); - BOOST_CHECK_EQUAL(4, b2.get()->id); - BOOST_CHECK_EQUAL(2, Foo::instances); - BOOST_CHECK_EQUAL(0, Bar::instances); - - b2.clear(); - BOOST_CHECK(b2.empty()); - BOOST_CHECK_EQUAL(1, Foo::instances); - } - BOOST_CHECK_EQUAL(0, Foo::instances); - BOOST_CHECK_EQUAL(0, Bar::instances); -} - - -QPID_AUTO_TEST_CASE(testClear) { - TestBlob b(in_place(5)); - TestBlob c(b); - BOOST_CHECK(!c.empty()); - BOOST_CHECK(!b.empty()); - BOOST_CHECK_EQUAL(2, Foo::instances); - - c.clear(); - BOOST_CHECK(c.empty()); - BOOST_CHECK_EQUAL(1, Foo::instances); - - b.clear(); - BOOST_CHECK(b.empty()); - BOOST_CHECK_EQUAL(0, Foo::instances); -} - -QPID_AUTO_TEST_SUITE_END() diff --git a/cpp/src/tests/ExchangeTest.cpp b/cpp/src/tests/ExchangeTest.cpp index 0946d3115d..2100fb5ed7 100644 --- a/cpp/src/tests/ExchangeTest.cpp +++ b/cpp/src/tests/ExchangeTest.cpp @@ -167,8 +167,8 @@ QPID_AUTO_TEST_CASE(testDeleteGetAndRedeclare) intrusive_ptr cmessage(std::string exchange, std::string routingKey) { intrusive_ptr msg(new Message()); - AMQFrame method(in_place(ProtocolVersion(), exchange, 0, 0)); - AMQFrame header(in_place()); + AMQFrame method((MessageTransferBody(ProtocolVersion(), exchange, 0, 0))); + AMQFrame header((AMQHeaderBody())); msg->getFrames().append(method); msg->getFrames().append(header); msg->getFrames().getHeaders()->get(true)->setRoutingKey(routingKey); diff --git a/cpp/src/tests/FramingTest.cpp b/cpp/src/tests/FramingTest.cpp index f82507c0a7..e09ee19bc2 100644 --- a/cpp/src/tests/FramingTest.cpp +++ b/cpp/src/tests/FramingTest.cpp @@ -123,7 +123,7 @@ QPID_AUTO_TEST_CASE(testConnectionRedirectBodyFrame) hosts.add(boost::shared_ptr(new Str16Value(a))); hosts.add(boost::shared_ptr(new Str16Value(b))); - AMQFrame in(in_place(version, a, hosts)); + AMQFrame in((ConnectionRedirectBody(version, a, hosts))); in.setChannel(999); in.encode(wbuff); @@ -138,7 +138,7 @@ QPID_AUTO_TEST_CASE(testMessageCancelBodyFrame) char buffer[1024]; ProtocolVersion version(highestProtocolVersion); Buffer wbuff(buffer, sizeof(buffer)); - AMQFrame in(in_place(version, "tag")); + AMQFrame in((MessageCancelBody(version, "tag"))); in.setChannel(999); in.encode(wbuff); diff --git a/cpp/src/tests/HeaderTest.cpp b/cpp/src/tests/HeaderTest.cpp index 33bf705e65..01e7c22ee6 100644 --- a/cpp/src/tests/HeaderTest.cpp +++ b/cpp/src/tests/HeaderTest.cpp @@ -49,7 +49,7 @@ QPID_AUTO_TEST_CASE(testGenericProperties) QPID_AUTO_TEST_CASE(testMessageProperties) { - AMQFrame out(in_place()); + AMQFrame out((AMQHeaderBody())); MessageProperties* props1 = out.castBody()->get(true); @@ -84,7 +84,7 @@ QPID_AUTO_TEST_CASE(testMessageProperties) QPID_AUTO_TEST_CASE(testDeliveryProperies) { - AMQFrame out(in_place()); + AMQFrame out((AMQHeaderBody())); DeliveryProperties* props1 = out.castBody()->get(true); diff --git a/cpp/src/tests/Makefile.am b/cpp/src/tests/Makefile.am index 6392322f9a..d675b587b1 100644 --- a/cpp/src/tests/Makefile.am +++ b/cpp/src/tests/Makefile.am @@ -54,7 +54,7 @@ unit_test_SOURCES= unit_test.cpp unit_test.h \ BrokerFixture.h SocketProxy.h \ exception_test.cpp \ RefCounted.cpp \ - SessionState.cpp Blob.cpp logging.cpp \ + SessionState.cpp logging.cpp \ AsyncCompletion.cpp \ Url.cpp Uuid.cpp \ Shlib.cpp FieldValue.cpp FieldTable.cpp Array.cpp \ diff --git a/cpp/src/tests/MessageBuilderTest.cpp b/cpp/src/tests/MessageBuilderTest.cpp index 313a91c053..a183742832 100644 --- a/cpp/src/tests/MessageBuilderTest.cpp +++ b/cpp/src/tests/MessageBuilderTest.cpp @@ -101,9 +101,8 @@ QPID_AUTO_TEST_CASE(testHeaderOnly) std::string exchange("builder-exchange"); std::string key("builder-exchange"); - AMQFrame method(in_place( - ProtocolVersion(), exchange, 0, 0)); - AMQFrame header(in_place()); + AMQFrame method((MessageTransferBody(ProtocolVersion(), exchange, 0, 0))); + AMQFrame header((AMQHeaderBody())); header.castBody()->get(true)->setContentLength(0); header.castBody()->get(true)->setRoutingKey(key); @@ -126,9 +125,9 @@ QPID_AUTO_TEST_CASE(test1ContentFrame) std::string exchange("builder-exchange"); std::string key("builder-exchange"); - AMQFrame method(in_place(ProtocolVersion(), exchange, 0, 0)); - AMQFrame header(in_place()); - AMQFrame content(in_place(data)); + AMQFrame method((MessageTransferBody(ProtocolVersion(), exchange, 0, 0))); + AMQFrame header((AMQHeaderBody())); + AMQFrame content((AMQContentBody(data))); method.setEof(false); header.setBof(false); header.setEof(false); @@ -160,11 +159,10 @@ QPID_AUTO_TEST_CASE(test2ContentFrames) std::string exchange("builder-exchange"); std::string key("builder-exchange"); - AMQFrame method(in_place( - ProtocolVersion(), exchange, 0, 0)); - AMQFrame header(in_place()); - AMQFrame content1(in_place(data1)); - AMQFrame content2(in_place(data2)); + AMQFrame method((MessageTransferBody(ProtocolVersion(), exchange, 0, 0))); + AMQFrame header((AMQHeaderBody())); + AMQFrame content1((AMQContentBody(data1))); + AMQFrame content2((AMQContentBody(data2))); method.setEof(false); header.setBof(false); header.setEof(false); @@ -197,11 +195,10 @@ QPID_AUTO_TEST_CASE(testStaging) std::string exchange("builder-exchange"); std::string key("builder-exchange"); - AMQFrame method(in_place( - ProtocolVersion(), exchange, 0, 0)); - AMQFrame header(in_place()); - AMQFrame content1(in_place(data1)); - AMQFrame content2(in_place(data2)); + AMQFrame method(MessageTransferBody(ProtocolVersion(), exchange, 0, 0)); + AMQFrame header((AMQHeaderBody())); + AMQFrame content1((AMQContentBody(data1))); + AMQFrame content2((AMQContentBody(data2))); header.castBody()->get(true)->setContentLength(data1.size() + data2.size()); header.castBody()->get(true)->setRoutingKey(key); diff --git a/cpp/src/tests/MessageTest.cpp b/cpp/src/tests/MessageTest.cpp index f9292ee53e..8fd9a53c7c 100644 --- a/cpp/src/tests/MessageTest.cpp +++ b/cpp/src/tests/MessageTest.cpp @@ -46,11 +46,10 @@ QPID_AUTO_TEST_CASE(testEncodeDecode) intrusive_ptr msg(new Message()); - AMQFrame method(in_place( - ProtocolVersion(), exchange, 0, 0)); - AMQFrame header(in_place()); - AMQFrame content1(in_place(data1)); - AMQFrame content2(in_place(data2)); + AMQFrame method((MessageTransferBody(ProtocolVersion(), exchange, 0, 0))); + AMQFrame header((AMQHeaderBody())); + AMQFrame content1((AMQContentBody(data1))); + AMQFrame content2((AMQContentBody(data2))); msg->getFrames().append(method); msg->getFrames().append(header); diff --git a/cpp/src/tests/MessageUtils.h b/cpp/src/tests/MessageUtils.h index 81508e534e..67a852aa10 100644 --- a/cpp/src/tests/MessageUtils.h +++ b/cpp/src/tests/MessageUtils.h @@ -35,8 +35,8 @@ struct MessageUtils { boost::intrusive_ptr msg(new Message()); - AMQFrame method(in_place(ProtocolVersion(), exchange, 0, 0)); - AMQFrame header(in_place()); + AMQFrame method(( MessageTransferBody(ProtocolVersion(), exchange, 0, 0))); + AMQFrame header((AMQHeaderBody())); msg->getFrames().append(method); msg->getFrames().append(header); @@ -49,7 +49,7 @@ struct MessageUtils static void addContent(boost::intrusive_ptr msg, const string& data) { - AMQFrame content(in_place(data)); + AMQFrame content((AMQContentBody(data))); msg->getFrames().append(content); } }; diff --git a/cpp/src/tests/QueueTest.cpp b/cpp/src/tests/QueueTest.cpp index dee6de83a7..079b9b0ba6 100644 --- a/cpp/src/tests/QueueTest.cpp +++ b/cpp/src/tests/QueueTest.cpp @@ -67,8 +67,8 @@ public: intrusive_ptr create_message(std::string exchange, std::string routingKey) { intrusive_ptr msg(new Message()); - AMQFrame method(in_place(ProtocolVersion(), exchange, 0, 0)); - AMQFrame header(in_place()); + AMQFrame method((MessageTransferBody(ProtocolVersion(), exchange, 0, 0))); + AMQFrame header((AMQHeaderBody())); msg->getFrames().append(method); msg->getFrames().append(header); msg->getFrames().getHeaders()->get(true)->setRoutingKey(routingKey); diff --git a/cpp/src/tests/SessionState.cpp b/cpp/src/tests/SessionState.cpp index 2db25f9fe8..5e21ff2b70 100644 --- a/cpp/src/tests/SessionState.cpp +++ b/cpp/src/tests/SessionState.cpp @@ -45,8 +45,7 @@ T applyAccumulate(Iter begin, Iter end, T seed, const F& f) { // Create a frame with a one-char string. AMQFrame& frame(char s) { - static AMQFrame frame; - frame.setBody(AMQContentBody(string(&s, 1))); + static AMQFrame frame((AMQContentBody(string(&s, 1)))); return frame; } @@ -64,7 +63,7 @@ string str(const boost::iterator_range::const_iterator>& frames } // Make a transfer command frame. AMQFrame transferFrame(bool hasContent) { - AMQFrame t(in_place()); + AMQFrame t((MessageTransferBody())); t.setFirstFrame(true); t.setLastFrame(true); t.setFirstSegment(true); @@ -73,7 +72,7 @@ AMQFrame transferFrame(bool hasContent) { } // Make a content frame AMQFrame contentFrame(string content, bool isLast=true) { - AMQFrame f(in_place(content)); + AMQFrame f((AMQContentBody(content))); f.setFirstFrame(true); f.setLastFrame(true); f.setFirstSegment(false); @@ -116,8 +115,8 @@ size_t transfers(qpid::SessionState& s, string content) { bind(transfer1Char, ref(s), _1)); } -size_t contentFrameSize(size_t n=1) { return AMQFrame(in_place()).encodedSize() + n; } -size_t transferFrameSize() { return AMQFrame(in_place()).encodedSize(); } +size_t contentFrameSize(size_t n=1) { return AMQFrame(( AMQContentBody())).encodedSize() + n; } +size_t transferFrameSize() { return AMQFrame((MessageTransferBody())).encodedSize(); } // ==== qpid::SessionState test classes @@ -134,7 +133,7 @@ QPID_AUTO_TEST_CASE(testSendGetReplyList) { transferN(s, "xyz"); BOOST_CHECK_EQUAL(str(s.senderExpected(SessionPoint(0,0))),"CabcCdCeCfCxyz"); // Ignore controls. - s.senderRecord(AMQFrame(in_place())); + s.senderRecord(AMQFrame(new SessionFlushBody())); BOOST_CHECK_EQUAL(str(s.senderExpected(SessionPoint(2,0))),"CeCfCxyz"); } diff --git a/cpp/src/tests/ssl_test b/cpp/src/tests/ssl_test index 047db93d20..c7b59b62ef 100755 --- a/cpp/src/tests/ssl_test +++ b/cpp/src/tests/ssl_test @@ -25,7 +25,7 @@ CONFIG=$(dirname $0)/config.null CERT_DIR=`pwd`/test_cert_db CERT_PW_FILE=`pwd`/cert.password HOSTNAME=`hostname` -COUNT=10000 +COUNT=10 trap stop_broker EXIT -- cgit v1.2.1