use of org.neo4j.unsafe.batchinsert.BatchInserter in project neo4j by neo4j.
the class BatchInsertTest method shouldBeAbleToRemoveDynamicProperty.
@Test
public void shouldBeAbleToRemoveDynamicProperty() throws Exception {
// Only triggered if assertions are enabled
// GIVEN
BatchInserter batchInserter = globalInserter;
String key = "tags";
long nodeId = batchInserter.createNode(MapUtil.map(key, new String[] { "one", "two", "three" }));
// WHEN
batchInserter.removeNodeProperty(nodeId, key);
// THEN
assertFalse(batchInserter.getNodeProperties(nodeId).containsKey(key));
}
use of org.neo4j.unsafe.batchinsert.BatchInserter in project neo4j by neo4j.
the class BatchInsertTest method shouldSortLabelIdsWhenGetOrCreate.
@Test
public void shouldSortLabelIdsWhenGetOrCreate() throws Exception {
// GIVEN
BatchInserter inserter = globalInserter;
// WHEN
long nodeId = inserter.createNode(map("Item", 123456789123L), label("AA"), label("BB"), label("CC"), label("DD"));
inserter.setNodeLabels(nodeId, label("CC"), label("AA"), label("DD"), label("EE"), label("FF"));
// THEN
NodeStore nodeStore = getFlushedNeoStores(inserter).getNodeStore();
NodeRecord node = nodeStore.getRecord(nodeId, nodeStore.newRecord(), RecordLoad.NORMAL);
NodeLabels labels = NodeLabelsField.parseLabelsField(node);
long[] labelIds = labels.get(nodeStore);
long[] sortedLabelIds = labelIds.clone();
Arrays.sort(sortedLabelIds);
assertArrayEquals(sortedLabelIds, labelIds);
}
use of org.neo4j.unsafe.batchinsert.BatchInserter in project neo4j by neo4j.
the class BatchInsertTest method shouldSkipStoreScanIfNoLabelsAdded.
@Test
public void shouldSkipStoreScanIfNoLabelsAdded() throws Exception {
// GIVEN
UpdateTrackingLabelScanStore labelScanStore = new UpdateTrackingLabelScanStore();
BatchInserter inserter = newBatchInserterWithLabelScanStore(new ControlledLabelScanStore(labelScanStore));
// WHEN
inserter.createNode(null);
inserter.createNode(null);
inserter.shutdown();
// THEN
assertEquals(0, labelScanStore.writersCreated);
}
use of org.neo4j.unsafe.batchinsert.BatchInserter in project neo4j by neo4j.
the class BatchInsertTest method makeSureLoopsCanBeCreated.
@Test
public void makeSureLoopsCanBeCreated() throws Exception {
BatchInserter graphDb = newBatchInserter();
long startNode = graphDb.createNode(properties);
long otherNode = graphDb.createNode(properties);
long selfRelationship = graphDb.createRelationship(startNode, startNode, relTypeArray[0], properties);
long relationship = graphDb.createRelationship(startNode, otherNode, relTypeArray[0], properties);
for (BatchRelationship rel : graphDb.getRelationships(startNode)) {
if (rel.getId() == selfRelationship) {
assertEquals(startNode, rel.getStartNode());
assertEquals(startNode, rel.getEndNode());
} else if (rel.getId() == relationship) {
assertEquals(startNode, rel.getStartNode());
assertEquals(otherNode, rel.getEndNode());
} else {
fail("Unexpected relationship " + rel.getId());
}
}
GraphDatabaseService db = switchToEmbeddedGraphDatabaseService(graphDb);
try (Transaction ignored = db.beginTx()) {
Node realStartNode = db.getNodeById(startNode);
Relationship realSelfRelationship = db.getRelationshipById(selfRelationship);
Relationship realRelationship = db.getRelationshipById(relationship);
assertEquals(realSelfRelationship, realStartNode.getSingleRelationship(RelTypes.REL_TYPE1, Direction.INCOMING));
assertEquals(asSet(realSelfRelationship, realRelationship), Iterables.asSet(realStartNode.getRelationships(Direction.OUTGOING)));
assertEquals(asSet(realSelfRelationship, realRelationship), Iterables.asSet(realStartNode.getRelationships()));
} finally {
db.shutdown();
}
}
use of org.neo4j.unsafe.batchinsert.BatchInserter in project neo4j by neo4j.
the class BatchInsertTest method shouldNotAllowDuplicatedIndexes.
@Test
public void shouldNotAllowDuplicatedIndexes() throws Exception {
// Given
Label label = label("Person3-" + denseNodeThreshold);
String property = "name";
BatchInserter inserter = globalInserter;
// When
inserter.createDeferredSchemaIndex(label).on(property).create();
try {
inserter.createDeferredSchemaIndex(label).on(property).create();
fail("Exception expected");
} catch (ConstraintViolationException e) {
// Then
assertEquals("Index for given {label;property} already exists", e.getMessage());
}
}
Aggregations