Search in sources :

Example 31 with BatchInserter

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

Example 32 with BatchInserter

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);
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) NodeStore(org.neo4j.kernel.impl.store.NodeStore) NodeLabels(org.neo4j.kernel.impl.store.NodeLabels) Test(org.junit.Test)

Example 33 with BatchInserter

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

Example 34 with BatchInserter

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();
    }
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) BatchRelationship(org.neo4j.unsafe.batchinsert.BatchRelationship) Relationship(org.neo4j.graphdb.Relationship) BatchRelationship(org.neo4j.unsafe.batchinsert.BatchRelationship) Test(org.junit.Test)

Example 35 with BatchInserter

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());
    }
}
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