Search in sources :

Example 46 with BatchInserter

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

the class BatchInsertTest method testRemoveProperties.

@Test
public void testRemoveProperties() throws Exception {
    BatchInserter inserter = newBatchInserter();
    long theNode = inserter.createNode(properties);
    long anotherNode = inserter.createNode(Collections.<String, Object>emptyMap());
    long relationship = inserter.createRelationship(theNode, anotherNode, RelationshipType.withName("foo"), properties);
    inserter.removeNodeProperty(theNode, "key0");
    inserter.removeRelationshipProperty(relationship, "key1");
    for (String key : properties.keySet()) {
        switch(key) {
            case "key0":
                assertFalse(inserter.nodeHasProperty(theNode, key));
                assertTrue(inserter.relationshipHasProperty(relationship, key));
                break;
            case "key1":
                assertTrue(inserter.nodeHasProperty(theNode, key));
                assertFalse(inserter.relationshipHasProperty(relationship, key));
                break;
            default:
                assertTrue(inserter.nodeHasProperty(theNode, key));
                assertTrue(inserter.relationshipHasProperty(relationship, key));
                break;
        }
    }
    inserter.shutdown();
    inserter = newBatchInserter();
    for (String key : properties.keySet()) {
        switch(key) {
            case "key0":
                assertFalse(inserter.nodeHasProperty(theNode, key));
                assertTrue(inserter.relationshipHasProperty(relationship, key));
                break;
            case "key1":
                assertTrue(inserter.nodeHasProperty(theNode, key));
                assertFalse(inserter.relationshipHasProperty(relationship, key));
                break;
            default:
                assertTrue(inserter.nodeHasProperty(theNode, key));
                assertTrue(inserter.relationshipHasProperty(relationship, key));
                break;
        }
    }
    inserter.shutdown();
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) Test(org.junit.Test)

Example 47 with BatchInserter

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

the class BatchInsertTest method shouldNotCreateSameLabelTwiceOnSameNode.

@Test
public void shouldNotCreateSameLabelTwiceOnSameNode() throws Exception {
    // GIVEN
    BatchInserter inserter = globalInserter;
    // WHEN
    long nodeId = inserter.createNode(map("itemId", 1000L), label("Item"), label("Item"));
    // THEN
    NodeStore nodeStore = getFlushedNeoStores(inserter).getNodeStore();
    NodeRecord node = nodeStore.getRecord(nodeId, nodeStore.newRecord(), NORMAL);
    NodeLabels labels = NodeLabelsField.parseLabelsField(node);
    long[] labelIds = labels.get(nodeStore);
    assertEquals(1, labelIds.length);
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) NodeStore(org.neo4j.kernel.impl.store.NodeStore) NodeLabels(org.neo4j.kernel.impl.store.NodeLabels) Test(org.junit.Test)

Example 48 with BatchInserter

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

the class BatchInsertTest method dbWithIndexAndSingleIndexedNode.

private long dbWithIndexAndSingleIndexedNode() throws Exception {
    IndexPopulator populator = mock(IndexPopulator.class);
    SchemaIndexProvider provider = mock(SchemaIndexProvider.class);
    when(provider.getProviderDescriptor()).thenReturn(InMemoryIndexProviderFactory.PROVIDER_DESCRIPTOR);
    when(provider.getPopulator(anyLong(), any(NewIndexDescriptor.class), any(IndexSamplingConfig.class))).thenReturn(populator);
    BatchInserter inserter = newBatchInserterWithSchemaIndexProvider(singleInstanceSchemaIndexProviderFactory(InMemoryIndexProviderFactory.KEY, provider));
    inserter.createDeferredSchemaIndex(label("Hacker")).on("handle").create();
    long nodeId = inserter.createNode(map("handle", "Jakewins"), label("Hacker"));
    inserter.shutdown();
    return nodeId;
}
Also used : IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) IndexSamplingConfig(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig) BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) SchemaIndexProvider(org.neo4j.kernel.api.index.SchemaIndexProvider) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)

Example 49 with BatchInserter

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

the class BatchInsertTest method shouldRunConstraintPopulationJobAtShutdown.

@Test
public void shouldRunConstraintPopulationJobAtShutdown() throws Throwable {
    // GIVEN
    IndexPopulator populator = mock(IndexPopulator.class);
    SchemaIndexProvider provider = mock(SchemaIndexProvider.class);
    when(provider.getProviderDescriptor()).thenReturn(InMemoryIndexProviderFactory.PROVIDER_DESCRIPTOR);
    when(provider.getPopulator(anyLong(), any(NewIndexDescriptor.class), any(IndexSamplingConfig.class))).thenReturn(populator);
    BatchInserter inserter = newBatchInserterWithSchemaIndexProvider(singleInstanceSchemaIndexProviderFactory(InMemoryIndexProviderFactory.KEY, provider));
    inserter.createDeferredConstraint(label("Hacker")).assertPropertyIsUnique("handle").create();
    long nodeId = inserter.createNode(map("handle", "Jakewins"), label("Hacker"));
    // WHEN
    inserter.shutdown();
    // THEN
    verify(provider).init();
    verify(provider).start();
    verify(provider).getPopulator(anyLong(), any(NewIndexDescriptor.class), any(IndexSamplingConfig.class));
    verify(populator).create();
    verify(populator).add(singletonList(IndexEntryUpdate.add(nodeId, internalUniqueIndex.schema(), "Jakewins")));
    verify(populator).verifyDeferredConstraints(any(PropertyAccessor.class));
    verify(populator).close(true);
    verify(provider).stop();
    verify(provider).shutdown();
    verifyNoMoreInteractions(populator);
}
Also used : IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) IndexSamplingConfig(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig) BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) SchemaIndexProvider(org.neo4j.kernel.api.index.SchemaIndexProvider) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) PropertyAccessor(org.neo4j.kernel.api.index.PropertyAccessor) Test(org.junit.Test)

Example 50 with BatchInserter

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

the class BatchInsertTest method propertiesCanBeReSetUsingBatchInserter.

@Test
public void propertiesCanBeReSetUsingBatchInserter() throws Exception {
    // GIVEN
    BatchInserter batchInserter = globalInserter;
    Map<String, Object> props = new HashMap<>();
    props.put("name", "One");
    props.put("count", 1);
    props.put("tags", new String[] { "one", "two" });
    props.put("something", "something");
    long nodeId = batchInserter.createNode(props);
    batchInserter.setNodeProperty(nodeId, "name", "NewOne");
    batchInserter.removeNodeProperty(nodeId, "count");
    batchInserter.removeNodeProperty(nodeId, "something");
    // WHEN setting new properties
    batchInserter.setNodeProperty(nodeId, "name", "YetAnotherOne");
    batchInserter.setNodeProperty(nodeId, "additional", "something");
    // THEN there should be no problems doing so
    assertEquals("YetAnotherOne", batchInserter.getNodeProperties(nodeId).get("name"));
    assertEquals("something", batchInserter.getNodeProperties(nodeId).get("additional"));
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) HashMap(java.util.HashMap) 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