Search in sources :

Example 31 with GraphDatabaseService

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

the class OnlineBackup method full.

public OnlineBackup full(String targetDirectory) {
    if (directoryContainsDb(targetDirectory)) {
        throw new RuntimeException(targetDirectory + " already contains a database");
    }
    //                                                     TODO OMG this is ugly
    BackupClient client = new BackupClient(hostNameOrIp, port, new NotYetExistingGraphDatabase(targetDirectory));
    try {
        Response<Void> response = client.fullBackup(new ToFileStoreWriter(targetDirectory));
        GraphDatabaseService targetDb = startTemporaryDb(targetDirectory);
        try {
            unpackResponse(response, targetDb, MasterUtil.txHandlerForFullCopy());
        } finally {
            targetDb.shutdown();
        }
    } finally {
        client.shutdown();
        // TODO This is also ugly
        StringLogger.close(targetDirectory);
    }
    return this;
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) ToFileStoreWriter(org.neo4j.com.ToFileStoreWriter)

Example 32 with GraphDatabaseService

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

the class TestBatchInsert method testGraphDbServiceGetRelationships.

@Test
public void testGraphDbServiceGetRelationships() {
    BatchInserter batchInserter = newBatchInserter();
    GraphDatabaseService graphDb = batchInserter.getGraphDbService();
    Node startNode = graphDb.createNode();
    for (int i = 0; i < 5; i++) {
        Node endNode = graphDb.createNode();
        startNode.createRelationshipTo(endNode, relTypeArray[i]);
    }
    try {
        startNode.createRelationshipTo(startNode, relTypeArray[0]);
        fail("Could create relationship with same start and end node");
    } catch (IllegalArgumentException e) {
    // ok good
    }
    for (int i = 0; i < 5; i++) {
        assertTrue(startNode.getSingleRelationship(relTypeArray[i], Direction.OUTGOING) != null);
    }
    for (int i = 0; i < 5; i++) {
        Iterator<Relationship> relItr = startNode.getRelationships(relTypeArray[i], Direction.OUTGOING).iterator();
        relItr.next();
        assertTrue(!relItr.hasNext());
    }
    for (int i = 0; i < 5; i++) {
        Iterator<Relationship> relItr = startNode.getRelationships(relTypeArray[i]).iterator();
        relItr.next();
        assertTrue(!relItr.hasNext());
    }
    graphDb.shutdown();
}
Also used : BatchInserter(org.neo4j.kernel.impl.batchinsert.BatchInserter) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) SimpleRelationship(org.neo4j.kernel.impl.batchinsert.SimpleRelationship) Test(org.junit.Test)

Example 33 with GraphDatabaseService

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

the class TestNeo4j method testMultipleNeos.

@Test
public void testMultipleNeos() {
    String storePath = getStorePath("test-neo2");
    deleteFileOrDirectory(storePath);
    GraphDatabaseService graphDb2 = new EmbeddedGraphDatabase(storePath);
    Transaction tx2 = graphDb2.beginTx();
    getGraphDb().createNode();
    graphDb2.createNode();
    tx2.success();
    tx2.finish();
    graphDb2.shutdown();
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) Test(org.junit.Test)

Example 34 with GraphDatabaseService

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

the class TestProveFiveBillion method proveIt.

@Test
public void proveIt() throws Exception {
    deleteFileOrDirectory(new File(PATH));
    BatchInserter inserter = new BatchInserterImpl(PATH);
    // Create one giant chain of nodes n1->n2->n3 where each node will have
    // an int property and each rel a long string property. This will yield
    // 5b nodes/relationships, 10b property records and 5b dynamic records.
    // Start off by creating the first 4 billion (or so) entities with the
    // batch inserter just to speed things up a little
    long first = inserter.getReferenceNode();
    int max = (int) pow(2, 32) - 1000;
    Map<String, Object> nodeProperties = map("number", 123);
    Map<String, Object> relationshipProperties = map("string", "A long string, which is longer than shortstring boundaries");
    long i = 0;
    for (; i < max; i++) {
        long second = inserter.createNode(nodeProperties);
        inserter.createRelationship(first, second, TYPE, relationshipProperties);
        if (i > 0 && i % 1000000 == 0)
            System.out.println((i / 1000000) + "M");
        first = second;
    }
    inserter.shutdown();
    System.out.println("Switch to embedded");
    // Then create the rest with embedded graph db.
    GraphDatabaseService db = new EmbeddedGraphDatabase(PATH);
    Node firstNode = db.getNodeById(first);
    Transaction tx = db.beginTx();
    for (; i < 5000000000L; i++) {
        Node secondNode = db.createNode();
        firstNode.createRelationshipTo(secondNode, TYPE);
        firstNode = secondNode;
        if (i % 100000 == 0) {
            tx.success();
            tx.finish();
            System.out.println((i / 1000000) + "M");
            tx = db.beginTx();
        }
    }
    // Here we have a huge db. Loop through it and count chain length.
    /*        long count = 0;
        Node node = db.getReferenceNode();
        while ( true )
        {
            Relationship relationship = node.getSingleRelationship( TYPE, Direction.OUTGOING );
            if ( relationship == null )
            {
                break;
            }
        }
        System.out.println( count );
        assertTrue( count > 4900000000L );*/
    db.shutdown();
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) BatchInserter(org.neo4j.kernel.impl.batchinsert.BatchInserter) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) BatchInserterImpl(org.neo4j.kernel.impl.batchinsert.BatchInserterImpl) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) File(java.io.File) Test(org.junit.Test)

Example 35 with GraphDatabaseService

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

the class TestCacheTypes method testWeakRefCache.

@Test
public void testWeakRefCache() {
    GraphDatabaseService db = newDb("weak");
    assertEquals(CacheType.weak, ((EmbeddedGraphDatabase) db).getConfig().getGraphDbModule().getNodeManager().getCacheType());
    db.shutdown();
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) 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