From: <tho...@us...> - 2013-11-22 15:43:48
|
Revision: 7581 http://bigdata.svn.sourceforge.net/bigdata/?rev=7581&view=rev Author: thompsonbry Date: 2013-11-22 15:43:38 +0000 (Fri, 22 Nov 2013) Log Message: ----------- Added ability to parse a comma delimited list of URLs as a LookupLocator[]. Added ability to parse a comma delimited list of groups. Integrated into the test suite. Modified Paths: -------------- branches/BIGDATA_RELEASE_1_3_0/bigdata-jini/src/java/com/bigdata/jini/util/ConfigMath.java branches/BIGDATA_RELEASE_1_3_0/bigdata-jini/src/test/com/bigdata/jini/TestAll.java Added Paths: ----------- branches/BIGDATA_RELEASE_1_3_0/bigdata-jini/src/test/com/bigdata/jini/util/ branches/BIGDATA_RELEASE_1_3_0/bigdata-jini/src/test/com/bigdata/jini/util/TestAll.java branches/BIGDATA_RELEASE_1_3_0/bigdata-jini/src/test/com/bigdata/jini/util/TestConfigMath.java Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata-jini/src/java/com/bigdata/jini/util/ConfigMath.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-jini/src/java/com/bigdata/jini/util/ConfigMath.java 2013-11-22 02:09:38 UTC (rev 7580) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-jini/src/java/com/bigdata/jini/util/ConfigMath.java 2013-11-22 15:43:38 UTC (rev 7581) @@ -28,9 +28,14 @@ package com.bigdata.jini.util; import java.io.File; +import java.net.MalformedURLException; import java.util.concurrent.TimeUnit; +import javax.net.SocketFactory; + import net.jini.config.Configuration; +import net.jini.core.discovery.LookupLocator; +import net.jini.discovery.LookupDiscovery; import com.sun.jini.config.ConfigUtil; @@ -331,5 +336,95 @@ return o != null; } - + + /** + * Parse a comma delimited list of zero or more unicast URIs of the form + * <code>jini://host/</code> or <code>jini://host:port/</code>. + * <p> + * This MAY be an empty array if you want to use multicast discovery + * <strong>and</strong> you have specified the groups as + * {@link LookupDiscovery#ALL_GROUPS} (a <code>null</code>). + * <p> + * Note: This method is intended for overrides expressed from scripts using + * environment variables where we need to parse an interpret the value + * rather than given the value directly in a {@link Configuration} file. As + * a consequence, you can not specify the optional {@link SocketFactory} for + * the {@link LookupLocator} with this method. + * + * @param locators + * The locators, expressed as a comma delimited list of URIs. + * + * @return An array of zero or more {@link LookupLocator}s. + * + * @throws MalformedURLException + * if any of the parse URLs is invalid. + * + * @throws IllegalArgumentException + * if the <i>locators</i> is <code>null</code>. + */ + public static LookupLocator[] getLocators(final String locators) + throws MalformedURLException { + + if (locators == null) + throw new IllegalArgumentException(); + + final String[] a = locators.split(","); + + final LookupLocator[] b = new LookupLocator[a.length]; + + if (a.length == 1 && a[0].trim().length() == 0) { + + return new LookupLocator[0]; + + } + + for (int i = 0; i < a.length; i++) { + + final String urlStr = a[i]; + + final LookupLocator locator = new LookupLocator(urlStr); + + b[i] = locator; + + } + + return b; + + } + + /** + * Return an array of zero or more groups -or- <code>null</code> if the + * given argument is either <code>null</code> or <code>"null"</code>. + * <p> + * Note: a <code>null</code> corresponds to + * {@link LookupDiscovery#ALL_GROUPS}. This option is only permissible when + * you have a single setup and are using multicast discovery. In all other + * cases, you need to specify the group(s). + * + * @param groups + * The groups, expressed as a comma delimited list or zero or + * more groups. + * + * @return A string array parsed out of that argument. + */ + public static String[] getGroups(final String groups) { + + if (groups == null) + return null; + + if (groups.trim().equals("null")) + return null; + + final String[] a = groups.split(","); + + if (a.length == 1 && a[0].trim().length() == 0) { + + return new String[0]; + + } + + return a; + + } + } Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata-jini/src/test/com/bigdata/jini/TestAll.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-jini/src/test/com/bigdata/jini/TestAll.java 2013-11-22 02:09:38 UTC (rev 7580) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-jini/src/test/com/bigdata/jini/TestAll.java 2013-11-22 15:43:38 UTC (rev 7581) @@ -79,6 +79,9 @@ final TestSuite suite = new TestSuite("jini"); + // jini configuration helpers. + suite.addTest(com.bigdata.jini.util.TestAll.suite()); + // zookeeper client library (queues, locks, etc). suite.addTest(com.bigdata.zookeeper.TestAll.suite()); Added: branches/BIGDATA_RELEASE_1_3_0/bigdata-jini/src/test/com/bigdata/jini/util/TestAll.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-jini/src/test/com/bigdata/jini/util/TestAll.java (rev 0) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-jini/src/test/com/bigdata/jini/util/TestAll.java 2013-11-22 15:43:38 UTC (rev 7581) @@ -0,0 +1,62 @@ +/** + +Copyright (C) SYSTAP, LLC 2006-2007. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + * Created on Jun 26, 2006 + */ +package com.bigdata.jini.util; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import com.bigdata.service.jini.AbstractServerTestCase; + +/** + * Aggregates tests in dependency order - see {@link AbstractServerTestCase} for + * <strong>required</strong> system properties in order to run this test suite. + * + * @version $Id$ + * @author <a href="mailto:tho...@us...">Bryan Thompson</a> + */ +public class TestAll extends TestCase { + + public TestAll() { + } + + public TestAll(String name) { + super(name); + } + + public static Test suite() { + + final TestSuite suite = new TestSuite(TestAll.class.getPackage() + .getName()); + + suite.addTestSuite(TestConfigMath.class); + + return suite; + + } + +} Added: branches/BIGDATA_RELEASE_1_3_0/bigdata-jini/src/test/com/bigdata/jini/util/TestConfigMath.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-jini/src/test/com/bigdata/jini/util/TestConfigMath.java (rev 0) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-jini/src/test/com/bigdata/jini/util/TestConfigMath.java 2013-11-22 15:43:38 UTC (rev 7581) @@ -0,0 +1,105 @@ +/** + +Copyright (C) SYSTAP, LLC 2006-2007. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +/* + * Created on Jun 26, 2006 + */ +package com.bigdata.jini.util; + +import java.net.MalformedURLException; + +import junit.framework.TestCase2; +import net.jini.core.discovery.LookupLocator; + +public class TestConfigMath extends TestCase2 { + + public TestConfigMath() { + } + + public TestConfigMath(final String name) { + super(name); + } + + public void test_getLocators() throws MalformedURLException { + + assertSameArray( + new LookupLocator[] {// + new LookupLocator("jini://bigdata15/"),// + new LookupLocator("jini://bigdata16/"),// + new LookupLocator("jini://bigdata17/"),// + }, + ConfigMath + .getLocators("jini://bigdata15/,jini://bigdata16/,jini://bigdata17/")); + + } + + public void test_getLocators_empty() throws MalformedURLException { + + assertSameArray(new LookupLocator[] {// + }, ConfigMath.getLocators("")); + + } + + public void test_getLocators_null_arg() throws MalformedURLException { + + try { + + ConfigMath.getLocators(null/* locators */); + + fail("Expecting " + IllegalArgumentException.class); + + } catch (IllegalArgumentException ex) { + + // ignore expected exception + + } + + } + + public void test_getGroups1() throws MalformedURLException { + + assertSameArray(new String[] { "a" }, + ConfigMath.getGroups("a")); + + } + + public void test_getGroups3() throws MalformedURLException { + + assertSameArray(new String[] { "a", "b", "c" }, + ConfigMath.getGroups("a,b,c")); + + } + + public void test_getGroups_empty() { + + assertSameArray(new String[] {}, ConfigMath.getGroups("")); + + } + + public void test_getGroups_null_label() { + + assertEquals(null, ConfigMath.getGroups("null")); + + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |