Search in sources :

Example 21 with BatchInserter

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

the class BatchInsertTest method setSingleProperty.

@Test
public void setSingleProperty() throws Exception {
    BatchInserter inserter = newBatchInserter();
    long node = inserter.createNode(null);
    String value = "Something";
    String key = "name";
    inserter.setNodeProperty(node, key, value);
    GraphDatabaseService db = switchToEmbeddedGraphDatabaseService(inserter);
    assertThat(getNodeInTx(node, db), inTx(db, hasProperty(key).withValue(value)));
    db.shutdown();
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Test(org.junit.Test)

Example 22 with BatchInserter

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

the class BatchInsertTest method testMore.

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

Example 23 with BatchInserter

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

the class BatchInsertTest method shouldPopulateLabelScanStoreOnShutdown.

@Test
public void shouldPopulateLabelScanStoreOnShutdown() throws Exception {
    // GIVEN
    // -- a database and a mocked label scan store
    UpdateTrackingLabelScanStore labelScanStore = new UpdateTrackingLabelScanStore();
    BatchInserter inserter = newBatchInserterWithLabelScanStore(new ControlledLabelScanStore(labelScanStore));
    // -- and some data that we insert
    long node1 = inserter.createNode(null, Labels.FIRST);
    long node2 = inserter.createNode(null, Labels.SECOND);
    long node3 = inserter.createNode(null, Labels.THIRD);
    long node4 = inserter.createNode(null, Labels.FIRST, Labels.SECOND);
    long node5 = inserter.createNode(null, Labels.FIRST, Labels.THIRD);
    // WHEN we shut down the batch inserter
    inserter.shutdown();
    // THEN the label scan store should receive all the updates.
    // of course, we don't know the label ids at this point, but we're assuming 0..2 (bad boy)
    labelScanStore.assertRecivedUpdate(node1, 0);
    labelScanStore.assertRecivedUpdate(node2, 1);
    labelScanStore.assertRecivedUpdate(node3, 2);
    labelScanStore.assertRecivedUpdate(node4, 0, 1);
    labelScanStore.assertRecivedUpdate(node5, 0, 2);
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) Test(org.junit.Test)

Example 24 with BatchInserter

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

the class BatchInsertTest method shouldReplaceExistingDynamicLabelsWithInlined.

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

Example 25 with BatchInserter

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

the class BatchInsertTest method shouldChangePropertiesInCurrentBatch.

@Test
public void shouldChangePropertiesInCurrentBatch() throws Exception {
    // GIVEN
    BatchInserter inserter = globalInserter;
    Map<String, Object> properties = map("key1", "value1");
    long node = inserter.createNode(properties);
    // WHEN
    properties.put("additionalKey", "Additional value");
    inserter.setNodeProperties(node, properties);
    // THEN
    assertEquals(properties, inserter.getNodeProperties(node));
}
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