added RemoveOptions to Exchange, remove auto deletion (this should be handled by the AutoDelete option), and added
a test for an invalid remove(roIfUnused)
This commit is contained in:
parent
8e2b66677d
commit
c2dad7d6bb
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Reference in New Issue