summaryrefslogtreecommitdiff
path: root/qpid/java
diff options
context:
space:
mode:
authorAlex Rudyy <orudyy@apache.org>2012-10-23 20:05:55 +0000
committerAlex Rudyy <orudyy@apache.org>2012-10-23 20:05:55 +0000
commitd1e6de3be23418071a717f08d643593a9040c204 (patch)
treef128823bfb53e0f4d529d9db3255f1c2f0cb1a0f /qpid/java
parent2f61f4fde4b3e600f6934b4dd0b69ac4e339e6c6 (diff)
downloadqpid-python-d1e6de3be23418071a717f08d643593a9040c204.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@1401426 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java')
-rw-r--r--qpid/java/perftests/src/main/java/org/apache/qpid/disttest/controller/ClientRegistry.java36
-rw-r--r--qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/ClientRegistryTest.java39
2 files changed, 66 insertions, 9 deletions
diff --git a/qpid/java/perftests/src/main/java/org/apache/qpid/disttest/controller/ClientRegistry.java b/qpid/java/perftests/src/main/java/org/apache/qpid/disttest/controller/ClientRegistry.java
index eaccb54f0e..5a726c50b4 100644
--- a/qpid/java/perftests/src/main/java/org/apache/qpid/disttest/controller/ClientRegistry.java
+++ b/qpid/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/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/ClientRegistryTest.java b/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/ClientRegistryTest.java
index cc969e1ef2..acb17eee0c 100644
--- a/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/ClientRegistryTest.java
+++ b/qpid/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()