Search in sources :

Example 41 with BatchInserter

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
    }
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) ConstraintViolationException(org.neo4j.graphdb.ConstraintViolationException) Test(org.junit.Test)

Example 42 with BatchInserter

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();
    }
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) Label(org.neo4j.graphdb.Label) ConstraintViolationException(org.neo4j.graphdb.ConstraintViolationException) ConstraintDefinition(org.neo4j.graphdb.schema.ConstraintDefinition) Test(org.junit.Test)

Example 43 with BatchInserter

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"));
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 44 with BatchInserter

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"));
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) Test(org.junit.Test)

Example 45 with BatchInserter

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());
    }
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) Label(org.neo4j.graphdb.Label) ConstraintViolationException(org.neo4j.graphdb.ConstraintViolationException) 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