zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hd...@apache.org
Subject svn commit: r1679401 - in /zookeeper/branches/branch-3.5: ./ src/java/test/org/apache/zookeeper/ src/java/test/org/apache/zookeeper/server/ src/java/test/org/apache/zookeeper/server/quorum/ src/java/test/org/apache/zookeeper/test/
Date Thu, 14 May 2015 16:43:40 GMT
Author: hdeng
Date: Thu May 14 16:43:39 2015
New Revision: 1679401

URL: http://svn.apache.org/r1679401
Log:
ZOOKEEPER-2183 Concurrent Testing Processes and Port Assignments (Chris Nauroth via hdeng)

Added:
    zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/PortAssignmentTest.java
Modified:
    zookeeper/branches/branch-3.5/CHANGES.txt
    zookeeper/branches/branch-3.5/build.xml
    zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/PortAssignment.java
    zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/ZxidRolloverTest.java
    zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/quorum/CommitProcessorTest.java
    zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/quorum/WatchLeakTest.java
    zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/quorum/Zab1_0Test.java
    zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/HierarchicalQuorumTest.java
    zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/NettyNettySuiteBase.java
    zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/NioNettySuiteBase.java
    zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/QuorumBase.java
    zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/QuorumUtil.java
    zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/TruncateTest.java
    zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/WatchEventWhenAutoResetTest.java

Modified: zookeeper/branches/branch-3.5/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/CHANGES.txt?rev=1679401&r1=1679400&r2=1679401&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/CHANGES.txt (original)
+++ zookeeper/branches/branch-3.5/CHANGES.txt Thu May 14 16:43:39 2015
@@ -125,8 +125,12 @@ IMPROVEMENTS:
   ZOOKEEPER-2153 X509 Authentication Documentation
   (Ian Dimayuga via hdeng)
 
+<<<<<<< HEAD
   ZOOKEEPER-2186 QuorumCnxManager#receiveConnection may crash with random input
   (rgs via michim)
+=======
+  ZOOKEEPER-2183 Concurrent Testing Processes and Port Assignments (Chris Nauroth via hdeng)
+>>>>>>> ZOOKEEPER-2183 Concurrent Testing Processes and Port Assignments
(Chris Nauroth via hdeng)
 
 Release 3.5.0 - 8/4/2014
 

Modified: zookeeper/branches/branch-3.5/build.xml
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/build.xml?rev=1679401&r1=1679400&r2=1679401&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/build.xml (original)
+++ zookeeper/branches/branch-3.5/build.xml Thu May 14 16:43:39 2015
@@ -84,6 +84,7 @@ xmlns:maven="antlib:org.apache.maven.art
     <property name="test.timeout" value="900000" />
     <property name="test.junit.output.format" value="plain" />
     <property name="test.junit.fork.mode" value="perTest" />
+    <property name="test.junit.threads" value="8" />
     <property name="test.junit.printsummary" value="yes" />
     <property name="test.junit.haltonfailure" value="no" />
     <property name="config.dir" value="${src.dir}/java/test/config" />
@@ -1314,6 +1315,7 @@ xmlns:maven="antlib:org.apache.maven.art
                haltonfailure="${test.junit.haltonfailure}"
                fork="yes"
                forkmode="${test.junit.fork.mode}"
+               threads="${test.junit.threads}"
                maxmemory="${test.junit.maxmem}"
                dir="${test.java.build.dir}" timeout="${test.timeout}"
                errorProperty="tests.failed" failureProperty="tests.failed">
@@ -1327,6 +1329,7 @@ xmlns:maven="antlib:org.apache.maven.art
                with junit fork mode set to "once")-->
           <sysproperty key="zookeeper.DigestAuthenticationProvider.superDigest"
                        value="super:D/InIHSb7yEEbrWz8b9l71RjZJU=" />
+          <sysproperty key="test.junit.threads" value="${test.junit.threads}" />
           <classpath refid="test.java.classpath"/>
           <classpath>
             <pathelement path="${test.java.classes}" />

Modified: zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/PortAssignment.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/PortAssignment.java?rev=1679401&r1=1679400&r2=1679401&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/PortAssignment.java (original)
+++ zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/PortAssignment.java Thu
May 14 16:43:39 2015
@@ -18,18 +18,193 @@
 
 package org.apache.zookeeper;
 
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /** Assign ports to tests */
-public class PortAssignment {
+public final class PortAssignment {
     private static final Logger LOG = LoggerFactory.getLogger(PortAssignment.class);
 
-    private static int nextPort = 11221;
+    // The available port range that we use stays away from the ephemeral port
+    // range, which the OS will assign to client socket connections.  We can't
+    // coordinate with the OS on the assignment of those ports, so it's best to
+    // stay out of that range to avoid conflicts.  Typical ranges for ephemeral
+    // ports are:
+    // - IANA suggests 49152 - 65535
+    // - Linux typically uses 32768 - 61000
+    // - FreeBSD modern versions typically use the IANA suggested range
+    // - Windows modern versions typically use the IANA suggested range
+    private static final int GLOBAL_BASE_PORT = 11221;
+    private static final int GLOBAL_MAX_PORT = 32767;
+
+    private static PortRange portRange = null;
+    private static int nextPort;
 
-    /** Assign a new, unique port to the test */
+    /**
+     * Assign a new, unique port to the test.  This method works by assigning
+     * ports from a valid port range as identified by the total number of
+     * concurrent test processes and the ID of this test process.  Each
+     * concurrent test process uses an isolated range, so it's not possible for
+     * multiple test processes to collide on the same port.  Within the port
+     * range, ports are assigned in monotonic increasing order, wrapping around
+     * to the beginning of the range if needed.  As an extra precaution, the
+     * method attempts to bind to the port and immediately close it before
+     * returning it to the caller.  If the port cannot be bound, then it tries
+     * the next one in the range.  This provides some resiliency in case the port
+     * is otherwise occupied, such as a developer running other servers on the
+     * machine running the tests.
+     *
+     * @return port
+     */
     public synchronized static int unique() {
-        LOG.info("assigning port " + nextPort);
-        return nextPort++;
+        if (portRange == null) {
+            portRange = setupPortRange(System.getProperty("test.junit.threads"),
+                    System.getProperty("sun.java.command"));
+            nextPort = portRange.getMinimum();
+        }
+        int candidatePort = nextPort;
+        for (;;) {
+            ++candidatePort;
+            if (candidatePort > portRange.getMaximum()) {
+                candidatePort = portRange.getMinimum();
+            }
+            if (candidatePort == nextPort) {
+                throw new IllegalStateException(String.format(
+                        "Could not assign port from range %s.  The entire " +
+                        "range has been exhausted.", portRange));
+            }
+            try {
+                ServerSocket s = new ServerSocket(candidatePort);
+                s.close();
+                nextPort = candidatePort;
+                LOG.info("Assigned port {} from range {}.", nextPort, portRange);
+                return nextPort;
+            } catch (IOException e) {
+                LOG.debug("Could not bind to port {} from range {}.  " +
+                        "Attempting next port.", candidatePort, portRange, e);
+            }
+        }
+    }
+
+    /**
+     * Sets up the port range to be used.  In typical usage, Ant invokes JUnit,
+     * possibly using multiple JUnit processes to execute multiple test suites
+     * concurrently.  The count of JUnit processes is passed from Ant as a system
+     * property named "test.junit.threads".  Ant's JUnit runner receives the
+     * thread ID as a command line argument of the form threadid=N, where N is an
+     * integer in the range [1, ${test.junit.threads}].  It's not otherwise
+     * accessible, so we need to parse it from the command line.  This method
+     * uses these 2 pieces of information to split the available ports into
+     * disjoint ranges.  Each JUnit process only assigns ports from its own range
+     * in order to prevent bind errors during concurrent test runs.  If any of
+     * this information is unavailable or unparseable, then the default behavior
+     * is for this process to use the entire available port range.  This is
+     * expected when running tests outside of Ant.
+     *
+     * @param strProcessCount string representation of integer process count,
+     *         typically taken from system property test.junit.threads
+     * @param cmdLine command line containing threadid=N argument, typically
+     *         taken from system property sun.java.command
+     * @return port range to use
+     */
+    static PortRange setupPortRange(String strProcessCount, String cmdLine) {
+        Integer processCount = null;
+        if (strProcessCount != null && !strProcessCount.isEmpty()) {
+            try {
+                processCount = Integer.valueOf(strProcessCount);
+            } catch (NumberFormatException e) {
+                LOG.warn("Error parsing test.junit.threads = {}.",
+                         strProcessCount, e);
+            }
+        }
+
+        Integer threadId = null;
+        if (processCount != null) {
+            if (cmdLine != null && !cmdLine.isEmpty()) {
+                Matcher m = Pattern.compile("threadid=(\\d+)").matcher(cmdLine);
+                if (m.find()) {
+                    try {
+                        threadId = Integer.valueOf(m.group(1));
+                    } catch (NumberFormatException e) {
+                        LOG.warn("Error parsing threadid from {}.", cmdLine, e);
+                    }
+                }
+            }
+        }
+
+        final PortRange newPortRange;
+        if (processCount != null && processCount > 1 && threadId != null)
{
+            // We know the total JUnit process count and this test process's ID.
+            // Use these values to calculate the valid range for port assignments
+            // within this test process.  We lose a few possible ports to the
+            // remainder, but that's acceptable.
+            int portRangeSize = (GLOBAL_MAX_PORT - GLOBAL_BASE_PORT) /
+                    processCount;
+            int minPort = GLOBAL_BASE_PORT + ((threadId - 1) * portRangeSize);
+            int maxPort = minPort + portRangeSize - 1;
+            newPortRange = new PortRange(minPort, maxPort);
+            LOG.info("Test process {}/{} using ports from {}.", threadId,
+                    processCount, newPortRange);
+        } else {
+            // If running outside the context of Ant or Ant is using a single
+            // test process, then use all valid ports.
+            newPortRange = new PortRange(GLOBAL_BASE_PORT, GLOBAL_MAX_PORT);
+            LOG.info("Single test process using ports from {}.", newPortRange);
+        }
+
+        return newPortRange;
+    }
+
+    /**
+     * Contains the minimum and maximum (both inclusive) in a range of ports.
+     */
+    static final class PortRange {
+        private final int minimum;
+        private final int maximum;
+
+        /**
+         * Creates a new PortRange.
+         *
+         * @param minimum lower bound port number
+         * @param maximum upper bound port number
+         */
+        PortRange(int minimum, int maximum) {
+            this.minimum = minimum;
+            this.maximum = maximum;
+        }
+
+        /**
+         * Returns maximum port in the range.
+         *
+         * @return maximum
+         */
+        int getMaximum() {
+            return maximum;
+        }
+
+        /**
+         * Returns minimum port in the range.
+         *
+         * @return minimum
+         */
+        int getMinimum() {
+            return minimum;
+        }
+
+        @Override
+        public String toString() {
+            return String.format("%d - %d", minimum, maximum);
+        }
+    }
+
+    /**
+     * There is no reason to instantiate this class.
+     */
+    private PortAssignment() {
     }
 }

Added: zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/PortAssignmentTest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/PortAssignmentTest.java?rev=1679401&view=auto
==============================================================================
--- zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/PortAssignmentTest.java
(added)
+++ zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/PortAssignmentTest.java
Thu May 14 16:43:39 2015
@@ -0,0 +1,79 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.zookeeper;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+import org.junit.Test;
+
+@RunWith(Parameterized.class)
+public class PortAssignmentTest {
+
+    private final String strProcessCount;
+    private final String cmdLine;
+    private final int expectedMinimumPort;
+    private final int expectedMaximumPort;
+
+    @Parameters
+    public static Collection<Object[]> data() {
+        return Arrays.<Object[]>asList(
+                new Object[] { "8", "threadid=1", 11221, 13913 },
+                new Object[] { "8", "threadid=2", 13914, 16606 },
+                new Object[] { "8", "threadid=3", 16607, 19299 },
+                new Object[] { "8", "threadid=4", 19300, 21992 },
+                new Object[] { "8", "threadid=5", 21993, 24685 },
+                new Object[] { "8", "threadid=6", 24686, 27378 },
+                new Object[] { "8", "threadid=7", 27379, 30071 },
+                new Object[] { "8", "threadid=8", 30072, 32764 },
+                new Object[] { "1", "threadid=1", 11221, 32767 },
+                new Object[] { "2", "threadid=1", 11221, 21993 },
+                new Object[] { "2", "threadid=2", 21994, 32766 },
+                new Object[] { null, null, 11221, 32767 },
+                new Object[] { "", "", 11221, 32767 });
+    }
+
+    public PortAssignmentTest(String strProcessCount, String cmdLine,
+            int expectedMinimumPort, int expectedMaximumPort) {
+        this.strProcessCount = strProcessCount;
+        this.cmdLine = cmdLine;
+        this.expectedMinimumPort = expectedMinimumPort;
+        this.expectedMaximumPort = expectedMaximumPort;
+    }
+
+    @Test
+    public void testSetupPortRange() {
+        PortAssignment.PortRange portRange = PortAssignment.setupPortRange(
+                strProcessCount, cmdLine);
+        assertEquals(buildAssertionMessage("minimum"), expectedMinimumPort,
+                portRange.getMinimum());
+        assertEquals(buildAssertionMessage("maximum"), expectedMaximumPort,
+                portRange.getMaximum());
+    }
+
+    private String buildAssertionMessage(String checkType) {
+        return String.format("strProcessCount = %s, cmdLine = %s, checking %s",
+                strProcessCount, cmdLine, checkType);
+    }
+}

Modified: zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/ZxidRolloverTest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/ZxidRolloverTest.java?rev=1679401&r1=1679400&r2=1679401&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/ZxidRolloverTest.java
(original)
+++ zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/ZxidRolloverTest.java
Thu May 14 16:43:39 2015
@@ -55,6 +55,7 @@ public class ZxidRolloverTest extends Te
     @Override
     protected void setUp() throws Exception {
         LOG.info("STARTING " + getName());
+        System.setProperty("zookeeper.admin.enableServer", "false");
 
         // set the snap count to something low so that we force log rollover
         // and verify that is working as part of the epoch rollover.

Modified: zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/quorum/CommitProcessorTest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/quorum/CommitProcessorTest.java?rev=1679401&r1=1679400&r2=1679401&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/quorum/CommitProcessorTest.java
(original)
+++ zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/quorum/CommitProcessorTest.java
Thu May 14 16:43:39 2015
@@ -87,6 +87,7 @@ public class CommitProcessorTest {
         System.setProperty(
             CommitProcessor.ZOOKEEPER_COMMIT_PROC_NUM_WORKER_THREADS,
             Integer.toString(numCommitThreads));
+        System.setProperty("zookeeper.admin.enableServer", "false");
         tmpDir = ClientBase.createTmpDir();
         ClientBase.setupTestEnv();
         zks = new TestZooKeeperServer(tmpDir, tmpDir, 4000);

Modified: zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/quorum/WatchLeakTest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/quorum/WatchLeakTest.java?rev=1679401&r1=1679400&r2=1679401&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/quorum/WatchLeakTest.java
(original)
+++ zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/quorum/WatchLeakTest.java
Thu May 14 16:43:39 2015
@@ -63,6 +63,7 @@ import org.apache.zookeeper.server.MockS
 import org.apache.zookeeper.server.ZKDatabase;
 import org.apache.zookeeper.server.ZooTrace;
 import org.apache.zookeeper.server.persistence.FileTxnSnapLog;
+import org.junit.Before;
 import org.junit.Test;
 import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
@@ -82,6 +83,11 @@ public class WatchLeakTest {
 
     private final boolean sessionTimedout;
 
+    @Before
+    public void setUp() {
+        System.setProperty("zookeeper.admin.enableServer", "false");
+    }
+
     public WatchLeakTest(boolean sessionTimedout) {
         this.sessionTimedout = sessionTimedout;
     }

Modified: zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/quorum/Zab1_0Test.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/quorum/Zab1_0Test.java?rev=1679401&r1=1679400&r2=1679401&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/quorum/Zab1_0Test.java
(original)
+++ zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/quorum/Zab1_0Test.java
Thu May 14 16:43:39 2015
@@ -64,6 +64,7 @@ import org.apache.zookeeper.txn.ErrorTxn
 import org.apache.zookeeper.txn.SetDataTxn;
 import org.apache.zookeeper.txn.TxnHeader;
 import org.junit.Assert;
+import org.junit.Before;
 import org.junit.Test;
 import org.apache.zookeeper.server.quorum.flexible.QuorumVerifier;
 import org.slf4j.Logger;
@@ -77,6 +78,11 @@ public class Zab1_0Test {
     private static final File testData = new File(
             System.getProperty("test.data.dir", "build/test/data"));
 
+    @Before
+    public void setUp() {
+        System.setProperty("zookeeper.admin.enableServer", "false");
+    }
+
     private static final class LeadThread extends Thread {
         private final Leader leader;
 

Modified: zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/HierarchicalQuorumTest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/HierarchicalQuorumTest.java?rev=1679401&r1=1679400&r2=1679401&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/HierarchicalQuorumTest.java
(original)
+++ zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/HierarchicalQuorumTest.java
Thu May 14 16:43:39 2015
@@ -108,11 +108,11 @@ public class HierarchicalQuorumTest exte
         "weight.3=1\n" +
         "weight.4=0\n" +
         "weight.5=0\n" +
-        "server.1=127.0.0.1:" + (port1 + 1000) + ":" + (leport1 + 1000) + ";" + clientport1
+ "\n" + 
-        "server.2=127.0.0.1:" + (port2 + 1000) + ":" + (leport2 + 1000) + ";" + clientport2
+ "\n" + 
-        "server.3=127.0.0.1:" + (port3 + 1000) + ":" + (leport3 + 1000) + ";" + clientport3
+ "\n" + 
-        "server.4=127.0.0.1:" + (port4 + 1000) + ":" + (leport4 + 1000) + ";" + clientport4
+ "\n" + 
-        "server.5=127.0.0.1:" + (port5 + 1000) + ":" + (leport5 + 1000) + ";" + clientport5
+ "\n";
+        "server.1=127.0.0.1:" + port1 + ":" + leport1 + ";" + clientport1 + "\n" +
+        "server.2=127.0.0.1:" + port2 + ":" + leport2 + ";" + clientport2 + "\n" +
+        "server.3=127.0.0.1:" + port3 + ":" + leport3 + ";" + clientport3 + "\n" +
+        "server.4=127.0.0.1:" + port4 + ":" + leport4 + ";" + clientport4 + "\n" +
+        "server.5=127.0.0.1:" + port5 + ":" + leport5 + ";" + clientport5 + "\n";
 
         ByteArrayInputStream is = new ByteArrayInputStream(config.getBytes());
         this.qp = new Properties();
@@ -147,26 +147,26 @@ public class HierarchicalQuorumTest exte
         int syncLimit = 3;
         HashMap<Long,QuorumServer> peers = new HashMap<Long,QuorumServer>();
         peers.put(Long.valueOf(1), new QuorumServer(1, 
-                new InetSocketAddress("127.0.0.1", port1 + 1000),
-                new InetSocketAddress("127.0.0.1", leport1 + 1000),
+                new InetSocketAddress("127.0.0.1", port1),
+                new InetSocketAddress("127.0.0.1", leport1),
                 new InetSocketAddress("127.0.0.1", clientport1)));        
         peers.put(Long.valueOf(2), new QuorumServer(2, 
-                new InetSocketAddress("127.0.0.1", port2 + 1000),
-                new InetSocketAddress("127.0.0.1", leport2 + 1000),
+                new InetSocketAddress("127.0.0.1", port2),
+                new InetSocketAddress("127.0.0.1", leport2),
                 new InetSocketAddress("127.0.0.1", clientport2)));
         peers.put(Long.valueOf(3), new QuorumServer(3, 
-                new InetSocketAddress("127.0.0.1", port3 + 1000),
-                new InetSocketAddress("127.0.0.1", leport3 + 1000),
+                new InetSocketAddress("127.0.0.1", port3),
+                new InetSocketAddress("127.0.0.1", leport3),
                 new InetSocketAddress("127.0.0.1", clientport3)));
         peers.put(Long.valueOf(4), new QuorumServer(4,
-                new InetSocketAddress("127.0.0.1", port4 + 1000),
+                new InetSocketAddress("127.0.0.1", port4),
                 new InetSocketAddress("127.0.0.1", leport4),
                 new InetSocketAddress("127.0.0.1", clientport4),
                 withObservers ? QuorumPeer.LearnerType.OBSERVER
                         : QuorumPeer.LearnerType.PARTICIPANT));
         peers.put(Long.valueOf(5), new QuorumServer(5,
-                new InetSocketAddress("127.0.0.1", port5 + 1000),
-                new InetSocketAddress("127.0.0.1", leport5 + 1000),
+                new InetSocketAddress("127.0.0.1", port5),
+                new InetSocketAddress("127.0.0.1", leport5),
                 new InetSocketAddress("127.0.0.1", clientport5),
                 withObservers ? QuorumPeer.LearnerType.OBSERVER
                         : QuorumPeer.LearnerType.PARTICIPANT));
@@ -174,8 +174,8 @@ public class HierarchicalQuorumTest exte
         LOG.info("creating QuorumPeer 1 port " + clientport1);
         
         if (withObservers) {
-               qp.setProperty("server.4", "127.0.0.1:" + (port4 + 1000) + ":" + (leport4
+ 1000) + ":observer" + ";" + clientport4);  
-               qp.setProperty("server.5", "127.0.0.1:" + (port5 + 1000) + ":" + (leport5
+ 1000) +  ":observer" + ";" + clientport5);
+               qp.setProperty("server.4", "127.0.0.1:" + port4 + ":" + leport4 + ":observer"
+ ";" + clientport4);
+               qp.setProperty("server.5", "127.0.0.1:" + port5 + ":" + leport5 +  ":observer"
+ ";" + clientport5);
         }
         QuorumHierarchical hq1 = new QuorumHierarchical(qp); 
         s1 = new QuorumPeer(peers, s1dir, s1dir, clientport1, 3, 1, tickTime, initLimit,
syncLimit, hq1);

Modified: zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/NettyNettySuiteBase.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/NettyNettySuiteBase.java?rev=1679401&r1=1679400&r2=1679401&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/NettyNettySuiteBase.java
(original)
+++ zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/NettyNettySuiteBase.java
Thu May 14 16:43:39 2015
@@ -38,6 +38,7 @@ public class NettyNettySuiteBase {
                 NettyServerCnxnFactory.class.getName());
         System.setProperty(ZooKeeper.ZOOKEEPER_CLIENT_CNXN_SOCKET,
                 ClientCnxnSocketNetty.class.getName());
+        System.setProperty("zookeeper.admin.enableServer", "false");
     }
 
     @AfterClass

Modified: zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/NioNettySuiteBase.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/NioNettySuiteBase.java?rev=1679401&r1=1679400&r2=1679401&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/NioNettySuiteBase.java
(original)
+++ zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/NioNettySuiteBase.java
Thu May 14 16:43:39 2015
@@ -34,6 +34,7 @@ public class NioNettySuiteBase {
     public static void setUp() {
         System.setProperty(ServerCnxnFactory.ZOOKEEPER_SERVER_CNXN_FACTORY,
                 NettyServerCnxnFactory.class.getName());
+        System.setProperty("zookeeper.admin.enableServer", "false");
     }
 
     @AfterClass

Modified: zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/QuorumBase.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/QuorumBase.java?rev=1679401&r1=1679400&r2=1679401&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/QuorumBase.java
(original)
+++ zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/QuorumBase.java
Thu May 14 16:43:39 2015
@@ -138,28 +138,28 @@ public class QuorumBase extends ClientBa
         int syncLimit = 3;
         HashMap<Long,QuorumServer> peers = new HashMap<Long,QuorumServer>();
         peers.put(Long.valueOf(1), new QuorumServer(1, 
-                new InetSocketAddress(LOCALADDR, port1 + 1000),
-                new InetSocketAddress(LOCALADDR, portLE1 + 1000),
+                new InetSocketAddress(LOCALADDR, port1),
+                new InetSocketAddress(LOCALADDR, portLE1),
                 new InetSocketAddress(LOCALADDR, portClient1),
                 LearnerType.PARTICIPANT));
         peers.put(Long.valueOf(2), new QuorumServer(2, 
-                new InetSocketAddress(LOCALADDR, port2 + 1000),
-                new InetSocketAddress(LOCALADDR, portLE2 + 1000),
+                new InetSocketAddress(LOCALADDR, port2),
+                new InetSocketAddress(LOCALADDR, portLE2),
                 new InetSocketAddress(LOCALADDR, portClient2),
                 LearnerType.PARTICIPANT));
         peers.put(Long.valueOf(3), new QuorumServer(3, 
-                new InetSocketAddress(LOCALADDR, port3 + 1000),
-                new InetSocketAddress(LOCALADDR, portLE3 + 1000),
+                new InetSocketAddress(LOCALADDR, port3),
+                new InetSocketAddress(LOCALADDR, portLE3),
                 new InetSocketAddress(LOCALADDR, portClient3),
                 LearnerType.PARTICIPANT));
         peers.put(Long.valueOf(4), new QuorumServer(4, 
-                new InetSocketAddress(LOCALADDR, port4 + 1000),
-                new InetSocketAddress(LOCALADDR, portLE4 + 1000),
+                new InetSocketAddress(LOCALADDR, port4),
+                new InetSocketAddress(LOCALADDR, portLE4),
                 new InetSocketAddress(LOCALADDR, portClient4),
                 LearnerType.PARTICIPANT));
         peers.put(Long.valueOf(5), new QuorumServer(5, 
-                new InetSocketAddress(LOCALADDR, port5 + 1000),
-                new InetSocketAddress(LOCALADDR, portLE5 + 1000),
+                new InetSocketAddress(LOCALADDR, port5),
+                new InetSocketAddress(LOCALADDR, portLE5),
                 new InetSocketAddress(LOCALADDR, portClient5),
                 LearnerType.PARTICIPANT));
         
@@ -303,28 +303,28 @@ public class QuorumBase extends ClientBa
             peers = new HashMap<Long,QuorumServer>();
 
             peers.put(Long.valueOf(1), new QuorumServer(1, 
-                new InetSocketAddress(LOCALADDR, port1 + 1000),
-                new InetSocketAddress(LOCALADDR, portLE1 + 1000),
+                new InetSocketAddress(LOCALADDR, port1),
+                new InetSocketAddress(LOCALADDR, portLE1),
                 new InetSocketAddress(LOCALADDR, portClient1),
                 LearnerType.PARTICIPANT));
             peers.put(Long.valueOf(2), new QuorumServer(2, 
-                new InetSocketAddress(LOCALADDR, port2 + 1000),
-                new InetSocketAddress(LOCALADDR, portLE2 + 1000),
+                new InetSocketAddress(LOCALADDR, port2),
+                new InetSocketAddress(LOCALADDR, portLE2),
                 new InetSocketAddress(LOCALADDR, portClient2),
                 LearnerType.PARTICIPANT));
             peers.put(Long.valueOf(3), new QuorumServer(3, 
-                new InetSocketAddress(LOCALADDR, port3 + 1000),
-                new InetSocketAddress(LOCALADDR, portLE3 + 1000),
+                new InetSocketAddress(LOCALADDR, port3),
+                new InetSocketAddress(LOCALADDR, portLE3),
                 new InetSocketAddress(LOCALADDR, portClient3),
                 LearnerType.PARTICIPANT));
             peers.put(Long.valueOf(4), new QuorumServer(4, 
-                new InetSocketAddress(LOCALADDR, port4 + 1000),
-                new InetSocketAddress(LOCALADDR, portLE4 + 1000),
+                new InetSocketAddress(LOCALADDR, port4),
+                new InetSocketAddress(LOCALADDR, portLE4),
                 new InetSocketAddress(LOCALADDR, portClient4),
                 LearnerType.PARTICIPANT));
             peers.put(Long.valueOf(5), new QuorumServer(5, 
-                new InetSocketAddress(LOCALADDR, port5 + 1000),
-                new InetSocketAddress(LOCALADDR, portLE5 + 1000),
+                new InetSocketAddress(LOCALADDR, port5),
+                new InetSocketAddress(LOCALADDR, portLE5),
                 new InetSocketAddress(LOCALADDR, portClient5),
                 LearnerType.PARTICIPANT));
         }

Modified: zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/QuorumUtil.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/QuorumUtil.java?rev=1679401&r1=1679400&r2=1679401&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/QuorumUtil.java
(original)
+++ zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/QuorumUtil.java
Thu May 14 16:43:39 2015
@@ -105,8 +105,8 @@ public class QuorumUtil {
                 peers.put(i, ps);
 
                 peersView.put(Long.valueOf(i), new QuorumServer(i, 
-                               new InetSocketAddress("127.0.0.1", PortAssignment.unique()
+ 1000), 
-                               new InetSocketAddress("127.0.0.1", PortAssignment.unique()
+ 1000), 
+                               new InetSocketAddress("127.0.0.1", PortAssignment.unique()),
+                               new InetSocketAddress("127.0.0.1", PortAssignment.unique()),
                                new InetSocketAddress("127.0.0.1", ps.clientPort), 
                                LearnerType.PARTICIPANT));
                 hostPort += "127.0.0.1:" + ps.clientPort + ((i == ALL) ? "" : ",");

Modified: zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/TruncateTest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/TruncateTest.java?rev=1679401&r1=1679400&r2=1679401&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/TruncateTest.java
(original)
+++ zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/TruncateTest.java
Thu May 14 16:43:39 2015
@@ -54,7 +54,6 @@ import org.slf4j.LoggerFactory;
 public class TruncateTest extends ZKTestCase {
 	private static final Logger LOG = LoggerFactory.getLogger(TruncateTest.class);
     File dataDir1, dataDir2, dataDir3;
-    final int baseHostPort = PortAssignment.unique();
     
     @Before
     public void setUp() throws IOException {
@@ -155,7 +154,7 @@ public class TruncateTest extends ZKTest
     @Test
     public void testTruncate() throws IOException, InterruptedException, KeeperException
{
         // Prime the server that is going to come in late with 50 txns
-        String hostPort = "127.0.0.1:" + baseHostPort;
+        String hostPort = "127.0.0.1:" + PortAssignment.unique();
         int maxCnxns = 100;
         ServerCnxnFactory factory = ClientBase.createNewServerInstance(null,
                 hostPort, maxCnxns);
@@ -191,21 +190,25 @@ public class TruncateTest extends ZKTest
         int tickTime = 2000;
         int initLimit = 3;
         int syncLimit = 3;
-        int port1 = baseHostPort+1;
-        int port2 = baseHostPort+2;
-        int port3 = baseHostPort+3;
+
+        int port1 = PortAssignment.unique();
+        int port2 = PortAssignment.unique();
+        int port3 = PortAssignment.unique();
         
         // Start up two of the quorum and add 10 txns
         HashMap<Long,QuorumServer> peers = new HashMap<Long,QuorumServer>();
-        peers.put(Long.valueOf(1), new QuorumServer(1, new InetSocketAddress("127.0.0.1",
port1 + 1000),
-        		new InetSocketAddress("127.0.0.1", port1 + 2000),
-        		new InetSocketAddress("127.0.0.1", port1 + 3000)));
-        peers.put(Long.valueOf(2), new QuorumServer(2, new InetSocketAddress("127.0.0.1",
port2 + 1000),
-        		new InetSocketAddress("127.0.0.1", port2 + 2000),
-        		new InetSocketAddress("127.0.0.1", port2 + 3000)));
-        peers.put(Long.valueOf(3), new QuorumServer(3, new InetSocketAddress("127.0.0.1",
port3 + 1000),
-        		new InetSocketAddress("127.0.0.1", port3 + 2000),
-        		new InetSocketAddress("127.0.0.1", port3 + 3000)));
+        peers.put(Long.valueOf(1), new QuorumServer(1,
+                       new InetSocketAddress("127.0.0.1", PortAssignment.unique()),
+                       new InetSocketAddress("127.0.0.1", PortAssignment.unique()),
+                       new InetSocketAddress("127.0.0.1", PortAssignment.unique())));
+        peers.put(Long.valueOf(2), new QuorumServer(2,
+                       new InetSocketAddress("127.0.0.1", PortAssignment.unique()),
+                       new InetSocketAddress("127.0.0.1", PortAssignment.unique()),
+                       new InetSocketAddress("127.0.0.1", PortAssignment.unique())));
+        peers.put(Long.valueOf(3), new QuorumServer(3,
+                       new InetSocketAddress("127.0.0.1", PortAssignment.unique()),
+                       new InetSocketAddress("127.0.0.1", PortAssignment.unique()),
+                       new InetSocketAddress("127.0.0.1", PortAssignment.unique())));
 
         QuorumPeer s2 = new QuorumPeer(peers, dataDir2, dataDir2, port2, 0, 2, tickTime,
initLimit, syncLimit);
         s2.start();

Modified: zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/WatchEventWhenAutoResetTest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/WatchEventWhenAutoResetTest.java?rev=1679401&r1=1679400&r2=1679401&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/WatchEventWhenAutoResetTest.java
(original)
+++ zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/test/WatchEventWhenAutoResetTest.java
Thu May 14 16:43:39 2015
@@ -30,6 +30,7 @@ import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.Watcher.Event.EventType;
 import org.apache.zookeeper.test.ClientBase.CountdownWatcher;
 import org.junit.Assert;
+import org.junit.Before;
 import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -88,6 +89,11 @@ public class WatchEventWhenAutoResetTest
         return createClient(qu, id, new EventsWatcher());
     }
 
+    @Before
+    public void setUp() {
+        System.setProperty("zookeeper.admin.enableServer", "false");
+    }
+
     @Test
     public void testNodeDataChanged() throws Exception {
         QuorumUtil qu = new QuorumUtil(1);



Mime
View raw message