From 5c65e1c2269ae3257010a7a3cbbc4bb57fff2053 Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Fri, 14 Dec 2007 19:33:48 +0000 Subject: Fix sequence numbers and sequence checks in perftest. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@604272 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/tests/perftest.cpp | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'cpp/src') diff --git a/cpp/src/tests/perftest.cpp b/cpp/src/tests/perftest.cpp index f844e9bb19..e15cb33164 100644 --- a/cpp/src/tests/perftest.cpp +++ b/cpp/src/tests/perftest.cpp @@ -383,8 +383,7 @@ struct PublishThread : public Client { for (size_t i=0; i(msg.getData().data()); - *reinterpret_cast(data) = i; + const_cast(msg.getData()).replace(0, sizeof(uint32_t), reinterpret_cast(&i), sizeof(uint32_t)); completion = session.messageTransfer( arg::destination=destination, arg::content=msg, @@ -425,7 +424,17 @@ struct SubscribeThread : public Client { arg::exchange=ex, arg::routingKey=key); } - + + void verify(bool cond, const char* test, uint32_t expect, uint32_t actual) { + if (!cond) { + Message error( + QPID_MSG("Sequence error: expected n" << test << expect << " but got " << actual), + "sub_done"); + session.messageTransfer(arg::content=error); + throw Exception(error.getData()); + } + } + void run() { // Subscribe try { SubscriptionManager subs(session); @@ -439,29 +448,21 @@ struct SubscribeThread : public Client { Message msg; AbsTime start=now(); - size_t lastMsg=0; + size_t expect=0; for (size_t i = 0; i < opts.subQuota; ++i) { msg=lq.pop(); // TODO aconway 2007-11-23: check message order for. - // multiple publishers. Need an array of counters, + // multiple publishers. Need an acorray of counters, // one per publisher and a publisher ID in the // message. Careful not to introduce a lot of overhead // here, e.g. no std::map, std::string etc. // // For now verify order only for a single publisher. + size_t n = *reinterpret_cast(msg.getData().data()); if (opts.pubs == 1) { - char* data = const_cast(msg.getData().data()); - size_t n = *reinterpret_cast(data); - if (n < lastMsg) { - // Report to control. - Message error( - QPID_MSG("Out-of-sequence messages, expected n>=" - << lastMsg << " got " << n), - "sub_done"); - session.messageTransfer(arg::content=error); - return; - } - lastMsg=n; + if (opts.subs == 1 || opts.mode == FANOUT) verify(n==expect, "==", expect, n); + else verify(n>=expect, ">=", expect, n); + expect = n+1; } } if (opts.ack !=0) -- cgit v1.2.1