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;
}
};
}
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();
}
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();
}
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();
}
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());
}
}
}
Aggregations