Search in sources :

Example 6 with BatchInserter

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

Example 7 with BatchInserter

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

Example 8 with BatchInserter

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));
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) Set(java.util.Set) Iterators.asSet(org.neo4j.helpers.collection.Iterators.asSet) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with BatchInserter

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

Example 10 with BatchInserter

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());
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) Matchers.anyLong(org.mockito.Matchers.anyLong) 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