Search in sources :

Example 1 with ArrayBackedList

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

the class AtomicTest method testRemoveOutOfArrayIndex.

@Test(expected = RuntimeException.class)
public void testRemoveOutOfArrayIndex() {
    db.execute("CREATE (p:Person {name:'Tom',age: [40,50,60]})");
    Node node = (Node) db.execute("MATCH (n:Person {name:'Tom'}) return n;").next().get("n");
    testCall(db, "CALL apoc.atomic.remove({node},{property},{position},{times})", map("node", node, "property", "age", "position", 5, "times", 5), (r) -> {
    });
    assertEquals(Arrays.asList(40, 50, 60).toArray(), new ArrayBackedList(db.execute("MATCH (n:Person {name:'Tom'}) RETURN n.age as age;").next().get("age")).toArray());
}
Also used : Node(org.neo4j.graphdb.Node) ArrayBackedList(apoc.util.ArrayBackedList)

Example 2 with ArrayBackedList

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

the class AtomicTest method testInsertArrayValueLongRelationship.

@Test
public void testInsertArrayValueLongRelationship() {
    db.execute("CREATE (p:Person {name:'Tom',age: 40}) CREATE (c:Person {name:'John',age: 40}) CREATE (p)-[:KNOWS{since:[40,50,60]}]->(c)");
    Relationship rel = (Relationship) db.execute("MATCH (n:Person {name:'Tom'})-[r:KNOWS]-(c) RETURN r;").next().get("r");
    testCall(db, "CALL apoc.atomic.insert({rel},{property},{position},{value},{times})", map("rel", rel, "property", "since", "position", 2, "value", 55L, "times", 5), (r) -> {
    });
    assertEquals(Arrays.asList(40L, 50L, 55L, 60L).toArray(), new ArrayBackedList(db.execute("MATCH (n:Person {name:'Tom'})-[r:KNOWS]-(c) RETURN r.since as since;").next().get("since")).toArray());
}
Also used : Relationship(org.neo4j.graphdb.Relationship) ArrayBackedList(apoc.util.ArrayBackedList)

Example 3 with ArrayBackedList

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

the class AtomicTest method testInsertArrayValueLong.

@Test
public void testInsertArrayValueLong() {
    db.execute("CREATE (p:Person {name:'Tom',age: 40})");
    Node node = (Node) db.execute("MATCH (n:Person {name:'Tom'}) return n;").next().get("n");
    testCall(db, "CALL apoc.atomic.insert({node},{property},{position},{value},{times})", map("node", node, "property", "age", "position", 2, "value", 55L, "times", 5), (r) -> {
    });
    assertEquals(Arrays.asList(40L, 55L).toArray(), new ArrayBackedList(db.execute("MATCH (n:Person {name:'Tom'}) RETURN n.age as age;").next().get("age")).toArray());
}
Also used : Node(org.neo4j.graphdb.Node) ArrayBackedList(apoc.util.ArrayBackedList)

Example 4 with ArrayBackedList

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

the class AtomicTest method testConcurrentRemove.

@Test
public void testConcurrentRemove() throws InterruptedException {
    db.execute("CREATE (p:Person {name:'Tom',age: [40,50,60]}) CREATE (c:Person {name:'John',age: 40}) CREATE (a:Person {name:'Anne',age: 22})");
    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.remove({node},{property},{position},{times})", map("node", node, "property", "age", "position", 0, "times", 5)).next().get("newValue");
    };
    Runnable task2 = () -> {
        db.execute("CALL apoc.atomic.remove({node},{property},{position},{times})", map("node", node, "property", "age", "position", 1, "times", 5)).next().get("newValue");
    };
    executorService.execute(task);
    executorService.execute(task2);
    executorService.shutdown();
    executorService.awaitTermination(10, TimeUnit.SECONDS);
    assertEquals(1, 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)

Example 5 with ArrayBackedList

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

the class AtomicTest method testRemoveLastElementArrayValueLong.

@Test
public void testRemoveLastElementArrayValueLong() {
    db.execute("CREATE (p:Person {name:'Tom',age: [40,50,60]})");
    Node node = (Node) db.execute("MATCH (n:Person {name:'Tom'}) return n;").next().get("n");
    testCall(db, "CALL apoc.atomic.remove({node},{property},{position},{times})", map("node", node, "property", "age", "position", 2, "times", 5), (r) -> {
    });
    assertEquals(Arrays.asList(40L, 50L).toArray(), new ArrayBackedList(db.execute("MATCH (n:Person {name:'Tom'}) RETURN n.age as age;").next().get("age")).toArray());
}
Also used : Node(org.neo4j.graphdb.Node) 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