diff options
| author | Robert Gemmell <robbie@apache.org> | 2012-09-21 15:43:04 +0000 |
|---|---|---|
| committer | Robert Gemmell <robbie@apache.org> | 2012-09-21 15:43:04 +0000 |
| commit | 2ebdd42622807564e81f8b0bd4a62d689bfc1ce6 (patch) | |
| tree | 9dfcdd797af079595f57631930c6ac58a41e7f47 /qpid/java/perftests | |
| parent | 1d55085f6f4fdf1a29ae7a468b189dabf9badef1 (diff) | |
| download | qpid-python-2ebdd42622807564e81f8b0bd4a62d689bfc1ce6.tar.gz | |
QPID-4311: throw exception if the test config requests a start delay greater than the imposed maximum time limit for the test. Add some additional logging, extract some variables for clarity.
Work by Oleksandr Rudyy and myself.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1388556 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/perftests')
2 files changed, 52 insertions, 17 deletions
diff --git a/qpid/java/perftests/src/main/java/org/apache/qpid/disttest/client/ProducerParticipant.java b/qpid/java/perftests/src/main/java/org/apache/qpid/disttest/client/ProducerParticipant.java index 567deea6f4..a9da837dea 100644 --- a/qpid/java/perftests/src/main/java/org/apache/qpid/disttest/client/ProducerParticipant.java +++ b/qpid/java/perftests/src/main/java/org/apache/qpid/disttest/client/ProducerParticipant.java @@ -58,17 +58,25 @@ public class ProducerParticipant implements Participant @Override public ParticipantResult doIt(String registeredClientName) throws Exception { - if (_command.getMaximumDuration() == 0 && _command.getNumberOfMessages() == 0) + long numberOfMessages = _command.getNumberOfMessages(); + long maximumDuration = _command.getMaximumDuration(); + + if (maximumDuration == 0 && numberOfMessages == 0) { throw new DistributedTestException("number of messages and duration cannot both be zero"); } - int acknowledgeMode = _jmsDelegate.getAcknowledgeMode(_command.getSessionName()); + long duration = maximumDuration - _command.getStartDelay(); + if (maximumDuration > 0 && duration <= 0) + { + throw new DistributedTestException("Start delay must be less than maximum test duration"); + } + final long requiredDuration = duration > 0 ? duration : 0; doSleepForStartDelay(); - final long requiredDuration = _command.getMaximumDuration() - _command.getStartDelay(); - + final int batchSize = _command.getBatchSize(); + final int acknowledgeMode = _jmsDelegate.getAcknowledgeMode(_command.getSessionName()); final long startTime = System.currentTimeMillis(); Message lastPublishedMessage = null; @@ -78,10 +86,20 @@ public class ProducerParticipant implements Participant _limiter = ExecutorWithLimitsFactory.createExecutorWithLimit(startTime, requiredDuration); - LOGGER.info("Producer {} about to send messages", getName()); + if (LOGGER.isInfoEnabled()) + { + LOGGER.info("Producer {} about to send messages. Duration limit: {} ms, Message limit: {}", + new Object[]{getName(), requiredDuration, numberOfMessages}); + } while (true) { + if (numberOfMessages > 0 && numberOfMessagesSent >= numberOfMessages + || requiredDuration > 0 && System.currentTimeMillis() - startTime >= requiredDuration) + { + break; + } + try { lastPublishedMessage = _limiter.execute(new Callable<Message>() @@ -110,37 +128,37 @@ public class ProducerParticipant implements Participant LOGGER.trace("message " + numberOfMessagesSent + " sent by " + this); } - final boolean batchLimitReached = _command.getBatchSize() <= 0 - || numberOfMessagesSent % _command.getBatchSize() == 0; + final boolean batchLimitReached = batchSize <= 0 + || numberOfMessagesSent % batchSize == 0; if (batchLimitReached) { - if (LOGGER.isTraceEnabled() && _command.getBatchSize() > 0) + if (LOGGER.isTraceEnabled() && batchSize > 0) { - LOGGER.trace("Committing: batch size " + _command.getBatchSize() ); + LOGGER.trace("Committing: batch size " + batchSize ); } _jmsDelegate.commitIfNecessary(_command.getSessionName()); doSleepForInterval(); } - - if (_command.getNumberOfMessages() > 0 && numberOfMessagesSent >= _command.getNumberOfMessages() - || requiredDuration > 0 && System.currentTimeMillis() - startTime >= requiredDuration) - { - break; - } } // commit the remaining batch messages - if (_command.getBatchSize() > 0 && numberOfMessagesSent % _command.getBatchSize() != 0) + if (batchSize > 0 && numberOfMessagesSent % batchSize != 0) { if (LOGGER.isTraceEnabled()) { - LOGGER.trace("Committing: batch size " + _command.getBatchSize() ); + LOGGER.trace("Committing: batch size " + batchSize ); } _jmsDelegate.commitIfNecessary(_command.getSessionName()); } + if (LOGGER.isInfoEnabled()) + { + LOGGER.info("Producer {} finished publishing. Number of messages published: {}", + getName(), numberOfMessagesSent); + } + Date start = new Date(startTime); Date end = new Date(); int payloadSize = getPayloadSizeForResultIfConstantOrZeroOtherwise(allProducedPayloadSizes); diff --git a/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/client/ProducerParticipantTest.java b/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/client/ProducerParticipantTest.java index ce36fdb9ad..cafb63d071 100644 --- a/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/client/ProducerParticipantTest.java +++ b/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/client/ProducerParticipantTest.java @@ -145,6 +145,23 @@ public class ProducerParticipantTest extends TestCase verify(_delegate, atLeastOnce()).commitIfNecessary(SESSION_NAME1); } + public void testSendMessagesForDurationWithDelayExceedingDuration() throws Exception + { + final long duration = 100; + _command.setMaximumDuration(duration); + _command.setStartDelay(150); + + try + { + _producer.doIt(CLIENT_NAME); + fail("Exception should be thrown indicating configuration error"); + } + catch(DistributedTestException e) + { + assertEquals("Start delay must be less than maximum test duration", e.getMessage()); + } + } + public void testSendMessageBatches() throws Exception { final int batchSize = 3; |
