Author: cmueller
Date: Sun Sep 9 12:11:36 2012
New Revision: 1382475
URL: http://svn.apache.org/viewvc?rev=1382475&view=rev
Log:
fixed test which randomly fail on slow CI server
Modified:
camel/trunk/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/policy/ZookeeperElectionTest.java
Modified:
camel/trunk/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/policy/ZookeeperElectionTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/policy/ZookeeperElectionTest.java?rev=1382475&r1=1382474&r2=1382475&view=diff
==============================================================================
---
camel/trunk/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/policy/ZookeeperElectionTest.java
(original)
+++
camel/trunk/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/policy/ZookeeperElectionTest.java
Sun Sep 9 12:11:36 2012
@@ -76,8 +76,7 @@ public class ZookeeperElectionTest exten
candidateOneContext.stop(); // the first candidate was killed.
- delay(3000); // more than the timeout on the zeekeeper server.
- assertTrue("The second candidate should have been elected.",
electionCandidate2.isMaster());
+ assertIsMaster(electionCandidate2);
}
@Test
@@ -89,7 +88,7 @@ public class ZookeeperElectionTest exten
assertTrue("The first candidate was not elected.",
electionCandidate1.isMaster());
ZooKeeperElection electionCandidate2 =
createElectionCandidate(candidateTwoContext, 2);
// Need to wait for a while to Candidate2 to be elected.
- Thread.sleep(2000);
+ Thread.sleep(3000);
assertTrue("The second candidate should also be a master.",
electionCandidate2.isMaster());
}
@@ -120,4 +119,15 @@ public class ZookeeperElectionTest exten
private ZooKeeperElection createElectionCandidate(final
DefaultCamelContext context, int masterCount) {
return new ZooKeeperElection(context.createProducerTemplate(),
context, ELECTION_URI, masterCount);
}
+
+ private void assertIsMaster(ZooKeeperElection electionCandidate) throws
InterruptedException {
+ // Need to wait for a while to be elected.
+ long timeout = System.currentTimeMillis() + 5000;
+
+ while (!electionCandidate.isMaster() && timeout >
System.currentTimeMillis()) {
+ Thread.sleep(200);
+ }
+
+ assertTrue("The candidate should have been elected.",
electionCandidate.isMaster());
+ }
}