Search in sources :

Example 6 with BatchInserter

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

the class TestLuceneBatchInsert method indexNumbers.

@Test
public void indexNumbers() throws Exception {
    BatchInserter inserter = new BatchInserterImpl(new File(PATH, "8").getAbsolutePath());
    BatchInserterIndexProvider provider = new LuceneBatchInserterIndexProvider(inserter);
    BatchInserterIndex index = provider.nodeIndex("mine", EXACT_CONFIG);
    long id = inserter.createNode(null);
    Map<String, Object> props = new HashMap<String, Object>();
    props.put("key", 123L);
    index.add(id, props);
    index.flush();
    assertEquals(1, index.get("key", 123L).size());
    assertEquals(1, index.get("key", "123").size());
    provider.shutdown();
    inserter.shutdown();
}
Also used : BatchInserter(org.neo4j.kernel.impl.batchinsert.BatchInserter) BatchInserterImpl(org.neo4j.kernel.impl.batchinsert.BatchInserterImpl) BatchInserterIndexProvider(org.neo4j.graphdb.index.BatchInserterIndexProvider) HashMap(java.util.HashMap) BatchInserterIndex(org.neo4j.graphdb.index.BatchInserterIndex) File(java.io.File) Test(org.junit.Test)

Example 7 with BatchInserter

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

the class TestLuceneBatchInsert method testInsertionSpeed.

@Ignore
@Test
public void testInsertionSpeed() {
    BatchInserter inserter = new BatchInserterImpl(new File(PATH, "3").getAbsolutePath());
    BatchInserterIndexProvider provider = new LuceneBatchInserterIndexProvider(inserter);
    BatchInserterIndex index = provider.nodeIndex("yeah", EXACT_CONFIG);
    index.setCacheCapacity("key", 1000000);
    long t = currentTimeMillis();
    for (int i = 0; i < 1000000; i++) {
        Map<String, Object> properties = map("key", "value" + i);
        long id = inserter.createNode(properties);
        index.add(id, properties);
    }
    System.out.println("insert:" + (currentTimeMillis() - t));
    index.flush();
    t = currentTimeMillis();
    for (int i = 0; i < 1000000; i++) {
        count((Iterator<Long>) index.get("key", "value" + i));
    }
    System.out.println("get:" + (currentTimeMillis() - t));
}
Also used : BatchInserter(org.neo4j.kernel.impl.batchinsert.BatchInserter) BatchInserterImpl(org.neo4j.kernel.impl.batchinsert.BatchInserterImpl) BatchInserterIndexProvider(org.neo4j.graphdb.index.BatchInserterIndexProvider) BatchInserterIndex(org.neo4j.graphdb.index.BatchInserterIndex) File(java.io.File) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with BatchInserter

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

the class TestBatchInsert method testSimple.

@Test
public void testSimple() {
    BatchInserter graphDb = newBatchInserter();
    long node1 = graphDb.createNode(null);
    long node2 = graphDb.createNode(null);
    long rel1 = graphDb.createRelationship(node1, node2, RelTypes.BATCH_TEST, null);
    SimpleRelationship rel = graphDb.getRelationshipById(rel1);
    assertEquals(rel.getStartNode(), node1);
    assertEquals(rel.getEndNode(), node2);
    assertEquals(RelTypes.BATCH_TEST.name(), rel.getType().name());
    graphDb.shutdown();
}
Also used : BatchInserter(org.neo4j.kernel.impl.batchinsert.BatchInserter) SimpleRelationship(org.neo4j.kernel.impl.batchinsert.SimpleRelationship) Test(org.junit.Test)

Example 9 with BatchInserter

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

the class TestBatchInsert method testWithGraphDbService.

@Test
public void testWithGraphDbService() {
    BatchInserter batchInserter = newBatchInserter();
    GraphDatabaseService graphDb = batchInserter.getGraphDbService();
    Node startNode = graphDb.createNode();
    setProperties(startNode);
    Node[] endNodes = new Node[25];
    Set<Relationship> rels = new HashSet<Relationship>();
    for (int i = 0; i < 25; i++) {
        endNodes[i] = graphDb.createNode();
        setProperties(endNodes[i]);
        Relationship rel = startNode.createRelationshipTo(endNodes[i], relTypeArray[i % 5]);
        rels.add(rel);
        setProperties(rel);
    }
    for (Relationship rel : startNode.getRelationships()) {
        assertTrue(rels.contains(rel));
        assertEquals(rel.getStartNode(), startNode);
    }
    setProperties(startNode);
    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) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with BatchInserter

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

the class ImdbExampleTest method batchInsert.

@Test
public void batchInsert() {
    // START SNIPPET: batchInsert
    BatchInserter inserter = new BatchInserterImpl("target/neo4jdb-batchinsert");
    BatchInserterIndexProvider indexProvider = new LuceneBatchInserterIndexProvider(inserter);
    BatchInserterIndex actors = indexProvider.nodeIndex("actors", MapUtil.stringMap("type", "exact"));
    actors.setCacheCapacity("name", 100000);
    Map<String, Object> properties = MapUtil.map("name", "Keanu Reeves");
    long node = inserter.createNode(properties);
    actors.add(node, properties);
    // Make sure to shut down the index provider
    indexProvider.shutdown();
    inserter.shutdown();
// END SNIPPET: batchInsert
}
Also used : BatchInserter(org.neo4j.kernel.impl.batchinsert.BatchInserter) BatchInserterImpl(org.neo4j.kernel.impl.batchinsert.BatchInserterImpl) BatchInserterIndexProvider(org.neo4j.graphdb.index.BatchInserterIndexProvider) LuceneBatchInserterIndexProvider(org.neo4j.index.impl.lucene.LuceneBatchInserterIndexProvider) LuceneBatchInserterIndexProvider(org.neo4j.index.impl.lucene.LuceneBatchInserterIndexProvider) BatchInserterIndex(org.neo4j.graphdb.index.BatchInserterIndex) 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