Search in sources :

Example 51 with GraphDatabaseService

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);
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction)

Example 52 with GraphDatabaseService

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());
    }
}
Also used : Path(java.nio.file.Path) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) JsonNode(org.codehaus.jackson.JsonNode) Node(org.neo4j.graphdb.Node) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) File(java.io.File) Test(org.junit.Test)

Example 53 with GraphDatabaseService

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;
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node)

Example 54 with GraphDatabaseService

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();
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) DbRepresentation(org.neo4j.test.DbRepresentation) Test(org.junit.Test)

Example 55 with GraphDatabaseService

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();
        }
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) Test(org.junit.Test)

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