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();
}
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);
}
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;
}
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);
}
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"));
}
Aggregations