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