use of org.neo4j.unsafe.batchinsert.BatchInserter in project neo4j by neo4j.
the class BatchInsertTest method shouldNotAllowCreationOfDuplicateConstraint.
@Test
public void shouldNotAllowCreationOfDuplicateConstraint() throws Exception {
// GIVEN
BatchInserter inserter = globalInserter;
String labelName = "Hacker2-" + denseNodeThreshold;
// WHEN
inserter.createDeferredConstraint(label(labelName)).assertPropertyIsUnique("handle").create();
try {
inserter.createDeferredConstraint(label(labelName)).assertPropertyIsUnique("handle").create();
fail("Should have thrown exception.");
} catch (ConstraintViolationException e) {
// THEN Good
}
}
use of org.neo4j.unsafe.batchinsert.BatchInserter in project neo4j by neo4j.
the class BatchInsertTest method shouldCreateUniquenessConstraint.
@Test
public void shouldCreateUniquenessConstraint() throws Exception {
// Given
Label label = label("Person");
String propertyKey = "name";
String duplicatedValue = "Tom";
BatchInserter inserter = newBatchInserter();
// When
inserter.createDeferredConstraint(label).assertPropertyIsUnique(propertyKey).create();
// Then
GraphDatabaseService db = switchToEmbeddedGraphDatabaseService(inserter);
try {
try (Transaction tx = db.beginTx()) {
List<ConstraintDefinition> constraints = Iterables.asList(db.schema().getConstraints());
assertEquals(1, constraints.size());
ConstraintDefinition constraint = constraints.get(0);
assertEquals(label.name(), constraint.getLabel().name());
assertEquals(propertyKey, single(constraint.getPropertyKeys()));
db.createNode(label).setProperty(propertyKey, duplicatedValue);
tx.success();
}
try (Transaction tx = db.beginTx()) {
db.createNode(label).setProperty(propertyKey, duplicatedValue);
tx.success();
}
fail("Uniqueness property constraint was violated, exception expected");
} catch (ConstraintViolationException e) {
assertEquals(format("Node(0) already exists with label `%s` and property `%s` = '%s'", label.name(), propertyKey, duplicatedValue), e.getMessage());
} finally {
db.shutdown();
}
}
use of org.neo4j.unsafe.batchinsert.BatchInserter in project neo4j by neo4j.
the class BatchInsertTest method replaceWithBiggerPropertySpillsOverIntoNewPropertyRecord.
@Test
public void replaceWithBiggerPropertySpillsOverIntoNewPropertyRecord() 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" });
long id = batchInserter.createNode(props);
batchInserter.setNodeProperty(id, "name", "NewOne");
// WHEN
batchInserter.setNodeProperty(id, "count", "something");
// THEN
assertEquals("something", batchInserter.getNodeProperties(id).get("count"));
}
use of org.neo4j.unsafe.batchinsert.BatchInserter in project neo4j by neo4j.
the class BatchInsertTest method testSetAndAddNodeProperties.
@Test
public void testSetAndAddNodeProperties() throws Exception {
BatchInserter inserter = globalInserter;
long tehNode = inserter.createNode(MapUtil.map("one", "one", "two", "two", "three", "three"));
inserter.setNodeProperty(tehNode, "four", "four");
inserter.setNodeProperty(tehNode, "five", "five");
Map<String, Object> props = inserter.getNodeProperties(tehNode);
assertEquals(5, props.size());
assertEquals("one", props.get("one"));
assertEquals("five", props.get("five"));
}
use of org.neo4j.unsafe.batchinsert.BatchInserter in project neo4j by neo4j.
the class BatchInsertTest method shouldNotAllowCreationOfUniquenessConstraintAndIndexOnSameLabelAndProperty.
@Test
public void shouldNotAllowCreationOfUniquenessConstraintAndIndexOnSameLabelAndProperty() throws Exception {
// Given
Label label = label("Person1-" + denseNodeThreshold);
String property = "name";
BatchInserter inserter = globalInserter;
// When
inserter.createDeferredConstraint(label).assertPropertyIsUnique(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