diff options
author | Alex Rudyy <orudyy@apache.org> | 2012-10-23 20:05:55 +0000 |
---|---|---|
committer | Alex Rudyy <orudyy@apache.org> | 2012-10-23 20:05:55 +0000 |
commit | a75bb8770d06f1013578bd59261a6a96b18bcf71 (patch) | |
tree | 787a289e7fec49719301be28c97a043cb69b4521 | |
parent | ca077b77293c43977c5cea2bab46a306c6108e5f (diff) | |
download | qpid-python-a75bb8770d06f1013578bd59261a6a96b18bcf71.tar.gz |
QPID-4385: perf test ClientRegistry timeout now only applies to each registration, not to the whole registration sequence, thus allowing large number of clients to register without false timeouts.
Applied patch from Philip Harvey <phil@philharveyonline.com>
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1401426 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | java/perftests/src/main/java/org/apache/qpid/disttest/controller/ClientRegistry.java | 36 | ||||
-rw-r--r-- | java/perftests/src/test/java/org/apache/qpid/disttest/controller/ClientRegistryTest.java | 39 |
2 files changed, 66 insertions, 9 deletions
diff --git a/java/perftests/src/main/java/org/apache/qpid/disttest/controller/ClientRegistry.java b/java/perftests/src/main/java/org/apache/qpid/disttest/controller/ClientRegistry.java index eaccb54f0e..5a726c50b4 100644 --- a/java/perftests/src/main/java/org/apache/qpid/disttest/controller/ClientRegistry.java +++ b/java/perftests/src/main/java/org/apache/qpid/disttest/controller/ClientRegistry.java @@ -57,34 +57,54 @@ public class ClientRegistry return Collections.unmodifiableSet(_registeredClientNames); } - public int awaitClients(int numberOfClientsToAwait, long timeout) + /** + * @return the number of clients that are still absent. + */ + public int awaitClients(final int numberOfClientsToAwait, final long idleTimeout) { - final long endTime = System.currentTimeMillis() + timeout; + long deadlineForNextRegistration = deadline(idleTimeout); - int numberOfClientsAbsent = numberOfClientsToAwait - _registeredClientNames.size(); - long remainingTimeout = endTime - System.currentTimeMillis(); + int numberOfClientsAbsent = numberAbsent(numberOfClientsToAwait); - while(numberOfClientsAbsent > 0 && remainingTimeout > 0) + while(numberOfClientsAbsent > 0 && System.currentTimeMillis() < deadlineForNextRegistration) { synchronized (_lock) { try { - _lock.wait(remainingTimeout); + _lock.wait(idleTimeout); } catch (InterruptedException e) { Thread.currentThread().interrupt(); + return numberOfClientsAbsent; } } - numberOfClientsAbsent = numberOfClientsToAwait - _registeredClientNames.size(); - remainingTimeout = endTime - System.currentTimeMillis(); + int newNumberAbsent = numberAbsent(numberOfClientsToAwait); + if(newNumberAbsent < numberOfClientsAbsent) + { + // a registration was received since the last loop, so reset the timeout + deadlineForNextRegistration = deadline(idleTimeout); + } + + numberOfClientsAbsent = newNumberAbsent; } return numberOfClientsAbsent < 0 ? 0 : numberOfClientsAbsent; } + + private long deadline(final long idleTimeout) + { + return System.currentTimeMillis() + idleTimeout; + } + + private int numberAbsent(int numberOfClientsToAwait) + { + return numberOfClientsToAwait - _registeredClientNames.size(); + } + private void notifyAllWaiters() { synchronized (_lock) diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/ClientRegistryTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/ClientRegistryTest.java index cc969e1ef2..acb17eee0c 100644 --- a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/ClientRegistryTest.java +++ b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/ClientRegistryTest.java @@ -29,6 +29,8 @@ public class ClientRegistryTest extends TestCase { private static final String CLIENT1_REGISTERED_NAME = "CLIENT1_REGISTERED_NAME"; private static final String CLIENT2_REGISTERED_NAME = "CLIENT2_REGISTERED_NAME"; + private static final String CLIENT3_REGISTERED_NAME = "CLIENT3_REGISTERED_NAME"; + private static final int AWAIT_DELAY = 100; private ClientRegistry _clientRegistry = new ClientRegistry(); @@ -70,7 +72,7 @@ public class ClientRegistryTest extends TestCase assertEquals(0, numberOfClientsAbsent); } - public void testAwaitTwoClientWhenClientRegistersWhilstWaiting() + public void testAwaitTwoClientsWhenClientRegistersWhilstWaiting() { _clientRegistry.registerClient(CLIENT1_REGISTERED_NAME); registerClientLater(CLIENT2_REGISTERED_NAME, 50); @@ -79,6 +81,41 @@ public class ClientRegistryTest extends TestCase assertEquals(0, numberOfClientsAbsent); } + public void testAwaitTimeoutForPromptRegistrations() + { + registerClientsLaterAndAssertResult("Clients registering every 100ms should be within 600ms timeout", + new int[] {300, 400, 500}, + 600, + 0); + } + + public void testAwaitTimeoutForWhenThirdRegistrationIsLate() + { + registerClientsLaterAndAssertResult("Third client registering tardily should exceed timeout", + new int[] {300, 400, 1500}, + 600, + 1); + } + + public void testAwaitTimeoutWhenSecondAndThirdRegistrationsAreLate() + { + registerClientsLaterAndAssertResult("Second and third clients registering tardily should exceed timeout", + new int[] {300, 1500, 1500}, + 600, + 2); + } + + private void registerClientsLaterAndAssertResult(String message, int[] registrationDelays, int timeout, int expectedNumberOfAbsentees) + { + registerClientLater(CLIENT1_REGISTERED_NAME, registrationDelays[0]); + registerClientLater(CLIENT2_REGISTERED_NAME, registrationDelays[1]); + registerClientLater(CLIENT3_REGISTERED_NAME, registrationDelays[2]); + + int numberOfClientsAbsent = _clientRegistry.awaitClients(3, timeout); + + assertEquals(message, expectedNumberOfAbsentees, numberOfClientsAbsent); + } + private void registerClientLater(final String clientName, long delayInMillis) { doLater(new TimerTask() |