Search in sources :

Example 36 with BatchInserter

use of org.neo4j.unsafe.batchinsert.BatchInserter in project neo4j by neo4j.

the class GitHub1304Test method givenBatchInserterWhenArrayPropertyUpdated4TimesThenShouldNotFail.

@Test
public void givenBatchInserterWhenArrayPropertyUpdated4TimesThenShouldNotFail() throws Exception {
    BatchInserter batchInserter = BatchInserters.inserter(folder.getRoot().getAbsoluteFile(), fileSystemRule.get());
    long nodeId = batchInserter.createNode(Collections.<String, Object>emptyMap());
    for (int i = 0; i < 4; i++) {
        batchInserter.setNodeProperty(nodeId, "array", new byte[] { 2, 3, 98, 1, 43, 50, 3, 33, 51, 55, 116, 16, 23, 56, 9, -10, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1 });
    }
    //fails here
    batchInserter.getNodeProperties(nodeId);
    batchInserter.shutdown();
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) Test(org.junit.Test)

Example 37 with BatchInserter

use of org.neo4j.unsafe.batchinsert.BatchInserter in project neo4j by neo4j.

the class BatchInsertTest method createBatchNodeAndRelationshipsDeleteAllInEmbedded.

@Test
public void createBatchNodeAndRelationshipsDeleteAllInEmbedded() throws Exception {
    /*
         *    ()--[REL_TYPE1]-->(node)--[BATCH_TEST]->()
         */
    BatchInserter inserter = newBatchInserter();
    long nodeId = inserter.createNode(null);
    inserter.createRelationship(nodeId, inserter.createNode(null), RelTypes.BATCH_TEST, null);
    inserter.createRelationship(inserter.createNode(null), nodeId, RelTypes.REL_TYPE1, null);
    // Delete node and all its relationships
    GraphDatabaseService db = switchToEmbeddedGraphDatabaseService(inserter);
    try (Transaction tx = db.beginTx()) {
        Node node = db.getNodeById(nodeId);
        for (Relationship relationship : node.getRelationships()) {
            relationship.delete();
        }
        node.delete();
        tx.success();
    }
    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) Test(org.junit.Test)

Example 38 with BatchInserter

use of org.neo4j.unsafe.batchinsert.BatchInserter in project neo4j by neo4j.

the class BatchInsertTest method shouldBeAbleToOverwriteDynamicProperty.

@Test
public void shouldBeAbleToOverwriteDynamicProperty() 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
    String[] secondValue = new String[] { "four", "five", "six" };
    batchInserter.setNodeProperty(nodeId, key, secondValue);
    // THEN
    assertTrue(Arrays.equals(secondValue, (String[]) batchInserter.getNodeProperties(nodeId).get(key)));
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) Test(org.junit.Test)

Example 39 with BatchInserter

use of org.neo4j.unsafe.batchinsert.BatchInserter in project neo4j by neo4j.

the class BatchInsertTest method testSetAndKeepRelationshipProperty.

@Test
public void testSetAndKeepRelationshipProperty() throws Exception {
    BatchInserter inserter = newBatchInserter();
    long from = inserter.createNode(Collections.<String, Object>emptyMap());
    long to = inserter.createNode(Collections.<String, Object>emptyMap());
    long theRel = inserter.createRelationship(from, to, RelationshipType.withName("TestingPropsHere"), MapUtil.map("foo", "bar"));
    inserter.setRelationshipProperty(theRel, "foo2", "bar2");
    Map<String, Object> props = inserter.getRelationshipProperties(theRel);
    assertEquals(2, props.size());
    assertEquals("bar", props.get("foo"));
    assertEquals("bar2", props.get("foo2"));
    inserter.shutdown();
    inserter = newBatchInserter();
    props = inserter.getRelationshipProperties(theRel);
    assertEquals(2, props.size());
    assertEquals("bar", props.get("foo"));
    assertEquals("bar2", props.get("foo2"));
    inserter.setRelationshipProperty(theRel, "foo", "bar3");
    props = inserter.getRelationshipProperties(theRel);
    assertEquals("bar3", props.get("foo"));
    assertEquals(2, props.size());
    assertEquals("bar3", props.get("foo"));
    assertEquals("bar2", props.get("foo2"));
    inserter.shutdown();
    inserter = newBatchInserter();
    props = inserter.getRelationshipProperties(theRel);
    assertEquals("bar3", props.get("foo"));
    assertEquals(2, props.size());
    assertEquals("bar3", props.get("foo"));
    assertEquals("bar2", props.get("foo2"));
    inserter.shutdown();
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) Test(org.junit.Test)

Example 40 with BatchInserter

use of org.neo4j.unsafe.batchinsert.BatchInserter in project neo4j by neo4j.

the class BatchInsertTest method testNodeHasProperty.

@Test
public void testNodeHasProperty() throws Exception {
    BatchInserter inserter = globalInserter;
    long theNode = inserter.createNode(properties);
    long anotherNode = inserter.createNode(Collections.<String, Object>emptyMap());
    long relationship = inserter.createRelationship(theNode, anotherNode, RelationshipType.withName("foo"), properties);
    for (String key : properties.keySet()) {
        assertTrue(inserter.nodeHasProperty(theNode, key));
        assertFalse(inserter.nodeHasProperty(theNode, key + "-"));
        assertTrue(inserter.relationshipHasProperty(relationship, key));
        assertFalse(inserter.relationshipHasProperty(relationship, key + "-"));
    }
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) 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