summaryrefslogtreecommitdiff
path: root/cpp/tests
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2007-02-06 15:01:45 +0000
committerAlan Conway <aconway@apache.org>2007-02-06 15:01:45 +0000
commitfbd97f554b04a109c95c01fe6ad538c5f50161af (patch)
tree0324d02ee4f8d6ca2387d1d3ff85bcd61a123a34 /cpp/tests
parent80b1b0b5f443bfb3c9d62a80e1419c224d0229d8 (diff)
downloadqpid-python-fbd97f554b04a109c95c01fe6ad538c5f50161af.tar.gz
* broker/Reference, tests/ReferenceTest: class representing a reference.
* broker/BrokerChannel.cpp (complete): get destination exchange from Message, don't assume only one message in progress (could have multiple references open.) * broker/BrokerMessageMessage.cpp,.h: Contains transfer body and vector of append bodies. Construct from Reference. * broker/CompletionHandler.h: Extracted from BrokerMessage, used for MessageMessage also. * broker/ExchangeRegistry.cpp: Moved throw for missing exchanges to registry. * cpp/tests/start_broker: Increased wait time to 5 secs. * cpp/tests/*: renamed DummyChannel as MockChannel. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/branches/qpid.0-9@504172 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/tests')
-rw-r--r--cpp/tests/ChannelTest.cpp15
-rw-r--r--cpp/tests/InMemoryContentTest.cpp4
-rw-r--r--cpp/tests/LazyLoadedContentTest.cpp4
-rw-r--r--cpp/tests/Makefile.am16
-rw-r--r--cpp/tests/MessageBuilderTest.cpp22
-rw-r--r--cpp/tests/MessageTest.cpp6
-rw-r--r--cpp/tests/MockChannel.h (renamed from cpp/tests/DummyChannel.h)18
-rw-r--r--cpp/tests/QueueTest.cpp4
-rw-r--r--cpp/tests/ReferenceTest.cpp116
-rw-r--r--cpp/tests/TxAckTest.cpp4
-rw-r--r--cpp/tests/TxPublishTest.cpp4
-rwxr-xr-xcpp/tests/start_broker2
12 files changed, 167 insertions, 48 deletions
diff --git a/cpp/tests/ChannelTest.cpp b/cpp/tests/ChannelTest.cpp
index a3dabe6408..dcfd2fdb90 100644
--- a/cpp/tests/ChannelTest.cpp
+++ b/cpp/tests/ChannelTest.cpp
@@ -28,7 +28,7 @@
#include <memory>
#include <AMQP_HighestVersion.h>
#include "AMQFrame.h"
-#include "DummyChannel.h"
+#include "MockChannel.h"
#include "broker/Connection.h"
#include "ProtocolInitiation.h"
@@ -39,7 +39,7 @@ using namespace qpid::sys;
using std::string;
using std::queue;
-struct DummyHandler : ConnectionOutputHandler{
+struct MockHandler : ConnectionOutputHandler{
std::vector<AMQFrame*> frames;
void send(AMQFrame* frame){ frames.push_back(frame); }
@@ -60,7 +60,7 @@ class ChannelTest : public CppUnit::TestCase
Broker::shared_ptr broker;
Connection connection;
- DummyHandler handler;
+ MockHandler handler;
class MockMessageStore : public NullMessageStore
{
@@ -240,10 +240,10 @@ class ChannelTest : public CppUnit::TestCase
Channel channel(
connection, 1, 1000/*framesize*/, &store, 10/*staging threshold*/);
const string data[] = {"abcde", "fghij", "klmno"};
-
+
Message* msg = new BasicMessage(
0, "my_exchange", "my_routing_key", false, false,
- DummyChannel::basicGetBody());
+ MockChannel::basicGetBody());
store.expect();
store.stage(msg);
@@ -253,7 +253,8 @@ class ChannelTest : public CppUnit::TestCase
store.destroy(msg);
store.test();
- Exchange::shared_ptr exchange(new FanOutExchange("my_exchange"));
+ Exchange::shared_ptr exchange =
+ broker->getExchanges().declare("my_exchange", "fanout").first;
Queue::shared_ptr queue(new Queue("my_queue"));
exchange->bind(queue, "", 0);
@@ -333,7 +334,7 @@ class ChannelTest : public CppUnit::TestCase
{
BasicMessage* msg = new BasicMessage(
0, exchange, routingKey, false, false,
- DummyChannel::basicGetBody());
+ MockChannel::basicGetBody());
AMQHeaderBody::shared_ptr header(new AMQHeaderBody(BASIC));
header->setContentSize(contentSize);
msg->setHeader(header);
diff --git a/cpp/tests/InMemoryContentTest.cpp b/cpp/tests/InMemoryContentTest.cpp
index db54ea44a0..c8433432e8 100644
--- a/cpp/tests/InMemoryContentTest.cpp
+++ b/cpp/tests/InMemoryContentTest.cpp
@@ -24,7 +24,7 @@
#include <iostream>
#include <list>
#include "AMQFrame.h"
-#include "DummyChannel.h"
+#include "MockChannel.h"
using std::list;
using std::string;
@@ -58,7 +58,7 @@ public:
void refragment(size_t inCount, string* in, size_t outCount, string* out, u_int32_t framesize = 5)
{
InMemoryContent content;
- DummyChannel channel(3);
+ MockChannel channel(3);
addframes(content, inCount, in);
content.send(channel, framesize);
diff --git a/cpp/tests/LazyLoadedContentTest.cpp b/cpp/tests/LazyLoadedContentTest.cpp
index 49e4ecc4ae..365e4f6a11 100644
--- a/cpp/tests/LazyLoadedContentTest.cpp
+++ b/cpp/tests/LazyLoadedContentTest.cpp
@@ -26,7 +26,7 @@
#include <list>
#include <sstream>
#include "AMQFrame.h"
-#include "DummyChannel.h"
+#include "MockChannel.h"
using std::list;
using std::string;
using boost::dynamic_pointer_cast;
@@ -92,7 +92,7 @@ public:
{
TestMessageStore store(in);
LazyLoadedContent content(&store, 0, in.size());
- DummyChannel channel(3);
+ MockChannel channel(3);
content.send(channel, framesize);
CPPUNIT_ASSERT_EQUAL(outCount, channel.out.frames.size());
diff --git a/cpp/tests/Makefile.am b/cpp/tests/Makefile.am
index a2bbc07213..7a8480cded 100644
--- a/cpp/tests/Makefile.am
+++ b/cpp/tests/Makefile.am
@@ -9,12 +9,6 @@ INCLUDES = \
-I$(top_srcdir)/lib/common/framing \
$(APR_CXXFLAGS)
-EXTRA_DIST = \
- topictest \
- qpid_test_plugin.h \
- MockConnectionInputHandler.h
-
-
client_exe_tests = \
client_test \
echo_service \
@@ -32,6 +26,7 @@ broker_tests = \
MessageBuilderTest \
MessageHandlerTest \
MessageTest \
+ ReferenceTest \
QueueRegistryTest \
QueueTest \
QueuePolicyTest \
@@ -69,7 +64,14 @@ noinst_PROGRAMS = $(client_exe_tests)
CLIENT_TESTS = client_test quick_topictest
TESTS = run-unit-tests start_broker $(CLIENT_TESTS) python_tests kill_broker
-EXTRA_DIST += $(TESTS) topictest
+
+EXTRA_DIST = \
+ $(TESTS) \
+ topictest \
+ qpid_test_plugin.h \
+ MockConnectionInputHandler.h \
+ MockChannel.h \
+ InProcessBroker.h
include gen.mk
diff --git a/cpp/tests/MessageBuilderTest.cpp b/cpp/tests/MessageBuilderTest.cpp
index dc660751b7..d1b9c6ee62 100644
--- a/cpp/tests/MessageBuilderTest.cpp
+++ b/cpp/tests/MessageBuilderTest.cpp
@@ -26,7 +26,7 @@
#include <qpid_test_plugin.h>
#include <iostream>
#include <memory>
-#include "DummyChannel.h"
+#include "MockChannel.h"
using namespace boost;
using namespace qpid::broker;
@@ -35,10 +35,10 @@ using namespace qpid::sys;
class MessageBuilderTest : public CppUnit::TestCase
{
- struct DummyHandler : MessageBuilder::CompletionHandler{
+ struct MockHandler : CompletionHandler {
Message::shared_ptr msg;
- virtual void complete(Message::shared_ptr& _msg){
+ virtual void complete(Message::shared_ptr _msg){
msg = _msg;
}
};
@@ -114,13 +114,13 @@ class MessageBuilderTest : public CppUnit::TestCase
public:
void testHeaderOnly(){
- DummyHandler handler;
+ MockHandler handler;
MessageBuilder builder(&handler);
Message::shared_ptr message(
new BasicMessage(
0, "test", "my_routing_key", false, false,
- DummyChannel::basicGetBody()));
+ MockChannel::basicGetBody()));
AMQHeaderBody::shared_ptr header(new AMQHeaderBody(BASIC));
header->setContentSize(0);
@@ -132,14 +132,14 @@ class MessageBuilderTest : public CppUnit::TestCase
}
void test1ContentFrame(){
- DummyHandler handler;
+ MockHandler handler;
MessageBuilder builder(&handler);
string data1("abcdefg");
Message::shared_ptr message(
new BasicMessage(0, "test", "my_routing_key", false, false,
- DummyChannel::basicGetBody()));
+ MockChannel::basicGetBody()));
AMQHeaderBody::shared_ptr header(new AMQHeaderBody(BASIC));
header->setContentSize(7);
AMQContentBody::shared_ptr part1(new AMQContentBody(data1));
@@ -154,7 +154,7 @@ class MessageBuilderTest : public CppUnit::TestCase
}
void test2ContentFrames(){
- DummyHandler handler;
+ MockHandler handler;
MessageBuilder builder(&handler);
string data1("abcdefg");
@@ -162,7 +162,7 @@ class MessageBuilderTest : public CppUnit::TestCase
Message::shared_ptr message(
new BasicMessage(0, "test", "my_routing_key", false, false,
- DummyChannel::basicGetBody()));
+ MockChannel::basicGetBody()));
AMQHeaderBody::shared_ptr header(new AMQHeaderBody(BASIC));
header->setContentSize(14);
AMQContentBody::shared_ptr part1(new AMQContentBody(data1));
@@ -185,7 +185,7 @@ class MessageBuilderTest : public CppUnit::TestCase
//loaded content is in use)
TestMessageStore store(14);
{
- DummyHandler handler;
+ MockHandler handler;
MessageBuilder builder(&handler, &store, 5);
string data1("abcdefg");
@@ -193,7 +193,7 @@ class MessageBuilderTest : public CppUnit::TestCase
Message::shared_ptr message(
new BasicMessage(0, "test", "my_routing_key", false, false,
- DummyChannel::basicGetBody()));
+ MockChannel::basicGetBody()));
AMQHeaderBody::shared_ptr header(new AMQHeaderBody(BASIC));
header->setContentSize(14);
BasicHeaderProperties* properties = dynamic_cast<BasicHeaderProperties*>(header->getProperties());
diff --git a/cpp/tests/MessageTest.cpp b/cpp/tests/MessageTest.cpp
index 103a23f0df..2f49a28b83 100644
--- a/cpp/tests/MessageTest.cpp
+++ b/cpp/tests/MessageTest.cpp
@@ -23,7 +23,7 @@
#include <iostream>
#include <AMQP_HighestVersion.h>
#include "AMQFrame.h"
-#include "DummyChannel.h"
+#include "MockChannel.h"
using namespace boost;
using namespace qpid::broker;
@@ -47,7 +47,7 @@ class MessageTest : public CppUnit::TestCase
BasicMessage::shared_ptr msg(
new BasicMessage(0, exchange, routingKey, false, false,
- DummyChannel::basicGetBody()));
+ MockChannel::basicGetBody()));
AMQHeaderBody::shared_ptr header(new AMQHeaderBody(BASIC));
header->setContentSize(14);
AMQContentBody::shared_ptr part1(new AMQContentBody(data1));
@@ -73,7 +73,7 @@ class MessageTest : public CppUnit::TestCase
CPPUNIT_ASSERT_EQUAL(string("xyz"), msg->getHeaderProperties()->getHeaders().getString("abc"));
CPPUNIT_ASSERT_EQUAL((u_int64_t) 14, msg->contentSize());
- DummyChannel channel(1);
+ MockChannel channel(1);
// FIXME aconway 2007-02-02: deliver should take const ProtocolVersion&
msg->deliver(channel, "ignore", 0, 100);
CPPUNIT_ASSERT_EQUAL((size_t) 3, channel.out.frames.size());
diff --git a/cpp/tests/DummyChannel.h b/cpp/tests/MockChannel.h
index 2b6bd9b2b9..10fcb56969 100644
--- a/cpp/tests/DummyChannel.h
+++ b/cpp/tests/MockChannel.h
@@ -1,5 +1,5 @@
-#ifndef _tests_DummyChannel_h
-#define _tests_DummyChannel_h
+#ifndef _tests_MockChannel_h
+#define _tests_MockChannel_h
/*
*
@@ -26,16 +26,16 @@
#include "framing/AMQFrame.h"
#include "BasicGetBody.h"
-/** Dummy output handler to collect frames */
-struct DummyOutputHandler : public qpid::framing::OutputHandler {
+/** Mock output handler to collect frames */
+struct MockOutputHandler : public qpid::framing::OutputHandler {
std::vector<qpid::framing::AMQFrame*> frames;
void send(qpid::framing::AMQFrame* frame){ frames.push_back(frame); }
};
/**
- * Combination dummy OutputHandler and ChannelAdapter for tests.
+ * Combination mock OutputHandler and ChannelAdapter for tests.
*/
-struct DummyChannel : public qpid::framing::ChannelAdapter
+struct MockChannel : public qpid::framing::ChannelAdapter
{
typedef qpid::framing::BasicGetBody Body;
static Body::shared_ptr basicGetBody() {
@@ -43,9 +43,9 @@ struct DummyChannel : public qpid::framing::ChannelAdapter
new Body(qpid::framing::ProtocolVersion()));
}
- DummyOutputHandler out;
+ MockOutputHandler out;
- DummyChannel(qpid::framing::ChannelId id) {
+ MockChannel(qpid::framing::ChannelId id) {
init(id, out, qpid::framing::ProtocolVersion());
}
@@ -66,4 +66,4 @@ struct DummyChannel : public qpid::framing::ChannelAdapter
};
-#endif /*!_tests_DummyChannel_h*/
+#endif /*!_tests_MockChannel_h*/
diff --git a/cpp/tests/QueueTest.cpp b/cpp/tests/QueueTest.cpp
index 7105509de6..59ca7728ca 100644
--- a/cpp/tests/QueueTest.cpp
+++ b/cpp/tests/QueueTest.cpp
@@ -22,7 +22,7 @@
#include <QueueRegistry.h>
#include <qpid_test_plugin.h>
#include <iostream>
-#include "DummyChannel.h"
+#include "MockChannel.h"
using namespace qpid::broker;
using namespace qpid::sys;
@@ -58,7 +58,7 @@ class QueueTest : public CppUnit::TestCase
Message::shared_ptr message(std::string exchange, std::string routingKey) {
return Message::shared_ptr(
new BasicMessage(0, exchange, routingKey, true, true,
- DummyChannel::basicGetBody()));
+ MockChannel::basicGetBody()));
}
void testConsumers(){
diff --git a/cpp/tests/ReferenceTest.cpp b/cpp/tests/ReferenceTest.cpp
new file mode 100644
index 0000000000..b50511f724
--- /dev/null
+++ b/cpp/tests/ReferenceTest.cpp
@@ -0,0 +1,116 @@
+/*
+ *
+ * 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 <iostream>
+#include <memory>
+#include "qpid_test_plugin.h"
+#include "Reference.h"
+#include "BrokerMessageMessage.h"
+#include "MessageTransferBody.h"
+#include "MessageAppendBody.h"
+#include "CompletionHandler.h"
+
+using namespace boost;
+using namespace qpid::broker;
+using namespace qpid::framing;
+using namespace std;
+
+class ReferenceTest : public CppUnit::TestCase
+{
+ CPPUNIT_TEST_SUITE(ReferenceTest);
+ CPPUNIT_TEST(testRegistry);
+ CPPUNIT_TEST(testReference);
+ CPPUNIT_TEST_SUITE_END();
+
+
+ struct MockCompletionHandler : public CompletionHandler {
+ std::vector<Message::shared_ptr> messages;
+ void complete(Message::shared_ptr msg) { messages.push_back(msg); }
+ };
+
+ MockCompletionHandler handler;
+ ProtocolVersion v;
+ ReferenceRegistry registry;
+ MessageTransferBody::shared_ptr t1, t2;
+ MessageAppendBody::shared_ptr a1, a2;
+ public:
+
+ ReferenceTest() :
+ registry(handler),
+ t1(new MessageTransferBody(v)),
+ t2(new MessageTransferBody(v)),
+ a1(new MessageAppendBody(v)),
+ a2(new MessageAppendBody(v))
+ {}
+
+ void testRegistry() {
+ Reference& ref = registry.open("foo");
+ CPPUNIT_ASSERT_EQUAL(string("foo"), ref.getId());
+ CPPUNIT_ASSERT(&ref == &registry.get("foo"));
+ try {
+ registry.get("none");
+ CPPUNIT_FAIL("Expected exception");
+ } catch (...) {}
+ try {
+ registry.open("foo");
+ CPPUNIT_FAIL("Expected exception");
+ } catch(...) {}
+ }
+
+ MessageMessage& handlerMessage(size_t i) {
+ CPPUNIT_ASSERT(handler.messages.size() > i);
+ MessageMessage* msg = dynamic_cast<MessageMessage*>(
+ handler.messages[i].get());
+ CPPUNIT_ASSERT(msg);
+ return *msg;
+ }
+
+ void testReference() {
+ Reference& ref = registry.open("foo");
+ ref.transfer(t1);
+ ref.transfer(t2);
+ CPPUNIT_ASSERT_EQUAL(size_t(2), ref.getTransfers().size());
+ ref.append(a1);
+ ref.append(a2);
+ CPPUNIT_ASSERT_EQUAL(size_t(2), ref.getAppends().size());
+ ref.close();
+ try {
+ registry.open("foo");
+ CPPUNIT_FAIL("Expected exception");
+ } catch(...) {}
+
+ vector<Message::shared_ptr>& messages = handler.messages;
+ CPPUNIT_ASSERT_EQUAL(size_t(2), messages.size());
+
+ CPPUNIT_ASSERT_EQUAL(handlerMessage(0).getTransfer(), t1);
+ CPPUNIT_ASSERT_EQUAL(handlerMessage(0).getAppends()[0], a1);
+ CPPUNIT_ASSERT_EQUAL(handlerMessage(0).getAppends()[1], a2);
+
+ CPPUNIT_ASSERT_EQUAL(handlerMessage(1).getTransfer(), t2);
+ CPPUNIT_ASSERT_EQUAL(handlerMessage(1).getAppends()[0], a1);
+ CPPUNIT_ASSERT_EQUAL(handlerMessage(1).getAppends()[1], a2);
+ }
+
+
+};
+
+// Make this test suite a plugin.
+CPPUNIT_PLUGIN_IMPLEMENT();
+CPPUNIT_TEST_SUITE_REGISTRATION(ReferenceTest);
diff --git a/cpp/tests/TxAckTest.cpp b/cpp/tests/TxAckTest.cpp
index 07381d187d..e464ff78f4 100644
--- a/cpp/tests/TxAckTest.cpp
+++ b/cpp/tests/TxAckTest.cpp
@@ -25,7 +25,7 @@
#include <iostream>
#include <list>
#include <vector>
-#include "DummyChannel.h"
+#include "MockChannel.h"
using std::list;
using std::vector;
@@ -72,7 +72,7 @@ public:
for(int i = 0; i < 10; i++){
Message::shared_ptr msg(
new BasicMessage(0, "exchange", "routing_key", false, false,
- DummyChannel::basicGetBody()));
+ MockChannel::basicGetBody()));
msg->setHeader(AMQHeaderBody::shared_ptr(new AMQHeaderBody(BASIC)));
msg->getHeaderProperties()->setDeliveryMode(PERSISTENT);
messages.push_back(msg);
diff --git a/cpp/tests/TxPublishTest.cpp b/cpp/tests/TxPublishTest.cpp
index 08e5339048..39d27a754d 100644
--- a/cpp/tests/TxPublishTest.cpp
+++ b/cpp/tests/TxPublishTest.cpp
@@ -25,7 +25,7 @@
#include <iostream>
#include <list>
#include <vector>
-#include "DummyChannel.h"
+#include "MockChannel.h"
using std::list;
using std::pair;
@@ -78,7 +78,7 @@ public:
queue1(new Queue("queue1", false, &store, 0)),
queue2(new Queue("queue2", false, &store, 0)),
msg(new BasicMessage(0, "exchange", "routing_key", false, false,
- DummyChannel::basicGetBody())),
+ MockChannel::basicGetBody())),
op(msg, &xid)
{
msg->setHeader(AMQHeaderBody::shared_ptr(new AMQHeaderBody(BASIC)));
diff --git a/cpp/tests/start_broker b/cpp/tests/start_broker
index 05510b17ac..fe30458463 100755
--- a/cpp/tests/start_broker
+++ b/cpp/tests/start_broker
@@ -11,4 +11,4 @@ rm -rf $LOG $PID
# FIXME aconway 2007-01-18: qpidd should not return till it is accepting
# connections, remove arbitrary sleep.
-sleep 2
+sleep 5