Search in sources :

Example 1 with ExecutionMonitor

use of org.neo4j.unsafe.impl.batchimport.staging.ExecutionMonitor in project neo4j by neo4j.

the class ParallelBatchImporterTest method shouldImportCsvData.

@Test
public void shouldImportCsvData() throws Exception {
    // GIVEN
    ExecutionMonitor processorAssigner = eagerRandomSaturation(config.maxNumberOfProcessors());
    final BatchImporter inserter = new ParallelBatchImporter(directory.graphDbDir(), fileSystemRule.get(), config, NullLogService.getInstance(), processorAssigner, EMPTY, Config.empty(), getFormat());
    boolean successful = false;
    IdGroupDistribution groups = new IdGroupDistribution(NODE_COUNT, 5, random.random());
    long nodeRandomSeed = random.nextLong(), relationshipRandomSeed = random.nextLong();
    try {
        // WHEN
        inserter.doImport(Inputs.input(nodes(nodeRandomSeed, NODE_COUNT, inputIdGenerator, groups), relationships(relationshipRandomSeed, RELATIONSHIP_COUNT, inputIdGenerator, groups), idMapper, idGenerator, /*insanely high bad tolerance, but it will actually never be that many*/
        silentBadCollector(RELATIONSHIP_COUNT)));
        // THEN
        GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder(directory.graphDbDir()).newGraphDatabase();
        try (Transaction tx = db.beginTx()) {
            inputIdGenerator.reset();
            verifyData(NODE_COUNT, RELATIONSHIP_COUNT, db, groups, nodeRandomSeed, relationshipRandomSeed);
            tx.success();
        } finally {
            db.shutdown();
        }
        assertConsistent(directory.graphDbDir());
        successful = true;
    } finally {
        if (!successful) {
            File failureFile = directory.file("input");
            try (PrintStream out = new PrintStream(failureFile)) {
                out.println("Seed used in this failing run: " + random.seed());
                out.println(inputIdGenerator);
                inputIdGenerator.reset();
                for (InputNode node : nodes(nodeRandomSeed, NODE_COUNT, inputIdGenerator, groups)) {
                    out.println(node);
                }
                for (InputRelationship relationship : relationships(relationshipRandomSeed, RELATIONSHIP_COUNT, inputIdGenerator, groups)) {
                    out.println(relationship);
                }
                out.println();
                out.println("Processor assignments");
                out.println(processorAssigner.toString());
            }
            System.err.println("Additional debug information stored in " + failureFile);
        }
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) PrintStream(java.io.PrintStream) InputNode(org.neo4j.unsafe.impl.batchimport.input.InputNode) InputRelationship(org.neo4j.unsafe.impl.batchimport.input.InputRelationship) Transaction(org.neo4j.graphdb.Transaction) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) ExecutionMonitor(org.neo4j.unsafe.impl.batchimport.staging.ExecutionMonitor) File(java.io.File) Test(org.junit.Test)

Aggregations

File (java.io.File)1 PrintStream (java.io.PrintStream)1 Test (org.junit.Test)1 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)1 Transaction (org.neo4j.graphdb.Transaction)1 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)1 InputNode (org.neo4j.unsafe.impl.batchimport.input.InputNode)1 InputRelationship (org.neo4j.unsafe.impl.batchimport.input.InputRelationship)1 ExecutionMonitor (org.neo4j.unsafe.impl.batchimport.staging.ExecutionMonitor)1