Return-Path: X-Original-To: apmail-accumulo-commits-archive@www.apache.org Delivered-To: apmail-accumulo-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 301D2F6D5 for ; Wed, 1 May 2013 14:04:36 +0000 (UTC) Received: (qmail 95042 invoked by uid 500); 1 May 2013 14:04:36 -0000 Delivered-To: apmail-accumulo-commits-archive@accumulo.apache.org Received: (qmail 94993 invoked by uid 500); 1 May 2013 14:04:35 -0000 Mailing-List: contact commits-help@accumulo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@accumulo.apache.org Delivered-To: mailing list commits@accumulo.apache.org Received: (qmail 94982 invoked by uid 99); 1 May 2013 14:04:35 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 01 May 2013 14:04:35 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 01 May 2013 14:04:32 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 167CE23889E7; Wed, 1 May 2013 14:04:11 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1478005 - in /accumulo/branches/1.5: proxy/src/test/java/org/apache/accumulo/proxy/SimpleTest.java server/src/main/java/org/apache/accumulo/server/util/PortUtils.java test/src/main/java/org/apache/accumulo/test/MiniAccumuloCluster.java Date: Wed, 01 May 2013 14:04:10 -0000 To: commits@accumulo.apache.org From: kturner@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130501140411.167CE23889E7@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: kturner Date: Wed May 1 14:04:10 2013 New Revision: 1478005 URL: http://svn.apache.org/r1478005 Log: ACCUMULO-1365 move getRandomFreePort() out of MAC API Added: accumulo/branches/1.5/server/src/main/java/org/apache/accumulo/server/util/PortUtils.java Modified: accumulo/branches/1.5/proxy/src/test/java/org/apache/accumulo/proxy/SimpleTest.java accumulo/branches/1.5/test/src/main/java/org/apache/accumulo/test/MiniAccumuloCluster.java Modified: accumulo/branches/1.5/proxy/src/test/java/org/apache/accumulo/proxy/SimpleTest.java URL: http://svn.apache.org/viewvc/accumulo/branches/1.5/proxy/src/test/java/org/apache/accumulo/proxy/SimpleTest.java?rev=1478005&r1=1478004&r2=1478005&view=diff ============================================================================== --- accumulo/branches/1.5/proxy/src/test/java/org/apache/accumulo/proxy/SimpleTest.java (original) +++ accumulo/branches/1.5/proxy/src/test/java/org/apache/accumulo/proxy/SimpleTest.java Wed May 1 14:04:10 2013 @@ -79,6 +79,7 @@ import org.apache.accumulo.proxy.thrift. import org.apache.accumulo.proxy.thrift.UnknownScanner; import org.apache.accumulo.proxy.thrift.UnknownWriter; import org.apache.accumulo.proxy.thrift.WriterOptions; +import org.apache.accumulo.server.util.PortUtils; import org.apache.accumulo.test.MiniAccumuloCluster; import org.apache.accumulo.test.functional.SlowIterator; import org.apache.commons.io.FileUtils; @@ -145,7 +146,7 @@ public class SimpleTest { protocolClass = getRandomProtocol(); System.out.println(protocolClass.getName()); - proxyPort = MiniAccumuloCluster.getRandomFreePort(); + proxyPort = PortUtils.getRandomFreePort(); proxyServer = Proxy.createProxyServer(org.apache.accumulo.proxy.thrift.AccumuloProxy.class, org.apache.accumulo.proxy.ProxyServer.class, proxyPort, protocolClass, props); thread = new Thread() { Added: accumulo/branches/1.5/server/src/main/java/org/apache/accumulo/server/util/PortUtils.java URL: http://svn.apache.org/viewvc/accumulo/branches/1.5/server/src/main/java/org/apache/accumulo/server/util/PortUtils.java?rev=1478005&view=auto ============================================================================== --- accumulo/branches/1.5/server/src/main/java/org/apache/accumulo/server/util/PortUtils.java (added) +++ accumulo/branches/1.5/server/src/main/java/org/apache/accumulo/server/util/PortUtils.java Wed May 1 14:04:10 2013 @@ -0,0 +1,51 @@ +/* + * 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.accumulo.server.util; + +import java.io.IOException; +import java.net.ServerSocket; +import java.util.Random; + +public class PortUtils { + + public static int getRandomFreePort() { + Random r = new Random(); + int count = 0; + + while (count < 13) { + int port = r.nextInt((1 << 16) - 1024) + 1024; + + ServerSocket so = null; + try { + so = new ServerSocket(port); + so.setReuseAddress(true); + return port; + } catch (IOException ioe) { + + } finally { + if (so != null) + try { + so.close(); + } catch (IOException e) {} + } + + } + + throw new RuntimeException("Unable to find port"); + } + +} Modified: accumulo/branches/1.5/test/src/main/java/org/apache/accumulo/test/MiniAccumuloCluster.java URL: http://svn.apache.org/viewvc/accumulo/branches/1.5/test/src/main/java/org/apache/accumulo/test/MiniAccumuloCluster.java?rev=1478005&r1=1478004&r2=1478005&view=diff ============================================================================== --- accumulo/branches/1.5/test/src/main/java/org/apache/accumulo/test/MiniAccumuloCluster.java (original) +++ accumulo/branches/1.5/test/src/main/java/org/apache/accumulo/test/MiniAccumuloCluster.java Wed May 1 14:04:10 2013 @@ -23,7 +23,6 @@ import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -import java.net.ServerSocket; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -31,13 +30,13 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Properties; -import java.util.Random; import org.apache.accumulo.core.conf.Property; import org.apache.accumulo.core.util.UtilWaitThread; import org.apache.accumulo.server.master.Master; import org.apache.accumulo.server.tabletserver.TabletServer; import org.apache.accumulo.server.util.Initialize; +import org.apache.accumulo.server.util.PortUtils; import org.apache.accumulo.server.util.time.SimpleTimer; import org.apache.accumulo.start.Main; import org.apache.zookeeper.server.ZooKeeperServerMain; @@ -121,32 +120,6 @@ public class MiniAccumuloCluster { private MiniAccumuloConfig config; private Process[] tabletServerProcesses; - static public int getRandomFreePort() { - Random r = new Random(); - int count = 0; - - while (count < 13) { - int port = r.nextInt((1 << 16) - 1024) + 1024; - - ServerSocket so = null; - try { - so = new ServerSocket(port); - so.setReuseAddress(true); - return port; - } catch (IOException ioe) { - - } finally { - if (so != null) - try { - so.close(); - } catch (IOException e) {} - } - - } - - throw new RuntimeException("Unable to find port"); - } - Process exec(Class clazz, String... args) throws IOException { String javaHome = System.getProperty("java.home"); String javaBin = javaHome + File.separator + "bin" + File.separator + "java"; @@ -240,7 +213,7 @@ public class MiniAccumuloCluster { walogDir.mkdirs(); libDir.mkdirs(); - zooKeeperPort = getRandomFreePort(); + zooKeeperPort = PortUtils.getRandomFreePort(); File siteFile = new File(confDir, "accumulo-site.xml"); @@ -253,8 +226,8 @@ public class MiniAccumuloCluster { appendProp(fileWriter, Property.INSTANCE_DFS_DIR, accumuloDir.getAbsolutePath(), siteConfig); appendProp(fileWriter, Property.INSTANCE_ZK_HOST, "localhost:" + zooKeeperPort, siteConfig); appendProp(fileWriter, Property.INSTANCE_SECRET, INSTANCE_SECRET, siteConfig); - appendProp(fileWriter, Property.MASTER_CLIENTPORT, "" + getRandomFreePort(), siteConfig); - appendProp(fileWriter, Property.TSERV_CLIENTPORT, "" + getRandomFreePort(), siteConfig); + appendProp(fileWriter, Property.MASTER_CLIENTPORT, "" + PortUtils.getRandomFreePort(), siteConfig); + appendProp(fileWriter, Property.TSERV_CLIENTPORT, "" + PortUtils.getRandomFreePort(), siteConfig); appendProp(fileWriter, Property.TSERV_PORTSEARCH, "true", siteConfig); appendProp(fileWriter, Property.LOGGER_DIR, walogDir.getAbsolutePath(), siteConfig); appendProp(fileWriter, Property.TSERV_DATACACHE_SIZE, "10M", siteConfig); @@ -263,7 +236,7 @@ public class MiniAccumuloCluster { appendProp(fileWriter, Property.TSERV_WALOG_MAX_SIZE, "100M", siteConfig); appendProp(fileWriter, Property.TSERV_NATIVEMAP_ENABLED, "false", siteConfig); appendProp(fileWriter, Property.TRACE_TOKEN_PROPERTY_PREFIX + ".password", config.getRootPassword(), siteConfig); - appendProp(fileWriter, Property.TRACE_PORT, "" + getRandomFreePort(), siteConfig); + appendProp(fileWriter, Property.TRACE_PORT, "" + PortUtils.getRandomFreePort(), siteConfig); // since there is a small amount of memory, check more frequently for majc... setting may not be needed in 1.5 appendProp(fileWriter, Property.TSERV_MAJC_DELAY, "3", siteConfig); String cp = System.getenv("ACCUMULO_HOME")+"/lib/.*.jar,"+