Search in sources :

Example 26 with GraphDatabaseService

use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.

the class ExactDepthPathFinder method instantiateTraverser.

@Override
protected Traverser instantiateTraverser(Node start, Node end) {
    GraphDatabaseService db = start.getGraphDatabase();
    TraversalDescription side = db.traversalDescription().breadthFirst().uniqueness(uniqueness).order(new BranchOrderingPolicy() {

        @Override
        public BranchSelector create(TraversalBranch startSource, PathExpander expander) {
            return new LiteDepthFirstSelector(startSource, startThreshold, expander);
        }
    });
    return db.bidirectionalTraversalDescription().startSide(side.expand(expander).evaluator(toDepth(onDepth / 2))).endSide(side.expand(expander.reverse()).evaluator(toDepth(onDepth - onDepth / 2))).collisionEvaluator(atDepth(onDepth)).traverse(start, end);
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) BranchOrderingPolicy(org.neo4j.graphdb.traversal.BranchOrderingPolicy) TraversalDescription(org.neo4j.graphdb.traversal.TraversalDescription) LiteDepthFirstSelector(org.neo4j.graphalgo.impl.util.LiteDepthFirstSelector) PathExpander(org.neo4j.graphdb.PathExpander) TraversalBranch(org.neo4j.graphdb.traversal.TraversalBranch) BranchSelector(org.neo4j.graphdb.traversal.BranchSelector)

Example 27 with GraphDatabaseService

use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.

the class KernelRecoveryTest method shouldHandleWritesProperlyAfterRecovery.

@Test
public void shouldHandleWritesProperlyAfterRecovery() throws Exception {
    // Given
    EphemeralFileSystemAbstraction fs = fsRule.get();
    GraphDatabaseService db = newDB(fs);
    long node1 = createNode(db);
    // And given the power goes out
    EphemeralFileSystemAbstraction crashedFs = fs.snapshot();
    db.shutdown();
    try {
        db = newDB(crashedFs);
        long node2 = createNode(db);
        db.shutdown();
        // Then the logical log should be in sync
        File logFile = new File(storeDir, PhysicalLogFile.DEFAULT_NAME + PhysicalLogFile.DEFAULT_VERSION_SUFFIX + "0");
        assertThat(logEntries(crashedFs, logFile), containsExactly(// Tx before recovery
        startEntry(-1, -1), commandEntry(node1, NodeCommand.class), commandEntry(ReadOperations.ANY_LABEL, NodeCountsCommand.class), commitEntry(2), // Tx after recovery
        startEntry(-1, -1), commandEntry(node2, NodeCommand.class), commandEntry(ReadOperations.ANY_LABEL, NodeCountsCommand.class), commitEntry(3), // checkpoint
        checkPoint(new LogPosition(0, 250))));
    } finally {
        crashedFs.close();
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) File(java.io.File) PhysicalLogFile(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) Test(org.junit.Test)

Example 28 with GraphDatabaseService

use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.

the class RecoveryRequiredCheckerTest method createSomeDataAndCrash.

private FileSystemAbstraction createSomeDataAndCrash(File store, EphemeralFileSystemAbstraction fileSystem) throws IOException {
    final GraphDatabaseService db = new TestGraphDatabaseFactory().setFileSystem(fileSystem).newImpermanentDatabase(store);
    try (Transaction tx = db.beginTx()) {
        db.createNode();
        tx.success();
    }
    EphemeralFileSystemAbstraction snapshot = fileSystem.snapshot();
    db.shutdown();
    return snapshot;
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory)

Example 29 with GraphDatabaseService

use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.

the class BatchInsertTest method setSingleProperty.

@Test
public void setSingleProperty() throws Exception {
    BatchInserter inserter = newBatchInserter();
    long node = inserter.createNode(null);
    String value = "Something";
    String key = "name";
    inserter.setNodeProperty(node, key, value);
    GraphDatabaseService db = switchToEmbeddedGraphDatabaseService(inserter);
    assertThat(getNodeInTx(node, db), inTx(db, hasProperty(key).withValue(value)));
    db.shutdown();
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Test(org.junit.Test)

Example 30 with GraphDatabaseService

use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.

the class BatchInsertTest method switchToEmbeddedGraphDatabaseService.

private GraphDatabaseService switchToEmbeddedGraphDatabaseService(BatchInserter inserter) {
    inserter.shutdown();
    TestGraphDatabaseFactory factory = new TestGraphDatabaseFactory();
    factory.setFileSystem(fileSystemRule.get());
    GraphDatabaseService db = factory.newImpermanentDatabaseBuilder(new File(inserter.getStoreDir())).setConfig(configuration()).newGraphDatabase();
    try (Transaction tx = db.beginTx()) {
        db.schema().awaitIndexesOnline(10, TimeUnit.SECONDS);
        tx.success();
    }
    return db;
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) File(java.io.File)

Aggregations

GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)322 Test (org.junit.Test)225 Transaction (org.neo4j.graphdb.Transaction)182 Node (org.neo4j.graphdb.Node)142 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)77 File (java.io.File)70 Relationship (org.neo4j.graphdb.Relationship)49 EmbeddedGraphDatabase (org.neo4j.kernel.EmbeddedGraphDatabase)32 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)17 Result (org.neo4j.graphdb.Result)14 Label (org.neo4j.graphdb.Label)13 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)12 HashMap (java.util.HashMap)11 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)11 ArrayList (java.util.ArrayList)10 Map (java.util.Map)10 PageCache (org.neo4j.io.pagecache.PageCache)10 DbRepresentation (org.neo4j.test.DbRepresentation)10 GraphDatabaseFactory (org.neo4j.graphdb.factory.GraphDatabaseFactory)9 TransactionFailureException (org.neo4j.graphdb.TransactionFailureException)8