Search in sources :

Example 1 with BatchInserter

use of org.neo4j.kernel.impl.batchinsert.BatchInserter in project graphdb by neo4j-attic.

the class TestBatchInsert method testBadStuff.

@Test
public void testBadStuff() {
    BatchInserter graphDb = newBatchInserter();
    long startNode = graphDb.createNode(properties);
    try {
        graphDb.createRelationship(startNode, startNode, relTypeArray[0], properties);
        fail("Could create relationship with same start and end node");
    } catch (IllegalArgumentException e) {
    // good
    } finally {
        graphDb.shutdown();
    }
}
Also used : BatchInserter(org.neo4j.kernel.impl.batchinsert.BatchInserter) Test(org.junit.Test)

Example 2 with BatchInserter

use of org.neo4j.kernel.impl.batchinsert.BatchInserter in project graphdb by neo4j-attic.

the class TestBatchInsert method testMore.

@Test
public void testMore() {
    BatchInserter graphDb = newBatchInserter();
    long startNode = graphDb.createNode(properties);
    long[] endNodes = new long[25];
    Set<Long> rels = new HashSet<Long>();
    for (int i = 0; i < 25; i++) {
        endNodes[i] = graphDb.createNode(properties);
        rels.add(graphDb.createRelationship(startNode, endNodes[i], relTypeArray[i % 5], properties));
    }
    for (SimpleRelationship rel : graphDb.getRelationships(startNode)) {
        assertTrue(rels.contains(rel.getId()));
        assertEquals(rel.getStartNode(), startNode);
    }
    graphDb.setNodeProperties(startNode, properties);
    graphDb.shutdown();
}
Also used : BatchInserter(org.neo4j.kernel.impl.batchinsert.BatchInserter) SimpleRelationship(org.neo4j.kernel.impl.batchinsert.SimpleRelationship) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with BatchInserter

use of org.neo4j.kernel.impl.batchinsert.BatchInserter 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 4 with BatchInserter

use of org.neo4j.kernel.impl.batchinsert.BatchInserter 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 5 with BatchInserter

use of org.neo4j.kernel.impl.batchinsert.BatchInserter in project graphdb by neo4j-attic.

the class TestLuceneBatchInsert method testNumericValues.

@Test
public void testNumericValues() {
    String path = new File(PATH, "7").getAbsolutePath();
    BatchInserter inserter = new BatchInserterImpl(path);
    BatchInserterIndexProvider provider = new LuceneBatchInserterIndexProvider(inserter);
    BatchInserterIndex index = provider.nodeIndex("mine", EXACT_CONFIG);
    long node1 = inserter.createNode(null);
    index.add(node1, map("number", numeric(45)));
    long node2 = inserter.createNode(null);
    index.add(node2, map("number", numeric(21)));
    assertContains(index.query("number", newIntRange("number", 21, 50, true, true)), node1, node2);
    provider.shutdown();
    inserter.shutdown();
    GraphDatabaseService db = new EmbeddedGraphDatabase(path);
    Node n1 = db.getNodeById(node1);
    Node n2 = db.getNodeById(node2);
    Index<Node> idx = db.index().forNodes("mine");
    assertContains(idx.query("number", newIntRange("number", 21, 45, false, true)), n1);
    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) BatchInserterIndexProvider(org.neo4j.graphdb.index.BatchInserterIndexProvider) BatchInserterIndex(org.neo4j.graphdb.index.BatchInserterIndex) Node(org.neo4j.graphdb.Node) File(java.io.File) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)16 BatchInserter (org.neo4j.kernel.impl.batchinsert.BatchInserter)16 BatchInserterImpl (org.neo4j.kernel.impl.batchinsert.BatchInserterImpl)11 BatchInserterIndex (org.neo4j.graphdb.index.BatchInserterIndex)10 File (java.io.File)9 BatchInserterIndexProvider (org.neo4j.graphdb.index.BatchInserterIndexProvider)9 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)7 Node (org.neo4j.graphdb.Node)7 EmbeddedGraphDatabase (org.neo4j.kernel.EmbeddedGraphDatabase)5 SimpleRelationship (org.neo4j.kernel.impl.batchinsert.SimpleRelationship)4 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Relationship (org.neo4j.graphdb.Relationship)2 Transaction (org.neo4j.graphdb.Transaction)2 ArrayList (java.util.ArrayList)1 Ignore (org.junit.Ignore)1 IndexManager (org.neo4j.graphdb.index.IndexManager)1 LuceneBatchInserterIndexProvider (org.neo4j.index.impl.lucene.LuceneBatchInserterIndexProvider)1