From e6ba448c493ad96c48a5a824dc589ff34b216da8 Mon Sep 17 00:00:00 2001 From: Rupert Smith Date: Wed, 26 Sep 2007 11:27:45 +0000 Subject: Added timeout to perftests, to fail tests if message loss causes test to jam. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/branches/M2.1@579602 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/qpid/requestreply/PingPongProducer.java | 44 +++++++++++----------- 1 file changed, 23 insertions(+), 21 deletions(-) (limited to 'java/perftests') diff --git a/java/perftests/src/main/java/org/apache/qpid/requestreply/PingPongProducer.java b/java/perftests/src/main/java/org/apache/qpid/requestreply/PingPongProducer.java index bd34fd8f20..8247a7cec0 100644 --- a/java/perftests/src/main/java/org/apache/qpid/requestreply/PingPongProducer.java +++ b/java/perftests/src/main/java/org/apache/qpid/requestreply/PingPongProducer.java @@ -885,24 +885,8 @@ public class PingPongProducer implements Runnable /*, MessageListener*/, Excepti synchronized (_sendPauseMonitor) { if ((_maxPendingSize > 0) && (unreceivedSize < _maxPendingSize)) - // && (_sendPauseBarrier.getNumberWaiting() == 1)) { - // log.debug("unreceived size estimate under limit = " + unreceivedSize); - - // Wait on the send pause barrier for the limit to be re-established. - /*try - {*/ - // _sendPauseBarrier.await(); _sendPauseMonitor.notify(); - /*} - catch (InterruptedException e) - { - throw new RuntimeException(e); - } - catch (BrokenBarrierException e) - { - throw new RuntimeException(e); - }*/ } } @@ -1159,12 +1143,23 @@ public class PingPongProducer implements Runnable /*, MessageListener*/, Excepti // If necessary, wait until the max pending message size comes within its limit. synchronized (_sendPauseMonitor) { + // Used to keep track of the number of times that send has to wait. + int numWaits = 0; + + // The maximum number of waits before the test gives up and fails. This has been chosen to correspond with + // the test timeout. + int waitLimit = (int) (TIMEOUT_DEFAULT / 100); + while ((_maxPendingSize > 0)) { // Get the size estimate of sent but not yet received messages. int unreceived = _unreceived.get(); int unreceivedSize = (unreceived * ((_messageSize == 0) ? 1 : _messageSize)); + // log.debug("unreceived = " + unreceived); + // log.debug("unreceivedSize = " + unreceivedSize); + // log.debug("_maxPendingSize = " + _maxPendingSize); + if (unreceivedSize > _maxPendingSize) { // log.debug("unreceived size estimate over limit = " + unreceivedSize); @@ -1172,8 +1167,8 @@ public class PingPongProducer implements Runnable /*, MessageListener*/, Excepti // Wait on the send pause barrier for the limit to be re-established. try { - // _sendPauseBarrier.await(); - _sendPauseMonitor.wait(1000); + _sendPauseMonitor.wait(100); + numWaits++; } catch (InterruptedException e) { @@ -1181,10 +1176,17 @@ public class PingPongProducer implements Runnable /*, MessageListener*/, Excepti Thread.currentThread().interrupt(); throw new RuntimeException(e); } - /*catch (BrokenBarrierException e) + + // Fail the test if the send has had to wait more than the maximum allowed number of times. + if (numWaits >= waitLimit) { - throw new RuntimeException(e); - }*/ + String errorMessage = + "Send has had to wait for the unreceivedSize (" + unreceivedSize + + ") to come below the maxPendingSize (" + _maxPendingSize + ") more that " + waitLimit + + " times."; + log.warn(errorMessage); + throw new RuntimeException(errorMessage); + } } else { -- cgit v1.2.1