Skip to content

Commit

Permalink
Merge pull request #280 from lqst/test_speedup
Browse files Browse the repository at this point in the history
Let's make unit tests run faster
  • Loading branch information
jbarrasa authored Nov 1, 2022
2 parents 7bdd301 + 720623a commit 4fc9451
Show file tree
Hide file tree
Showing 14 changed files with 908 additions and 1,367 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# neosemantics (n10s)
![n10s Logo](https://guides.neo4j.com/rdf/n10s.png) neosemantics is a plugin that enables the **use of RDF in Neo4j**. [RDF is a W3C standard model](https://www.w3.org/RDF/) for data interchange. Some key features of n10s are:


* **Store RDF data in Neo4j** in a
lossless manner (imported RDF can subsequently be exported without losing a single triple in the process).
* On-demand **export property graph data** from Neo4j *as RDF*.
Expand Down
1 change: 0 additions & 1 deletion src/test/java/n10s/ModelTestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public static boolean compareModels(String expected, RDFFormat formatExpected, S

Model expectedModel = createModel(expected, formatExpected);
Model actualModel = createModel(actual, formatActual);

return Models.isomorphic(expectedModel, actualModel);
}

Expand Down
380 changes: 147 additions & 233 deletions src/test/java/n10s/RDFExportTest.java

Large diffs are not rendered by default.

407 changes: 147 additions & 260 deletions src/test/java/n10s/RDFProceduresTest.java

Large diffs are not rendered by default.

143 changes: 68 additions & 75 deletions src/test/java/n10s/aggregate/CollectTriplesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import n10s.rdf.load.RDFLoadProcedures;
import n10s.rdf.stream.RDFStreamProcedures;
import org.eclipse.rdf4j.rio.RDFFormat;
import org.junit.Rule;
import org.junit.Test;
import org.junit.*;
import org.neo4j.driver.*;
import org.neo4j.driver.exceptions.DatabaseException;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.harness.junit.rule.Neo4jRule;

Expand Down Expand Up @@ -63,106 +63,99 @@ public class CollectTriplesTest {
" skos:prefLabel \"Business Administration and Finance Theory\" ;\n" +
" a <http://permid.org/ontology/person/Major> .";

@Rule
public Neo4jRule neo4j = new Neo4jRule()
public static Driver driver;

@ClassRule
public static Neo4jRule neo4j = new Neo4jRule()
.withProcedure(RDFStreamProcedures.class)
.withProcedure(RDFLoadProcedures.class)
.withProcedure(GraphConfigProcedures.class)
.withProcedure(RDFExportProcedures.class)
.withProcedure(NsPrefixDefProcedures.class)
.withAggregationFunction(CollectTriples.class);

@Test
public void testCollectTriplesBasic() throws Exception {
try (Driver driver = GraphDatabase.driver(neo4j.boltURI(),
Config.builder().withoutEncryption().build())) {

Session session = driver.session();
Result results = session.run("CALL n10s.rdf.stream.inline('"+ TURTLE_FRAGMENT +"', 'Turtle') " +
" yield subject, predicate, object, isLiteral, literalType, literalLang "
+ " return n10s.rdf.collect(subject, predicate, object, isLiteral, literalType, literalLang) as rdf");
assertEquals(true, results.hasNext());
assertTrue(ModelTestUtils
.compareModels(results.next().get("rdf").asString(),
RDFFormat.NTRIPLES,TURTLE_FRAGMENT,RDFFormat.TURTLE));

@BeforeClass
public static void init() {
driver = GraphDatabase.driver(neo4j.boltURI(),
Config.builder().withoutEncryption().build());
}

@Before
public void cleanDatabase() {
driver.session().run("match (n) detach delete n").consume();
driver.session().run("drop constraint n10s_unique_uri if exists").consume();
}

}
@Test
public void testCollectTriplesBasic() throws Exception {
Session session = driver.session();
Result results = session.run("CALL n10s.rdf.stream.inline('"+ TURTLE_FRAGMENT +"', 'Turtle') " +
" yield subject, predicate, object, isLiteral, literalType, literalLang "
+ " return n10s.rdf.collect(subject, predicate, object, isLiteral, literalType, literalLang) as rdf");
assertEquals(true, results.hasNext());
assertTrue(ModelTestUtils
.compareModels(results.next().get("rdf").asString(),
RDFFormat.NTRIPLES,TURTLE_FRAGMENT,RDFFormat.TURTLE));
}

@Test
public void testCollectTriplesPostFilter() throws Exception {
try (Driver driver = GraphDatabase.driver(neo4j.boltURI(),
Config.builder().withoutEncryption().build())) {

Session session = driver.session();
Result results = session.run(
"call n10s.rdf.stream.fetch('" + CollectTriplesTest.class.getClassLoader()
.getResource("100k.nt")
.toURI() + "',\"N-Triples\" ,{ limit: 999999}) yield subject, predicate, object\n" +
"where predicate = \"http://www.w3.org/2004/02/skos/core#prefLabel\" and " +
"object contains \"Business Administration and Finance\"\n" +
"with collect(subject) as indivList \n" +
"call n10s.rdf.stream.fetch('"+ CollectTriplesTest.class.getClassLoader()
.getResource("100k.nt")
.toURI() + "',\"N-Triples\" ,{ limit: 999999}) yield subject, predicate, object, isLiteral, literalType, literalLang\n" +
"where subject in indivList\n" +
"return n10s.rdf.collect(subject, predicate, object, isLiteral, literalType, literalLang) as rdf");
assertEquals(true, results.hasNext());
assertTrue(ModelTestUtils
.compareModels(results.next().get("rdf").asString(),
RDFFormat.NTRIPLES,TURTLE_FRAGMENT_2,RDFFormat.TURTLE));



}
Session session = driver.session();
Result results = session.run(
"call n10s.rdf.stream.fetch('" + CollectTriplesTest.class.getClassLoader()
.getResource("100k.nt")
.toURI() + "',\"N-Triples\" ,{ limit: 999999}) yield subject, predicate, object\n" +
"where predicate = \"http://www.w3.org/2004/02/skos/core#prefLabel\" and " +
"object contains \"Business Administration and Finance\"\n" +
"with collect(subject) as indivList \n" +
"call n10s.rdf.stream.fetch('"+ CollectTriplesTest.class.getClassLoader()
.getResource("100k.nt")
.toURI() + "',\"N-Triples\" ,{ limit: 999999}) yield subject, predicate, object, isLiteral, literalType, literalLang\n" +
"where subject in indivList\n" +
"return n10s.rdf.collect(subject, predicate, object, isLiteral, literalType, literalLang) as rdf");
assertEquals(true, results.hasNext());
assertTrue(ModelTestUtils
.compareModels(results.next().get("rdf").asString(),
RDFFormat.NTRIPLES,TURTLE_FRAGMENT_2,RDFFormat.TURTLE));
}

@Test
public void testCollectTriplesDataTypes() throws Exception {
try (Driver driver = GraphDatabase.driver(neo4j.boltURI(),
Config.builder().withoutEncryption().build())) {
Session session = driver.session();
Result results = session.run("CALL n10s.rdf.stream.fetch('"+ CollectTriplesTest.class.getClassLoader()
.getResource("datetime/datetime-and-other.ttl")
.toURI() +"', 'Turtle') " +
" yield subject, predicate, object, isLiteral, literalType, literalLang "
+ " return n10s.rdf.collect(subject, predicate, object, isLiteral, literalType, literalLang) as rdf");
assertEquals(true, results.hasNext());

Session session = driver.session();
Result results = session.run("CALL n10s.rdf.stream.fetch('"+ CollectTriplesTest.class.getClassLoader()
.getResource("datetime/datetime-and-other.ttl")
.toURI() +"', 'Turtle') " +
" yield subject, predicate, object, isLiteral, literalType, literalLang "
+ " return n10s.rdf.collect(subject, predicate, object, isLiteral, literalType, literalLang) as rdf");
assertEquals(true, results.hasNext());

String fileAsString = new String ( Files.readAllBytes( Paths.get(CollectTriplesTest.class.getClassLoader()
.getResource("datetime/datetime-and-other.ttl").toURI()) ) );

String fileAsString = new String ( Files.readAllBytes( Paths.get(CollectTriplesTest.class.getClassLoader()
.getResource("datetime/datetime-and-other.ttl").toURI()) ) );

assertTrue(ModelTestUtils
.compareModels(results.next().get("rdf").asString(),
RDFFormat.NTRIPLES, fileAsString,RDFFormat.TURTLE));
}
}
assertTrue(ModelTestUtils
.compareModels(results.next().get("rdf").asString(),
RDFFormat.NTRIPLES, fileAsString,RDFFormat.TURTLE));
}

@Test
public void testCollectTriplesDataTypesTurtle() throws Exception {
try (Driver driver = GraphDatabase.driver(neo4j.boltURI(),
Config.builder().withoutEncryption().build())) {
Session session = driver.session();
Result results = session.run("CALL n10s.rdf.stream.fetch('"+ CollectTriplesTest.class.getClassLoader()
.getResource("datetime/datetime-and-other.ttl")
.toURI() +"', 'Turtle') " +
" yield subject, predicate, object, isLiteral, literalType, literalLang "
+ " return n10s.rdf.collect.ttl(subject, predicate, object, isLiteral, literalType, literalLang) as rdf");
assertEquals(true, results.hasNext());

Session session = driver.session();
Result results = session.run("CALL n10s.rdf.stream.fetch('"+ CollectTriplesTest.class.getClassLoader()
.getResource("datetime/datetime-and-other.ttl")
.toURI() +"', 'Turtle') " +
" yield subject, predicate, object, isLiteral, literalType, literalLang "
+ " return n10s.rdf.collect.ttl(subject, predicate, object, isLiteral, literalType, literalLang) as rdf");
assertEquals(true, results.hasNext());

String fileAsString = new String ( Files.readAllBytes( Paths.get(CollectTriplesTest.class.getClassLoader()
.getResource("datetime/datetime-and-other.ttl").toURI()) ) );

String fileAsString = new String ( Files.readAllBytes( Paths.get(CollectTriplesTest.class.getClassLoader()
.getResource("datetime/datetime-and-other.ttl").toURI()) ) );
assertTrue(ModelTestUtils
.compareModels(results.next().get("rdf").asString(),
RDFFormat.TURTLE, fileAsString,RDFFormat.TURTLE));

assertTrue(ModelTestUtils
.compareModels(results.next().get("rdf").asString(),
RDFFormat.TURTLE, fileAsString,RDFFormat.TURTLE));
}
}

@Test
Expand Down
Loading

0 comments on commit 4fc9451

Please sign in to comment.