From: <ble...@us...> - 2010-09-07 19:08:11
|
Revision: 3513 http://bigdata.svn.sourceforge.net/bigdata/?rev=3513&view=rev Author: blevine218 Date: 2010-09-07 19:08:05 +0000 (Tue, 07 Sep 2010) Log Message: ----------- removed Eclipse-specific files Removed Paths: ------------- branches/maven_scaleout/bigdata-integ/.classpath branches/maven_scaleout/bigdata-integ/.project branches/maven_scaleout/bigdata-integ/.settings/ Property Changed: ---------------- branches/maven_scaleout/bigdata-integ/ Property changes on: branches/maven_scaleout/bigdata-integ ___________________________________________________________________ Added: svn:ignore + target Deleted: branches/maven_scaleout/bigdata-integ/.classpath =================================================================== --- branches/maven_scaleout/bigdata-integ/.classpath 2010-09-07 19:04:36 UTC (rev 3512) +++ branches/maven_scaleout/bigdata-integ/.classpath 2010-09-07 19:08:05 UTC (rev 3513) @@ -1,16 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<classpath> - <classpathentry kind="src" output="target/classes" path="src/main/java"/> - <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/> - <classpathentry kind="src" output="target/test-classes" path="src/test/java"/> - <classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/> - <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/> - <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/> - <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/java-6-sun-1.6.0.20"> - <attributes> - <attribute name="owner.project.facets" value="jst.java"/> - </attributes> - </classpathentry> - <classpathentry kind="output" path="target/classes"/> -</classpath> Deleted: branches/maven_scaleout/bigdata-integ/.project =================================================================== --- branches/maven_scaleout/bigdata-integ/.project 2010-09-07 19:04:36 UTC (rev 3512) +++ branches/maven_scaleout/bigdata-integ/.project 2010-09-07 19:08:05 UTC (rev 3513) @@ -1,42 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<projectDescription> - <name>rds-integration-test</name> - <comment></comment> - <projects> - </projects> - <buildSpec> - <buildCommand> - <name>org.eclipse.wst.jsdt.core.javascriptValidator</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>org.eclipse.wst.common.project.facet.core.builder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>org.eclipse.jdt.core.javabuilder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>org.eclipse.wst.validation.validationbuilder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>org.maven.ide.eclipse.maven2Builder</name> - <arguments> - </arguments> - </buildCommand> - </buildSpec> - <natures> - <nature>org.eclipse.jem.workbench.JavaEMFNature</nature> - <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature> - <nature>org.eclipse.jdt.core.javanature</nature> - <nature>org.maven.ide.eclipse.maven2Nature</nature> - <nature>org.eclipse.wst.common.project.facet.core.nature</nature> - <nature>org.eclipse.wst.jsdt.core.jsNature</nature> - </natures> -</projectDescription> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ble...@us...> - 2010-09-10 19:44:46
|
Revision: 3530 http://bigdata.svn.sourceforge.net/bigdata/?rev=3530&view=rev Author: blevine218 Date: 2010-09-10 19:44:37 +0000 (Fri, 10 Sep 2010) Log Message: ----------- Get initial test to pass. Re-work setting of system properties. Modified Paths: -------------- branches/maven_scaleout/bigdata-integ/pom.xml Added Paths: ----------- branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/service/ branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/service/jini/ branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/service/jini/AbstractServerTestCase.java branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/service/jini/TestBigdataClient.java branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/service/jini/TestBigdataClientRemote.java branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/test/util/ branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/test/util/Util.java Modified: branches/maven_scaleout/bigdata-integ/pom.xml =================================================================== --- branches/maven_scaleout/bigdata-integ/pom.xml 2010-09-10 17:12:33 UTC (rev 3529) +++ branches/maven_scaleout/bigdata-integ/pom.xml 2010-09-10 19:44:37 UTC (rev 3530) @@ -1,5 +1,4 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <parent> @@ -15,7 +14,40 @@ <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - <project.build.deployDirectory>${project.build.directory}/deploy</project.build.deployDirectory> + <deploy.root.dir>${project.build.directory}/deploy</deploy.root.dir> + <bigdata.dependency>bigdata-core</bigdata.dependency> + + + <!-- + This is kinda hokey, but not sure there's a better way to + construct the path to the root of the exploded tarball --> + + <deploy.dir>${deploy.root.dir}/${bigdata.dependency}-${project.version}</deploy.dir> + <test.dir>${deploy.dir}/testing</test.dir> + <testScript>${test.dir}/test.xml</testScript> + + <basedir>${test.dir}</basedir> + <app.home>${deploy.dir}</app.home> + <deploy.conf.dir>${test.dir}/conf</deploy.conf.dir> + <deploy.lib>${deploy.dir}/lib</deploy.lib> + <deploy.lib.test>${test.dir}/lib-test</deploy.lib.test> + <deploy.lib.dl>${deploy.dir}/lib-dl</deploy.lib.dl> + <test.codebase.dir>${deploy.lib.dl}</test.codebase.dir> + <test.codebase.port>23333</test.codebase.port> + <java.security.policy>${deploy.conf.dir}/policy.all</java.security.policy> + <log4j.configuration>${deploy.dir}/var/config/logging/log4j.properties</log4j.configuration> + <java.net.preferIPv4Stack>true</java.net.preferIPv4Stack> + <default.nic>eth0</default.nic> + <parent.artifactName>bigdata-core</parent.artifactName> + + + <!-- + In the ANT script, hostname is obtained by an exec of the + 'hostname' command. Hard-coding to localhost for now. + --> + <hostname>blevine-desktop</hostname> + <test.codebase>http://${hostname}:${test.codebase.port}/jsk-dl.jar</test.codebase> + <federation.name>bigdata.test.group-${hostname}</federation.name> </properties> @@ -33,15 +65,17 @@ <configuration> <artifactItems> <artifactItem> - <groupId>com.nokia.dataos.rds.bigdata</groupId> - <artifactId>bigdata-dist</artifactId> - <version>0.83.2-SNAPSHOT</version> - <type>tgz</type> - <outputDirectory>${project.build.deployDirectory}</outputDirectory> + <groupId>com.bigdata</groupId> + <artifactId>bigdata-core</artifactId> + <classifier>deploy</classifier> + <type>tar.gz</type> + <outputDirectory>${deploy.directory}</outputDirectory> </artifactItem> </artifactItems> + <useSubdirPerArtifact>true</useSubdirPerArtifact> + <!-- <overWriteSnapshots>true</overWriteSnapshots> - <overWriteReleases>true</overWriteReleases> + <overWriteReleases>true</overWriteReleases> --> </configuration> </execution> </executions> @@ -64,13 +98,55 @@ </plugin> <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>failsafe-maven-plugin</artifactId> - <version>2.4.3-alpha-1</version> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-failsafe-plugin</artifactId> <configuration> <includes> - <include>**/*.java</include> + <include>**/Test*.java</include> + <include>**/*Test.java</include> </includes> + <excludes> + <exclude>**/TestBigdataClientRemote.java</exclude> + </excludes> + <systemPropertyVariables> + <foo.bar.prop>hello</foo.bar.prop> + <java.security.policy>${java.security.policy}</java.security.policy> + <java.net.preferIPv4Stack>{java.net.preferIPv4Stack}"</java.net.preferIPv4Stack> + <log4j.configuration>${log4j.configuration}</log4j.configuration> + <!-- ><log4j.debug>true"</log4j.debug> --> + + <basedir>${basedir}</basedir> <!-- Tells the unit tests where the ant script is, so they can find resources. --> + <app.home>${app.home}</app.home> <!-- This is the deployment directory, easily accessed by the DataFinder class. --> + <log4j.path>${log4j.configuration}</log4j.path> + <default.nic>${default.nic}</default.nic> + + <!-- Jini group name --> + <federation.name>${federation.name}</federation.name> + + <!-- TODO !!!!!! + <property key="java.class.path" value="${junit.classpath.text}" /> + --> + + <classserver.jar>${deploy.lib}/classserver.jar</classserver.jar> + <colt.jar>${deploy.lib}/colt.jar</colt.jar> + <ctc_utils.jar>${deploy.lib}/ctc_utils.jar</ctc_utils.jar> + <cweb-commons.jar>${deploy.lib}/cweb-commons.jar</cweb-commons.jar> + <cweb-extser.jar>${deploy.lib}/cweb-extser.jar</cweb-extser.jar> + <highscalelib.jar>${deploy.lib}/highscalelib.jar</highscalelib.jar> + <dsiutils.jar>${deploy.lib}/dsiutils.jar</dsiutils.jar> + <lgplutils.jar>${deploy.lib}/lgplutils.jar</lgplutils.jar> + <fastutil.jar>${deploy.lib}/fastutil.jar</fastutil.jar> + <icu4j.jar>${deploy.lib}/icu4j.jar</icu4j.jar> + <jsk-lib.jar>${deploy.lib}/jsk-lib.jar</jsk-lib.jar> + <jsk-platform.jar>${deploy.lib}jsk-platform.jar</jsk-platform.jar> + <log4j.jar>${deploy.lib}/log4j.jar</log4j.jar> + <iris.jar>${deploy.lib}/iris.jar</iris.jar> + <jgrapht.jar>${deploy.lib}/jgrapht.jar</jgrapht.jar> + <openrdf-sesame.jar>${deploy.lib}/openrdf-sesame.jar</openrdf-sesame.jar> + <slf4j.jar>${deploy.lib}/slf4j.jar</slf4j.jar> + <nxparser.jar>${deploy.lib}/nxparser.jar</nxparser.jar> + <zookeeper.jar>${deploy.lib}/zookeeper.jar</zookeeper.jar> + </systemPropertyVariables> </configuration> <executions> <execution> @@ -91,9 +167,8 @@ <phase>pre-integration-test</phase> <configuration> <tasks> - <ant - antfile="${project.build.testOutputDirectory}/test.xml" - target="hello" /> + <echo message="testscript = ${testScript}" /> + <ant antfile="${testScript}" target="startTestServices" useNativeBasedir="true" inheritAll="false"/> </tasks> </configuration> <goals> @@ -106,9 +181,8 @@ <phase>post-integration-test</phase> <configuration> <tasks> - <ant - antfile="${project.build.testOutputDirectory}/test.xml" - target="hello" /> + <echo message="testscript = ${testScript}" /> + <ant antfile="${testScript}" target="stopTestServices" useNativeBasedir="true" inheritAll="false"/> </tasks> </configuration> <goals> @@ -127,9 +201,16 @@ <groupId>com.bigdata</groupId> <artifactId>bigdata-core</artifactId> <version>${project.version}</version> + <classifier>deploy</classifier> + <type>tar.gz</type> <scope>test</scope> </dependency> + <dependency> + <groupId>com.bigdata</groupId> + <artifactId>bigdata-core</artifactId> + <version>${project.version}</version> + </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> @@ -137,6 +218,13 @@ <scope>test</scope> </dependency> + <dependency> + <groupId>com.bigdata.thirdparty</groupId> + <artifactId>cweb-junit-ext</artifactId> + <version>1.1.0-b3-dev</version> + <scope>test</scope> + </dependency> + </dependencies> </project> Added: branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/service/jini/AbstractServerTestCase.java =================================================================== --- branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/service/jini/AbstractServerTestCase.java (rev 0) +++ branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/service/jini/AbstractServerTestCase.java 2010-09-10 19:44:37 UTC (rev 3530) @@ -0,0 +1,503 @@ +/** + +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 Apr 22, 2007 + */ + +package com.bigdata.service.jini; + +import java.io.IOException; +import java.net.InetAddress; + +import junit.framework.AssertionFailedError; +import junit.framework.TestCase2; +import net.jini.core.discovery.LookupLocator; +import net.jini.core.lookup.ServiceID; +import net.jini.core.lookup.ServiceRegistrar; +import net.jini.core.lookup.ServiceTemplate; + +import com.bigdata.journal.ITx; +import com.bigdata.mdi.IResourceMetadata; +import com.bigdata.mdi.LocalPartitionMetadata; +import com.bigdata.mdi.PartitionLocator; +import com.bigdata.service.DataService; +import com.bigdata.service.IDataService; +import com.bigdata.service.MetadataService; +import com.sun.jini.tool.ClassServer; +import com.bigdata.util.config.ConfigDeployUtil; +import com.bigdata.util.config.NicUtil; + +/** + * Abstract base class for tests of remote services. + * <p> + * Note: jini MUST be running. You can get the jini starter kit and install it + * to get jini running. + * </p> + * <p> + * Note: You MUST specify a security policy that is sufficiently lax. + * </p> + * <p> + * Note: You MUST specify the codebase for downloadable code. + * </p> + * <p> + * Note: The <code>bigdata</code> JAR must be current in order for the client + * and the service to agree on interface definitions, etc. You can use + * <code>build.xml</code> in the root of this module to update that JAR. + * </p> + * <p> + * Note: A {@link ClassServer} will be started on port 8081 by default. If that + * port is in use then you MUST specify another port. + * </p> + * + * The following system properties will do the trick unless you have something + * running on port 8081. + * + * <pre> + * -Djava.security.policy=policy.all -Djava.rmi.server.codebase=http://localhost:8081 + * </pre> + * + * To use another port, try: + * + * <pre> + * -Djava.security.policy=policy.all -Dbigdata.test.port=8082 -Djava.rmi.server.codebase=http://localhost:8082 + * </pre> + * + * You can enable NIO using: + * <pre> + * -Dcom.sun.jini.jeri.tcp.useNIO=true + * </pre> + * + * @author <a href="mailto:tho...@us...">Bryan Thompson</a> + * @version $Id$ + */ +public abstract class AbstractServerTestCase extends TestCase2 { + + /** + * Equal to {@link ITx#UNISOLATED}. + */ + protected final long UNISOLATED = ITx.UNISOLATED; + + /** + * + */ + public AbstractServerTestCase() { + } + + /** + * @param arg0 + */ + public AbstractServerTestCase(String arg0) { + super(arg0); + } + +// /** +// * Return an open port on current machine. Try the suggested port first. If +// * suggestedPort is zero, just select a random port +// */ +// private static int getPort(int suggestedPort) throws IOException { +// ServerSocket openSocket; +// try { +// openSocket = new ServerSocket(suggestedPort); +// } catch (BindException ex) { +// // the port is busy, so look for a random open port +// openSocket = new ServerSocket(0); +// } +// +// int port = openSocket.getLocalPort(); +// openSocket.close(); +// +// return port; +// } + +// /** +// * This may be used to verify that a specific port is available. The method +// * will return iff the port is available at the time that this method was +// * called. The method will retry a few times since sometimes it takes a bit +// * for a socket to get released and we are reusing the same socket for the +// * {@link ClassServer} for each test. +// * +// * @param port +// * The port to try. +// * +// * @exception AssertionFailedError +// * if the port is not available. +// */ +// protected static void assertOpenPort(final int port) throws IOException { +// +// ServerSocket openSocket; +// +// int i = 0; +// +// final int maxTries = 3; +// +// while (i < maxTries) { +// +// try { +// +// // try to open a server socket on that port. +// openSocket = new ServerSocket(port); +// +// // close the socket - it is available for the moment. +// openSocket.close(); +// +// return; +// +// } catch (BindException ex) { +// +// if (i++ < maxTries) { +// +// log.warn("Port " + port + " is busy - retrying: " + ex); +// +// try { +// Thread.sleep(100/* ms */); +// } catch (InterruptedException t) { +// /* ignore */ +// } +// +// } else { +// +// fail("Port is busy: " + ex + " - use " + PORT_OPTION +// + " to specify another port?"); +// +// } +// +// } +// +// } +// +// } + +// private ClassServer classServer; +// +// /** +// * The name of the System property that may be used to change the port on which +// * the {@link ClassServer} will be started. +// */ +// public static final String PORT_OPTION = "bigdata.test.port"; +// +// /** +// * The default port on which the {@link ClassServer} will be started. +// * <p> +// * Note: Outlook appears to conflict with 8081. +// */ +// public static final String DEFAULT_PORT = "8082"; +// +// /** +// * Starts a {@link ClassServer} that supports downloadable code for the unit +// * test. The {@link ClassServer} will start on the port named by the System +// * property {@link #PORT_OPTION} and on port {@link #DEFAULT_PORT} if that +// * system property is not set. +// * +// * @throws IOException +// */ +// protected void startClassServer() throws IOException { +// +// // Note: See below. +//// if(true) return; +// +// Logger.getLogger("com.sun.jini.tool.ClassServer").setLevel(Level.ALL); +// +// /* +// * Obtain port from System.getProperties() so that other ports may be +// * used. +// */ +// final int port = Integer.parseInt(System.getProperty(PORT_OPTION,DEFAULT_PORT)); +// +// /* +// * The directories containing the JARs and the compiled classes for the +// * bigdata project. +// */ +// String dirlist = +// "lib"+File.pathSeparatorChar+ +// "lib"+File.separatorChar+"icu"+File.pathSeparatorChar+ +// "lib"+File.separatorChar+"jini"+File.pathSeparatorChar +// /* +// * FIXME This does not seem to be resolving the bigdata classes +// * necessitating that we list that jar explicitly below (and that it +// * be up to date). The problem can be seen in the Jini Service +// * Browser and the console for the Service Browser. In fact, the +// * test suite executes just fine if you do NOT use the ClassServer! +// * +// * I can only get this working right now by placing bigdata-core.jar into +// * the lib directory (or some other directory below the current +// * working directory, but not ant-build since that gives the ant +// * script fits). +// * +// * I still see a ClassNotFound problem in the Jini console complaining +// * that it can not find IDataService, but only when I select the +// * registrar on which the services are running! +// */ +//// + +//// "bin" +// //+File.pathSeparatorChar+ +//// "ant-build" +// ; +// +// assertOpenPort(port); +// +// classServer = new ClassServer( +// port, +// dirlist, +// true, // trees - serve up files inside of JARs, +// true // verbose +// ); +// +// classServer.start(); +// +// } + + public void setUp() throws Exception { + + if (log.isInfoEnabled()) + log.info(getName()); + +// startClassServer(); + + } + + /** + * Stops the {@link ClassServer}. + */ + public void tearDown() throws Exception { + +// if (classServer != null) { +// +// classServer.terminate(); +// +// } + + super.tearDown(); + + if (log.isInfoEnabled()) + log.info(getName()); + + } + + /** + * Return the {@link ServiceID} of a server that we started ourselves. The + * method waits until the {@link ServiceID} becomes available on + * {@link AbstractServer#getServiceID()}. + * + * @exception AssertionFailedError + * If the {@link ServiceID} can not be found after a timeout. + * + * @exception InterruptedException + * if the thread is interrupted while it is waiting to retry. + */ + static public ServiceID getServiceID(final AbstractServer server) + throws AssertionFailedError, InterruptedException { + + ServiceID serviceID = null; + + for(int i=0; i<10 && serviceID == null; i++) { + + /* + * Note: This can be null since the serviceID is not assigned + * synchronously by the registrar. + */ + + serviceID = server.getServiceID(); + + if(serviceID == null) { + + /* + * We wait a bit and retry until we have it or timeout. + */ + + Thread.sleep(200); + + } + + } + + assertNotNull("serviceID",serviceID); + + /* + * Verify that we have discovered the _correct_ service. This is a + * potential problem when starting a stopping services for the test + * suite. + */ + assertEquals("serviceID", server.getServiceID(), serviceID); + + return serviceID; + + } + + /** + * Lookup a {@link DataService} by its {@link ServiceID} using unicast + * discovery on localhost. + * + * @param serviceID + * The {@link ServiceID}. + * + * @return The service. + * + * @todo Modify to return the service item? + * + * @todo Modify to not be specific to {@link DataService} vs + * {@link MetadataService} (we need a common base interface for both + * that carries most of the functionality but allows us to make + * distinctions easily during discovery). + */ + public IDataService lookupDataService(ServiceID serviceID) + throws IOException, ClassNotFoundException, InterruptedException { + + /* + * Lookup the discover service (unicast on localhost). + */ + + // get the hostname. + String hostname = NicUtil.getIpAddress("default.nic", "default", true); + + // Find the service registrar (unicast protocol). + final int timeout = 4*1000; // seconds. + System.err.println("hostname: "+hostname); + LookupLocator lookupLocator = new LookupLocator("jini://"+hostname); + ServiceRegistrar serviceRegistrar = lookupLocator.getRegistrar( timeout ); + + /* + * Prepare a template for lookup search. + * + * Note: The client needs a local copy of the interface in order to be + * able to invoke methods on the service without using reflection. The + * implementation class will be downloaded from the codebase identified + * by the server. + */ + ServiceTemplate template = new ServiceTemplate(// + /* + * use this to request the service by its serviceID. + */ + serviceID, + /* + * Use this to filter services by an interface that they expose. + */ +// new Class[] { IDataService.class }, + null, + /* + * use this to filter for services by Entry attributes. + */ + null); + + /* + * Lookup a service. This can fail if the service registrar has not + * finished processing the service registration. If it does, you can + * generally just retry the test and it will succeed. However this + * points out that the client may need to wait and retry a few times if + * you are starting everything up at once (or just register for + * notification events for the service if it is not found and enter a + * wait state). + */ + + IDataService service = null; + + for (int i = 0; i < 10 && service == null; i++) { + + service = (IDataService) serviceRegistrar + .lookup(template /* , maxMatches */); + + if (service == null) { + + System.err.println("Service not found: sleeping..."); + + Thread.sleep(200); + + } + + } + + if (service != null) { + + System.err.println("Service found."); + + } + + return service; + + } + + /** + * Compares two representations of the {@link PartitionLocator} + * without the left- and right-separator keys that bound the index + * partition. + * + * @param expected + * @param actual + */ + protected void assertEquals(PartitionLocator expected, PartitionLocator actual) { + + assertEquals("partitionId", expected.getPartitionId(), actual + .getPartitionId()); + + assertEquals("dataServiceUUID", expected.getDataServiceUUID(), actual + .getDataServiceUUID()); + + } + + /** + * Compares two representations of the {@link LocalPartitionMetadata} for an + * index partition including the optional resource descriptions. + * + * @param expected + * @param actual + */ + protected void assertEquals(LocalPartitionMetadata expected, + LocalPartitionMetadata actual) { + + assertEquals("partitionId",expected.getPartitionId(), actual.getPartitionId()); + + assertEquals("leftSeparatorKey", expected.getLeftSeparatorKey(), + ((LocalPartitionMetadata) actual) + .getLeftSeparatorKey()); + + assertEquals("rightSeparatorKey", expected.getRightSeparatorKey(), + ((LocalPartitionMetadata) actual) + .getRightSeparatorKey()); + + final IResourceMetadata[] expectedResources = expected.getResources(); + + final IResourceMetadata[] actualResources = actual.getResources(); + + assertEquals("#resources",expectedResources.length,actualResources.length); + + for(int i=0;i<expected.getResources().length; i++) { + + // verify by components so that it is obvious what is wrong. + + assertEquals("filename[" + i + "]", expectedResources[i].getFile(), + actualResources[i].getFile()); + +// assertEquals("size[" + i + "]", expectedResources[i].size(), +// actualResources[i].size()); + + assertEquals("UUID[" + i + "]", expectedResources[i].getUUID(), + actualResources[i].getUUID()); + + // verify by equals. + assertTrue("resourceMetadata",expectedResources[i].equals(actualResources[i])); + + } + + } + +} Added: branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/service/jini/TestBigdataClient.java =================================================================== --- branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/service/jini/TestBigdataClient.java (rev 0) +++ branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/service/jini/TestBigdataClient.java 2010-09-10 19:44:37 UTC (rev 3530) @@ -0,0 +1,214 @@ +/** + +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 Apr 23, 2007 + */ + +package com.bigdata.service.jini; + +import java.io.Serializable; +import java.util.Random; +import java.util.UUID; + +import com.bigdata.btree.IIndex; +import com.bigdata.btree.ITuple; +import com.bigdata.btree.ITupleIterator; +import com.bigdata.btree.IndexMetadata; + +import com.bigdata.btree.proc.BatchInsert.BatchInsertConstructor; +import com.bigdata.journal.ITx; +import com.bigdata.service.DataService; +import com.bigdata.service.IBigdataFederation; +import com.bigdata.service.IDataService; +import com.bigdata.service.jini.util.JiniServicesHelper; +import com.bigdata.test.util.Util; + +/** + * Test suite for the {@link JiniClient}. + * <p> + * Note: The core test suite has already verified the basic semantics of the + * {@link IDataService} interface and partitioned indices so all we have to + * focus on here is the jini integration and verifying that the serialization + * imposed by RMI goes off without a hitch (e.g., that everything implements + * {@link Serializable} and that those {@link Serializable} implementations can + * correctly round trip the data). + * + * @author <a href="mailto:tho...@us...">Bryan Thompson</a> + * @version $Id$ + */ +public class TestBigdataClient extends AbstractServerTestCase { + + protected boolean serviceImplRemote; + + public TestBigdataClient() { + this.serviceImplRemote = false; + } + + public TestBigdataClient(String name) { + super(name); + this.serviceImplRemote = false; + } + + public TestBigdataClient(boolean serviceImplRemote) { + this.serviceImplRemote = serviceImplRemote; + } + + public TestBigdataClient(String name, boolean serviceImplRemote) { + super(name); + this.serviceImplRemote = serviceImplRemote; + } + + /** + * Starts a {@link DataServer} ({@link #dataServer1}) and then a + * {@link MetadataServer} ({@link #metadataServer0}). Each runs in its own + * thread. + */ + public void setUp() throws Exception { + super.setUp(); + helper = new JiniServicesHelper(serviceImplRemote); + helper.start(); + } + + protected JiniServicesHelper helper = null; + + /** + * Destroy the test services. + */ + public void tearDown() throws Exception { + if (helper != null) { + helper.destroy(); + } + + super.tearDown(); + } + + /** + * Test ability to registers a scale-out index on one of the + * {@link DataService}s. + * + * @throws Exception + */ + public void test_registerIndex1() throws Exception { + final IBigdataFederation<?> fed = helper.client.connect(); + final String name = "testIndex"; + final IndexMetadata metadata = new IndexMetadata(name, UUID.randomUUID()); + + metadata.setDeleteMarkers(true); + fed.registerIndex(metadata); + final IIndex ndx = fed.getIndex(name, ITx.UNISOLATED); + + assertEquals("indexUUID", metadata.getIndexUUID(), ndx + .getIndexMetadata().getIndexUUID()); + + doBasicIndexTests(ndx); + } + + /** + * Test ability to registers a scale-out index on both of the + * {@link DataService}s. + * + * @throws Exception + */ + public void test_registerIndex2() throws Exception { + final IBigdataFederation<?> fed = helper.client.connect(); + final String name = "testIndex"; + final IndexMetadata metadata = new IndexMetadata(name,UUID.randomUUID()); + + metadata.setDeleteMarkers(true); + + final UUID indexUUID = fed.registerIndex( metadata, // + // separator keys. + new byte[][] { + new byte[]{}, + Util.asSortKey(500) + },// + // data service assignments. + new UUID[] { // + helper.getDataService0().getServiceUUID(),// + helper.getDataService1().getServiceUUID() // + }); + + final IIndex ndx = fed.getIndex(name, ITx.UNISOLATED); + + assertEquals("indexUUID", indexUUID, ndx.getIndexMetadata() + .getIndexUUID()); + + // verify partition 0 on dataService0 + assertNotNull(helper.getDataService0().getIndexMetadata( + DataService.getIndexPartitionName(name, 0), ITx.UNISOLATED)); + + // verify partition 1 on dataService1 + assertNotNull(helper.getDataService1().getIndexMetadata( + DataService.getIndexPartitionName(name, 1), ITx.UNISOLATED)); + + doBasicIndexTests(ndx); + } + + /** + * Test helper reads and writes some data on the index in order to verify + * that these operations can be performed without serialization errors + * arising from the RPC calls. + * + * @param ndx + */ + protected void doBasicIndexTests(final IIndex ndx) { + + final int limit = 1000; + + final byte[][] keys = new byte[limit][]; + final byte[][] vals = new byte[limit][]; + + final Random r = new Random(); + + for (int i = 0; i < limit; i++) { + keys[i] = Util.asSortKey(i); + final byte[] val = new byte[10]; + r.nextBytes(val); + vals[i] = val; + } + + // batch insert. + ndx.submit(0/* fromIndex */, limit/* toIndex */, keys, vals, BatchInsertConstructor.RETURN_NO_VALUES, null); + + // verify #of index entries. + assertEquals(limit, ndx.rangeCount(null, null)); + + // verify data. + { + final ITupleIterator<?> itr = ndx.rangeIterator(null, null); + + int i = 0; + + while (itr.hasNext()) { + final ITuple<?> tuple = itr.next(); + + assertEquals(keys[i], tuple.getKey()); + assertEquals(vals[i], tuple.getValue()); + i++; + } + + assertEquals(limit, i); + } + } +} Added: branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/service/jini/TestBigdataClientRemote.java =================================================================== --- branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/service/jini/TestBigdataClientRemote.java (rev 0) +++ branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/service/jini/TestBigdataClientRemote.java 2010-09-10 19:44:37 UTC (rev 3530) @@ -0,0 +1,40 @@ +/** + +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 +*/ + +package com.bigdata.service.jini; + +/** + * Test suite for the {@link JiniClient} using the purely remote + * service implementations. + */ +public class TestBigdataClientRemote extends TestBigdataClient { + + public TestBigdataClientRemote() { + super(true); + } + + public TestBigdataClientRemote(String name) { + super(name, true); + } +} Added: branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/test/util/Util.java =================================================================== --- branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/test/util/Util.java (rev 0) +++ branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/test/util/Util.java 2010-09-10 19:44:37 UTC (rev 3530) @@ -0,0 +1,100 @@ +/** + +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 +*/ +package com.bigdata.test.util; + +import java.util.Locale; + +import com.bigdata.btree.keys.IKeyBuilder; +import com.bigdata.btree.keys.KeyBuilder; + +/** + * A utility class for utility methods useful to unit and integration tests. + * + * @todo This may need to be moved into the unit test component and a dependency + * on that component added to the integration tests. + * + * @author blevine + * + */ +public class Util +{ + /** + * Used to unbox an application key (convert it to an unsigned byte[]). + */ + static private final IKeyBuilder _keyBuilder = KeyBuilder.newUnicodeInstance(); + + /** + * Utility method converts an application key to a sort key (an unsigned + * byte[] that imposes the same sort order). + * <p> + * Note: This method is thread-safe. + * <p> + * Note: Strings are Unicode safe for the default locale. See + * {@link Locale#getDefault()}. If you require a specific local or different + * locals at different times or for different indices then you MUST + * provision and apply your own {@link KeyBuilder}. + * <p> + * Note: This method circumvents explicit configuration of the + * {@link KeyBuilder} and is used nearly exclusively by unit tests. While + * explicit configuration is not required for keys which do not include + * Unicode sort key components, this method also relies on a single global + * {@link KeyBuilder} instance protected by a lock. That lock is therefore a + * bottleneck. The correct practice is to use thread-local or per task + * {@link IKeyBuilder}s to avoid lock contention. + * + * This method is cloned from a method of the same name in <code>TestKeyBuilder</code>. + * Moving it into a utility class to remove a direct dependency from one test on + * another. + * + * @param val + * An application key. + * + * @return The unsigned byte[] equivalent of that key. This will be + * <code>null</code> iff the <i>key</i> is <code>null</code>. If the + * <i>key</i> is a byte[], then the byte[] itself will be returned. + */ + public static final byte[] asSortKey(final Object val) + { + + if (val == null) + { + return null; + } + + if (val instanceof byte[]) + { + return (byte[]) val; + } + + /* + * Synchronize on the keyBuilder to avoid concurrent modification of its + * state. + */ + + synchronized (_keyBuilder) + { + return _keyBuilder.getSortKey(val); + } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ble...@us...> - 2010-09-13 19:56:31
|
Revision: 3537 http://bigdata.svn.sourceforge.net/bigdata/?rev=3537&view=rev Author: blevine218 Date: 2010-09-13 19:56:24 +0000 (Mon, 13 Sep 2010) Log Message: ----------- Remove dependencies on cweb-junit Move to JUnit 4 fix-up deploy directories in POM Enable TestBigdataClientRemote Modified Paths: -------------- branches/maven_scaleout/bigdata-integ/pom.xml branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/service/jini/AbstractServerTestCase.java branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/service/jini/TestBigdataClient.java branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/service/jini/TestBigdataClientRemote.java Property Changed: ---------------- branches/maven_scaleout/bigdata-integ/ Property changes on: branches/maven_scaleout/bigdata-integ ___________________________________________________________________ Modified: svn:ignore - target + target .classpath .project .settings Modified: branches/maven_scaleout/bigdata-integ/pom.xml =================================================================== --- branches/maven_scaleout/bigdata-integ/pom.xml 2010-09-13 15:17:50 UTC (rev 3536) +++ branches/maven_scaleout/bigdata-integ/pom.xml 2010-09-13 19:56:24 UTC (rev 3537) @@ -43,10 +43,10 @@ <!-- In the ANT script, hostname is obtained by an exec of the - 'hostname' command. Hard-coding to localhost for now. + 'hostname' command. Hard-coding for now. --> - <hostname>blevine-desktop</hostname> - <test.codebase>http://${hostname}:${test.codebase.port}/jsk-dl.jar</test.codebase> + <hostname>blevine-laptop</hostname> + <test.codebase>http://${hostname}:${test.codebase.port}/jsk-dl.jar</test.codebase> <!-- Not used??? --> <federation.name>bigdata.test.group-${hostname}</federation.name> </properties> @@ -69,7 +69,7 @@ <artifactId>bigdata-core</artifactId> <classifier>deploy</classifier> <type>tar.gz</type> - <outputDirectory>${deploy.directory}</outputDirectory> + <outputDirectory>${deploy.root.dir}</outputDirectory> </artifactItem> </artifactItems> <useSubdirPerArtifact>true</useSubdirPerArtifact> @@ -106,10 +106,9 @@ <include>**/*Test.java</include> </includes> <excludes> - <exclude>**/TestBigdataClientRemote.java</exclude> + <exclude>**/TestBigdataClientremove.java</exclude> </excludes> <systemPropertyVariables> - <foo.bar.prop>hello</foo.bar.prop> <java.security.policy>${java.security.policy}</java.security.policy> <java.net.preferIPv4Stack>{java.net.preferIPv4Stack}"</java.net.preferIPv4Stack> <log4j.configuration>${log4j.configuration}</log4j.configuration> @@ -217,14 +216,6 @@ <version>4.7</version> <scope>test</scope> </dependency> - - <dependency> - <groupId>com.bigdata.thirdparty</groupId> - <artifactId>cweb-junit-ext</artifactId> - <version>1.1.0-b3-dev</version> - <scope>test</scope> - </dependency> - </dependencies> </project> Modified: branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/service/jini/AbstractServerTestCase.java =================================================================== --- branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/service/jini/AbstractServerTestCase.java 2010-09-13 15:17:50 UTC (rev 3536) +++ branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/service/jini/AbstractServerTestCase.java 2010-09-13 19:56:24 UTC (rev 3537) @@ -20,7 +20,7 @@ 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 Apr 22, 2007 */ @@ -28,10 +28,10 @@ package com.bigdata.service.jini; import java.io.IOException; -import java.net.InetAddress; +import junit.framework.Assert; import junit.framework.AssertionFailedError; -import junit.framework.TestCase2; + import net.jini.core.discovery.LookupLocator; import net.jini.core.lookup.ServiceID; import net.jini.core.lookup.ServiceRegistrar; @@ -45,7 +45,6 @@ import com.bigdata.service.IDataService; import com.bigdata.service.MetadataService; import com.sun.jini.tool.ClassServer; -import com.bigdata.util.config.ConfigDeployUtil; import com.bigdata.util.config.NicUtil; /** @@ -84,6 +83,7 @@ * </pre> * * You can enable NIO using: + * * <pre> * -Dcom.sun.jini.jeri.tcp.useNIO=true * </pre> @@ -91,210 +91,22 @@ * @author <a href="mailto:tho...@us...">Bryan Thompson</a> * @version $Id$ */ -public abstract class AbstractServerTestCase extends TestCase2 { +public abstract class AbstractServerTestCase +{ /** * Equal to {@link ITx#UNISOLATED}. */ - protected final long UNISOLATED = ITx.UNISOLATED; - + protected final long UNISOLATED = ITx.UNISOLATED; + /** * */ - public AbstractServerTestCase() { + public AbstractServerTestCase() + { } /** - * @param arg0 - */ - public AbstractServerTestCase(String arg0) { - super(arg0); - } - -// /** -// * Return an open port on current machine. Try the suggested port first. If -// * suggestedPort is zero, just select a random port -// */ -// private static int getPort(int suggestedPort) throws IOException { -// ServerSocket openSocket; -// try { -// openSocket = new ServerSocket(suggestedPort); -// } catch (BindException ex) { -// // the port is busy, so look for a random open port -// openSocket = new ServerSocket(0); -// } -// -// int port = openSocket.getLocalPort(); -// openSocket.close(); -// -// return port; -// } - -// /** -// * This may be used to verify that a specific port is available. The method -// * will return iff the port is available at the time that this method was -// * called. The method will retry a few times since sometimes it takes a bit -// * for a socket to get released and we are reusing the same socket for the -// * {@link ClassServer} for each test. -// * -// * @param port -// * The port to try. -// * -// * @exception AssertionFailedError -// * if the port is not available. -// */ -// protected static void assertOpenPort(final int port) throws IOException { -// -// ServerSocket openSocket; -// -// int i = 0; -// -// final int maxTries = 3; -// -// while (i < maxTries) { -// -// try { -// -// // try to open a server socket on that port. -// openSocket = new ServerSocket(port); -// -// // close the socket - it is available for the moment. -// openSocket.close(); -// -// return; -// -// } catch (BindException ex) { -// -// if (i++ < maxTries) { -// -// log.warn("Port " + port + " is busy - retrying: " + ex); -// -// try { -// Thread.sleep(100/* ms */); -// } catch (InterruptedException t) { -// /* ignore */ -// } -// -// } else { -// -// fail("Port is busy: " + ex + " - use " + PORT_OPTION -// + " to specify another port?"); -// -// } -// -// } -// -// } -// -// } - -// private ClassServer classServer; -// -// /** -// * The name of the System property that may be used to change the port on which -// * the {@link ClassServer} will be started. -// */ -// public static final String PORT_OPTION = "bigdata.test.port"; -// -// /** -// * The default port on which the {@link ClassServer} will be started. -// * <p> -// * Note: Outlook appears to conflict with 8081. -// */ -// public static final String DEFAULT_PORT = "8082"; -// -// /** -// * Starts a {@link ClassServer} that supports downloadable code for the unit -// * test. The {@link ClassServer} will start on the port named by the System -// * property {@link #PORT_OPTION} and on port {@link #DEFAULT_PORT} if that -// * system property is not set. -// * -// * @throws IOException -// */ -// protected void startClassServer() throws IOException { -// -// // Note: See below. -//// if(true) return; -// -// Logger.getLogger("com.sun.jini.tool.ClassServer").setLevel(Level.ALL); -// -// /* -// * Obtain port from System.getProperties() so that other ports may be -// * used. -// */ -// final int port = Integer.parseInt(System.getProperty(PORT_OPTION,DEFAULT_PORT)); -// -// /* -// * The directories containing the JARs and the compiled classes for the -// * bigdata project. -// */ -// String dirlist = -// "lib"+File.pathSeparatorChar+ -// "lib"+File.separatorChar+"icu"+File.pathSeparatorChar+ -// "lib"+File.separatorChar+"jini"+File.pathSeparatorChar -// /* -// * FIXME This does not seem to be resolving the bigdata classes -// * necessitating that we list that jar explicitly below (and that it -// * be up to date). The problem can be seen in the Jini Service -// * Browser and the console for the Service Browser. In fact, the -// * test suite executes just fine if you do NOT use the ClassServer! -// * -// * I can only get this working right now by placing bigdata-core.jar into -// * the lib directory (or some other directory below the current -// * working directory, but not ant-build since that gives the ant -// * script fits). -// * -// * I still see a ClassNotFound problem in the Jini console complaining -// * that it can not find IDataService, but only when I select the -// * registrar on which the services are running! -// */ -//// + -//// "bin" -// //+File.pathSeparatorChar+ -//// "ant-build" -// ; -// -// assertOpenPort(port); -// -// classServer = new ClassServer( -// port, -// dirlist, -// true, // trees - serve up files inside of JARs, -// true // verbose -// ); -// -// classServer.start(); -// -// } - - public void setUp() throws Exception { - - if (log.isInfoEnabled()) - log.info(getName()); - -// startClassServer(); - - } - - /** - * Stops the {@link ClassServer}. - */ - public void tearDown() throws Exception { - -// if (classServer != null) { -// -// classServer.terminate(); -// -// } - - super.tearDown(); - - if (log.isInfoEnabled()) - log.info(getName()); - - } - - /** * Return the {@link ServiceID} of a server that we started ourselves. The * method waits until the {@link ServiceID} becomes available on * {@link AbstractServer#getServiceID()}. @@ -305,45 +117,40 @@ * @exception InterruptedException * if the thread is interrupted while it is waiting to retry. */ - static public ServiceID getServiceID(final AbstractServer server) - throws AssertionFailedError, InterruptedException { - + static public ServiceID getServiceID(final AbstractServer server) throws AssertionFailedError, InterruptedException + { ServiceID serviceID = null; - for(int i=0; i<10 && serviceID == null; i++) { - + for (int i = 0; i < 10 && serviceID == null; i++) + { /* * Note: This can be null since the serviceID is not assigned * synchronously by the registrar. */ - serviceID = server.getServiceID(); - - if(serviceID == null) { - + + if (serviceID == null) + { /* * We wait a bit and retry until we have it or timeout. */ - Thread.sleep(200); - } - } - - assertNotNull("serviceID",serviceID); - + + Assert.assertNotNull("serviceID", serviceID); + /* * Verify that we have discovered the _correct_ service. This is a * potential problem when starting a stopping services for the test * suite. */ - assertEquals("serviceID", server.getServiceID(), serviceID); + Assert.assertEquals("serviceID", server.getServiceID(), serviceID); return serviceID; - + } - + /** * Lookup a {@link DataService} by its {@link ServiceID} using unicast * discovery on localhost. @@ -360,10 +167,9 @@ * that carries most of the functionality but allows us to make * distinctions easily during discovery). */ - public IDataService lookupDataService(ServiceID serviceID) - throws IOException, ClassNotFoundException, InterruptedException { - - /* + public IDataService lookupDataService(ServiceID serviceID) throws IOException, ClassNotFoundException, InterruptedException + { + /* * Lookup the discover service (unicast on localhost). */ @@ -371,10 +177,9 @@ String hostname = NicUtil.getIpAddress("default.nic", "default", true); // Find the service registrar (unicast protocol). - final int timeout = 4*1000; // seconds. - System.err.println("hostname: "+hostname); - LookupLocator lookupLocator = new LookupLocator("jini://"+hostname); - ServiceRegistrar serviceRegistrar = lookupLocator.getRegistrar( timeout ); + final int timeout = 4 * 1000; // seconds. + LookupLocator lookupLocator = new LookupLocator("jini://" + hostname); + ServiceRegistrar serviceRegistrar = lookupLocator.getRegistrar(timeout); /* * Prepare a template for lookup search. @@ -385,19 +190,20 @@ * by the server. */ ServiceTemplate template = new ServiceTemplate(// - /* - * use this to request the service by its serviceID. - */ - serviceID, - /* - * Use this to filter services by an interface that they expose. - */ -// new Class[] { IDataService.class }, - null, - /* - * use this to filter for services by Entry attributes. - */ - null); + /* + * use this to request the service by its serviceID. + */ + serviceID, + /* + * Use this to filter services by an interface that they + * expose. + */ + // new Class[] { IDataService.class }, + null, + /* + * use this to filter for services by Entry attributes. + */ + null); /* * Lookup a service. This can fail if the service registrar has not @@ -408,52 +214,42 @@ * notification events for the service if it is not found and enter a * wait state). */ - + IDataService service = null; - - for (int i = 0; i < 10 && service == null; i++) { - - service = (IDataService) serviceRegistrar - .lookup(template /* , maxMatches */); - - if (service == null) { - + + for (int i = 0; i < 10 && service == null; i++) + { + service = (IDataService) serviceRegistrar.lookup(template); + + if (service == null) + { System.err.println("Service not found: sleeping..."); - Thread.sleep(200); - } - + } - if (service != null) { - + if (service != null) + { System.err.println("Service found."); - } return service; - } /** - * Compares two representations of the {@link PartitionLocator} - * without the left- and right-separator keys that bound the index - * partition. + * Compares two representations of the {@link PartitionLocator} without the + * left- and right-separator keys that bound the index partition. * * @param expected * @param actual */ - protected void assertEquals(PartitionLocator expected, PartitionLocator actual) { - - assertEquals("partitionId", expected.getPartitionId(), actual - .getPartitionId()); - - assertEquals("dataServiceUUID", expected.getDataServiceUUID(), actual - .getDataServiceUUID()); - + protected void assertEquals(PartitionLocator expected, PartitionLocator actual) + { + Assert.assertEquals("partitionId", expected.getPartitionId(), actual.getPartitionId()); + Assert.assertEquals("dataServiceUUID", expected.getDataServiceUUID(), actual.getDataServiceUUID()); } - + /** * Compares two representations of the {@link LocalPartitionMetadata} for an * index partition including the optional resource descriptions. @@ -461,43 +257,30 @@ * @param expected * @param actual */ - protected void assertEquals(LocalPartitionMetadata expected, - LocalPartitionMetadata actual) { + protected void assertEquals(LocalPartitionMetadata expected, LocalPartitionMetadata actual) + { + Assert.assertEquals("partitionId", expected.getPartitionId(), actual.getPartitionId()); + Assert.assertEquals("leftSeparatorKey", expected.getLeftSeparatorKey(), ((LocalPartitionMetadata) actual).getLeftSeparatorKey()); + Assert.assertEquals("rightSeparatorKey", expected.getRightSeparatorKey(), ((LocalPartitionMetadata) actual).getRightSeparatorKey()); - assertEquals("partitionId",expected.getPartitionId(), actual.getPartitionId()); - - assertEquals("leftSeparatorKey", expected.getLeftSeparatorKey(), - ((LocalPartitionMetadata) actual) - .getLeftSeparatorKey()); - - assertEquals("rightSeparatorKey", expected.getRightSeparatorKey(), - ((LocalPartitionMetadata) actual) - .getRightSeparatorKey()); - final IResourceMetadata[] expectedResources = expected.getResources(); - final IResourceMetadata[] actualResources = actual.getResources(); - - assertEquals("#resources",expectedResources.length,actualResources.length); - for(int i=0;i<expected.getResources().length; i++) { - + Assert.assertEquals("#resources", expectedResources.length, actualResources.length); + + for (int i = 0; i < expected.getResources().length; i++) + { // verify by components so that it is obvious what is wrong. - - assertEquals("filename[" + i + "]", expectedResources[i].getFile(), - actualResources[i].getFile()); -// assertEquals("size[" + i + "]", expectedResources[i].size(), -// actualResources[i].size()); + Assert.assertEquals("filename[" + i + "]", expectedResources[i].getFile(), actualResources[i].getFile()); - assertEquals("UUID[" + i + "]", expectedResources[i].getUUID(), - actualResources[i].getUUID()); + // assertEquals("size[" + i + "]", expectedResources[i].size(), + // actualResources[i].size()); + Assert.assertEquals("UUID[" + i + "]", expectedResources[i].getUUID(), actualResources[i].getUUID()); + // verify by equals. - assertTrue("resourceMetadata",expectedResources[i].equals(actualResources[i])); - + Assert.assertTrue("resourceMetadata", expectedResources[i].equals(actualResources[i])); } - } - } Modified: branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/service/jini/TestBigdataClient.java =================================================================== --- branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/service/jini/TestBigdataClient.java 2010-09-13 15:17:50 UTC (rev 3536) +++ branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/service/jini/TestBigdataClient.java 2010-09-13 19:56:24 UTC (rev 3537) @@ -31,6 +31,12 @@ import java.util.Random; import java.util.UUID; +import junit.framework.Assert; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + import com.bigdata.btree.IIndex; import com.bigdata.btree.ITuple; import com.bigdata.btree.ITupleIterator; @@ -65,27 +71,18 @@ this.serviceImplRemote = false; } - public TestBigdataClient(String name) { - super(name); - this.serviceImplRemote = false; - } - public TestBigdataClient(boolean serviceImplRemote) { this.serviceImplRemote = serviceImplRemote; } - public TestBigdataClient(String name, boolean serviceImplRemote) { - super(name); - this.serviceImplRemote = serviceImplRemote; - } /** * Starts a {@link DataServer} ({@link #dataServer1}) and then a * {@link MetadataServer} ({@link #metadataServer0}). Each runs in its own * thread. */ + @Before public void setUp() throws Exception { - super.setUp(); helper = new JiniServicesHelper(serviceImplRemote); helper.start(); } @@ -95,12 +92,11 @@ /** * Destroy the test services. */ + @After public void tearDown() throws Exception { if (helper != null) { helper.destroy(); } - - super.tearDown(); } /** @@ -109,6 +105,7 @@ * * @throws Exception */ + @Test public void test_registerIndex1() throws Exception { final IBigdataFederation<?> fed = helper.client.connect(); final String name = "testIndex"; @@ -118,8 +115,7 @@ fed.registerIndex(metadata); final IIndex ndx = fed.getIndex(name, ITx.UNISOLATED); - assertEquals("indexUUID", metadata.getIndexUUID(), ndx - .getIndexMetadata().getIndexUUID()); + Assert.assertEquals("indexUUID", metadata.getIndexUUID(), ndx.getIndexMetadata().getIndexUUID()); doBasicIndexTests(ndx); } @@ -130,6 +126,7 @@ * * @throws Exception */ + @Test public void test_registerIndex2() throws Exception { final IBigdataFederation<?> fed = helper.client.connect(); final String name = "testIndex"; @@ -151,16 +148,13 @@ final IIndex ndx = fed.getIndex(name, ITx.UNISOLATED); - assertEquals("indexUUID", indexUUID, ndx.getIndexMetadata() - .getIndexUUID()); + Assert.assertEquals("indexUUID", indexUUID, ndx.getIndexMetadata().getIndexUUID()); // verify partition 0 on dataService0 - assertNotNull(helper.getDataService0().getIndexMetadata( - DataService.getIndexPartitionName(name, 0), ITx.UNISOLATED)); + Assert.assertNotNull(helper.getDataService0().getIndexMetadata(DataService.getIndexPartitionName(name, 0), ITx.UNISOLATED)); // verify partition 1 on dataService1 - assertNotNull(helper.getDataService1().getIndexMetadata( - DataService.getIndexPartitionName(name, 1), ITx.UNISOLATED)); + Assert.assertNotNull(helper.getDataService1().getIndexMetadata(DataService.getIndexPartitionName(name, 1), ITx.UNISOLATED)); doBasicIndexTests(ndx); } @@ -192,7 +186,7 @@ ndx.submit(0/* fromIndex */, limit/* toIndex */, keys, vals, BatchInsertConstructor.RETURN_NO_VALUES, null); // verify #of index entries. - assertEquals(limit, ndx.rangeCount(null, null)); + Assert.assertEquals(limit, ndx.rangeCount(null, null)); // verify data. { @@ -203,12 +197,12 @@ while (itr.hasNext()) { final ITuple<?> tuple = itr.next(); - assertEquals(keys[i], tuple.getKey()); - assertEquals(vals[i], tuple.getValue()); + Assert.assertEquals(keys[i], tuple.getKey()); + Assert.assertEquals(vals[i], tuple.getValue()); i++; } - assertEquals(limit, i); + Assert.assertEquals(limit, i); } } } Modified: branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/service/jini/TestBigdataClientRemote.java =================================================================== --- branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/service/jini/TestBigdataClientRemote.java 2010-09-13 15:17:50 UTC (rev 3536) +++ branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/service/jini/TestBigdataClientRemote.java 2010-09-13 19:56:24 UTC (rev 3537) @@ -33,8 +33,4 @@ public TestBigdataClientRemote() { super(true); } - - public TestBigdataClientRemote(String name) { - super(name, true); - } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ble...@us...> - 2010-09-14 17:39:53
|
Revision: 3545 http://bigdata.svn.sourceforge.net/bigdata/?rev=3545&view=rev Author: blevine218 Date: 2010-09-14 17:39:46 +0000 (Tue, 14 Sep 2010) Log Message: ----------- Move certain dependencies on extensions to Assert into new com.bigdata.test.util.Assert class. Modified Paths: -------------- branches/maven_scaleout/bigdata-integ/pom.xml Added Paths: ----------- branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/test/util/Assert.java Removed Paths: ------------- branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/service/jini/AbstractServerTestCase.java branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/service/jini/TestBigdataClient.java branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/service/jini/TestBigdataClientRemote.java Modified: branches/maven_scaleout/bigdata-integ/pom.xml =================================================================== --- branches/maven_scaleout/bigdata-integ/pom.xml 2010-09-14 17:19:56 UTC (rev 3544) +++ branches/maven_scaleout/bigdata-integ/pom.xml 2010-09-14 17:39:46 UTC (rev 3545) @@ -45,7 +45,7 @@ In the ANT script, hostname is obtained by an exec of the 'hostname' command. Hard-coding for now. --> - <hostname>blevine-laptop</hostname> + <hostname>blevine-desktop</hostname> <test.codebase>http://${hostname}:${test.codebase.port}/jsk-dl.jar</test.codebase> <!-- Not used??? --> <federation.name>bigdata.test.group-${hostname}</federation.name> </properties> @@ -206,7 +206,6 @@ <groupId>com.bigdata</groupId> <artifactId>bigdata-core</artifactId> <version>${project.version}</version> - </dependency> <dependency> <groupId>junit</groupId> Deleted: branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/service/jini/AbstractServerTestCase.java =================================================================== --- branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/service/jini/AbstractServerTestCase.java 2010-09-14 17:19:56 UTC (rev 3544) +++ branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/service/jini/AbstractServerTestCase.java 2010-09-14 17:39:46 UTC (rev 3545) @@ -1,286 +0,0 @@ -/** - -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 Apr 22, 2007 - */ - -package com.bigdata.service.jini; - -import java.io.IOException; - -import junit.framework.Assert; -import junit.framework.AssertionFailedError; - -import net.jini.core.discovery.LookupLocator; -import net.jini.core.lookup.ServiceID; -import net.jini.core.lookup.ServiceRegistrar; -import net.jini.core.lookup.ServiceTemplate; - -import com.bigdata.journal.ITx; -import com.bigdata.mdi.IResourceMetadata; -import com.bigdata.mdi.LocalPartitionMetadata; -import com.bigdata.mdi.PartitionLocator; -import com.bigdata.service.DataService; -import com.bigdata.service.IDataService; -import com.bigdata.service.MetadataService; -import com.sun.jini.tool.ClassServer; -import com.bigdata.util.config.NicUtil; - -/** - * Abstract base class for tests of remote services. - * <p> - * Note: jini MUST be running. You can get the jini starter kit and install it - * to get jini running. - * </p> - * <p> - * Note: You MUST specify a security policy that is sufficiently lax. - * </p> - * <p> - * Note: You MUST specify the codebase for downloadable code. - * </p> - * <p> - * Note: The <code>bigdata</code> JAR must be current in order for the client - * and the service to agree on interface definitions, etc. You can use - * <code>build.xml</code> in the root of this module to update that JAR. - * </p> - * <p> - * Note: A {@link ClassServer} will be started on port 8081 by default. If that - * port is in use then you MUST specify another port. - * </p> - * - * The following system properties will do the trick unless you have something - * running on port 8081. - * - * <pre> - * -Djava.security.policy=policy.all -Djava.rmi.server.codebase=http://localhost:8081 - * </pre> - * - * To use another port, try: - * - * <pre> - * -Djava.security.policy=policy.all -Dbigdata.test.port=8082 -Djava.rmi.server.codebase=http://localhost:8082 - * </pre> - * - * You can enable NIO using: - * - * <pre> - * -Dcom.sun.jini.jeri.tcp.useNIO=true - * </pre> - * - * @author <a href="mailto:tho...@us...">Bryan Thompson</a> - * @version $Id$ - */ -public abstract class AbstractServerTestCase -{ - - /** - * Equal to {@link ITx#UNISOLATED}. - */ - protected final long UNISOLATED = ITx.UNISOLATED; - - /** - * - */ - public AbstractServerTestCase() - { - } - - /** - * Return the {@link ServiceID} of a server that we started ourselves. The - * method waits until the {@link ServiceID} becomes available on - * {@link AbstractServer#getServiceID()}. - * - * @exception AssertionFailedError - * If the {@link ServiceID} can not be found after a timeout. - * - * @exception InterruptedException - * if the thread is interrupted while it is waiting to retry. - */ - static public ServiceID getServiceID(final AbstractServer server) throws AssertionFailedError, InterruptedException - { - ServiceID serviceID = null; - - for (int i = 0; i < 10 && serviceID == null; i++) - { - /* - * Note: This can be null since the serviceID is not assigned - * synchronously by the registrar. - */ - serviceID = server.getServiceID(); - - if (serviceID == null) - { - /* - * We wait a bit and retry until we have it or timeout. - */ - Thread.sleep(200); - } - } - - Assert.assertNotNull("serviceID", serviceID); - - /* - * Verify that we have discovered the _correct_ service. This is a - * potential problem when starting a stopping services for the test - * suite. - */ - Assert.assertEquals("serviceID", server.getServiceID(), serviceID); - - return serviceID; - - } - - /** - * Lookup a {@link DataService} by its {@link ServiceID} using unicast - * discovery on localhost. - * - * @param serviceID - * The {@link ServiceID}. - * - * @return The service. - * - * @todo Modify to return the service item? - * - * @todo Modify to not be specific to {@link DataService} vs - * {@link MetadataService} (we need a common base interface for both - * that carries most of the functionality but allows us to make - * distinctions easily during discovery). - */ - public IDataService lookupDataService(ServiceID serviceID) throws IOException, ClassNotFoundException, InterruptedException - { - /* - * Lookup the discover service (unicast on localhost). - */ - - // get the hostname. - String hostname = NicUtil.getIpAddress("default.nic", "default", true); - - // Find the service registrar (unicast protocol). - final int timeout = 4 * 1000; // seconds. - LookupLocator lookupLocator = new LookupLocator("jini://" + hostname); - ServiceRegistrar serviceRegistrar = lookupLocator.getRegistrar(timeout); - - /* - * Prepare a template for lookup search. - * - * Note: The client needs a local copy of the interface in order to be - * able to invoke methods on the service without using reflection. The - * implementation class will be downloaded from the codebase identified - * by the server. - */ - ServiceTemplate template = new ServiceTemplate(// - /* - * use this to request the service by its serviceID. - */ - serviceID, - /* - * Use this to filter services by an interface that they - * expose. - */ - // new Class[] { IDataService.class }, - null, - /* - * use this to filter for services by Entry attributes. - */ - null); - - /* - * Lookup a service. This can fail if the service registrar has not - * finished processing the service registration. If it does, you can - * generally just retry the test and it will succeed. However this - * points out that the client may need to wait and retry a few times if - * you are starting everything up at once (or just register for - * notification events for the service if it is not found and enter a - * wait state). - */ - - IDataService service = null; - - for (int i = 0; i < 10 && service == null; i++) - { - service = (IDataService) serviceRegistrar.lookup(template); - - if (service == null) - { - System.err.println("Service not found: sleeping..."); - Thread.sleep(200); - } - - } - - if (service != null) - { - System.err.println("Service found."); - } - - return service; - } - - /** - * Compares two representations of the {@link PartitionLocator} without the - * left- and right-separator keys that bound the index partition. - * - * @param expected - * @param actual - */ - protected void assertEquals(PartitionLocator expected, PartitionLocator actual) - { - Assert.assertEquals("partitionId", expected.getPartitionId(), actual.getPartitionId()); - Assert.assertEquals("dataServiceUUID", expected.getDataServiceUUID(), actual.getDataServiceUUID()); - } - - /** - * Compares two representations of the {@link LocalPartitionMetadata} for an - * index partition including the optional resource descriptions. - * - * @param expected - * @param actual - */ - protected void assertEquals(LocalPartitionMetadata expected, LocalPartitionMetadata actual) - { - Assert.assertEquals("partitionId", expected.getPartitionId(), actual.getPartitionId()); - Assert.assertEquals("leftSeparatorKey", expected.getLeftSeparatorKey(), ((LocalPartitionMetadata) actual).getLeftSeparatorKey()); - Assert.assertEquals("rightSeparatorKey", expected.getRightSeparatorKey(), ((LocalPartitionMetadata) actual).getRightSeparatorKey()); - - final IResourceMetadata[] expectedResources = expected.getResources(); - final IResourceMetadata[] actualResources = actual.getResources(); - - Assert.assertEquals("#resources", expectedResources.length, actualResources.length); - - for (int i = 0; i < expected.getResources().length; i++) - { - // verify by components so that it is obvious what is wrong. - - Assert.assertEquals("filename[" + i + "]", expectedResources[i].getFile(), actualResources[i].getFile()); - - // assertEquals("size[" + i + "]", expectedResources[i].size(), - // actualResources[i].size()); - - Assert.assertEquals("UUID[" + i + "]", expectedResources[i].getUUID(), actualResources[i].getUUID()); - - // verify by equals. - Assert.assertTrue("resourceMetadata", expectedResources[i].equals(actualResources[i])); - } - } -} Deleted: branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/service/jini/TestBigdataClient.java =================================================================== --- branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/service/jini/TestBigdataClient.java 2010-09-14 17:19:56 UTC (rev 3544) +++ branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/service/jini/TestBigdataClient.java 2010-09-14 17:39:46 UTC (rev 3545) @@ -1,208 +0,0 @@ -/** - -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 Apr 23, 2007 - */ - -package com.bigdata.service.jini; - -import java.io.Serializable; -import java.util.Random; -import java.util.UUID; - -import junit.framework.Assert; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.bigdata.btree.IIndex; -import com.bigdata.btree.ITuple; -import com.bigdata.btree.ITupleIterator; -import com.bigdata.btree.IndexMetadata; - -import com.bigdata.btree.proc.BatchInsert.BatchInsertConstructor; -import com.bigdata.journal.ITx; -import com.bigdata.service.DataService; -import com.bigdata.service.IBigdataFederation; -import com.bigdata.service.IDataService; -import com.bigdata.service.jini.util.JiniServicesHelper; -import com.bigdata.test.util.Util; - -/** - * Test suite for the {@link JiniClient}. - * <p> - * Note: The core test suite has already verified the basic semantics of the - * {@link IDataService} interface and partitioned indices so all we have to - * focus on here is the jini integration and verifying that the serialization - * imposed by RMI goes off without a hitch (e.g., that everything implements - * {@link Serializable} and that those {@link Serializable} implementations can - * correctly round trip the data). - * - * @author <a href="mailto:tho...@us...">Bryan Thompson</a> - * @version $Id$ - */ -public class TestBigdataClient extends AbstractServerTestCase { - - protected boolean serviceImplRemote; - - public TestBigdataClient() { - this.serviceImplRemote = false; - } - - public TestBigdataClient(boolean serviceImplRemote) { - this.serviceImplRemote = serviceImplRemote; - } - - - /** - * Starts a {@link DataServer} ({@link #dataServer1}) and then a - * {@link MetadataServer} ({@link #metadataServer0}). Each runs in its own - * thread. - */ - @Before - public void setUp() throws Exception { - helper = new JiniServicesHelper(serviceImplRemote); - helper.start(); - } - - protected JiniServicesHelper helper = null; - - /** - * Destroy the test services. - */ - @After - public void tearDown() throws Exception { - if (helper != null) { - helper.destroy(); - } - } - - /** - * Test ability to registers a scale-out index on one of the - * {@link DataService}s. - * - * @throws Exception - */ - @Test - public void test_registerIndex1() throws Exception { - final IBigdataFederation<?> fed = helper.client.connect(); - final String name = "testIndex"; - final IndexMetadata metadata = new IndexMetadata(name, UUID.randomUUID()); - - metadata.setDeleteMarkers(true); - fed.registerIndex(metadata); - final IIndex ndx = fed.getIndex(name, ITx.UNISOLATED); - - Assert.assertEquals("indexUUID", metadata.getIndexUUID(), ndx.getIndexMetadata().getIndexUUID()); - - doBasicIndexTests(ndx); - } - - /** - * Test ability to registers a scale-out index on both of the - * {@link DataService}s. - * - * @throws Exception - */ - @Test - public void test_registerIndex2() throws Exception { - final IBigdataFederation<?> fed = helper.client.connect(); - final String name = "testIndex"; - final IndexMetadata metadata = new IndexMetadata(name,UUID.randomUUID()); - - metadata.setDeleteMarkers(true); - - final UUID indexUUID = fed.registerIndex( metadata, // - // separator keys. - new byte[][] { - new byte[]{}, - Util.asSortKey(500) - },// - // data service assignments. - new UUID[] { // - helper.getDataService0().getServiceUUID(),// - helper.getDataService1().getServiceUUID() // - }); - - final IIndex ndx = fed.getIndex(name, ITx.UNISOLATED); - - Assert.assertEquals("indexUUID", indexUUID, ndx.getIndexMetadata().getIndexUUID()); - - // verify partition 0 on dataService0 - Assert.assertNotNull(helper.getDataService0().getIndexMetadata(DataService.getIndexPartitionName(name, 0), ITx.UNISOLATED)); - - // verify partition 1 on dataService1 - Assert.assertNotNull(helper.getDataService1().getIndexMetadata(DataService.getIndexPartitionName(name, 1), ITx.UNISOLATED)); - - doBasicIndexTests(ndx); - } - - /** - * Test helper reads and writes some data on the index in order to verify - * that these operations can be performed without serialization errors - * arising from the RPC calls. - * - * @param ndx - */ - protected void doBasicIndexTests(final IIndex ndx) { - - final int limit = 1000; - - final byte[][] keys = new byte[limit][]; - final byte[][] vals = new byte[limit][]; - - final Random r = new Random(); - - for (int i = 0; i < limit; i++) { - keys[i] = Util.asSortKey(i); - final byte[] val = new byte[10]; - r.nextBytes(val); - vals[i] = val; - } - - // batch insert. - ndx.submit(0/* fromIndex */, limit/* toIndex */, keys, vals, BatchInsertConstructor.RETURN_NO_VALUES, null); - - // verify #of index entries. - Assert.assertEquals(limit, ndx.rangeCount(null, null)); - - // verify data. - { - final ITupleIterator<?> itr = ndx.rangeIterator(null, null); - - int i = 0; - - while (itr.hasNext()) { - final ITuple<?> tuple = itr.next(); - - Assert.assertEquals(keys[i], tuple.getKey()); - Assert.assertEquals(vals[i], tuple.getValue()); - i++; - } - - Assert.assertEquals(limit, i); - } - } -} Deleted: branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/service/jini/TestBigdataClientRemote.java =================================================================== --- branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/service/jini/TestBigdataClientRemote.java 2010-09-14 17:19:56 UTC (rev 3544) +++ branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/service/jini/TestBigdataClientRemote.java 2010-09-14 17:39:46 UTC (rev 3545) @@ -1,36 +0,0 @@ -/** - -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 -*/ - -package com.bigdata.service.jini; - -/** - * Test suite for the {@link JiniClient} using the purely remote - * service implementations. - */ -public class TestBigdataClientRemote extends TestBigdataClient { - - public TestBigdataClientRemote() { - super(true); - } -} Added: branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/test/util/Assert.java =================================================================== --- branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/test/util/Assert.java (rev 0) +++ branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/test/util/Assert.java 2010-09-14 17:39:46 UTC (rev 3545) @@ -0,0 +1,82 @@ +/** + +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 +*/ +package com.bigdata.test.util; + + +/** + * Utility class that extends JUnit's Assert class with additional utilities. + * + * @author blevine + * + */ +public class Assert extends org.junit.Assert +{ + public static void assertEquals(byte[] expected, byte[] actual) + { + assertEquals(null, expected, actual); + } + public static void assertEquals(String message, byte[] expected, byte[] actual) + { + if (expected == null && actual == null) + { + return; + } + + if ( (expected == null) && (actual != null) ) + { + assertNull(message, actual); + } + + if ( (expected != null) && (actual == null) ) + { + assertNotNull(message, actual); + } + + if (expected.length != actual.length) + { + String msg = "(array lengths do not match)."; + + if (message != null) + { + msg = message + " " + msg; + } + + fail(msg); + } + + for (int i = 0; i < expected.length; i++) + { + if (expected[i] != actual[i]) + { + String msg = "(index = i)."; + + if (message != null) + { + msg = message + " " + msg; + } + assertEquals(msg, expected[i], actual[i]); + } + } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ble...@us...> - 2010-09-21 16:47:28
|
Revision: 3605 http://bigdata.svn.sourceforge.net/bigdata/?rev=3605&view=rev Author: blevine218 Date: 2010-09-21 16:47:18 +0000 (Tue, 21 Sep 2010) Log Message: ----------- Adding zookeeper suite of tests All tests now run without failures Modified Paths: -------------- branches/maven_scaleout/bigdata-integ/pom.xml branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/jini/start/AbstractFedZooTestCase.java branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/jini/start/JiniStartSuite.java branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/jini/start/config/JiniStartConfigSuite.java Added Paths: ----------- branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/zookeeper/ branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/zookeeper/AbstractZooTestCase.java branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/zookeeper/TestHierarchicalZNodeWatcher.java branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/zookeeper/TestUnknownChildrenWatcher.java branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/zookeeper/TestZLockImpl.java branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/zookeeper/TestZNodeCreatedWatcher.java branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/zookeeper/TestZNodeDeletedWatcher.java branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/zookeeper/TestZooBarrier.java branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/zookeeper/TestZooElection.java branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/zookeeper/TestZooQueue.java branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/zookeeper/TestZookeeperAccessor.java branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/zookeeper/ZookeeperSuite.java Modified: branches/maven_scaleout/bigdata-integ/pom.xml =================================================================== --- branches/maven_scaleout/bigdata-integ/pom.xml 2010-09-21 15:00:39 UTC (rev 3604) +++ branches/maven_scaleout/bigdata-integ/pom.xml 2010-09-21 16:47:18 UTC (rev 3605) @@ -108,7 +108,11 @@ <include>**/Test*Remote.java</include> </includes> <excludes> + <!-- Don't include suites as part of the normal test run --> <exclude>**/*Suite.java</exclude> + + <!-- Don't include anonymous inner classes that happen to match the test pattern --> + <exclude>**/*$*.java</exclude> </excludes> <systemPropertyVariables> Modified: branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/jini/start/AbstractFedZooTestCase.java =================================================================== --- branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/jini/start/AbstractFedZooTestCase.java 2010-09-21 15:00:39 UTC (rev 3604) +++ branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/jini/start/AbstractFedZooTestCase.java 2010-09-21 16:47:18 UTC (rev 3605) @@ -38,9 +38,8 @@ import org.apache.zookeeper.ZooKeeper; import org.apache.zookeeper.ZooDefs.Ids; import org.apache.zookeeper.data.ACL; -import org.junit.Rule; -import org.junit.rules.TestName; + import com.bigdata.jini.start.config.ZookeeperClientConfig; import com.bigdata.jini.start.process.ProcessHelper; import com.bigdata.jini.start.process.ZookeeperProcessHelper; Modified: branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/jini/start/JiniStartSuite.java =================================================================== --- branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/jini/start/JiniStartSuite.java 2010-09-21 15:00:39 UTC (rev 3604) +++ branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/jini/start/JiniStartSuite.java 2010-09-21 16:47:18 UTC (rev 3605) @@ -1,17 +1,4 @@ -/*********************************************************************** - * - * $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; import org.junit.runner.RunWith; Modified: 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 2010-09-21 15:00:39 UTC (rev 3604) +++ branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/jini/start/config/JiniStartConfigSuite.java 2010-09-21 16:47:18 UTC (rev 3605) @@ -1,17 +1,4 @@ -/*********************************************************************** - * - * $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; Copied: branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/zookeeper/AbstractZooTestCase.java (from rev 3580, branches/maven_scaleout/bigdata-core/src/test/java/com/bigdata/zookeeper/AbstractZooTestCase.java) =================================================================== --- branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/zookeeper/AbstractZooTestCase.java (rev 0) +++ branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/zookeeper/AbstractZooTestCase.java 2010-09-21 16:47:18 UTC (rev 3605) @@ -0,0 +1,528 @@ +/* + + 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 4, 2009 + */ + +package com.bigdata.zookeeper; + +import java.io.File; +import java.io.IOException; +import java.net.BindException; +import java.net.ServerSocket; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.ReentrantLock; + +import com.bigdata.DataFinder; +import net.jini.config.Configuration; +import net.jini.config.ConfigurationProvider; + +import org.apache.log4j.Logger; +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.KeeperException.NodeExistsException; +import org.apache.zookeeper.KeeperException.SessionExpiredException; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.data.ACL; +import org.apache.zookeeper.server.quorum.QuorumPeerMain; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; + +import com.bigdata.jini.start.MockListener; +import com.bigdata.jini.start.config.ZookeeperServerConfiguration; +import com.bigdata.jini.start.process.ProcessHelper; +import com.bigdata.jini.start.process.ZookeeperProcessHelper; +import com.bigdata.jini.util.ConfigMath; +import com.bigdata.resources.ResourceFileFilter; + +/** + * Abstract base class for zookeeper integration tests. + * + * @author <a href="mailto:tho...@us...">Bryan Thompson</a> + * @version $Id$ + */ +public abstract class AbstractZooTestCase { + + public final static Logger log = Logger.getLogger(AbstractZooTestCase.class); + + /** + * Constructor + */ + public AbstractZooTestCase() { + + } + + /** + * Return an open port on current machine. Try the suggested port first. If + * suggestedPort is zero, just select a random port + */ + protected static int getPort(final int suggestedPort) throws IOException { + + ServerSocket openSocket; + + try { + openSocket = new ServerSocket(suggestedPort); + } catch (BindException ex) { + // the port is busy, so look for a random open port + openSocket = new ServerSocket(0); + } + + final int port = openSocket.getLocalPort(); + + openSocket.close(); + + return port; + } + + /** + * A configuration file used by some of the unit tests in this package. It + * contains a description of the zookeeper server instance in case we need + * to start one. + */ + protected final String configFile = DataFinder.bestURI("testing/data/com/bigdata/zookeeper/testzoo.config").toASCIIString(); + + /** + * Note: The sessionTimeout is computed as 2x the tickTime as read out of + * the configuration file by {@link #setUp()}. This corresponds to the + * actual sessionTimeout for the client rather than a requested value. + */ + int sessionTimeout; + + /** + * The initial {@link ZooKeeper} instance obtained from the + * {@link #zookeeperAccessor} when the test was setup. + * <p> + * Note: Some unit tests use {@link #expireSession(ZooKeeper)} to expire the + * session associated with this {@link ZooKeeper} instance. + * + * @see ZooKeeperAccessor + */ + protected ZooKeeper zookeeper; + + /** + * Factory for {@link ZooKeeper} instances using the configured hosts and + * session timeout. + */ + protected ZooKeeperAccessor zookeeperAccessor; + + /** + * ACL used by the unit tests. + */ + protected final List<ACL> acl = Ids.OPEN_ACL_UNSAFE; + + protected final MockListener listener = new MockListener(); + + private File dataDir = null; + + // the chosen client port. + int clientPort = -1; + + @Before + public void setUp() throws Exception { + + try { + // find ports that are not in use. + clientPort = getPort(2181/* suggestedPort */); + final int peerPort = getPort(2888/* suggestedPort */); + final int leaderPort = getPort(3888/* suggestedPort */); + final String servers = "1=localhost:" + peerPort + ":" + leaderPort; + + // create a temporary file for zookeeper's state. + dataDir = File.createTempFile("test", ".zoo"); + // delete the file so that it can be re-created as a directory. + dataDir.delete(); + // recreate the file as a directory. + dataDir.mkdirs(); + + final String[] args = new String[] { + // The configuration file (overrides follow). + configFile, + // overrides the clientPort to be unique. + QuorumPeerMain.class.getName() + "." + + ZookeeperServerConfiguration.Options.CLIENT_PORT + "=" + + clientPort, + // overrides servers declaration. + QuorumPeerMain.class.getName() + "." + + ZookeeperServerConfiguration.Options.SERVERS + "=\"" + + servers + "\"", + // overrides the dataDir + QuorumPeerMain.class.getName() + "." + + ZookeeperServerConfiguration.Options.DATA_DIR + + "=new java.io.File(" + + ConfigMath.q(dataDir.toString()) + ")"// + }; + + System.err.println("args=" + Arrays.toString(args)); + + final Configuration config = ConfigurationProvider.getInstance(args); + + final int tickTime = (Integer) config.getEntry(QuorumPeerMain.class + .getName(), ZookeeperServerConfiguration.Options.TICK_TIME, + Integer.TYPE); + + /* + * Note: This is the actual session timeout that the zookeeper service + * will impose on the client. + */ + this.sessionTimeout = tickTime * 2; + + // if necessary, start zookeeper (a server instance). + ZookeeperProcessHelper.startZookeeper(config, listener); + + zookeeperAccessor = new ZooKeeperAccessor("localhost:" + clientPort, sessionTimeout); + + zookeeper = zookeeperAccessor.getZookeeper(); + + try { + + /* + * Since all unit tests use children of this node we must make sure + * that it exists. + */ + zookeeper + .create("/test", new byte[] {}, acl, CreateMode.PERSISTENT); + + } catch (NodeExistsException ex) { + + if (log.isInfoEnabled()) + log.info("/test already exits."); + + } + + } catch (Throwable t) { + + // don't leave around the dataDir if the setup fails. + recursiveDelete(dataDir); + + throw new Exception(t); + + } + + } + + @After + public void tearDown() throws Exception { + try { + if (zookeeperAccessor != null) { + zookeeperAccessor.close(); + } + + for (ProcessHelper h : listener.running) { + // destroy zookeeper service iff we started it. + h.kill(true/* immediateShutdown */); + } + + if (dataDir != null) { + // clean out the zookeeper data dir. + recursiveDelete(dataDir); + } + + } catch (Throwable t) { + log.error(t, t); + } + } + + /** + * Return a new {@link Zookeeper} instance that is connected to the same + * zookeeper ensemble but which has a distinct session. + * + * @return + * @throws IOException + * @throws InterruptedException + */ + protected ZooKeeper getDistinctZooKeeperWithDistinctSession() throws IOException, InterruptedException { + + final ZooKeeper zookeeper2 = new ZooKeeper(zookeeperAccessor.hosts, + zookeeperAccessor.sessionTimeout, new Watcher() { + public void process(WatchedEvent e) { + + } + }); + + /* + * Wait until this instance is connected. + */ + final long timeout = TimeUnit.MILLISECONDS.toNanos(1000/* ms */); + + final long begin = System.nanoTime(); + + while (zookeeper2.getState() != ZooKeeper.States.CONNECTED + && zookeeper2.getState().isAlive()) { + + final long elapsed = System.nanoTime() - begin; + + if (elapsed > timeout) { + Assert.fail("ZooKeeper session did not connect? elapsed="+ TimeUnit.NANOSECONDS.toMillis(elapsed)); + } + + if (log.isInfoEnabled()) { + log.info("Awaiting connected."); + } + + Thread.sleep(100/* ms */); + + } + + if (!zookeeper2.getState().isAlive()) { + Assert.fail("Zookeeper died?"); + } + + if(log.isInfoEnabled()) + log.info("Zookeeper connected."); + + return zookeeper2; + + } + + /** + * Return a new {@link ZooKeeper} instance that is connected to the same + * zookeeper ensemble as the given instance and is using the same session + * but is nevertheless a distinct instance. + * <p> + * Note: This is used by some unit tests to force the given + * {@link ZooKeeper} to report a {@link SessionExpiredException} by closing + * the returned instance. + * + * @param zookeeper + * A zookeeper instance. + * + * @return A distinct instance associated with the same session. + * + * @throws IOException + * @throws InterruptedException + */ + protected ZooKeeper getDistinctZooKeeperForSameSession(ZooKeeper zookeeper1) + throws IOException, InterruptedException { + + final ZooKeeper zookeeper2 = new ZooKeeper(zookeeperAccessor.hosts, + zookeeperAccessor.sessionTimeout, new Watcher() { + public void process(WatchedEvent e) { + + } + }, zookeeper1.getSessionId(), zookeeper1.getSessionPasswd()); + + /* + * Wait until this instance is connected. + */ + final long timeout = TimeUnit.MILLISECONDS.toNanos(1000/* ms */); + final long begin = System.nanoTime(); + + while (zookeeper2.getState() != ZooKeeper.States.CONNECTED + && zookeeper2.getState().isAlive()) { + final long elapsed = System.nanoTime() - begin; + + if (elapsed > timeout) { + Assert.fail("ZooKeeper session did not connect? elapsed=" + TimeUnit.NANOSECONDS.toMillis(elapsed)); + } + + if (log.isInfoEnabled()) { + log.info("Awaiting connected."); + } + + Thread.sleep(100/* ms */); + } + + if (!zookeeper2.getState().isAlive()) { + Assert.fail("Zookeeper died?"); + } + + if(log.isInfoEnabled()) + log.info("Zookeeper connected."); + + return zookeeper2; + } + + /** + * Expires the session associated with the {@link Zookeeper} client + * instance. + * + * @param zookeeper + * + * @throws IOException + * @throws InterruptedException + */ + protected void expireSession(ZooKeeper zookeeper) throws IOException,InterruptedException { + + /* + * Obtain a distinct ZooKeeper instance associated with the _same_ + * session. + */ + final ZooKeeper zookeeper2 = getDistinctZooKeeperForSameSession(zookeeper); + + /* + * Close this instance, forcing the original instance to report a + * SessionExpiredException. Note that this is not synchronous so we need + * to wait until the original ZooKeeper instance notices that its + * session is expired. + */ + zookeeper2.close(); + + /* + * Wait up to the session timeout and then wait some more so that the + * events triggered by that timeout have time to propagate. + */ + final long timeout = TimeUnit.MILLISECONDS.toNanos(sessionTimeout * 2); + final long begin = System.nanoTime(); + + while (zookeeper.getState().isAlive()) { + final long elapsed = System.nanoTime() - begin; + + if (elapsed > timeout) { + Assert.fail("ZooKeeper session did not expire? elapsed=" + + TimeUnit.NANOSECONDS.toMillis(elapsed) + + ", sessionTimeout=" + sessionTimeout); + } + + if(log.isInfoEnabled()) { + log.info("Awaiting session expired."); + } + + Thread.sleep(500/* ms */); + } + + if (log.isInfoEnabled()) { + final long elapsed = System.nanoTime() - begin; + + log.info("Session was expired: elapsed=" + + TimeUnit.NANOSECONDS.toMillis(elapsed) + + ", sessionTimeout=" + sessionTimeout); + } + } + + /** + * Class used to test concurrency primitives. + * + * @author <a href="mailto:tho...@us...">Bryan Thompson</a> + * @version $Id$ + */ + abstract protected class ClientThread extends Thread { + + private final Thread main; + protected final ReentrantLock lock; + + /** + * + * @param main + * The thread in which the test is running. + * @param lock + * A lock. + */ + public ClientThread(final Thread main, final ReentrantLock lock) { + + if (main == null) + throw new IllegalArgumentException(); + + if (lock == null) + throw new IllegalArgumentException(); + + this.main = main; + this.lock = lock; + setDaemon(true); + } + + public void run() { + try { + run2(); + } catch (Throwable t) { + + // log error since won't be seen otherwise. + log.error(t.getLocalizedMessage(), t); + + // interrupt the main thread. + main.interrupt(); + } + } + + abstract void run2() throws Exception; + } + + /** + * Recursively removes any files and subdirectories and then removes the + * file (or directory) itself. + * <p> + * Note: Files that are not recognized will be logged by the + * {@link ResourceFileFilter}. + * + * @param f + * A file or directory. + */ + private void recursiveDelete(final File f) { + + if (f.isDirectory()) { + + final File[] children = f.listFiles(); + + if (children == null) { + // The directory does not exist. + return; + } + + for (int i = 0; i < children.length; i++) { + recursiveDelete(children[i]); + } + } + + if(log.isInfoEnabled()) + log.info("Removing: " + f); + + if (f.exists() && !f.delete()) { + log.warn("Could not remove: " + f); + } + } + + /** + * Recursive delete of znodes. + * + * @param zpath + * + * @throws KeeperException + * @throws InterruptedException + */ + protected void destroyZNodes(final ZooKeeper zookeeper, final String zpath) + throws KeeperException, InterruptedException { + + // System.err.println("enter : " + zpath); + + final List<String> children = zookeeper.getChildren(zpath, false); + + for (String child : children) { + destroyZNodes(zookeeper, zpath + "/" + child); + } + + if(log.isInfoEnabled()) + log.info("delete: " + zpath); + + zookeeper.delete(zpath, -1/* version */); + } + + protected String getName() { + return getClass().getSimpleName(); + } +} Copied: branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/zookeeper/TestHierarchicalZNodeWatcher.java (from rev 3580, branches/maven_scaleout/bigdata-core/src/test/java/com/bigdata/zookeeper/TestHierarchicalZNodeWatcher.java) =================================================================== --- branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/zookeeper/TestHierarchicalZNodeWatcher.java (rev 0) +++ branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/zookeeper/TestHierarchicalZNodeWatcher.java 2010-09-21 16:47:18 UTC (rev 3605) @@ -0,0 +1,317 @@ +/* + +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 12, 2009 + */ + +package com.bigdata.zookeeper; + +import java.util.concurrent.TimeUnit; + +import junit.framework.AssertionFailedError; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher.Event; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +/** + * Test suite for {@link HierarchicalZNodeWatcher}. + * <p> + * Note: Zookeeper has other events that could appear during these unit tests, + * such as the connection status change events. However the unit test are not + * expecting such events during testing. If they appear, those events could + * cause test failures when we examine the queue. Basically, the tests are not + * robust if your zookeeper client is flakey. + * + * @author <a href="mailto:tho...@us...">Bryan Thompson</a> + * @version $Id$ + */ +public class TestHierarchicalZNodeWatcher extends AbstractZooTestCase implements + HierarchicalZNodeWatcherFlags { + + /** + * + */ + public TestHierarchicalZNodeWatcher() { + + } + + + protected String zroot; + + /** + * Sets up a unique {@link #zroot}. + */ + @Before + public void setUp() throws Exception { + super.setUp(); + zroot = zookeeper.create("/test", new byte[0], acl, CreateMode.PERSISTENT_SEQUENTIAL); + } + + /** + * Destroys the {@link #zroot} and its children. + */ + @After + public void tearDown() throws Exception { + if (zroot != null) { + destroyZNodes(zookeeperAccessor.getZookeeper(), zroot); + } + super.tearDown(); + } + + /** + * Test when the node at the root of the hierarchy does not exist when we + * setup the watcher, then create the znode and verify that we see the event + * in the queue. + * + * @throws KeeperException + * @throws InterruptedException + */ + @Test + public void test_noticeCreate() throws KeeperException, + InterruptedException { + + WatchedEvent e; + + final String zroot = this.zroot + "/" + "a"; + final HierarchicalZNodeWatcher watcher = new HierarchicalZNodeWatcher( + zookeeper, zroot, EXISTS) { + + @Override + protected int watch(String path, String child) { + return NONE; + } + }; + + Assert.assertTrue(watcher.queue.isEmpty()); + Assert.assertTrue(watcher.isWatched(zroot)); + + /* + * Create the zroot and verify the event is placed into the queue. + */ + + zookeeper.create(zroot, new byte[0], acl, CreateMode.PERSISTENT); + + // look for the create event. + e= watcher.queue.poll(1000, TimeUnit.MILLISECONDS); + + Assert.assertNotNull(e); + Assert.assertEquals(zroot,e.getPath()); + Assert.assertEquals(Event.EventType.NodeCreated,e.getType()); + Assert.assertTrue(watcher.queue.isEmpty()); + + /* + * Delete the znode and verify the event is placed into the queue. + */ + + zookeeper.delete(zroot, -1/*version*/); + + // look for the delete event. + e = watcher.queue.poll(1000, TimeUnit.MILLISECONDS); + + Assert.assertNotNull(e); + Assert.assertEquals(zroot,e.getPath()); + Assert.assertEquals(Event.EventType.NodeDeleted, e.getType()); + Assert.assertTrue(watcher.queue.isEmpty()); + + /* + * Re-create the zroot and verify the event is placed into the queue + * (this makes sure that we are keeping the watch in place). + */ + + zookeeper.create(zroot, new byte[0], acl, CreateMode.PERSISTENT); + + // look for the create event. + e = watcher.queue.poll(1000, TimeUnit.MILLISECONDS); + + Assert.assertNotNull(e); + Assert.assertEquals(zroot, e.getPath()); + Assert.assertEquals(Event.EventType.NodeCreated, e.getType()); + Assert.assertTrue(watcher.queue.isEmpty()); + + /* + * cancel the watcher and verify that it does not notice a delete of the + * zroot after it was cancelled. + */ + watcher.cancel(); + + /* + * Delete the znode - no event should appear. + */ + + zookeeper.delete(zroot, -1/*version*/); + + // look for the delete event. + e = watcher.queue.poll(1000, TimeUnit.MILLISECONDS); + + Assert.assertNull(e); + + } + + /** + * Unit test verifies that we notice specific children as they are created + * and destroyed. "red" znodes are ignored. if the znode is "blue" then we + * extend the watch over its children as well. + * + * @throws KeeperException + * @throws InterruptedException + * + * @todo test queue when data is changed. + */ + @Test + public void test_noticeChildren() throws InterruptedException, KeeperException { + + WatchedEvent e; + + HierarchicalZNodeWatcher watcher = new HierarchicalZNodeWatcher(zookeeper, zroot, EXISTS | CHILDREN) { + + @Override + protected int watch(String path, String child) { + + if (child.equals("red")) + return NONE; + + if (child.equals("blue")) + return EXISTS | CHILDREN; + + if (child.equals("green")) + return DATA; + + throw new AssertionFailedError("Not expecting: path=" + path + + ", child=" + child); + + } + + }; + + zookeeper.create(zroot + "/" + "red", new byte[0], acl, CreateMode.PERSISTENT); + + e = watcher.queue.poll(1000,TimeUnit.MILLISECONDS); + Assert.assertNotNull(e); + Assert.assertEquals(zroot,e.getPath()); + Assert.assertEquals(Event.EventType.NodeChildrenChanged,e.getType()); + + zookeeper.create(zroot + "/" + "blue", new byte[0], acl, + CreateMode.PERSISTENT); + +// e = watcher.queue.poll(1000,TimeUnit.MILLISECONDS); +// assertNotNull(e); +// assertEquals(zroot+"/"+"red",e.getPath()); +// assertEquals(Event.EventType.NodeCreated,e.getType()); + + zookeeper.create(zroot + "/" + "blue" + "/" + "green", new byte[0], + acl, CreateMode.PERSISTENT); + + Assert.assertEquals(NONE, watcher.getFlags(zroot + "/" + "red")); + Assert.assertEquals(EXISTS | CHILDREN, watcher.getFlags(zroot + "/" + "blue")); + Assert.assertEquals(DATA, watcher.getFlags(zroot + "/" + "blue" + "/" + "green")); + + // clear any events in the queue. + watcher.queue.clear(); + + // update the data. + zookeeper.setData(zroot + "/" + "blue" + "/" + "green", new byte[] { 1 }, -1/* version */); + + // verify event. + e = watcher.queue.poll(1000,TimeUnit.MILLISECONDS); + Assert.assertNotNull(e); + Assert.assertEquals(zroot + "/" + "blue" + "/" + "green",e.getPath()); + Assert.assertEquals(Event.EventType.NodeDataChanged,e.getType()); + + // won't been seen since a "red" path. + zookeeper.create(zroot + "/" + "red" + "/" + "blue", new byte[0], acl, CreateMode.PERSISTENT); + + Assert.assertEquals(NONE, watcher.getFlags(zroot + "/" + "red" + "/" + "blue")); + + /* + * There should be three watched znodes: zroot; zroot/blue; and + * zroot/blue/green + */ + Assert.assertEquals(3,watcher.getWatchedSize()); + + watcher.cancel(); + + Assert.assertEquals(0,watcher.getWatchedSize()); + Assert.assertFalse(watcher.isWatched(zroot)); + Assert.assertFalse(watcher.isWatched(zroot+"/"+"blue")); + Assert.assertFalse(watcher.isWatched(zroot+"/"+"blue"+"/"+"green")); + + Assert.assertTrue(watcher.queue.isEmpty()); + + /* + * Setup a new watcher that wathes all paths but the red ones. The + * znodes already exist. Now verify that we receive various notices when + * the watcher is created. + */ + watcher = new HierarchicalZNodeWatcher(zookeeper, zroot, ALL, true/* pumpMockEventsDuringStartup */) { + + @Override + protected int watch(String path, String child) { + + return ALL; + + } + +// @Override +// protected void addedWatch(String path, int flags) { +// +// placeMockEventInQueue(path, flags); +// +// } + + }; + + /* + * We created 4 znodes plus the pre-existing zroot, so there should be + * five nodes picked up by the new watcher. + */ + final String[] nodes = new String[] { + zroot, + zroot + "/" + "red", + zroot + "/" + "red" + "/" + "blue", + zroot + "/" + "blue", + zroot + "/" + "green" + "/" + "green", + }; + + // verify new watched size. + Assert.assertEquals(nodes.length, watcher.getWatchedSize()); + + /* + * Verify mock events were pumped into the queue. Since we specified + * ALL, there should be three events for each znode. + */ + Assert.assertEquals(3 * 5, watcher.queue.size()); + + while ((e = watcher.queue.poll()) != null) { + System.err.println("mockEvent: "+e); + } + + watcher.cancel(); + } +} Copied: branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/zookeeper/TestUnknownChildrenWatcher.java (from rev 3580, branches/maven_scaleout/bigdata-core/src/test/java/com/bigdata/zookeeper/TestUnknownChildrenWatcher.java) =================================================================== --- branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/zookeeper/TestUnknownChildrenWatcher.java (rev 0) +++ branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/zookeeper/TestUnknownChildrenWatcher.java 2010-09-21 16:47:18 UTC (rev 3605) @@ -0,0 +1,53 @@ +/* + +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 22, 2009 + */ + +package com.bigdata.zookeeper; + +import org.junit.Test; + +/** + * Test suite for watcher for unknown children (those not previously seen). + * + * @author <a href="mailto:tho...@us...">Bryan Thompson</a> + * @version $Id$ + */ +public class TestUnknownChildrenWatcher extends AbstractZooTestCase { + + /** + * + */ + public TestUnknownChildrenWatcher() { + } + + + /** @todo place holder for unit tests. */ + @Test + public void test_nothing() { + + } + +} Copied: branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/zookeeper/TestZLockImpl.java (from rev 3580, branches/maven_scaleout/bigdata-core/src/test/java/com/bigdata/zookeeper/TestZLockImpl.java) =================================================================== --- branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/zookeeper/TestZLockImpl.java (rev 0) +++ branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/zookeeper/TestZLockImpl.java 2010-09-21 16:47:18 UTC (rev 3605) @@ -0,0 +1,626 @@ +/* + + 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 7, 2009 + */ + +package com.bigdata.zookeeper; + +import java.io.IOException; +import java.util.LinkedList; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.KeeperException.NoNodeException; +import org.apache.zookeeper.KeeperException.SessionExpiredException; +import org.junit.Assert; +import org.junit.Test; + +import com.bigdata.util.concurrent.DaemonThreadFactory; + +/** + * Test suite for {@link ZLockImpl}. + * + * @author <a href="mailto:tho...@us...">Bryan Thompson</a> + * @version $Id$ + * + * @todo do test w/ ensemble where we kill the server to which the client is + * connected and verify that the client transparently reconnects to + * another server and continues to await the lock. + */ +public class TestZLockImpl extends AbstractZooTestCase { + + /** + * + */ + public TestZLockImpl() { + } + + + /** + * Simple lock protocol test. + * + * @todo test w/ timeout. + * + * @throws KeeperException + * @throws InterruptedException + */ + @Test + public void test_lock() throws KeeperException, InterruptedException { + + final Thread mainThread = Thread.currentThread(); + + // a node that is guarenteed to be unique w/in the test namespace. + final String zpath = "/test/" + getName() + UUID.randomUUID(); + + try { + /* + * verify no such node (should be unique and therefore not + * preexist). + */ + zookeeper.getChildren(zpath, false); + Assert.fail("zpath exists: " + zpath); + } catch (NoNodeException ex) { + // ignore. + } + + // instances that can contend for the lock. + final ZLockImpl lock1 = ZLockImpl.getLock(zookeeper, zpath, acl); + + // znode not created during ctor (more robust this way). + Assert.assertNull(zookeeper.exists(zpath, false)); + + final ZLockImpl lock2 = ZLockImpl.getLock(zookeeper, zpath, acl); + + // znode not created during ctor (more robust this way). + Assert.assertNull(zookeeper.exists(zpath, false)); + + // obtain the lock. + lock1.lock(); + + log.info("lock1 was granted in main thread"); + + // one child in the queue - the one that holds the lock. + Assert.assertEquals(1, zookeeper.getChildren(zpath, false).size()); + + Assert.assertTrue(lock1.isLockHeld()); + + // run a thread that will contend for the lock. + final Thread t2 = new Thread() { + + public void run() { + + try { + + log.info("Starting 2nd thread."); + + Assert.assertTrue(lock1.isLockHeld()); + + log.info("Should block seeking lock2 in 2nd thread."); + + lock2.lock(); + + log.info("lock2 was granted"); + + // one child in the queue - the one that holds the lock. + Assert.assertEquals(1, zookeeper.getChildren(zpath, false).size()); + + } catch (Throwable t) { + + // log error + log.error(t, t); + + // interrupt the main thread. + mainThread.interrupt(); + + } + } + + }; + + t2.setDaemon(true); + + t2.start(); + + // wait until the other child is also contending for the lock + for (int i = 0; i < 10; i++) { + + final int n = zookeeper.getChildren(zpath, false).size(); + + log.info("nchildren=" + n); + + if (n == 2) + break; + + Thread.sleep(10/* ms */); + + } + + // should be exactly two children in the queue. + Assert.assertEquals(2, zookeeper.getChildren(zpath, false).size()); + + log.info("Will release lock1."); + + // release the lock. + lock1.unlock(); + + log.info("Released lock1."); + + // wait until the other thread gains the lock. + for (int i = 0; i < 10 && !lock2.isLockHeld(); i++) { + + Thread.sleep(10/* ms */); + + } + + log.info("Verifying lock2 is held."); + + // verify lock is held. + Assert.assertTrue(lock2.isLockHeld()); + + log.info("Verifying queue contains only lock2."); + + // verify one child in the queue. + Assert.assertEquals(1, zookeeper.getChildren(zpath, false).size()); + + log.info("Releasing lock2 from main thread."); + + // release the lock. + lock2.unlock(); + + log.info("Verifying queue is empty."); + + // queue is empty. + Assert.assertEquals(0, zookeeper.getChildren(zpath, false).size()); + + log.info("Test done."); + + } + + /** + * Unit test explores behavior when someone stomps on the zchild while a + * lock is held and another lock is in the queue (note that you can not + * delete the parent without deleting the children in zookeeper, so you will + * always see a queue purged of children before the queue node itself is + * deleted). + * + * @throws InterruptedException + * @throws KeeperException + */ + @Test + public void test_breakLock() throws KeeperException, InterruptedException { + + final Thread mainThread = Thread.currentThread(); + + // a node that is guarenteed to be unique w/in the test namespace. + final String zpath = "/test/" + getName() + UUID.randomUUID(); + + try { + /* + * verify no such node (should be unique and therefore not + * preexist). + */ + zookeeper.getChildren(zpath, false); + Assert.fail("zpath exists: " + zpath); + } catch (NoNodeException ex) { + // ignore. + } + + // instances that can contend for the lock. + final ZLockImpl lock1 = ZLockImpl.getLock(zookeeper, zpath, acl); + + // znode not created during ctor (more robust this way). + Assert.assertNull(zookeeper.exists(zpath, false)); + + final ZLockImpl lock2 = ZLockImpl.getLock(zookeeper, zpath, acl); + + // znode not created during ctor (more robust this way). + Assert.assertNull(zookeeper.exists(zpath, false)); + + // obtain the lock. + lock1.lock(); + + log.info("lock1 was granted"); + + // one child in the queue - the one that holds the lock. + Assert.assertEquals(1, zookeeper.getChildren(zpath, false).size()); + + Assert.assertTrue(lock1.isLockHeld()); + + // run a thread that will contend for the lock. + final Thread t2 = new Thread() { + + public void run() { + + try { + + Assert.assertTrue(lock1.isLockHeld()); + + lock2.lock(); + + log.info("lock2 granted."); + + } catch (Throwable t) { + + // log error + log.error(t, t); + + // interrupt the main thread. + mainThread.interrupt(); + + } + + } + + }; + + t2.setDaemon(true); + + t2.start(); + + // wait until the other child is also contending for the lock + for (int i = 0; i < 10 + && zookeeper.getChildren(zpath, false).size() != 2; i++) { + + Thread.sleep(10/* ms */); + + } + + // should be exactly two children in the queue. + Assert.assertEquals(2, zookeeper.getChildren(zpath, false).size()); + + // break the lock. + { + final String z = zpath + "/" + + ((ZLockImpl) lock1).getLockRequestZNode(); + log.info("breaking lock: deleting " + z); + zookeeper.delete(z, -1/* version */); + log.info("broke lock: deleted " + z); + } + + Assert.assertTrue(!lock1.isLockHeld()); + + Assert.assertTrue(lock2.isLockHeld()); + + log.info("lock1.unlock() - begin"); + + lock1.unlock(); + + log.info("lock1.unlock() - done"); + + Assert.assertFalse(lock1.isLockHeld()); + + } + + /** + * Unit test verifies that a {@link Thread} holding a {@link ZLock} may NOT + * acquire it again. + * + * @throws InterruptedException + * @throws KeeperException + */ + @Test + public void test_notReentrant() throws KeeperException, + InterruptedException { + + // a node that is guarenteed to be unique w/in the test namespace. + final String zpath = "/test/" + getName() + UUID.randomUUID(); + + final ZLockImpl zlock = ZLockImpl.getLock(zookeeper, zpath, acl); + + zlock.lock(); + + Assert.assertTrue(zlock.isLockHeld()); + + try { + zlock.lock(500, TimeUnit.MILLISECONDS); + Assert.fail("Expecting: " + TimeoutException.class); + } catch (TimeoutException ex) { + log.info("Expected exception: " + ex); + } + + // Assert.assertTrue(zlock.isLockHeld()); + // + // zlock.unlock(); + // + // Assert.assertTrue(zlock.isLockHeld()); + // + // zlock.unlock(); + // + // Assert.assertFalse(zlock.isLockHeld()); + + } + + /** + * Unit test where the session is expired before the lock is requested. + * lock() should throw out the {@link SessionExpiredException}. We then + * verify that we can obtain a new {@link ZooKeeper} instance associated + * with a new session and request and obtain the zlock. + * + * @throws IOException + * @throws InterruptedException + * @throws KeeperException + */ + @Test + public void test_sessionExpiredBeforeLockRequest() throws IOException, + KeeperException, InterruptedException { + + // a node that is guarenteed to be unique w/in the test namespace. + final String zpath = "/test/" + getName() + UUID.randomUUID(); + + expireSession(zookeeper); + + { + + // obtain a lock object. + final ZLockImpl zlock = ZLockImpl.getLock(zookeeper, zpath, acl); + + try { + + zlock.lock(); + + Assert.fail("Expecting: " + SessionExpiredException.class); + + } catch (SessionExpiredException ex) { + + if (log.isInfoEnabled()) + log.info("Ignoring expected exception: " + ex); + + } + + } + + // get a new instance associated with a new session. + zookeeper = zookeeperAccessor.getZookeeper(); + + // obtain a lock object. + final ZLockImpl zlock = ZLockImpl.getLock(zookeeper, zpath, acl); + zlock.lock(); + try { + + } finally { + zlock.unlock(); + } + + } + + /** + * Unit test where the session is expired while the caller is holding the + * lock. The test verifies that isLockHeld() throws a + * {@link SessionExpiredException}. + * + * @throws IOException + * @throws InterruptedException + * @throws KeeperException + */ + @Test + public void test_sessionExpiredWhileHoldingLock() throws IOException, + KeeperException, InterruptedException { + + // a node that is guarenteed to be unique w/in the test namespace. + final String zpath = "/test/" + getName() + UUID.randomUUID(); + + // obtain a lock object. + final ZLockImpl zlock = ZLockImpl.getLock(zookeeper, zpath, acl); + zlock.lock(); + try { + + Assert.assertTrue(zlock.isLockHeld()); + + expireSession(zookeeper); + + try { + + zlock.isLockHeld(); + + Assert.fail("Expecting: " + SessionExpiredException.class); + + } catch (SessionExpiredException ex) { + + if (log.isInfoEnabled()) + log.info("Ignoring expected exception: " + ex); + + } + + } finally { + /* + * Note: This also verifies that NO exception is thrown here even + * though the session has been expired. This is done to avoid have + * the expired session problem appear to arise from unlock() when it + * matters more that people see if when testing to verify that they + * hold the lock. + */ + zlock.unlock(); + } + + } + + /** + * Unit test for destroying a lock which is actively contended by other + * processes. + * + * @throws InterruptedException + * @throws KeeperException + * @throws ExecutionException + */ + @Test + public void test_destroyLock() throws KeeperException, + InterruptedException, ExecutionException { + + // a node that is guarenteed to be unique w/in the test namespace. + final String zpath = "/test/" + getName() + UUID.randomUUID(); + + final int ntasks = 4; + + final ExecutorService service = Executors.newFixedThreadPool(ntasks, + DaemonThreadFactory.defaultThreadFactory()); + + final LinkedList<Callable<Void>> tasks = new LinkedList<Callable<Void>>(); + + for (int i = 0; i < ntasks; i++) { + + tasks.add(new Callable<Void>() { + + /** + * Contends for the zlock. + * <p> + * Note: Task uses a distinct ZooKeeper having a distinct + * session. + */ + public Void call() throws Exception { + + final ZooKeeper zookeeper2 = getDistinctZooKeeperWithDistinctSession(); + + // obtain a lock object. + final ZLockImpl zlock = ZLockImpl.getLock(zookeeper2, + zpath, acl); + + zlock.lock(); + try { + + Assert.fail("Should not have obtained the lock."); + + } finally { + + zlock.unlock(); + + } + + return null; + + } + + }); + + } + + final List<Future<Void>> futures = new LinkedList<Future<Void>>(); + try { + + // obtain a lock object. + final ZLockImpl zlock = ZLockImpl.getLock(zookeeper, zpath, acl); + + zlock.lock(); + try { + + // verify that the main thread holds the zlock. + Assert.assertTrue(zlock.isLockHeld()); + + // start the other tasks. they will contend for the same zlock. + for (Callable<Void> task : tasks) { + + futures.add(service.submit(task)); + + } + + // wait until everyone is contending for the lock. + int queueSize; + while ((queueSize = zlock.getQueue().length) < ntasks + 1) { + + if (log.isInfoEnabled()) + log.info("Waiting for other processes: queueSize=" + + queueSize); + + Thread.sleep(100/* ms */); + + } + + if (log.isInfoEnabled()) + log.info("Main thread will now destroy the lock."); + + zlock.destroyLock(); + + // verify lock no longer held. + Assert.assertFalse(zlock.isLockHeld()); + + } finally { + + // note: should quitely succeed if the lock was destroyed. + zlock.unlock(); + + } + + } finally { + + service.shutdownNow(); + + } + + // verify all tasks started. + Assert.assertEquals(ntasks, futures.size()); + + // check their futures. + for (Future<Void> f : futures) { + + try { + + f.get(); + + } catch (ExecutionException ex) { + + final Throwable cause = ex.getCause(); + + if (cause != null && cause instanceof InterruptedException) { + + /* + * When the lock znode is destroyed, the other processes + * contending for the zlock will notice in their + * ZLockWatcher. The ZLockWatcher will be set its + * [cancelled] flag and an InterruptedException will be + * thrown out of lock(). + */ + + if (log.isInfoEnabled()) { + + log.info("Ignoring expected exception: " + cause); + + } + + continue; + + } + + /* + * Rethrow the execption. + * + * Note: If any of the tasks gains the lock, then it will throw + * an AssertionFailedError. + */ + + throw ex; + + } + + } + } +} Copied: branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/zookeeper/TestZNodeCreatedWatcher.java (from rev 3580, branches/maven_scaleout/bigdata-core/src/test/java/com/bigdata/zookeeper/TestZNodeCreatedWatcher.java) =================================================================== --- branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/zookeeper/TestZNodeCreatedWatcher.java (rev 0) +++ branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/zookeeper/TestZNodeCreatedWatcher.java 2010-09-21 16:47:18 UTC (rev 3605) @@ -0,0 +1,113 @@ +/* + +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 7, 2009 + */ + +package com.bigdata.zookeeper; + +import java.util.UUID; +import java.util.concurrent.TimeUnit; + +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.ZooDefs.Ids; +import org.junit.Assert; +import org.junit.Test; + +/** + * Test suite for {@link ZNodeCreatedWatcher}. + * + * @author <a href="mailto:tho...@us...">Bryan Thompson</a> + * @version $Id$ + * + * @todo do test where we kill and then restart the server while awaiting the + * event and verify that we reconnect to the server and continue to await + * the event. + * + * @todo do test w/ ensemble where we kill the server to which the client is + * connected and verify that reconnect to another server and continue to + * await the event. + */ +public class TestZNodeCreatedWatcher extends AbstractZooTestCase { + + /** + * + */ + public TestZNodeCreatedWatcher() { + } + + + /** + * Verify that we can detect the create of a znode. + * + * @throws KeeperException + * @throws InterruptedException + */ + @Test + public void test_awaitCreate() throws KeeperException, InterruptedException { + + // a node that is guaranteed to be unique w/in the test namespace. + final String zpath = "/test/" + getName() + UUID.randomUUID(); + + final Thread mainThread = Thread.currentThread(); + + final Thread t = new Thread() { + + public void run() { + + try { + + Thread.sleep(100/*ms*/); + + zookeeper.create(zpath, new byte[0], Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + + } catch (Throwable t) { + + // log error + log.error(t, t); + + // interrupt the main thread. + mainThread.interrupt(); + + } + } + + }; + + t.setDaemon(true); + + t.start(); + + ZNodeCreatedWatcher.awaitCreate(zookeeper, zpath, 250, + TimeUnit.MILLISECONDS); + +// ZNodeCreatedWatcher.awaitCreate(zookeeper, zpath, 250, +// TimeUnit.MILLISECONDS); + + // verify znode was created. + Assert.assertNotNull(zookeeper.exists(zpath, false)); + } +} Copied: branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/zookeeper/TestZNodeDeletedWatcher.java (from rev 3580, branches/maven_scaleout/bigdata-core/src/test/java/com/bigdata/zookeeper/TestZNodeDeletedWatcher.java) =================================================================== --- branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/zookeeper/TestZNodeDeletedWatcher.java (rev 0) +++ branches/maven_scaleout/bigdata-integ/src/test/java/com/bigdata/zookeeper/TestZNodeDele... [truncated message content] |
From: <ble...@us...> - 2010-09-23 20:22:57
|
Revision: 3619 http://bigdata.svn.sourceforge.net/bigdata/?rev=3619&view=rev Author: blevine218 Date: 2010-09-23 20:22:50 +0000 (Thu, 23 Sep 2010) Log Message: ----------- break dependency on test.xml script from bigdata-core. bigdata-integ now uses its own ANT script to start/stop the class and lookup services. Modified Paths: -------------- branches/maven_scaleout/bigdata-integ/pom.xml Added Paths: ----------- branches/maven_scaleout/bigdata-integ/src/test/resources/services.xml Modified: branches/maven_scaleout/bigdata-integ/pom.xml =================================================================== --- branches/maven_scaleout/bigdata-integ/pom.xml 2010-09-23 20:20:24 UTC (rev 3618) +++ branches/maven_scaleout/bigdata-integ/pom.xml 2010-09-23 20:22:50 UTC (rev 3619) @@ -1,6 +1,4 @@ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - - <parent> <groupId>com.bigdata</groupId> <artifactId>bigdata</artifactId> @@ -14,40 +12,33 @@ <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - <deploy.root.dir>${project.build.directory}/deploy</deploy.root.dir> - <bigdata.dependency>bigdata-core</bigdata.dependency> + <integ.deploy.root.dir>${project.build.directory}/deploy</integ.deploy.root.dir> + <integ.bigdata.dependency>bigdata-core</integ.bigdata.dependency> <!-- This is kinda hokey, but not sure there's a better way to construct the path to the root of the exploded tarball --> - - <deploy.dir>${deploy.root.dir}/${bigdata.dependency}-${project.version}</deploy.dir> - <test.dir>${deploy.dir}/testing</test.dir> - <testScript>${test.dir}/test.xml</testScript> - - <basedir>${test.dir}</basedir> - <app.home>${deploy.dir}</app.home> - <deploy.conf.dir>${test.dir}/conf</deploy.conf.dir> - <deploy.lib>${deploy.dir}/lib</deploy.lib> - <deploy.lib.test>${test.dir}/lib-test</deploy.lib.test> - <deploy.lib.dl>${deploy.dir}/lib-dl</deploy.lib.dl> - <test.codebase.dir>${deploy.lib.dl}</test.codebase.dir> - <test.codebase.port>23333</test.codebase.port> - <java.security.policy>${deploy.conf.dir}/policy.all</java.security.policy> - <log4j.configuration>${deploy.dir}/var/config/logging/log4j.properties</log4j.configuration> - <java.net.preferIPv4Stack>true</java.net.preferIPv4Stack> - <default.nic>eth0</default.nic> - <parent.artifactName>bigdata-core</parent.artifactName> - - - <!-- - In the ANT script, hostname is obtained by an exec of the - 'hostname' command. Hard-coding for now. - --> - <hostname>blevine-desktop</hostname> - <test.codebase>http://${hostname}:${test.codebase.port}/jsk-dl.jar</test.codebase> <!-- Not used??? --> - <federation.name>bigdata.test.group-${hostname}</federation.name> + <integ.deploy.dir>${integ.deploy.root.dir}/${integ.bigdata.dependency}-${project.version}</integ.deploy.dir> + + <integ.test.dir>${integ.deploy.dir}/testing</integ.test.dir> + <integ.testScript>${integ.test.dir}/test.xml</integ.testScript> + <integ.basedir>${integ.test.dir}</integ.basedir> + <integ.app.home>${integ.deploy.dir}</integ.app.home> + <integ.deploy.conf.dir>${integ.test.dir}/conf</integ.deploy.conf.dir> + <integ.deploy.lib>${integ.deploy.dir}/lib</integ.deploy.lib> + <integ.deploy.lib.test>${integ.test.dir}/lib-test</integ.deploy.lib.test> + <integ.deploy.lib.dl>${integ.deploy.dir}/lib-dl</integ.deploy.lib.dl> + <integ.test.codebase.dir>${integ.deploy.lib.dl}</integ.test.codebase.dir> + <integ.test.codebase.port>23333</integ.test.codebase.port> + <integ.java.security.policy>${integ.deploy.conf.dir}/policy.all</integ.java.security.policy> + <integ.log4j.configuration>${integ.deploy.dir}/var/config/logging/log4j.properties</integ.log4j.configuration> + <integ.java.net.preferIPv4Stack>true</integ.java.net.preferIPv4Stack> + <integ.default.nic>eth0</integ.default.nic> + <integ.parent.artifactName>bigdata-core</integ.parent.artifactName> + + <!-- Set to empty string to indicate "unset." Application code will set a reasonable default --> + <integ.federation.name></integ.federation.name> </properties> @@ -69,7 +60,7 @@ <artifactId>bigdata-core</artifactId> <classifier>deploy</classifier> <type>tar.gz</type> - <outputDirectory>${deploy.root.dir}</outputDirectory> + <outputDirectory>${integ.deploy.root.dir}</outputDirectory> </artifactItem> </artifactItems> <useSubdirPerArtifact>true</useSubdirPerArtifact> @@ -116,42 +107,34 @@ </excludes> <systemPropertyVariables> - <java.security.policy>${java.security.policy}</java.security.policy> - <java.net.preferIPv4Stack>{java.net.preferIPv4Stack}"</java.net.preferIPv4Stack> - <log4j.configuration>${log4j.configuration}</log4j.configuration> - <!-- ><log4j.debug>true"</log4j.debug> --> + <java.security.policy>${integ.java.security.policy}</java.security.policy> + <java.net.preferIPv4Stack>{integ.java.net.preferIPv4Stack}"</java.net.preferIPv4Stack> + <log4j.configuration>${integ.log4j.configuration}</log4j.configuration> - <basedir>${basedir}</basedir> <!-- Tells the unit tests where the ant script is, so they can find resources. --> - <app.home>${app.home}</app.home> <!-- This is the deployment directory, easily accessed by the DataFinder class. --> - <log4j.path>${log4j.configuration}</log4j.path> - <default.nic>${default.nic}</default.nic> - - <!-- Jini group name - <federation.name>${federation.name}</federation.name> --> - - <!-- TODO !!!!!! - <property key="java.class.path" value="${junit.classpath.text}" /> - --> - - <classserver.jar>${deploy.lib}/classserver.jar</classserver.jar> - <colt.jar>${deploy.lib}/colt.jar</colt.jar> - <ctc_utils.jar>${deploy.lib}/ctc_utils.jar</ctc_utils.jar> - <cweb-commons.jar>${deploy.lib}/cweb-commons.jar</cweb-commons.jar> - <cweb-extser.jar>${deploy.lib}/cweb-extser.jar</cweb-extser.jar> - <highscalelib.jar>${deploy.lib}/highscalelib.jar</highscalelib.jar> - <dsiutils.jar>${deploy.lib}/dsiutils.jar</dsiutils.jar> - <lgplutils.jar>${deploy.lib}/lgplutils.jar</lgplutils.jar> - <fastutil.jar>${deploy.lib}/fastutil.jar</fastutil.jar> - <icu4j.jar>${deploy.lib}/icu4j.jar</icu4j.jar> - <jsk-lib.jar>${deploy.lib}/jsk-lib.jar</jsk-lib.jar> - <jsk-platform.jar>${deploy.lib}jsk-platform.jar</jsk-platform.jar> - <log4j.jar>${deploy.lib}/log4j.jar</log4j.jar> - <iris.jar>${deploy.lib}/iris.jar</iris.jar> - <jgrapht.jar>${deploy.lib}/jgrapht.jar</jgrapht.jar> - <openrdf-sesame.jar>${deploy.lib}/openrdf-sesame.jar</openrdf-sesame.jar> - <slf4j.jar>${deploy.lib}/slf4j.jar</slf4j.jar> - <nxparser.jar>${deploy.lib}/nxparser.jar</nxparser.jar> - <zookeeper.jar>${deploy.lib}/zookeeper.jar</zookeeper.jar> + <basedir>${integ.basedir}</basedir> <!-- Tells the unit tests where the ant script is, so they can find resources. --> + <app.home>${integ.app.home}</app.home> <!-- This is the deployment directory, easily accessed by the DataFinder class. --> + <log4j.path>${integ.log4j.configuration}</log4j.path> + <default.nic>${integ.default.nic}</default.nic> + <federation.name>${integ.federation.name}</federation.name> + <classserver.jar>${integ.deploy.lib}/classserver.jar</classserver.jar> + <colt.jar>${integ.deploy.lib}/colt.jar</colt.jar> + <ctc_utils.jar>${integ.deploy.lib}/ctc_utils.jar</ctc_utils.jar> + <cweb-commons.jar>${integ.deploy.lib}/cweb-commons.jar</cweb-commons.jar> + <cweb-extser.jar>${integ.deploy.lib}/cweb-extser.jar</cweb-extser.jar> + <highscalelib.jar>${integ.deploy.lib}/highscalelib.jar</highscalelib.jar> + <dsiutils.jar>${integ.deploy.lib}/dsiutils.jar</dsiutils.jar> + <lgplutils.jar>${integ.deploy.lib}/lgplutils.jar</lgplutils.jar> + <fastutil.jar>${integ.deploy.lib}/fastutil.jar</fastutil.jar> + <icu4j.jar>${integ.deploy.lib}/icu4j.jar</icu4j.jar> + <jsk-lib.jar>${integ.deploy.lib}/jsk-lib.jar</jsk-lib.jar> + <jsk-platform.jar>${integ.deploy.lib}jsk-platform.jar</jsk-platform.jar> + <log4j.jar>${integ.deploy.lib}/log4j.jar</log4j.jar> + <iris.jar>${integ.deploy.lib}/iris.jar</iris.jar> + <jgrapht.jar>${integ.deploy.lib}/jgrapht.jar</jgrapht.jar> + <openrdf-sesame.jar>${integ.deploy.lib}/openrdf-sesame.jar</openrdf-sesame.jar> + <slf4j.jar>${integ.deploy.lib}/slf4j.jar</slf4j.jar> + <nxparser.jar>${integ.deploy.lib}/nxparser.jar</nxparser.jar> + <zookeeper.jar>${integ.deploy.lib}/zookeeper.jar</zookeeper.jar> </systemPropertyVariables> </configuration> <executions> @@ -173,8 +156,7 @@ <phase>pre-integration-test</phase> <configuration> <tasks> - <echo message="testscript = ${testScript}" /> - <ant antfile="${testScript}" target="startTestServices" useNativeBasedir="true" inheritAll="false"/> + <ant antfile="${project.build.testOutputDirectory}/services.xml" target="start" useNativeBasedir="true" inheritAll="true"/> </tasks> </configuration> <goals> @@ -188,7 +170,7 @@ <configuration> <tasks> <echo message="testscript = ${testScript}" /> - <ant antfile="${testScript}" target="stopTestServices" useNativeBasedir="true" inheritAll="false"/> + <ant antfile="${project.build.testOutputDirectory}/services.xml" target="stop" useNativeBasedir="true" inheritAll="true"/> </tasks> </configuration> <goals> Added: branches/maven_scaleout/bigdata-integ/src/test/resources/services.xml =================================================================== --- branches/maven_scaleout/bigdata-integ/src/test/resources/services.xml (rev 0) +++ branches/maven_scaleout/bigdata-integ/src/test/resources/services.xml 2010-09-23 20:22:50 UTC (rev 3619) @@ -0,0 +1,104 @@ +<project name="bigdata-integration-lookup-starter" default="help" basedir="."> +<!-- + <property name="integ.deploy.dir" location="${basedir}/.." /> + <property name="integ.app.home" location="${deploy.dir}" /> + <property name="integ.deploy.conf.dir" location="${deploy.dir}/conf" /> + <property name="integ.deploy.lib" location="${deploy.dir}/lib" /> + <property name="integ.deploy.lib.test" location="${deploy.dir}/testing/lib-test" /> + <property name="integ.deploy.lib.dl" location="${deploy.dir}/lib-dl" /> + <property name="integ.test.codebase.dir" location="${deploy.lib.dl}" /> + <property name="integ.test.codebase.port" value="23333" /> + <property name="integ.java.security.policy" location="conf/policy.all" /> + <property name="integ.log4j.configuration" location="${deploy.dir}/var/config/logging/log4j.properties" /> + <property name="integ.java.net.preferIPv4Stack" value="true" /> + <property name="integ.default.nic" value="eth0" /> + <property name="integ.parent.artifactName" value="bigdata-core" /> +--> + + <!-- Set to the empty string to indicate "unset". Application code will determine correct + default value. + <property name="integ.federation.name" value="" /> + --> + + <target name="help"> + <echo level="error" message="This script must be run with either the 'start' or 'stop' targets" /> + <antcall target="dumpProps" /> + </target> + + <target name="dumpProps"> + <echo message="Application properties:\n" /> + <echoproperties prefix="integ." /> + </target> + + <target name="start"> + <echo message="Starting support services..." /> + <antcall target="dumpProps" /> + <antcall target="startHttpd" /> + <antcall target="startLookup" /> + </target> + + <target name="stop"> + <echo message="Stopping support services..." /> + <antcall target="dumpProps" /> + <antcall target="stopLookup" /> + <antcall target="stopHttpd" /> + </target> + + <target name="startHttpd"> + <echo message="Starting class(http) service..." /> + <java jar="${integ.deploy.lib}/classserver.jar" fork="true" spawn="true"> + <arg value="-verbose" /> + <arg value="-stoppable" /> + <arg line="-port ${integ.test.codebase.port}" /> + <arg line="-dir '${integ.test.codebase.dir}'" /> + </java> + </target> + + <target name="stopHttpd"> + <echo message="Stopping class(http) service..." /> + <java jar="${integ.deploy.lib}/classserver.jar" fork="true" spawn="false" failonerror="true"> + <arg line="-port ${integ.test.codebase.port}" /> + <arg line="-dir '${integ.test.codebase.dir}'" /> + <arg value="-stop" /> + </java> + </target> + + <target name="startLookup"> + <echo message="Starting lookup service..." /> + <java jar="${integ.deploy.lib}/${integ.parent.artifactName}-lookupstarter.jar" fork="true" spawn="true"> + <sysproperty key="app.home" value="${integ.app.home}" /> + <sysproperty key="jini.lib" value="${integ.deploy.lib}" /> + <sysproperty key="jini.lib.dl" value="${integ.deploy.lib.dl}" /> + <sysproperty key="java.security.policy" value="${integ.java.security.policy}" /> + <sysproperty key="java.security.debug" value="off" /> + <sysproperty key="java.protocol.handler.pkgs" value="net.jini.url" /> + <sysproperty key="log4j.configuration" value="${integ.log4j.configuration}" /> + <sysproperty key="codebase.port" value="${integ.test.codebase.port}" /> + <sysproperty key="java.net.preferIPv4Stack" value="${integ.java.net.preferIPv4Stack}" /> + <sysproperty key="federation.name" value="${integ.federation.name}" /> + <sysproperty key="default.nic" value="${integ.default.nic}" /> + </java> + </target> + + <target name="stopLookup"> + <echo message="Stopping lookup service..." /> + <java jar="${integ.deploy.lib}/${integ.parent.artifactName}-lookupstarter.jar" fork="true" spawn="false" failonerror="true"> + <sysproperty key="app.home" value="${integ.app.home}" /> + <sysproperty key="jini.lib" value="${integ.deploy.lib}" /> + <sysproperty key="jini.lib.dl" value="${integ.deploy.lib.dl}" /> + <sysproperty key="java.security.policy" value="${integ.java.security.policy}" /> + <sysproperty key="log4j.configuration" value="${integ.log4j.configuration}" /> + <sysproperty key="java.net.preferIPv4Stack" value="${integ.java.net.preferIPv4Stack}" /> + <sysproperty key="federation.name" value="${integ.federation.name}" /> + <sysproperty key="default.nic" value="${integ.default.nic}" /> + <arg value="-stop" /> + </java> + </target> + + <target name="clean-sparql-test-suite" description="delete the files unpacked by the Sesame SPARQL test suite."> + <echo>"clearing: ${java.io.tmpdir}/sparql-*"</echo> + <delete verbose="true"> + <dirset dir="${java.io.tmpdir}" includes="sparql-*" /> + </delete> + </target> +</project> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ble...@us...> - 2010-09-24 13:51:41
|
Revision: 3621 http://bigdata.svn.sourceforge.net/bigdata/?rev=3621&view=rev Author: blevine218 Date: 2010-09-24 13:51:34 +0000 (Fri, 24 Sep 2010) Log Message: ----------- untar tarball during the package phase so it happens just before the pre-integration-test phase Modified Paths: -------------- branches/maven_scaleout/bigdata-integ/pom.xml branches/maven_scaleout/bigdata-integ/src/test/resources/services.xml Modified: branches/maven_scaleout/bigdata-integ/pom.xml =================================================================== --- branches/maven_scaleout/bigdata-integ/pom.xml 2010-09-24 13:38:31 UTC (rev 3620) +++ branches/maven_scaleout/bigdata-integ/pom.xml 2010-09-24 13:51:34 UTC (rev 3621) @@ -9,6 +9,11 @@ <groupId>com.bigdata</groupId> <artifactId>bigdata-integration-test</artifactId> <name>bigdata Integration Tests</name> + + <!-- + Note: Most properties include the "integ." prefix so that they + can displayed easily using the ANT <echoproperties> task in the services.xml script + --> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> @@ -22,7 +27,7 @@ <integ.deploy.dir>${integ.deploy.root.dir}/${integ.bigdata.dependency}-${project.version}</integ.deploy.dir> <integ.test.dir>${integ.deploy.dir}/testing</integ.test.dir> - <integ.testScript>${integ.test.dir}/test.xml</integ.testScript> + <integ.testScript>${project.build.testOutputDirectory}/services.xml</integ.testScript> <integ.basedir>${integ.test.dir}</integ.basedir> <integ.app.home>${integ.deploy.dir}</integ.app.home> <integ.deploy.conf.dir>${integ.test.dir}/conf</integ.deploy.conf.dir> @@ -50,6 +55,11 @@ <executions> <execution> <id>unpack</id> + + <!-- Bound to the package phase so that we untar the tarball just + before the pre-integration-test phase --> + <phase>package</phase> + <goals> <goal>unpack</goal> </goals> @@ -156,7 +166,7 @@ <phase>pre-integration-test</phase> <configuration> <tasks> - <ant antfile="${project.build.testOutputDirectory}/services.xml" target="start" useNativeBasedir="true" inheritAll="true"/> + <ant antfile="${integ.testScript}" target="start" useNativeBasedir="true" inheritAll="true"/> </tasks> </configuration> <goals> @@ -169,8 +179,7 @@ <phase>post-integration-test</phase> <configuration> <tasks> - <echo message="testscript = ${testScript}" /> - <ant antfile="${project.build.testOutputDirectory}/services.xml" target="stop" useNativeBasedir="true" inheritAll="true"/> + <ant antfile="${integ.testScript}" target="stop" useNativeBasedir="true" inheritAll="true"/> </tasks> </configuration> <goals> Modified: branches/maven_scaleout/bigdata-integ/src/test/resources/services.xml =================================================================== --- branches/maven_scaleout/bigdata-integ/src/test/resources/services.xml 2010-09-24 13:38:31 UTC (rev 3620) +++ branches/maven_scaleout/bigdata-integ/src/test/resources/services.xml 2010-09-24 13:51:34 UTC (rev 3621) @@ -26,8 +26,10 @@ </target> <target name="dumpProps"> - <echo message="Application properties:\n" /> + <echo message="Application properties:" /> + <echo message="-----------------------" /> <echoproperties prefix="integ." /> + <echo message="-----------------------" /> </target> <target name="start"> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |