Skip to content
Browse files

Refactored into a more generic version, supporting different sets of …

…tests for different versions, for code compatibility reasons.
  • Loading branch information...
1 parent a21fb6b commit 1db93b25fb4c5c12b1cfebc1632eaa09e7dadb40 @dmontag committed Feb 10, 2011
View
51 build.xml
@@ -1,26 +1,41 @@
<project name="compatibility-tests" xmlns:ivy="antlib:org.apache.ivy.ant">
+ <!--xmlns:artifact="antlib:org.apache.maven.artifact.ant">-->
+
+ <!--<path id="maven-ant-tasks.classpath" path="/Users/david/dev/resources/libs/maven-ant-tasks-2.1.1.jar" />-->
+ <!--<typedef resource="org/apache/maven/artifact/ant/antlib.xml"-->
+ <!--uri="antlib:org.apache.maven.artifact.ant"-->
+ <!--classpathref="maven-ant-tasks.classpath" />-->
<taskdef resource="org/apache/ivy/ant/antlib.xml" uri="antlib:org.apache.ivy.ant">
<classpath>
<fileset dir="/Users/david/dev/resources/libs/ivy/apache-ivy-2.2.0-rc1" includes="*.jar"/>
</classpath>
</taskdef>
+ <property name="dev.version" value="1.3-SNAPSHOT" />
+
<target name="clean" depends="init">
<delete dir="${build.dir}"/>
<delete dir="${lib.dir}"/>
</target>
<target name="init">
- <property name="neo4j.version" value="1.3.M01"/>
+ <fail unless="neo4j.version" message="Neo4j version not set: neo4j.version" />
<property name="build.dir" value="${basedir}/build"/>
<property name="lib.dir" value="${basedir}/lib"/>
- <property name="src.dir" value="${basedir}/src"/>
- <property name="versions.top.dir" value="${build.dir}/db"/>
- <property name="version.dir" value="${versions.top.dir}/${neo4j.version}"/>
+ <property name="src.dir" value="${basedir}/src" />
+ <property name="src.framework.dir" value="${src.dir}/framework"/>
+
+ <condition property="src.version" value="${neo4j.version}">
+ <available file="${src.dir}/versions/${neo4j.version}" type="dir" />
+ </condition>
+ <property name="src.version" value="default" />
+
+ <property name="src.version.dir" value="${src.dir}/versions/${src.version}"/>
+ <property name="db.versions.top.dir" value="${build.dir}/db"/>
+ <property name="db.version.dir" value="${db.versions.top.dir}/${neo4j.version}"/>
<property name="classes.dir" value="${build.dir}/classes"/>
<property name="ivy.retrieve.pattern" value="${lib.dir}/[module]-[artifact]-[revision]-[conf].[ext]"/>
- <property name="ivy.retrieve.storepattern" value="${versions.top.dir}/[artifact].[ext]"/>
<property name="ivy.file" value="${basedir}/neo4j-ivy.xml"/>
<property name="repo.dir" value="repo"/>
<mkdir dir="${repo.dir}"/>
@@ -46,12 +61,17 @@
</target>
<target name="compile" depends="init">
+ <echo message="Using framework src dir: ${src.framework.dir}" />
+ <echo message="Using version src dir: ${src.version.dir}" />
<mkdir dir="${classes.dir}"/>
- <javac classpathref="classpath" srcdir="${src.dir}" destdir="${classes.dir}"/>
+ <javac debug="true" classpathref="classpath" srcdir="${src.framework.dir}" destdir="${classes.dir}" />
+ <javac debug="true" classpathref="classpath" srcdir="${src.version.dir}" destdir="${classes.dir}"/>
<copy todir="${classes.dir}">
- <fileset dir="${src.dir}">
+ <fileset dir="${src.framework.dir}">
+ <include name="**/*" />
+ </fileset>
+ <fileset dir="${src.version.dir}">
<include name="**/*" />
- <exclude name="**/*.java" />
</fileset>
</copy>
</target>
@@ -60,22 +80,25 @@
<!-- Dev -->
<target name="dev-setup">
- <property name="neo4j.version" value="1.3.M01"/>
+ <property name="neo4j.version" value="${dev.version}"/>
<property name="lib.dir" value="${basedir}/dev-lib"/>
+ <delete dir="${lib.dir}" />
</target>
- <target name="retrieve-dev-dependencies" depends="dev-setup,init,retrieve-dependencies"/>
+ <target name="retrieve-dev-dependencies" depends="dev-setup,init,retrieve-dependencies"
+ description="Retrieves the dependencies based on the dev.version property."/>
<!-- Generate -->
<target name="generate-test-graph" depends="init,clean,retrieve-dependencies,compile">
+ <mkdir dir="${db.version.dir}" />
<java classpathref="classpath" classname="org.neo4j.compatibility.Generate" failonerror="true">
- <sysproperty key="version.dir" value="${version.dir}"/>
+ <sysproperty key="version.dir" value="${db.version.dir}"/>
</java>
<property name="version.zip.file" value="${build.dir}/db-${neo4j.version}.zip"/>
<zip destfile="${version.zip.file}">
- <zipfileset prefix="${neo4j.version}" dir="${version.dir}"/>
+ <zipfileset prefix="${neo4j.version}" dir="${db.version.dir}"/>
</zip>
<copy file="${version.zip.file}" todir="${repo.dir}"/>
</target>
@@ -84,13 +107,13 @@
<!-- Verify -->
<target name="unpack-stores">
- <unzip dest="${versions.top.dir}">
+ <unzip dest="${db.versions.top.dir}">
<fileset dir="${repo.dir}" includes="*.zip"/>
</unzip>
</target>
<target name="verify-build" depends="init,clean,retrieve-dependencies,compile,unpack-stores">
- <dirset id="versions.csv" dir="${versions.top.dir}" includes="*"/>
+ <dirset id="versions.csv" dir="${db.versions.top.dir}" includes="*"/>
<pathconvert dirsep="/" pathsep="," property="versions.csv" refid="versions.csv" />
<java classpathref="classpath" classname="org.neo4j.compatibility.Verify" failonerror="true">
<sysproperty key="versions.csv" value="${versions.csv}"/>
View
9 generate-ivy.xml
@@ -1,9 +0,0 @@
-<ivy-module version="2.0">
-
- <info organisation="org.neo4j" module="compatibility-tests" />
-
- <dependencies>
- <dependency org="org.neo4j" name="neo4j" rev="${1.3.M01}" />
- </dependencies>
-
-</ivy-module>
View
5 generate.sh
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+for version in {1.2.M01,1.2.M02,1.2.M03,1.2.M04,1.2.M05,1.2.M06,1.2,1.3.M01}; do
+ ant generate-test-graph -Dneo4j.version=$version
+done
View
1 neo4j-ivy.xml
@@ -8,6 +8,7 @@
<dependencies>
<dependency org="org.neo4j" name="neo4j" rev="${neo4j.version}" conf="default" />
+ <dependency org="junit" name="junit" rev="4.8.1" conf="default" />
</dependencies>
</ivy-module>
View
1 src/META-INF/services/org.neo4j.compatibility.StoreAgent
@@ -1 +0,0 @@
-org.neo4j.compatibility.agents.SimpleGraph
View
18 ...org/neo4j/compatibility/AgentManager.java → ...org/neo4j/compatibility/AgentManager.java
@@ -40,7 +40,23 @@ public void verify( File versionDir )
{
StoreAgent agent = agentEntry.getValue();
String agentName = agentEntry.getKey();
- agent.verify( new File( versionDir, agentName ).getAbsolutePath() );
+ File storePath = new File( versionDir, agentName );
+ if ( storePath.exists() )
+ {
+ try
+ {
+ agent.verify( storePath.getAbsolutePath() );
+ }
+ catch ( Exception e )
+ {
+ System.out.println( String.format( "Failed to verify version: %s with agent: %s", versionDir, agentName ) );
+ e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ }
+ }
+ else
+ {
+ System.out.println( String.format( "Version [%s] missing store for agent [%s]", versionDir, agentName ) );
+ }
}
}
}
View
0 src/org/neo4j/compatibility/Generate.java → ...ork/org/neo4j/compatibility/Generate.java
File renamed without changes.
View
0 src/org/neo4j/compatibility/StoreAgent.java → ...k/org/neo4j/compatibility/StoreAgent.java
File renamed without changes.
View
55 src/framework/org/neo4j/compatibility/Verify.java
@@ -0,0 +1,55 @@
+package org.neo4j.compatibility;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.ServiceLoader;
+
+public class Verify {
+
+ private AgentManager agentManager = new AgentManager();
+ Map<String, Exception> errors = new HashMap<String, Exception>();
+
+ private void run()
+ {
+ String versionsCsv = System.getProperty( "versions.csv" );
+ for ( String versionDir : versionsCsv.split( "," ) )
+ {
+ verifyVersion( versionDir );
+ }
+ }
+
+ private void verifyVersion( String versionDir )
+ {
+ try
+ {
+ agentManager.verify( new File( versionDir ) );
+ }
+ catch ( Exception e )
+ {
+ errors.put( versionDir, e );
+ }
+ }
+
+ private int exit()
+ {
+ if (errors.size() > 0)
+ {
+ for ( Map.Entry<String, Exception> errorEntry : errors.entrySet() )
+ {
+ System.out.println( String.format( "Verification of [%s] encountered an error:", errorEntry.getKey() ) );
+ errorEntry.getValue().printStackTrace( System.out );
+ }
+ return 1;
+ }
+ return 0;
+ }
+
+ public static void main( String[] args )
+ {
+ Verify verify = new Verify();
+ verify.run();
+ System.exit( verify.exit() );
+ }
+
+}
View
36 src/org/neo4j/compatibility/Verify.java
@@ -1,36 +0,0 @@
-package org.neo4j.compatibility;
-
-import java.io.File;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.ServiceLoader;
-
-public class Verify {
-
- private AgentManager agentManager;
-
- public Verify()
- {
- agentManager = new AgentManager();
- }
-
- private void run()
- {
- String versionsCsv = System.getProperty( "versions.csv" );
- for ( String versionDir : versionsCsv.split( "," ) )
- {
- verifyVersion( versionDir );
- }
- }
-
- private void verifyVersion( String versionDir )
- {
- agentManager.verify( new File( versionDir ) );
- }
-
- public static void main( String[] args )
- {
- new Verify().run();
- }
-
-}
View
31 src/org/neo4j/compatibility/agents/SimpleGraph.java
@@ -1,31 +0,0 @@
-package org.neo4j.compatibility.agents;
-
-import org.neo4j.compatibility.StoreAgent;
-import org.neo4j.graphdb.GraphDatabaseService;
-import org.neo4j.graphdb.Transaction;
-import org.neo4j.kernel.EmbeddedGraphDatabase;
-
-public class SimpleGraph implements StoreAgent
-{
- public void generate( String dbPath )
- {
- GraphDatabaseService graphDb = new EmbeddedGraphDatabase( dbPath );
- Transaction tx = graphDb.beginTx();
- try
- {
- graphDb.createNode();
- tx.success();
- }
- finally
- {
- tx.finish();
- }
- graphDb.shutdown();
- System.out.println( "generate" );
- }
-
- public void verify( String dbPath )
- {
- System.out.println( "verifying: " + dbPath );
- }
-}
View
2 src/versions/1.2.M01/META-INF/services/org.neo4j.compatibility.StoreAgent
@@ -0,0 +1,2 @@
+v12M01.agents.SimpleGraph
+v12M01.agents.UnclosedGraph
View
48 src/versions/1.2.M01/v12M01/agents/SimpleGraph.java
@@ -0,0 +1,48 @@
+package v12M01.agents;
+
+import org.neo4j.compatibility.StoreAgent;
+import org.neo4j.graphdb.Direction;
+import org.neo4j.graphdb.DynamicRelationshipType;
+import org.neo4j.graphdb.GraphDatabaseService;
+import org.neo4j.graphdb.Node;
+import org.neo4j.graphdb.RelationshipType;
+import org.neo4j.graphdb.Transaction;
+import org.neo4j.helpers.collection.IteratorUtil;
+import org.neo4j.kernel.EmbeddedGraphDatabase;
+
+import java.util.Arrays;
+import java.util.HashSet;
+
+import static org.junit.Assert.assertEquals;
+
+public class SimpleGraph implements StoreAgent
+{
+ private static final RelationshipType REL_TYPE = DynamicRelationshipType.withName( "REL" );
+
+ public void generate( String dbPath )
+ {
+ GraphDatabaseService graphDb = new EmbeddedGraphDatabase( dbPath );
+ Transaction tx = graphDb.beginTx();
+ try
+ {
+ Node n = graphDb.createNode();
+ n.createRelationshipTo( graphDb.createNode(), REL_TYPE );
+ tx.success();
+ }
+ finally
+ {
+ tx.finish();
+ }
+ graphDb.shutdown();
+ }
+
+ public void verify( String dbPath )
+ {
+ GraphDatabaseService graphDb = new EmbeddedGraphDatabase( dbPath );
+ Node n = graphDb.getNodeById( 1 );
+ Node n2 = n.getSingleRelationship( REL_TYPE, Direction.OUTGOING ).getEndNode();
+ assertEquals( new HashSet<Node>( Arrays.asList( graphDb.getReferenceNode(), n, n2 ) ),
+ IteratorUtil.addToCollection( graphDb.getAllNodes(), new HashSet<Node>() ) );
+ graphDb.shutdown();
+ }
+}
View
51 src/versions/1.2.M01/v12M01/agents/UnclosedGraph.java
@@ -0,0 +1,51 @@
+package v12M01.agents;
+
+import org.neo4j.compatibility.StoreAgent;
+import org.neo4j.graphdb.Direction;
+import org.neo4j.graphdb.DynamicRelationshipType;
+import org.neo4j.graphdb.GraphDatabaseService;
+import org.neo4j.graphdb.Node;
+import org.neo4j.graphdb.Relationship;
+import org.neo4j.graphdb.RelationshipType;
+import org.neo4j.graphdb.Transaction;
+import org.neo4j.helpers.collection.IteratorUtil;
+import org.neo4j.kernel.EmbeddedGraphDatabase;
+
+import java.util.Arrays;
+import java.util.HashSet;
+
+import static org.junit.Assert.assertEquals;
+
+public class UnclosedGraph implements StoreAgent
+{
+ private static final RelationshipType REL_TYPE = DynamicRelationshipType.withName( "REL" );
+
+ public void generate( String dbPath )
+ {
+ GraphDatabaseService graphDb = new EmbeddedGraphDatabase( dbPath );
+ Transaction tx = graphDb.beginTx();
+ try
+ {
+ Node n = graphDb.createNode();
+ Node n2 = graphDb.createNode();
+ Relationship rel = n.createRelationshipTo( n2, REL_TYPE );
+
+ tx.success();
+ }
+ finally
+ {
+ tx.finish();
+ }
+ }
+
+ public void verify( String dbPath )
+ {
+ GraphDatabaseService graphDb = new EmbeddedGraphDatabase( dbPath );
+ Node n = graphDb.getNodeById( 1 );
+ Relationship rel = n.getSingleRelationship( REL_TYPE, Direction.OUTGOING );
+ Node n2 = rel.getEndNode();
+ assertEquals( new HashSet<Node>( Arrays.asList( graphDb.getReferenceNode(), n, n2 ) ),
+ IteratorUtil.addToCollection( graphDb.getAllNodes(), new HashSet<Node>() ) );
+ graphDb.shutdown();
+ }
+}
View
3 src/versions/default/META-INF/services/org.neo4j.compatibility.StoreAgent
@@ -0,0 +1,3 @@
+latest.agents.SimpleGraph
+latest.agents.SimpleIndexingGraph
+latest.agents.UnclosedIndexingGraph
View
48 src/versions/default/latest/agents/SimpleGraph.java
@@ -0,0 +1,48 @@
+package latest.agents;
+
+import org.neo4j.compatibility.StoreAgent;
+import org.neo4j.graphdb.Direction;
+import org.neo4j.graphdb.DynamicRelationshipType;
+import org.neo4j.graphdb.GraphDatabaseService;
+import org.neo4j.graphdb.Node;
+import org.neo4j.graphdb.RelationshipType;
+import org.neo4j.graphdb.Transaction;
+import org.neo4j.helpers.collection.IteratorUtil;
+import org.neo4j.kernel.EmbeddedGraphDatabase;
+
+import java.util.Arrays;
+import java.util.HashSet;
+
+import static org.junit.Assert.assertEquals;
+
+public class SimpleGraph implements StoreAgent
+{
+ private static final RelationshipType REL_TYPE = DynamicRelationshipType.withName( "REL" );
+
+ public void generate( String dbPath )
+ {
+ GraphDatabaseService graphDb = new EmbeddedGraphDatabase( dbPath );
+ Transaction tx = graphDb.beginTx();
+ try
+ {
+ Node n = graphDb.createNode();
+ n.createRelationshipTo( graphDb.createNode(), REL_TYPE );
+ tx.success();
+ }
+ finally
+ {
+ tx.finish();
+ }
+ graphDb.shutdown();
+ }
+
+ public void verify( String dbPath )
+ {
+ GraphDatabaseService graphDb = new EmbeddedGraphDatabase( dbPath );
+ Node n = graphDb.getNodeById( 1 );
+ Node n2 = n.getSingleRelationship( REL_TYPE, Direction.OUTGOING ).getEndNode();
+ assertEquals( new HashSet<Node>( Arrays.asList( graphDb.getReferenceNode(), n, n2 ) ),
+ new HashSet<Node>( IteratorUtil.asCollection( graphDb.getAllNodes() ) ) );
+ graphDb.shutdown();
+ }
+}
View
63 src/versions/default/latest/agents/SimpleIndexingGraph.java
@@ -0,0 +1,63 @@
+package latest.agents;
+
+import org.neo4j.compatibility.StoreAgent;
+import org.neo4j.graphdb.Direction;
+import org.neo4j.graphdb.DynamicRelationshipType;
+import org.neo4j.graphdb.GraphDatabaseService;
+import org.neo4j.graphdb.Node;
+import org.neo4j.graphdb.Relationship;
+import org.neo4j.graphdb.RelationshipType;
+import org.neo4j.graphdb.Transaction;
+import org.neo4j.graphdb.index.Index;
+import org.neo4j.helpers.collection.IteratorUtil;
+import org.neo4j.kernel.EmbeddedGraphDatabase;
+
+import java.util.Arrays;
+import java.util.HashSet;
+
+import static org.junit.Assert.assertEquals;
+
+public class SimpleIndexingGraph implements StoreAgent
+{
+ private static final RelationshipType REL_TYPE = DynamicRelationshipType.withName( "REL" );
+
+ public void generate( String dbPath )
+ {
+ GraphDatabaseService graphDb = new EmbeddedGraphDatabase( dbPath );
+ Index<Node> nodeIndex = graphDb.index().forNodes( "nodes" );
+ Index<Relationship> relationshipIndex = graphDb.index().forRelationships( "relationships" );
+ Transaction tx = graphDb.beginTx();
+ try
+ {
+ Node n = graphDb.createNode();
+ Node n2 = graphDb.createNode();
+ Relationship rel = n.createRelationshipTo( n2, REL_TYPE );
+
+ nodeIndex.add( n, "name", "a" );
+ nodeIndex.add( n2, "name", "b" );
+ relationshipIndex.add( rel, "name", "a" );
+
+ tx.success();
+ }
+ finally
+ {
+ tx.finish();
+ }
+ graphDb.shutdown();
+ }
+
+ public void verify( String dbPath )
+ {
+ GraphDatabaseService graphDb = new EmbeddedGraphDatabase( dbPath );
+ Index<Node> nodeIndex = graphDb.index().forNodes( "nodes" );
+ Index<Relationship> relationshipIndex = graphDb.index().forRelationships( "relationships" );
+
+ Node n = nodeIndex.get( "name", "a" ).getSingle();
+ Node n2 = nodeIndex.get( "name", "b" ).getSingle();
+ Relationship rel = relationshipIndex.get( "name", "a" ).getSingle();
+ assertEquals( n, rel.getStartNode() );
+ assertEquals( n2, rel.getEndNode() );
+
+ graphDb.shutdown();
+ }
+}
View
57 src/versions/default/latest/agents/UnclosedIndexingGraph.java
@@ -0,0 +1,57 @@
+package latest.agents;
+
+import org.neo4j.compatibility.StoreAgent;
+import org.neo4j.graphdb.DynamicRelationshipType;
+import org.neo4j.graphdb.GraphDatabaseService;
+import org.neo4j.graphdb.Node;
+import org.neo4j.graphdb.Relationship;
+import org.neo4j.graphdb.RelationshipType;
+import org.neo4j.graphdb.Transaction;
+import org.neo4j.graphdb.index.Index;
+import org.neo4j.kernel.EmbeddedGraphDatabase;
+
+import static org.junit.Assert.assertEquals;
+
+public class UnclosedIndexingGraph implements StoreAgent
+{
+ private static final RelationshipType REL_TYPE = DynamicRelationshipType.withName( "REL" );
+
+ public void generate( String dbPath )
+ {
+ GraphDatabaseService graphDb = new EmbeddedGraphDatabase( dbPath );
+ Index<Node> nodeIndex = graphDb.index().forNodes( "nodes" );
+ Index<Relationship> relationshipIndex = graphDb.index().forRelationships( "relationships" );
+ Transaction tx = graphDb.beginTx();
+ try
+ {
+ Node n = graphDb.createNode();
+ Node n2 = graphDb.createNode();
+ Relationship rel = n.createRelationshipTo( n2, REL_TYPE );
+
+ nodeIndex.add( n, "name", "a" );
+ nodeIndex.add( n2, "name", "b" );
+ relationshipIndex.add( rel, "name", "a" );
+
+ tx.success();
+ }
+ finally
+ {
+ tx.finish();
+ }
+ }
+
+ public void verify( String dbPath )
+ {
+ GraphDatabaseService graphDb = new EmbeddedGraphDatabase( dbPath );
+ Index<Node> nodeIndex = graphDb.index().forNodes( "nodes" );
+ Index<Relationship> relationshipIndex = graphDb.index().forRelationships( "relationships" );
+
+ Node n = nodeIndex.get( "name", "a" ).getSingle();
+ Node n2 = nodeIndex.get( "name", "b" ).getSingle();
+ Relationship rel = relationshipIndex.get( "name", "a" ).getSingle();
+ assertEquals( n, rel.getStartNode() );
+ assertEquals( n2, rel.getEndNode() );
+
+ graphDb.shutdown();
+ }
+}
View
9 verify-ivy.xml
@@ -1,9 +0,0 @@
-<ivy-module version="2.0">
-
- <info organisation="org.neo4j" module="compatibility-tests" />
-
- <dependencies>
- <dependency org="org.neo4j" name="neo4j" rev="${neo4j.version}" />
- </dependencies>
-
-</ivy-module>
View
3 verify.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+ant verify-build -Dneo4j.version=$1

0 comments on commit 1db93b2

Please sign in to comment.
Something went wrong with that request. Please try again.