summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorGordon Sim <gsim@apache.org>2007-06-27 15:29:17 +0000
committerGordon Sim <gsim@apache.org>2007-06-27 15:29:17 +0000
commitd7c68d138a1151db2b0d133c94f8b1843850e867 (patch)
tree1171bf86137f08f2ece9e0516407a3735ecc3fca /cpp/src
parentd3f472ec2033df0cc35f020819477e4f59077046 (diff)
downloadqpid-python-d7c68d138a1151db2b0d133c94f8b1843850e867.tar.gz
Fixes and tests:
* ExchangeRegistry::get() caused a pair to be inserted with a 'null' pointer if the xchange didn't exist * HeadersExchange::isBound() didn't check queue param git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@551197 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/qpid/broker/BrokerAdapter.cpp1
-rw-r--r--cpp/src/qpid/broker/ExchangeRegistry.cpp6
-rw-r--r--cpp/src/qpid/broker/HeadersExchange.cpp2
-rw-r--r--cpp/src/tests/ExchangeTest.cpp16
4 files changed, 20 insertions, 5 deletions
diff --git a/cpp/src/qpid/broker/BrokerAdapter.cpp b/cpp/src/qpid/broker/BrokerAdapter.cpp
index 93a3a319ac..c31f4d197d 100644
--- a/cpp/src/qpid/broker/BrokerAdapter.cpp
+++ b/cpp/src/qpid/broker/BrokerAdapter.cpp
@@ -153,7 +153,6 @@ void BrokerAdapter::ExchangeHandlerImpl::declare(const MethodContext& context, u
void BrokerAdapter::ExchangeHandlerImpl::delete_(const MethodContext& context, uint16_t /*ticket*/,
const string& name, bool /*ifUnused*/, bool nowait){
-
//TODO: implement unused
Exchange::shared_ptr exchange(broker.getExchanges().get(name));
if (exchange->isDurable()) broker.getStore().destroy(*exchange);
diff --git a/cpp/src/qpid/broker/ExchangeRegistry.cpp b/cpp/src/qpid/broker/ExchangeRegistry.cpp
index 3bf211b960..9555fa43a4 100644
--- a/cpp/src/qpid/broker/ExchangeRegistry.cpp
+++ b/cpp/src/qpid/broker/ExchangeRegistry.cpp
@@ -71,10 +71,10 @@ void ExchangeRegistry::destroy(const string& name){
Exchange::shared_ptr ExchangeRegistry::get(const string& name){
Mutex::ScopedLock locker(lock);
- Exchange::shared_ptr exchange =exchanges[name];
- if (!exchange)
+ ExchangeMap::iterator i = exchanges.find(name);
+ if (i == exchanges.end())
throw ChannelException(404, "Exchange not found:" + name);
- return exchange;
+ return i->second;
}
namespace
diff --git a/cpp/src/qpid/broker/HeadersExchange.cpp b/cpp/src/qpid/broker/HeadersExchange.cpp
index a9405e1f6d..36f7330433 100644
--- a/cpp/src/qpid/broker/HeadersExchange.cpp
+++ b/cpp/src/qpid/broker/HeadersExchange.cpp
@@ -84,7 +84,7 @@ void HeadersExchange::route(Deliverable& msg, const string& /*routingKey*/, cons
bool HeadersExchange::isBound(Queue::shared_ptr queue, const string* const, const FieldTable* const args)
{
for (Bindings::iterator i = bindings.begin(); i != bindings.end(); ++i) {
- if ( (!args || equal(i->first, *args)) && i->second == queue) {
+ if ( (!args || equal(i->first, *args)) && (!queue || i->second == queue)) {
return true;
}
}
diff --git a/cpp/src/tests/ExchangeTest.cpp b/cpp/src/tests/ExchangeTest.cpp
index 0033aa7529..595b025e86 100644
--- a/cpp/src/tests/ExchangeTest.cpp
+++ b/cpp/src/tests/ExchangeTest.cpp
@@ -19,10 +19,12 @@
*
*/
+#include "qpid/Exception.h"
#include "qpid/broker/BrokerExchange.h"
#include "qpid/broker/BrokerQueue.h"
#include "qpid/broker/DeliverableMessage.h"
#include "qpid/broker/DirectExchange.h"
+#include "qpid/broker/ExchangeRegistry.h"
#include "qpid/broker/FanOutExchange.h"
#include "qpid/broker/HeadersExchange.h"
#include "qpid/broker/TopicExchange.h"
@@ -33,12 +35,14 @@
using namespace qpid::broker;
using namespace qpid::framing;
using namespace qpid::sys;
+using namespace qpid;
class ExchangeTest : public CppUnit::TestCase
{
CPPUNIT_TEST_SUITE(ExchangeTest);
CPPUNIT_TEST(testMe);
CPPUNIT_TEST(testIsBound);
+ CPPUNIT_TEST(testDeleteGetAndRedeclare);
CPPUNIT_TEST_SUITE_END();
public:
@@ -158,6 +162,18 @@ class ExchangeTest : public CppUnit::TestCase
CPPUNIT_ASSERT(!headers.isBound(d, 0, &args2));
CPPUNIT_ASSERT(!headers.isBound(d, 0, &args3));
}
+
+ void testDeleteGetAndRedeclare() {
+ ExchangeRegistry exchanges;
+ exchanges.declare("my-exchange", "direct", false, FieldTable());
+ exchanges.destroy("my-exchange");
+ try {
+ exchanges.get("my-exchange");
+ } catch (const ChannelException&) {}
+ std::pair<Exchange::shared_ptr, bool> response = exchanges.declare("my-exchange", "direct", false, FieldTable());
+ CPPUNIT_ASSERT_EQUAL(string("direct"), response.first->getType());
+
+ }
};
// Make this test suite a plugin.