camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [01/13] git commit: Fixed test. Do not use hardcoded port
Date Sun, 13 Oct 2013 09:14:57 GMT
Updated Branches:
  refs/heads/camel-2.11.x 464833737 -> 1765f1a2e
  refs/heads/camel-2.12.x 66cb6537f -> c4ad5ea68
  refs/heads/master 802cfbe45 -> 975964675


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/c1340cfc
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/c1340cfc
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/c1340cfc

Branch: refs/heads/master
Commit: c1340cfc5fee5fd4cd02e05a841b8cde21499a46
Parents: 802cfbe
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sun Oct 13 10:55:27 2013 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sun Oct 13 10:55:27 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/c1340cfc/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/c1340cfc/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);


Mime
View raw message