From c2dad7d6bbd1d32e9cdf6413dc1e19d7f9973e0f Mon Sep 17 00:00:00 2001 From: Matt Broadstone Date: Tue, 10 Jun 2014 21:41:28 -0400 Subject: [PATCH] added RemoveOptions to Exchange, remove auto deletion (this should be handled by the AutoDelete option), and added a test for an invalid remove(roIfUnused) --- src/amqp_exchange.cpp | 10 ++---- src/amqp_exchange.h | 9 +++++- .../auto/qamqpexchange/tst_qamqpexchange.cpp | 32 +++++++++++++++++-- 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/src/amqp_exchange.cpp b/src/amqp_exchange.cpp index 4dc70f2..0e76192 100644 --- a/src/amqp_exchange.cpp +++ b/src/amqp_exchange.cpp @@ -118,7 +118,6 @@ Exchange::Exchange(int channelNumber, Client *parent) Exchange::~Exchange() { - remove(); } void Exchange::channelOpened() @@ -130,7 +129,6 @@ void Exchange::channelOpened() void Exchange::channelClosed() { - remove(true, true); } Exchange::ExchangeOptions Exchange::options() const @@ -159,7 +157,7 @@ void Exchange::declare(const QString &type, ExchangeOptions options , const Fram d->declare(); } -void Exchange::remove(bool ifUnused, bool noWait) +void Exchange::remove(int options) { Q_D(Exchange); Frame::Method frame(Frame::fcExchange, ExchangePrivate::miDelete); @@ -170,11 +168,7 @@ void Exchange::remove(bool ifUnused, bool noWait) stream << qint16(0); //reserved 1 Frame::writeField('s', stream, d->name); - - qint8 flag = 0; - flag |= (ifUnused ? 0x1 : 0); - flag |= (noWait ? 0x2 : 0); - stream << flag; //reserved 1 + stream << qint8(options); frame.setArguments(arguments); d->sendFrame(frame); diff --git a/src/amqp_exchange.h b/src/amqp_exchange.h index 8f380db..0ce303e 100644 --- a/src/amqp_exchange.h +++ b/src/amqp_exchange.h @@ -26,6 +26,13 @@ public: }; QString type() const; + enum RemoveOption { + roForce = 0x0, + roIfUnused = 0x1, + roNoWait = 0x04 + }; + Q_DECLARE_FLAGS(RemoveOptions, RemoveOption) + enum ExchangeOption { NoOptions = 0x0, Passive = 0x01, @@ -46,7 +53,7 @@ public: void declare(const QString &type = QLatin1String("direct"), ExchangeOptions options = NoOptions, const Frame::TableField &args = Frame::TableField()); - void remove(bool ifUnused = true, bool noWait = true); + void remove(int options = roIfUnused|roNoWait); // AMQP Basic void publish(const QString &key, const QString &message, diff --git a/tests/auto/qamqpexchange/tst_qamqpexchange.cpp b/tests/auto/qamqpexchange/tst_qamqpexchange.cpp index a27273a..6375ebd 100644 --- a/tests/auto/qamqpexchange/tst_qamqpexchange.cpp +++ b/tests/auto/qamqpexchange/tst_qamqpexchange.cpp @@ -14,7 +14,7 @@ class tst_QAMQPExchange : public TestCase private Q_SLOTS: void standardTypes_data(); void standardTypes(); - + void removeIfUnused(); }; void tst_QAMQPExchange::standardTypes_data() @@ -37,12 +37,40 @@ void tst_QAMQPExchange::standardTypes() Exchange *exchange = client.createExchange("test"); exchange->declare(type); QVERIFY(waitForSignal(exchange, SIGNAL(declared()))); - exchange->remove(false, false); + exchange->remove(Exchange::roForce); QVERIFY(waitForSignal(exchange, SIGNAL(removed()))); client.disconnectFromHost(); QVERIFY(waitForSignal(&client, SIGNAL(disconnected()))); } +void tst_QAMQPExchange::removeIfUnused() +{ + Client client; + client.connectToHost(); + QVERIFY(waitForSignal(&client, SIGNAL(connected()))); + + Exchange *exchange = client.createExchange("test-if-unused-exchange"); + exchange->declare(Exchange::Direct, Exchange::AutoDelete); + QVERIFY(waitForSignal(exchange, SIGNAL(declared()))); + + Queue *queue = client.createQueue("test-if-unused-queue"); + queue->declare(); + QVERIFY(waitForSignal(queue, SIGNAL(declared()))); + queue->bind("test-if-unused-exchange", "testRoutingKey"); + QVERIFY(waitForSignal(queue, SIGNAL(bound()))); + + exchange->remove(Exchange::roIfUnused); + QVERIFY(waitForSignal(exchange, SIGNAL(error(ChannelError)))); + QCOMPARE(exchange->error(), Exchange::PreconditionFailedError); + QVERIFY(!exchange->errorString().isEmpty()); + + // cleanup + queue->remove(Queue::roForce); + QVERIFY(waitForSignal(queue, SIGNAL(removed()))); + client.disconnectFromHost(); + QVERIFY(waitForSignal(&client, SIGNAL(disconnected()))); +} + QTEST_MAIN(tst_QAMQPExchange) #include "tst_qamqpexchange.moc"