use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.
the class Fixtures method applyTo.
public void applyTo(InProcessServerControls controls) {
GraphDatabaseService db = controls.graph();
for (String fixtureStatement : fixtureStatements) {
try (Transaction tx = db.beginTx()) {
db.execute(fixtureStatement);
tx.success();
}
}
for (Function<GraphDatabaseService, Void> fixtureFunction : fixtureFunctions) {
fixtureFunction.apply(db);
}
}
use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.
the class InProcessBuilderTest method shouldRunBuilderOnExistingStoreDir.
@Test
public void shouldRunBuilderOnExistingStoreDir() throws Exception {
// When
// create graph db with one node upfront
Path dir = Files.createTempDirectory(getClass().getSimpleName() + "_shouldRunBuilderOnExistingStorageDir");
File storeDir = Config.embeddedDefaults(stringMap(DatabaseManagementSystemSettings.data_directory.name(), dir.toString())).get(DatabaseManagementSystemSettings.database_path);
try {
GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabase(storeDir);
try {
db.execute("create ()");
} finally {
db.shutdown();
}
try (ServerControls server = getTestServerBuilder(testDir.directory()).copyFrom(dir.toFile()).newServer()) {
// Then
try (Transaction tx = server.graph().beginTx()) {
ResourceIterable<Node> allNodes = Iterables.asResourceIterable(server.graph().getAllNodes());
assertTrue(Iterables.count(allNodes) > 0);
// When: create another node
server.graph().createNode();
tx.success();
}
}
// Then: we still only have one node since the server is supposed to work on a copy
db = new TestGraphDatabaseFactory().newEmbeddedDatabase(storeDir);
try {
try (Transaction tx = db.beginTx()) {
assertEquals(1, Iterables.count(db.getAllNodes()));
tx.success();
}
} finally {
db.shutdown();
}
} finally {
FileUtils.forceDelete(dir.toFile());
}
}
use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.
the class CdTest method createNodeWithSomeSubNodes.
private Node createNodeWithSomeSubNodes(String... names) {
GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
try (Transaction tx = db.beginTx()) {
Node root = db.createNode();
for (String name : names) {
Node node = db.createNode();
node.setProperty("name", name);
root.createRelationshipTo(node, MyRelTypes.TEST);
}
tx.success();
return root;
}
}
use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.
the class TestBackup method shouldIncrementallyBackupDenseNodes.
@Test
public void shouldIncrementallyBackupDenseNodes() throws Exception {
GraphDatabaseService db = startGraphDatabase(serverPath, true);
try {
createInitialDataset(db);
OnlineBackup backup = OnlineBackup.from("127.0.0.1");
backup.full(backupPath.getPath());
DbRepresentation representation = addLotsOfData(db);
backup.incremental(backupPath.getPath());
assertEquals(representation, getDbRepresentation());
} finally {
db.shutdown();
}
}
use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.
the class TestBackup method backupIndexWithNoCommits.
@Test
public void backupIndexWithNoCommits() throws Exception {
GraphDatabaseService db = null;
try {
db = getEmbeddedTestDataBaseService();
try (Transaction transaction = db.beginTx()) {
db.index().forNodes("created-no-commits");
transaction.success();
}
OnlineBackup backup = OnlineBackup.from("127.0.0.1");
backup.full(backupPath.getPath());
assertTrue("Should be consistent", backup.isConsistent());
assertTrue(backup.isConsistent());
} finally {
if (db != null) {
db.shutdown();
}
}
}
Aggregations