Search in sources :

Example 56 with GraphDatabaseAPI

use of org.neo4j.kernel.internal.GraphDatabaseAPI in project neo4j-documentation by neo4j.

the class DocsExecutionEngineTest method createStuff.

private static DocsSetup createStuff() {
    EphemeralFileSystemAbstraction fs = new EphemeralFileSystemAbstraction();
    GraphDatabaseService graph = new TestEnterpriseGraphDatabaseFactory().setFileSystem(fs).newImpermanentDatabase();
    GraphDatabaseCypherService database = new GraphDatabaseCypherService(graph);
    GraphDatabaseCypherService queryService = new GraphDatabaseCypherService(graph);
    GraphDatabaseAPI graphAPI = (GraphDatabaseAPI) graph;
    DependencyResolver resolver = graphAPI.getDependencyResolver();
    LogService logService = resolver.resolveDependency(LogService.class);
    Monitors monitors = resolver.resolveDependency(Monitors.class);
    LogProvider logProvider = logService.getInternalLogProvider();
    CommunityCompatibilityFactory inner = new CommunityCompatibilityFactory(queryService, monitors, logProvider);
    EnterpriseCompatibilityFactory compatibilityFactory = new EnterpriseCompatibilityFactory(inner, queryService, monitors, logProvider);
    NullLogProvider logProvider1 = NullLogProvider.getInstance();
    DocsExecutionEngine engine = new DocsExecutionEngine(database, logProvider1, compatibilityFactory);
    PropertyContainerLocker locker = new PropertyContainerLocker();
    TransactionalContextFactory contextFactory = Neo4jTransactionalContextFactory.create(database, locker);
    return new DocsSetup() {

        @Override
        public GraphDatabaseCypherService database() {
            return database;
        }

        @Override
        public DocsExecutionEngine engine() {
            return engine;
        }

        @Override
        public TransactionalContextFactory contextFactory() {
            return contextFactory;
        }
    };
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) TestEnterpriseGraphDatabaseFactory(org.neo4j.test.TestEnterpriseGraphDatabaseFactory) EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) GraphDatabaseCypherService(org.neo4j.cypher.internal.javacompat.GraphDatabaseCypherService) EnterpriseCompatibilityFactory(org.neo4j.cypher.internal.EnterpriseCompatibilityFactory) TransactionalContextFactory(org.neo4j.kernel.impl.query.TransactionalContextFactory) Neo4jTransactionalContextFactory(org.neo4j.kernel.impl.query.Neo4jTransactionalContextFactory) DependencyResolver(org.neo4j.graphdb.DependencyResolver) LogProvider(org.neo4j.logging.LogProvider) NullLogProvider(org.neo4j.logging.NullLogProvider) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) PropertyContainerLocker(org.neo4j.kernel.impl.coreapi.PropertyContainerLocker) Monitors(org.neo4j.kernel.monitoring.Monitors) CommunityCompatibilityFactory(org.neo4j.cypher.internal.CommunityCompatibilityFactory) NullLogProvider(org.neo4j.logging.NullLogProvider) DocsExecutionEngine(org.neo4j.cypher.internal.DocsExecutionEngine) LogService(org.neo4j.kernel.impl.logging.LogService)

Example 57 with GraphDatabaseAPI

use of org.neo4j.kernel.internal.GraphDatabaseAPI in project neo4j-documentation by neo4j.

the class ShellDocTest method testDumpDatabase.

@Test
public void testDumpDatabase() throws Exception {
    GraphDatabaseAPI db = (GraphDatabaseAPI) new TestGraphDatabaseFactory().newImpermanentDatabase();
    final GraphDatabaseShellServer server = new GraphDatabaseShellServer(db, false);
    Documenter doc = new Documenter("database dump", server);
    doc.add("create index on :Person(name);", "", "create an index");
    doc.add("create (m:Person:Hacker {name:'Mattias'}), (m)-[:KNOWS]->(m);", "", "create one labeled node and a relationship");
    doc.add("dump", "begin" + lineSeparator() + "create index on :`Person`(`name`);" + lineSeparator() + "commit" + lineSeparator() + "begin" + lineSeparator() + "create (_0:`Person`:`Hacker` {`name`:\"Mattias\"})" + lineSeparator() + "create (_0)-[:`KNOWS`]->(_0)" + lineSeparator() + ";" + lineSeparator() + "commit", "Export the whole database including indexes");
    doc.run();
    server.shutdown();
    db.shutdown();
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) GraphDatabaseShellServer(org.neo4j.shell.kernel.GraphDatabaseShellServer) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) Test(org.junit.Test)

Example 58 with GraphDatabaseAPI

use of org.neo4j.kernel.internal.GraphDatabaseAPI in project neo4j-documentation by neo4j.

the class ShellDocTest method testRemoveReferenceNode.

@Test
public void testRemoveReferenceNode() throws Exception {
    GraphDatabaseAPI db = (GraphDatabaseAPI) new TestGraphDatabaseFactory().newImpermanentDatabase();
    final GraphDatabaseShellServer server = new GraphDatabaseShellServer(db, false);
    Documenter doc = new Documenter("sample session", server);
    doc.add("mknode --cd", "", "Create a node");
    doc.add("pwd", "", "where are we?");
    doc.add("set name \"Jon\"", "", "On the current node, set the key \"name\" to value \"Jon\"");
    doc.add("match (n) where id(n) = 0 return n;", "Jon", "send a cypher query");
    doc.add("mkrel -c -d i -t LIKES --np \"{'app':'foobar'}\"", "", "make an incoming relationship of type " + "LIKES, create the end node with the node properties specified.");
    doc.add("ls", "1", "where are we?");
    doc.add("cd 1", "", "change to the newly created node");
    doc.add("ls -avr", "LIKES", "list relationships, including relationship id");
    doc.add("mkrel -c -d i -t KNOWS --np \"{'name':'Bob'}\"", "", "create one more KNOWS relationship and the " + "end node");
    doc.add("pwd", "0", "print current history stack");
    doc.add("ls -avr", "KNOWS", "verbose list relationships");
    db.beginTx();
    doc.run();
    doc.add("rmnode -f 0", "", "delete node 0");
    doc.add("cd 0", "", "cd back to node 0");
    doc.add("pwd", "(?)", "the node doesn't exist now");
    doc.add("mknode --cd --np \"{'name':'Neo'}\"", "", "create a new node and go to it");
    server.shutdown();
    db.shutdown();
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) GraphDatabaseShellServer(org.neo4j.shell.kernel.GraphDatabaseShellServer) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) Test(org.junit.Test)

Example 59 with GraphDatabaseAPI

use of org.neo4j.kernel.internal.GraphDatabaseAPI in project neo4j-apoc-procedures by neo4j-contrib.

the class PregelTest method runPageRank.

@Test
public void runPageRank() throws Exception {
    GraphDatabaseAPI db = (GraphDatabaseAPI) new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig(GraphDatabaseSettings.pagecache_memory, "100M").newGraphDatabase();
    int nodeCount = 100_001;
    int[] degrees = new int[nodeCount];
    createRankTestData(db, nodeCount, degrees);
    long start = System.currentTimeMillis();
    Pregel pregel = new Pregel(db, guard).withBatchSize(10000);
    PrimitiveLongIterator nodes;
    try (Transaction tx = db.beginTx()) {
        ReadOperations reads = pregel.statement().readOperations();
        nodes = reads.nodesGetAll();
        tx.success();
    }
    float[] ranks = pregel.runProgram2(nodes, new Pregel.AllExpander(), new PageRankProgram(nodeCount, degrees, new float[nodeCount], new LinkedList<>()));
    long time = System.currentTimeMillis() - start;
    Arrays.sort(ranks);
    // System.err.println("PageRank Program ran for "+nodeCount+" nodes in "+time+" ms. 10 hightest Ranks "+Arrays.toString(Arrays.copyOfRange(ranks,ranks.length-10,ranks.length)));
    db.shutdown();
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) ReadOperations(org.neo4j.kernel.api.ReadOperations) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) Test(org.junit.Test)

Example 60 with GraphDatabaseAPI

use of org.neo4j.kernel.internal.GraphDatabaseAPI in project neo4j by neo4j.

the class IndexingServiceIntegrationTest method tracePageCacheAccessOnIndexUpdatesApply.

@ParameterizedTest
@MethodSource("parameters")
void tracePageCacheAccessOnIndexUpdatesApply(GraphDatabaseSettings.SchemaIndex schemaIndex) throws KernelException {
    setUp(schemaIndex);
    var marker = Label.label("marker");
    var propertyName = "property";
    var testConstraint = "testConstraint";
    try (Transaction transaction = database.beginTx()) {
        transaction.schema().constraintFor(marker).withName(testConstraint).assertPropertyIsUnique(propertyName).create();
        transaction.commit();
    }
    var dependencyResolver = ((GraphDatabaseAPI) database).getDependencyResolver();
    var indexingService = dependencyResolver.resolveDependency(IndexingService.class);
    var pageCacheTracer = dependencyResolver.resolveDependency(PageCacheTracer.class);
    try (Transaction transaction = database.beginTx()) {
        var kernelTransaction = ((InternalTransaction) transaction).kernelTransaction();
        var indexDescriptor = kernelTransaction.schemaRead().indexGetForName(testConstraint);
        try (var cursorContext = new CursorContext(pageCacheTracer.createPageCursorTracer("tracePageCacheAccessOnIndexUpdatesApply"))) {
            Iterable<IndexEntryUpdate<IndexDescriptor>> updates = List.of(add(1, indexDescriptor, longValue(4)));
            indexingService.applyUpdates(updates, cursorContext);
            PageCursorTracer cursorTracer = cursorContext.getCursorTracer();
            assertEquals(5L, cursorTracer.pins());
            assertEquals(5L, cursorTracer.unpins());
            assertEquals(2L, cursorTracer.hits());
            assertEquals(3L, cursorTracer.faults());
        }
    }
}
Also used : IndexEntryUpdate(org.neo4j.storageengine.api.IndexEntryUpdate) PageCursorTracer(org.neo4j.io.pagecache.tracing.cursor.PageCursorTracer) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) CursorContext(org.neo4j.io.pagecache.context.CursorContext) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)262 Test (org.junit.Test)91 Test (org.junit.jupiter.api.Test)88 Transaction (org.neo4j.graphdb.Transaction)87 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)61 Node (org.neo4j.graphdb.Node)38 Path (java.nio.file.Path)30 TestDatabaseManagementServiceBuilder (org.neo4j.test.TestDatabaseManagementServiceBuilder)30 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)28 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)26 File (java.io.File)25 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)24 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)19 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)18 DependencyResolver (org.neo4j.graphdb.DependencyResolver)17 Label (org.neo4j.graphdb.Label)15 PageCache (org.neo4j.io.pagecache.PageCache)15 Config (org.neo4j.kernel.configuration.Config)15 DatabaseStateService (org.neo4j.dbms.DatabaseStateService)14 IOException (java.io.IOException)11