You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2013/10/13 11:14:59 UTC
[03/13] git commit: Fixed test. Do not use hardcoded port
Fixed test. Do not use hardcoded port
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/1547ed6c
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/1547ed6c
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/1547ed6c
Branch: refs/heads/camel-2.12.x
Commit: 1547ed6ca788fef302dfdcd0d2c94025cc5af4c3
Parents: 66cb653
Author: Claus Ibsen <da...@apache.org>
Authored: Sun Oct 13 10:55:27 2013 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Oct 13 10:58:49 2013 +0200
----------------------------------------------------------------------
.../operations/SetDataOperationTest.java | 6 +--
.../zookeeper/policy/ZookeeperElectionTest.java | 41 +++++++++++++-------
2 files changed, 29 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/1547ed6c/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/operations/SetDataOperationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/operations/SetDataOperationTest.java b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/operations/SetDataOperationTest.java
index 7c1d3fe..35fe314 100644
--- a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/operations/SetDataOperationTest.java
+++ b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/operations/SetDataOperationTest.java
@@ -16,8 +16,6 @@
*/
package org.apache.camel.component.zookeeper.operations;
-import java.util.concurrent.ExecutionException;
-
import org.apache.camel.component.zookeeper.ZooKeeperTestSupport;
import org.apache.zookeeper.ZooKeeper;
import org.junit.Before;
@@ -43,7 +41,6 @@ public class SetDataOperationTest extends ZooKeeperTestSupport {
@Test
public void setSpecificVersionOfData() throws Exception {
-
client.create("/two", testPayload);
for (int x = 0; x < 10; x++) {
byte[] payload = ("Updated_" + x).getBytes();
@@ -56,10 +53,9 @@ public class SetDataOperationTest extends ZooKeeperTestSupport {
public void setWithNull() throws Exception {
client.create("/three", testPayload);
updateDataOnNode("/three", null, -1, 1);
-
}
- private void updateDataOnNode(String node, byte[] payload, int version, int expectedVersion) throws InterruptedException, ExecutionException, Exception {
+ private void updateDataOnNode(String node, byte[] payload, int version, int expectedVersion) throws Exception {
SetDataOperation operation = new SetDataOperation(connection, node, payload);
operation.setVersion(version);
OperationResult<byte[]> result = operation.get();
http://git-wip-us.apache.org/repos/asf/camel/blob/1547ed6c/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/policy/ZookeeperElectionTest.java
----------------------------------------------------------------------
diff --git a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/policy/ZookeeperElectionTest.java b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/policy/ZookeeperElectionTest.java
index e0818ed..fd63cee 100644
--- a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/policy/ZookeeperElectionTest.java
+++ b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/policy/ZookeeperElectionTest.java
@@ -17,6 +17,8 @@
package org.apache.camel.component.zookeeper.policy;
import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.apache.camel.CamelContext;
import org.apache.camel.component.zookeeper.ZooKeeperTestSupport;
import org.apache.camel.impl.DefaultCamelContext;
import org.junit.After;
@@ -30,7 +32,9 @@ public class ZookeeperElectionTest extends ZooKeeperTestSupport {
private static final String NODE_BASE_KEY = "/someapp";
private static final String NODE_PARTICULAR_KEY = "/someapp/somepolicy";
- private static final String ELECTION_URI = "zookeeper:localhost:39913/someapp/somepolicy";
+
+ private CamelContext candidateOneContext;
+ private CamelContext candidateTwoContext;
@Before
public void before() throws Exception {
@@ -43,18 +47,29 @@ public class ZookeeperElectionTest extends ZooKeeperTestSupport {
public void after() throws Exception {
client.deleteAll(NODE_PARTICULAR_KEY);
client.delete(NODE_BASE_KEY);
+
+ if (candidateOneContext != null) {
+ candidateOneContext.stop();
+ }
+ if (candidateTwoContext != null) {
+ candidateTwoContext.stop();
+ }
+ }
+
+ private String getElectionUri() {
+ return "zookeeper:localhost:" + getServerPort() + "/someapp/somepolicy";
}
@Test
public void masterCanBeElected() throws Exception {
- ZooKeeperElection candidate = new ZooKeeperElection(template, context, ELECTION_URI, 1);
+ ZooKeeperElection candidate = new ZooKeeperElection(template, context, getElectionUri(), 1);
assertTrue("The only election candidate was not elected as master.", candidate.isMaster());
}
@Test
public void masterAndSlave() throws Exception {
- final DefaultCamelContext candidateOneContext = createNewContext();
- final DefaultCamelContext candidateTwoContext = createNewContext();
+ candidateOneContext = createNewContext();
+ candidateTwoContext = createNewContext();
ZooKeeperElection electionCandidate1 = createElectionCandidate(candidateOneContext, 1);
assertTrue("The first candidate was not elected.", electionCandidate1.isMaster());
@@ -64,8 +79,8 @@ public class ZookeeperElectionTest extends ZooKeeperTestSupport {
@Test
public void testMasterGoesAway() throws Exception {
- final DefaultCamelContext candidateOneContext = createNewContext();
- final DefaultCamelContext candidateTwoContext = createNewContext();
+ candidateOneContext = createNewContext();
+ candidateTwoContext = createNewContext();
ZooKeeperElection electionCandidate1 = createElectionCandidate(candidateOneContext, 1);
assertTrue("The first candidate was not elected.", electionCandidate1.isMaster());
@@ -80,8 +95,8 @@ public class ZookeeperElectionTest extends ZooKeeperTestSupport {
@Test
public void testDualMaster() throws Exception {
- final DefaultCamelContext candidateOneContext = createNewContext();
- final DefaultCamelContext candidateTwoContext = createNewContext();
+ candidateOneContext = createNewContext();
+ candidateTwoContext = createNewContext();
ZooKeeperElection electionCandidate1 = createElectionCandidate(candidateOneContext, 2);
assertTrue("The first candidate was not elected.", electionCandidate1.isMaster());
@@ -92,8 +107,8 @@ public class ZookeeperElectionTest extends ZooKeeperTestSupport {
@Test
public void testWatchersAreNotified() throws Exception {
- final DefaultCamelContext candidateOneContext = createNewContext();
- final DefaultCamelContext candidateTwoContext = createNewContext();
+ candidateOneContext = createNewContext();
+ candidateTwoContext = createNewContext();
final AtomicBoolean notified = new AtomicBoolean(false);
ElectionWatcher watcher = new ElectionWatcher() {
@@ -114,13 +129,13 @@ public class ZookeeperElectionTest extends ZooKeeperTestSupport {
return controlledContext;
}
- private ZooKeeperElection createElectionCandidate(final DefaultCamelContext context, int masterCount) {
- return new ZooKeeperElection(context.createProducerTemplate(), context, ELECTION_URI, masterCount);
+ private ZooKeeperElection createElectionCandidate(final CamelContext context, int masterCount) {
+ return new ZooKeeperElection(context.createProducerTemplate(), context, getElectionUri(), masterCount);
}
private void assertIsMaster(ZooKeeperElection electionCandidate) throws InterruptedException {
// Need to wait for a while to be elected.
- long timeout = System.currentTimeMillis() + 10000;
+ long timeout = System.currentTimeMillis() + 20000;
while (!electionCandidate.isMaster() && timeout > System.currentTimeMillis()) {
Thread.sleep(200);