Skip to content

Commit

Permalink
added local file tests - small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
vga91 committed Dec 9, 2022
1 parent 4d14a8d commit 3d226f2
Show file tree
Hide file tree
Showing 10 changed files with 65,304 additions and 16 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/apoc/export/graphml/ExportGraphML.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public Stream<ProgressInfo> file(@Name("urlOrBinaryFile") Object urlOrBinaryFile

if (exportConfig.storeNodeIds()) graphMLReader.storeNodeIds();

graphMLReader.parseXML(FileUtils.readerFor(urlOrBinaryFile, exportConfig.getCompressionAlgo()));
graphMLReader.parseXML(FileUtils.readerFor(urlOrBinaryFile, exportConfig.getCompressionAlgo()), terminationGuard);
return reporter.getTotal();
});
return Stream.of(result);
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/apoc/export/graphml/XmlGraphMLReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import apoc.util.JsonUtil;
import org.apache.commons.lang3.StringUtils;
import org.neo4j.graphdb.*;
import org.neo4j.procedure.TerminationGuard;

import javax.xml.namespace.QName;
import javax.xml.stream.XMLEventReader;
Expand Down Expand Up @@ -214,6 +215,7 @@ public long parseXML(Reader input) throws XMLStreamException {
try (BatchTransaction tx = new BatchTransaction(db, batchSize * 10, reporter)) {

while (reader.hasNext()) {
terminationGuard.check();
XMLEvent event;
try {
event = (XMLEvent) reader.next();
Expand Down
9 changes: 2 additions & 7 deletions core/src/test/java/apoc/export/BigGraphTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,11 @@ public static void setUp() throws Exception {
@Test
public void testTerminateExportCsv() {
checkTerminationGuard(db, "CALL apoc.export.csv.all('testTerminate.csv',{bulkImport: true})");

checkTerminationGuard(db, "CALL apoc.import.csv([{fileName: 'testTerminate.nodes.Other.csv', labels: ['Other']}], [], {})");
}

@Test
public void testTerminateExportGraphMl() {
public void testTerminateExportImportGraphMl() {
checkTerminationGuard(db, "CALL apoc.export.graphml.all('testTerminate.graphml', {})");

checkTerminationGuard(db, "CALL apoc.import.graphml('testTerminate.graphml', {})");
}

@Test
Expand All @@ -77,9 +73,8 @@ public void testTerminateExportCypher() {
}

@Test
public void testTerminateExportJson() {
public void testTerminateExportImportLoadJson() {
checkTerminationGuard(db, "CALL apoc.export.json.all('testTerminate.json',{})");
checkTerminationGuard(db, "CALL apoc.import.json('testTerminate.json',{})");
}

@Test
Expand Down
6 changes: 3 additions & 3 deletions core/src/test/java/apoc/export/csv/ImportCsvTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import static apoc.util.BinaryTestUtil.fileToBinary;
import static apoc.util.CompressionConfig.COMPRESSION;
import static apoc.util.MapUtil.map;
import static apoc.util.TransactionTestUtil.checkTerminationGuard;
import static java.util.Arrays.asList;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -186,10 +187,9 @@ public void testImportCsvLargeFile() {

@Test
public void testImportCsvTerminate() {
TestUtil.testCall(db, "CALL apoc.import.csv([{fileName: $nodeFile, labels: ['Person']}], [], $config)",
checkTerminationGuard(db, "CALL apoc.import.csv([{fileName: $nodeFile, labels: ['Person']}], [], $config)",
map("nodeFile", "file:/largeFile.csv",
"config", map("batchSize", 100L)),
(r) -> assertEquals(664850L, r.get("nodes")));
"config", map("batchSize", 100L)));
}

@Test
Expand Down
8 changes: 8 additions & 0 deletions core/src/test/java/apoc/export/graphml/ExportGraphMLTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import static apoc.util.BinaryTestUtil.fileToBinary;
import static apoc.util.MapUtil.map;
import static apoc.util.TestUtil.isRunningInCI;
import static apoc.util.TransactionTestUtil.checkTerminationGuard;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
Expand Down Expand Up @@ -267,6 +268,13 @@ public void testImportGraphMLLargeFile() {
});
}

@Test
public void testImportGraphMLTerminate() {
final String file = ClassLoader.getSystemResource("largeFile.graphml").toString();
checkTerminationGuard(db, 5L, "CALL apoc.import.graphml($file,{readLabels:true})",
map("file", file));
}

@Test
public void testImportGraphMLWithEdgeWithoutDataKeys() throws Exception {
db.executeTransactionally("MATCH (n) DETACH DELETE n");
Expand Down
7 changes: 7 additions & 0 deletions core/src/test/java/apoc/export/json/ImportJsonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import static apoc.util.BinaryTestUtil.fileToBinary;
import static apoc.util.CompressionConfig.COMPRESSION;
import static apoc.util.MapUtil.map;
import static apoc.util.TransactionTestUtil.checkTerminationGuard;
import static java.lang.String.format;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
Expand Down Expand Up @@ -306,6 +307,12 @@ public void shouldImportAllJsonFromBinary() {
assertionsAllJsonDbResult();
}

@Test
public void shouldTerminateImportJson() {
createConstraints(List.of("Movie", "Other", "Person"));
checkTerminationGuard(db, "CALL apoc.import.json('testTerminate.json',{})");
}

private void assertionsAllJsonProgressInfo(Map<String, Object> r, boolean isBinary) {
// then
Assert.assertEquals(isBinary ? null : "all.json", r.get("file"));
Expand Down
8 changes: 5 additions & 3 deletions core/src/test/java/apoc/load/LoadJsonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import static apoc.util.MapUtil.map;
import static apoc.util.TestUtil.testCall;
import static apoc.util.TestUtil.testResult;
import static apoc.util.TransactionTestUtil.checkTerminationGuard;
import static java.util.Arrays.asList;
import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -423,8 +424,9 @@ public void testLoadJsonParams() {
}

@Test
public void shouldTerminateLoadWhenTransactionIsTimedOut() {
final String query = "CALL apoc.load.json('https://github.com/knowitall/yelp-dataset-challenge/blob/master/data/yelp_phoenix_academic_dataset/yelp_academic_dataset_review.json?raw=truehttps://github.com/knowitall/yelp-dataset-challenge/blob/master/data/yelp_phoenix_academic_dataset/yelp_academic_dataset_review.json?raw=true')";
TransactionTestUtil.checkTerminationGuard(db, query);
public void shouldTerminateLoadJson() {
URL url = ClassLoader.getSystemResource("exportJSON/testTerminate.json");
checkTerminationGuard(db, "CALL apoc.load.json($file)",
Map.of("file", url.toString()));
}
}
Loading

0 comments on commit 3d226f2

Please sign in to comment.