Search in sources :

Example 11 with ArrayBackedList

use of apoc.util.ArrayBackedList in project neo4j-apoc-procedures by neo4j-contrib.

the class AtomicTest method testConcurrentInsert.

@Test
public void testConcurrentInsert() throws InterruptedException {
    db.execute("CREATE (p:Person {name:'Tom',age: 40})");
    Node node = (Node) db.execute("MATCH (n:Person {name:'Tom'}) RETURN n;").next().get("n");
    ExecutorService executorService = Executors.newFixedThreadPool(2);
    Runnable task = () -> {
        db.execute("CALL apoc.atomic.insert({node},{property},{position},{value},{times})", map("node", node, "property", "age", "position", 2, "value", 41L, "times", 5)).next().get("newValue");
    };
    Runnable task2 = () -> {
        db.execute("CALL apoc.atomic.insert({node},{property},{position},{value},{times})", map("node", node, "property", "age", "position", 2, "value", 42L, "times", 5)).next().get("newValue");
    };
    executorService.execute(task);
    executorService.execute(task2);
    executorService.shutdown();
    executorService.awaitTermination(2, TimeUnit.SECONDS);
    assertEquals(3, new ArrayBackedList(db.execute("MATCH (n:Person {name:'Tom'}) RETURN n.age as age;").next().get("age")).toArray().length);
}
Also used : Node(org.neo4j.graphdb.Node) ExecutorService(java.util.concurrent.ExecutorService) ArrayBackedList(apoc.util.ArrayBackedList)

Aggregations

ArrayBackedList (apoc.util.ArrayBackedList)11 Node (org.neo4j.graphdb.Node)9 ExecutorService (java.util.concurrent.ExecutorService)2 PropertyContainer (org.neo4j.graphdb.PropertyContainer)1 Relationship (org.neo4j.graphdb.Relationship)1