Skip to content
Snippets Groups Projects
Commit 66de23a4 authored by Ruud Overeem's avatar Ruud Overeem
Browse files

Task #7342: Created minimal unit test and added minimal cout-based logging.

parent 2608c41b
No related branches found
No related tags found
No related merge requests found
......@@ -26,12 +26,14 @@ namespace LOFAR {
itsNrMissingACKs(0)
{
itsConnection.open();
cout << "Connected to: " << itsConnection.getUrl() << endl;
itsSession = itsConnection.createSession();
Address addr(address+options);
Receiver receiver = itsSession.createReceiver(addr);
receiver.setCapacity(1);
cout << "Receiver started at queue: " << receiver.getName() << endl;
} catch(const qpid::types::Exception &ex) {
THROW(MessageBusException, ex.what());
}
......@@ -50,7 +52,7 @@ namespace LOFAR {
cout << "waiting for message..." << endl;
if (itsSession.nextReceiver(next,TimeOutDuration(timeout)))
{
cout << "message available..." << endl;
cout << "message available on queue: " << next.getName() << endl;
itsNrMissingACKs++;
return next.get(msg);
}
......@@ -82,6 +84,7 @@ namespace LOFAR {
Address addr(address+options);
Receiver receiver = itsSession.createReceiver(addr);
receiver.setCapacity(1);
cout << "Receiver started at queue: " << receiver.getName() << endl;
} catch(const qpid::types::Exception &ex) {
//THROW(MessageBusException, ex.what());
return false;
......@@ -94,9 +97,12 @@ namespace LOFAR {
itsConnection(broker)
{
itsConnection.open();
cout << "Connected to: " << itsConnection.getUrl() << endl;
itsSession = itsConnection.createSession();
Address addr(address+options);
itsSender = itsSession.createSender(addr);
cout << "Sender created: " << itsSender.getName() << endl;
} catch(const qpid::types::Exception &ex) {
THROW(MessageBusException, ex.what());
}
......
......@@ -46,17 +46,68 @@ void showMessage(Message& msg)
cout << "Content : " << msg.getContent() << endl;
}
void compareMessages(Message& lhm, Message& rhm)
{
ASSERTSTR(lhm.getMessageId() == rhm.getMessageId(), "messageIDs differ");
ASSERTSTR(lhm.getUserId() == rhm.getUserId(), "UserIDs differ");
ASSERTSTR(lhm.getCorrelationId() == rhm.getCorrelationId(), "CorrelationIDs differ");
ASSERTSTR(lhm.getSubject() == rhm.getSubject(), "Subjects differ");
ASSERTSTR(lhm.getReplyTo() == rhm.getReplyTo(), "ReplyTos differ");
ASSERTSTR(lhm.getContentType() == rhm.getContentType(), "ContentTypes differ");
ASSERTSTR(lhm.getPriority() == rhm.getPriority(), "Priorities differ");
ASSERTSTR(lhm.getTtl() == rhm.getTtl(), "TTLs differ");
ASSERTSTR(lhm.getDurable() == rhm.getDurable(), "Durability differs");
ASSERTSTR(lhm.getRedelivered() == rhm.getRedelivered(), "Redelivered differs");
// ASSERTSTR(lhm.getProperties() == rhm.getProperties(), "Properties differ");
ASSERTSTR(lhm.getContentSize() == rhm.getContentSize(), "ContentSize differs");
ASSERTSTR(lhm.getContent() == rhm.getContent(), "Content differs");
}
int main(int argc, char* argv[]) {
if (argc != 2) {
cout << "Syntax: abc messagebus" << endl;
cout << "Syntax: " << argv[0] << " messagebus" << endl;
return (1);
}
cout << "--- Drain the queue ---" << endl;
FromBus fb(argv[1]);
Message msg;
fb.getMessage(msg);
showMessage(msg);
Message receivedMsg;
while (fb.getMessage(receivedMsg, 0.01)) {
fb.ack(receivedMsg);
}
cout << "--- TEST 1: create a message from a string, send it, receive it, print it. --- " << endl;
ToBus tb(argv[1]);
string someText("An example message constructed from text");
tb.send(someText);
fb.getMessage(receivedMsg);
fb.ack(receivedMsg);
showMessage(receivedMsg);
cout << "--- TEST 2: create a message by hand, send it, receive it, print it, compare them. --- " << endl;
Message msg2Send;
msg2Send.setContent("Manually constructed message");
tb.send(msg2Send);
fb.getMessage(receivedMsg);
fb.ack(receivedMsg);
showMessage(receivedMsg);
compareMessages(msg2Send, receivedMsg);
cout << "--- TEST 3: add an extra queue, send messages to both queues, receive them. --- " << endl;
ToBus tbExtra("extraTestQ");
tbExtra.send("Message send to extra queue");
tb.send("Message send to original queue");
fb.addQueue("extraTestQ");
fb.getMessage(receivedMsg);
fb.ack(receivedMsg);
showMessage(receivedMsg);
fb.getMessage(receivedMsg);
fb.ack(receivedMsg);
showMessage(receivedMsg);
cout << "--- All test successful! ---" << endl;
return (0);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment