add test for sharing a channel

Though it's not necessarily recommended (per spec), Channels can be
shared by multiple Exchanges and Queues. I've added a test here showing
that's possible with QAMQP
This commit is contained in:
Matt Broadstone 2014-08-08 17:09:00 -04:00
parent 870af7b5d4
commit 0bc1c32bd8
4 changed files with 25 additions and 13 deletions

View File

@ -75,7 +75,6 @@ bool ExchangePrivate::_q_method(const Frame::Method &frame)
break;
default:
qDebug() << Q_FUNC_INFO << "unhandled exchange method: " << frame.id();
break;
}
@ -87,7 +86,6 @@ bool ExchangePrivate::_q_method(const Frame::Method &frame)
break;
default:
qDebug() << Q_FUNC_INFO << "unhandled basic method: " << frame.id();
break;
}

View File

@ -17,6 +17,7 @@ private Q_SLOTS:
void close();
void resume();
void sharedChannel();
private:
QScopedPointer<Client> client;
@ -70,5 +71,19 @@ void tst_QAMQPChannel::resume()
QVERIFY(waitForSignal(queue, SIGNAL(resumed())));
}
void tst_QAMQPChannel::sharedChannel()
{
QString routingKey = "test-shared-channel";
Queue *queue = client->createQueue(routingKey);
declareQueueAndVerifyConsuming(queue);
Exchange *defaultExchange = client->createExchange("", queue->channelNumber());
defaultExchange->publish("first message", routingKey);
QVERIFY(waitForSignal(queue, SIGNAL(messageReceived())));
Message message = queue->dequeue();
verifyStandardMessageHeaders(message, routingKey);
QCOMPARE(message.payload(), QByteArray("first message"));
}
QTEST_MAIN(tst_QAMQPChannel)
#include "tst_qamqpchannel.moc"

View File

@ -48,21 +48,10 @@ private Q_SLOTS:
void messageProperties();
private:
void verifyStandardMessageHeaders(const Message &message, const QString &routingKey,
const QString &exchangeName = QLatin1String(""),
bool redelivered = false);
QScopedPointer<Client> client;
};
void tst_QAMQPQueue::verifyStandardMessageHeaders(const Message &message, const QString &routingKey,
const QString &exchangeName, bool redelivered)
{
QCOMPARE(message.routingKey(), routingKey);
QCOMPARE(message.exchangeName(), exchangeName);
QCOMPARE(message.isRedelivered(), redelivered);
}
void tst_QAMQPQueue::init()
{
client.reset(new Client);

View File

@ -38,6 +38,16 @@ protected:
QList<QVariant> arguments = spy.takeFirst();
QCOMPARE(arguments.at(0).toString(), queue->consumerTag());
}
void verifyStandardMessageHeaders(const Message &message, const QString &routingKey,
const QString &exchangeName = QLatin1String(""),
bool redelivered = false)
{
QCOMPARE(message.routingKey(), routingKey);
QCOMPARE(message.exchangeName(), exchangeName);
QCOMPARE(message.isRedelivered(), redelivered);
}
};
} // namespace QAMQP