From: <ble...@us...> - 2010-09-20 17:54:38
|
Revision: 3594 http://bigdata.svn.sourceforge.net/bigdata/?rev=3594&view=rev Author: blevine218 Date: 2010-09-20 17:54:31 +0000 (Mon, 20 Sep 2010) Log Message: ----------- check in tests in com.bigdata.jini.start.config package Added Paths: ----------- branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/jini/start/config/JiniStartConfigSuite.java branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/jini/start/config/TestServiceConfiguration.java branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/jini/start/config/TestServiceConfigurationRemote.java branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/jini/start/config/TestZookeeperServerEntry.java Added: branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/jini/start/config/JiniStartConfigSuite.java =================================================================== --- branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/jini/start/config/JiniStartConfigSuite.java (rev 0) +++ branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/jini/start/config/JiniStartConfigSuite.java 2010-09-20 17:54:31 UTC (rev 3594) @@ -0,0 +1,33 @@ +/*********************************************************************** + * + * $Id$ + * + * Copyright (c) 2000-2010 Nokia Corporation. + * + * This material, including documentation and any related computer + * programs, is protected by copyright controlled by Nokia Corporation. + * All rights are reserved. Copying, including reproducing, storing, + * adapting or translating, any or all of this material requires the prior + * written consent of Nokia Corporation. This material also contains + * confidential information which may not be disclosed to others without + * the prior written consent of Nokia Corporation. + **********************************************************************/ +package com.bigdata.jini.start.config; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +/** + * @author blevine + * + */ +@RunWith(Suite.class) +...@Su...iteClasses({ + TestServiceConfiguration.class, + TestServiceConfigurationRemote.class, + TestZookeeperServerEntry.class +}) + +public class JiniStartConfigSuite +{ +} Copied: branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/jini/start/config/TestServiceConfiguration.java (from rev 3580, branches/maven_scaleout/bigdata-core/src/test/java/com/bigdata/jini/start/config/TestServiceConfiguration.java) =================================================================== --- branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/jini/start/config/TestServiceConfiguration.java (rev 0) +++ branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/jini/start/config/TestServiceConfiguration.java 2010-09-20 17:54:31 UTC (rev 3594) @@ -0,0 +1,176 @@ +/* + +Copyright (C) SYSTAP, LLC 2006-2008. 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 Jan 6, 2009 + */ + +package com.bigdata.jini.start.config; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Arrays; + +import org.junit.Assert; +import org.junit.Test; + +import com.bigdata.DataFinder; +import net.jini.config.Configuration; +import net.jini.config.ConfigurationException; +import net.jini.config.ConfigurationProvider; + +import com.bigdata.jini.start.config.BigdataServiceConfiguration; +import com.bigdata.jini.start.config.IServiceConstraint; +import com.bigdata.jini.start.config.ServiceConfiguration; +import com.bigdata.jini.start.config.TransactionServerConfiguration; +import com.bigdata.service.jini.TransactionServer; +import com.bigdata.util.config.ConfigDeployUtil; + + +/** + * Some unit tests for {@link ServiceConfiguration} and friends focused on + * verifying correct extraction of properties and the correct generation of + * command lines and configuration files. + * <p> + * Note: all of this can be tested directly since we can parse the generated + * configuration files. + * + * @author <a href="mailto:tho...@us...">Bryan Thompson</a> + * @version $Id$ + * + * @todo not testing correct generation of command lines + * + * @todo not testing correct generation of configuration files. + */ +public class TestServiceConfiguration { + + protected boolean serviceImplRemote; + + /** + * + */ + public TestServiceConfiguration() { + this.serviceImplRemote = false; + } + + protected TestServiceConfiguration(boolean serviceImplRemote) { + this.serviceImplRemote = serviceImplRemote; + } + + /** + * A configuration file used by some of the unit tests in this package. + */ + private final String configFile = DataFinder.bestURI("testing/data/com/bigdata/jini/start/config/testfed.config").toASCIIString(); + + /** + * + * + * @throws FileNotFoundException + * @throws ConfigurationException + */ + @Test + public void test01() throws FileNotFoundException, ConfigurationException { + + // Note: reads from a URI. + final Configuration config = ConfigurationProvider.getInstance(new String[] { configFile }); + + System.err.println(Arrays.toString((String[])config.getEntry( + ServiceConfiguration.class.getName(), "classpath", + String[].class))); + + File serviceDirFromConfig = + (File)config.getEntry(ServiceConfiguration.class.getName(), "serviceDir", + File.class, new File("serviceDir-NOT-SET")); + + BigdataServiceConfiguration serviceConfig = null; + if(serviceImplRemote) { + serviceConfig = new TransactionServerConfiguration + (TransactionServer.class, config); + Assert.assertEquals(TransactionServer.class.getName(), serviceConfig.className); + Assert.assertArrayEquals(new String[] {"-Xmx1G", "-server"}, serviceConfig.args); + Assert.assertArrayEquals( + new String[] { "com.bigdata.service.jini.TransactionServer.Options.SNAPSHOT_INTERVAL=60000" }, + serviceConfig.options); + } else { + serviceConfig = + new TransactionServerConfiguration + (com.bigdata.transaction.ServiceImpl.class, config); + + Assert.assertEquals(com.bigdata.transaction.ServiceImpl.class.getName(), serviceConfig.className); + + String appHome = System.getProperty("app.home"); + String fSep = System.getProperty("file.separator"); + String logDir = + appHome+fSep+"dist"+fSep+"bigdata"+fSep+"var"+fSep+"log"; + String logFile = + appHome+fSep+"dist"+fSep+"bigdata"+fSep+"var"+fSep+"config" + +fSep+"logging"+fSep+"transaction-logging.properties"; + String configFile = + appHome+fSep+"dist"+fSep+"bigdata"+fSep+"var"+fSep+"config" + +fSep+"jini"+fSep+"transaction.config"; + + String memVal = "-Xmx1G"; + String securityMgr = "-Djava.security.manager="; + String log4jProp = "-Dlog4j.configuration="+logFile; + String log4jPrimProp = "-Dlog4j.primary.configuration="+logFile; + String logDirProp = "-Dbigdata.logDir="+logDir; + String javaUtilProp = "-Djava.util.logging.config.file="+logFile; + String appHomeProp = "-Dapp.home="+appHome; + String configProp = "-Dconfig="+configFile; + String usingProp = "-DusingServiceConfiguration=true"; + + String[] expectedArgsArray = + new String[] { memVal, securityMgr, log4jProp, log4jPrimProp, + javaUtilProp, logDirProp, appHomeProp, + configProp, usingProp }; + + Assert.assertArrayEquals(expectedArgsArray, serviceConfig.args); + + String quote = "\""; + String comma = ","; + String openBracket = "{"; + String closeBracket = "}"; + String snapshotOpt = "com.bigdata.transaction.EmbeddedTransactionService.Options.SNAPSHOT_INTERVAL=60000"; + String groupsOpt = "com.bigdata.transaction.groupsToJoin=" + +"new String[]" + +openBracket + +quote+ /*System.getProperty("federation.name","testFed")*/ ConfigDeployUtil.getFederationName() +quote + +comma + +quote+System.getProperty("bigdata.zrootname","testZroot")+quote + +closeBracket; + String locatorsOpt = "com.bigdata.transaction.locatorsToJoin=" + +"new LookupLocator[]" + +openBracket + +closeBracket; + + String[] expectedOptsArray = new String[] { snapshotOpt, groupsOpt, locatorsOpt }; + + Assert.assertArrayEquals( expectedOptsArray, serviceConfig.options); + } + + Assert.assertEquals(serviceDirFromConfig, serviceConfig.serviceDir); + Assert.assertEquals(1, serviceConfig.serviceCount); + Assert.assertEquals(1, serviceConfig.replicationCount); + Assert.assertArrayEquals(new IServiceConstraint[0], serviceConfig.constraints); + } +} Copied: branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/jini/start/config/TestServiceConfigurationRemote.java (from rev 3580, branches/maven_scaleout/bigdata-core/src/test/java/com/bigdata/jini/start/config/TestServiceConfigurationRemote.java) =================================================================== --- branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/jini/start/config/TestServiceConfigurationRemote.java (rev 0) +++ branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/jini/start/config/TestServiceConfigurationRemote.java 2010-09-20 17:54:31 UTC (rev 3594) @@ -0,0 +1,36 @@ +/* + +Copyright (C) SYSTAP, LLC 2006-2008. 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 +*/ + +package com.bigdata.jini.start.config; + +/** + * Uses the purely remote implementation of the service(s) tested + * by this test's smart proxy based super class counterpart. + */ +public class TestServiceConfigurationRemote extends TestServiceConfiguration +{ + public TestServiceConfigurationRemote() { + super(true); + } +} Copied: branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/jini/start/config/TestZookeeperServerEntry.java (from rev 3580, branches/maven_scaleout/bigdata-core/src/test/java/com/bigdata/jini/start/config/TestZookeeperServerEntry.java) =================================================================== --- branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/jini/start/config/TestZookeeperServerEntry.java (rev 0) +++ branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/jini/start/config/TestZookeeperServerEntry.java 2010-09-20 17:54:31 UTC (rev 3594) @@ -0,0 +1,124 @@ +/* + +Copyright (C) SYSTAP, LLC 2006-2008. 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 Jan 2, 2009 + */ + +package com.bigdata.jini.start.config; + +import java.io.IOException; +import java.net.InetAddress; +import java.net.SocketException; +import java.net.UnknownHostException; + +import org.junit.Assert; +import org.junit.Test; + +import net.jini.config.ConfigurationException; + +import com.bigdata.util.config.NicUtil; + +/** + * Unit tests for the {@link ZookeeperServerEntry}. + * + * @author <a href="mailto:tho...@us...">Bryan Thompson</a> + * @version $Id$ + */ +public class TestZookeeperServerEntry { + + /** + * + */ + public TestZookeeperServerEntry() { + } + + + @Test + public void test_correctRejection() { + try { + new ZookeeperServerEntry(0, null); + Assert.fail("Expecting " + IllegalArgumentException.class); + } catch (IllegalArgumentException ex) { + } + } + + /** + * Test {@link ZookeeperServerEntry} parsing. + */ + @Test + public void test001() { + final int expectedId = 0; + final String expectedHostname = "192.168.1.2"; + final int expectedPeerPort = 233; + final int expectedLeaderPort = 1992; + + ZookeeperServerEntry entry = new ZookeeperServerEntry(expectedId, + expectedHostname + ":" + expectedPeerPort + ":" + + expectedLeaderPort); + + Assert.assertEquals(expectedId, entry.id); + Assert.assertEquals(expectedHostname, entry.hostname); + Assert.assertEquals(expectedPeerPort, entry.peerPort); + Assert.assertEquals(expectedLeaderPort, entry.leaderPort); + } + + /** + * Unit test for + * {@link ZookeeperServerConfiguration#getZookeeperServerEntries(String)} + * + * @throws ConfigurationException + * @throws SocketException + * @throws UnknownHostException + */ + @Test + public void test002() throws ConfigurationException, SocketException, UnknownHostException, IOException { + + final String server = NicUtil.getIpAddress("default.nic", "default", true); + + final String[] hosts = new String[] { + "127.0.0.1", + "localhost", + server + }; + + final String servers = "1=127.0.0.1:2888:3888, 2=localhost:2888:3888, 3="+ server + ":2888:3888"; + + final ZookeeperServerEntry[] a = ZookeeperServerConfiguration.getZookeeperServerEntries(servers); + + for (int i = 0; i < a.length; i++) { + final ZookeeperServerEntry entry = a[i]; + + Assert.assertEquals(i + 1, entry.id); + Assert.assertEquals(hosts[i], entry.hostname); + Assert.assertEquals(2888, entry.peerPort); + Assert.assertEquals(3888, entry.leaderPort); + + InetAddress.getByName(entry.hostname); + + Assert.assertTrue(entry.isLocalHost()); + Assert.assertTrue(new HostAllowConstraint(entry.hostname).allow()); + Assert.assertFalse(new HostRejectConstraint(entry.hostname).allow()); + } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |