Search in sources :

Example 26 with BatchInserter

use of org.neo4j.unsafe.batchinsert.BatchInserter in project neo4j by neo4j.

the class BatchInsertTest method shouldCreateDeferredSchemaIndexesInEmptyDatabase.

@Test
public void shouldCreateDeferredSchemaIndexesInEmptyDatabase() throws Exception {
    // GIVEN
    BatchInserter inserter = newBatchInserter();
    // WHEN
    IndexDefinition definition = inserter.createDeferredSchemaIndex(label("Hacker")).on("handle").create();
    // THEN
    assertEquals("Hacker", definition.getLabel().name());
    assertEquals(asCollection(iterator("handle")), Iterables.asCollection(definition.getPropertyKeys()));
    inserter.shutdown();
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) Test(org.junit.Test)

Example 27 with BatchInserter

use of org.neo4j.unsafe.batchinsert.BatchInserter in project neo4j by neo4j.

the class LegacyIndexTest method legacyIndexPopulationWithBunchOfFields.

@Test(timeout = TEST_TIMEOUT)
public void legacyIndexPopulationWithBunchOfFields() throws Exception {
    BatchInserter batchNode = BatchInserters.inserter(directory.graphDbDir());
    LuceneBatchInserterIndexProvider provider = new LuceneBatchInserterIndexProvider(batchNode);
    try {
        BatchInserterIndex batchIndex = provider.nodeIndex("node_auto_index", stringMap(IndexManager.PROVIDER, "lucene", "type", "fulltext"));
        Map<String, Object> properties = new HashMap<>();
        for (int i = 0; i < 2000; i++) {
            properties.put(Integer.toString(i), RandomStringUtils.randomAlphabetic(200));
        }
        long node = batchNode.createNode(properties, Label.label("NODE"));
        batchIndex.add(node, properties);
    } finally {
        provider.shutdown();
        batchNode.shutdown();
    }
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) LuceneBatchInserterIndexProvider(org.neo4j.index.lucene.unsafe.batchinsert.LuceneBatchInserterIndexProvider) HashMap(java.util.HashMap) BatchInserterIndex(org.neo4j.unsafe.batchinsert.BatchInserterIndex) Test(org.junit.Test)

Example 28 with BatchInserter

use of org.neo4j.unsafe.batchinsert.BatchInserter in project neo4j by neo4j.

the class GeoDataGenerator method generate.

public void generate(File storeDir) throws IOException {
    try (DefaultFileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction()) {
        BatchInserter inserter = BatchInserters.inserter(storeDir.getAbsoluteFile(), fileSystem);
        Grid grid = new Grid();
        try {
            for (int i = 0; i < numberOfNodes; i++) {
                grid.createNodeAtRandomLocation(random, inserter);
            }
            for (int i = 0; i < numberOfConnections; i++) {
                grid.createConnection(random, inserter);
            }
        } finally {
            inserter.shutdown();
        }
    }
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction)

Example 29 with BatchInserter

use of org.neo4j.unsafe.batchinsert.BatchInserter in project neo4j by neo4j.

the class BatchInsertTest method testSimple.

@Test
public void testSimple() throws Exception {
    BatchInserter graphDb = globalInserter;
    long node1 = graphDb.createNode(null);
    long node2 = graphDb.createNode(null);
    long rel1 = graphDb.createRelationship(node1, node2, RelTypes.BATCH_TEST, null);
    BatchRelationship rel = graphDb.getRelationshipById(rel1);
    assertEquals(rel.getStartNode(), node1);
    assertEquals(rel.getEndNode(), node2);
    assertEquals(RelTypes.BATCH_TEST.name(), rel.getType().name());
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) BatchRelationship(org.neo4j.unsafe.batchinsert.BatchRelationship) Test(org.junit.Test)

Example 30 with BatchInserter

use of org.neo4j.unsafe.batchinsert.BatchInserter in project neo4j by neo4j.

the class BatchInsertTest method shouldGetNodeLabels.

@Test
public void shouldGetNodeLabels() throws Exception {
    // GIVEN
    BatchInserter inserter = globalInserter;
    long node = inserter.createNode(map(), Labels.FIRST, Labels.THIRD);
    // WHEN
    Iterable<String> labelNames = asNames(inserter.getNodeLabels(node));
    // THEN
    assertEquals(asSet(Labels.FIRST.name(), Labels.THIRD.name()), Iterables.asSet(labelNames));
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) Test(org.junit.Test)

Aggregations

BatchInserter (org.neo4j.unsafe.batchinsert.BatchInserter)60 Test (org.junit.Test)58 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)9 File (java.io.File)8 ConstraintViolationException (org.neo4j.graphdb.ConstraintViolationException)8 Transaction (org.neo4j.graphdb.Transaction)8 Label (org.neo4j.graphdb.Label)5 HashMap (java.util.HashMap)4 IndexPopulator (org.neo4j.kernel.api.index.IndexPopulator)4 SchemaIndexProvider (org.neo4j.kernel.api.index.SchemaIndexProvider)4 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)4 IndexSamplingConfig (org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig)4 BatchRelationship (org.neo4j.unsafe.batchinsert.BatchRelationship)4 HashSet (java.util.HashSet)3 Matchers.anyLong (org.mockito.Matchers.anyLong)3 Node (org.neo4j.graphdb.Node)3 PropertyAccessor (org.neo4j.kernel.api.index.PropertyAccessor)3 NeoStores (org.neo4j.kernel.impl.store.NeoStores)3 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)3 Set (java.util.Set)2