use of org.neo4j.unsafe.batchinsert.BatchInserter in project neo4j by neo4j.
the class BatchInsertTest method testCleanupEmptyPropertyRecords.
/**
* Test checks that during node property set we will cleanup not used property records
* During initial node creation properties will occupy 5 property records.
* Last property record will have only empty array for email.
* During first update email property will be migrated to dynamic property and last property record will become
* empty. That record should be deleted form property chain or otherwise on next node load user will get an
* property record not in use exception.
* @throws Exception
*/
@Test
public void testCleanupEmptyPropertyRecords() throws Exception {
BatchInserter inserter = globalInserter;
Map<String, Object> properties = new HashMap<>();
properties.put("id", 1099511659993L);
properties.put("firstName", "Edward");
properties.put("lastName", "Shevchenko");
properties.put("gender", "male");
properties.put("birthday", new SimpleDateFormat("yyyy-MM-dd").parse("1987-11-08").getTime());
properties.put("birthday_month", 11);
properties.put("birthday_day", 8);
properties.put("creationDate", new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").parse("2010-04-22T18:05:40.912+0000").getTime());
properties.put("locationIP", "46.151.255.205");
properties.put("browserUsed", "Firefox");
properties.put("email", new String[0]);
properties.put("languages", new String[0]);
long personNodeId = inserter.createNode(properties);
assertEquals("Shevchenko", inserter.getNodeProperties(personNodeId).get("lastName"));
assertThat((String[]) inserter.getNodeProperties(personNodeId).get("email"), is(emptyArray()));
inserter.setNodeProperty(personNodeId, "email", new String[] { "Edward1099511659993@gmail.com" });
assertThat((String[]) inserter.getNodeProperties(personNodeId).get("email"), arrayContaining("Edward1099511659993@gmail.com"));
inserter.setNodeProperty(personNodeId, "email", new String[] { "Edward1099511659993@gmail.com", "backup@gmail.com" });
assertThat((String[]) inserter.getNodeProperties(personNodeId).get("email"), arrayContaining("Edward1099511659993@gmail.com", "backup@gmail.com"));
}
use of org.neo4j.unsafe.batchinsert.BatchInserter in project neo4j by neo4j.
the class BatchInsertTest method shouldAddInitialLabelsToCreatedNode.
@Test
public void shouldAddInitialLabelsToCreatedNode() throws Exception {
// GIVEN
BatchInserter inserter = globalInserter;
// WHEN
long node = inserter.createNode(map(), Labels.FIRST, Labels.SECOND);
// THEN
assertTrue(inserter.nodeHasLabel(node, Labels.FIRST));
assertTrue(inserter.nodeHasLabel(node, Labels.SECOND));
assertFalse(inserter.nodeHasLabel(node, Labels.THIRD));
}
use of org.neo4j.unsafe.batchinsert.BatchInserter in project neo4j by neo4j.
the class BatchInsertTest method shouldReplaceExistingInlinedLabelsWithDynamic.
@Test
public void shouldReplaceExistingInlinedLabelsWithDynamic() throws Exception {
// GIVEN
BatchInserter inserter = globalInserter;
long node = inserter.createNode(map(), Labels.FIRST);
// WHEN
Pair<Label[], Set<String>> labels = manyLabels(100);
inserter.setNodeLabels(node, labels.first());
// THEN
Iterable<String> labelNames = asNames(inserter.getNodeLabels(node));
assertEquals(labels.other(), Iterables.asSet(labelNames));
}
use of org.neo4j.unsafe.batchinsert.BatchInserter in project neo4j by neo4j.
the class BatchInsertTest method shouldNotAllowDuplicatedUniquenessConstraints.
@Test
public void shouldNotAllowDuplicatedUniquenessConstraints() throws Exception {
// Given
Label label = label("Person2-" + denseNodeThreshold);
String property = "name";
BatchInserter inserter = globalInserter;
// When
inserter.createDeferredConstraint(label).assertPropertyIsUnique(property).create();
try {
inserter.createDeferredConstraint(label).assertPropertyIsUnique(property).create();
fail("Exception expected");
} catch (ConstraintViolationException e) {
// Then
assertEquals("It is not allowed to create uniqueness constraints and indexes on the same {label;property}", e.getMessage());
}
}
use of org.neo4j.unsafe.batchinsert.BatchInserter in project neo4j by neo4j.
the class BatchInsertTest method shouldGetRelationships.
@Test
public void shouldGetRelationships() throws Exception {
// GIVEN
BatchInserter inserter = globalInserter;
long node = inserter.createNode(null);
createRelationships(inserter, node, RelTypes.REL_TYPE1, 3, 2, 1);
createRelationships(inserter, node, RelTypes.REL_TYPE2, 4, 5, 6);
// WHEN
Set<Long> gottenRelationships = Iterables.asSet(inserter.getRelationshipIds(node));
// THEN
assertEquals(21, gottenRelationships.size());
}
Aggregations