Search in sources :

Example 26 with Node

use of org.neo4j.graphdb.Node in project neo4j by neo4j.

the class BigStoreIT method createReferenceNode.

private Node createReferenceNode(GraphDatabaseService db) {
    try (Transaction tx = db.beginTx()) {
        Node node = db.createNode(REFERENCE);
        tx.success();
        return node;
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node)

Example 27 with Node

use of org.neo4j.graphdb.Node in project neo4j by neo4j.

the class BigStoreIT method testHighIds.

private void testHighIds(long highMark, int minus, int requiredHeapMb) throws IOException {
    if (!machineIsOkToRunThisTest(requiredHeapMb)) {
        return;
    }
    long idBelow = highMark - minus;
    setHighIds(idBelow);
    String propertyKey = "name";
    int intPropertyValue = 123;
    String stringPropertyValue = "Long string, longer than would fit in shortstring";
    long[] arrayPropertyValue = new long[] { 1021L, 321L, 343212L };
    Transaction tx = db.beginTx();
    Node nodeBelowTheLine = db.createNode();
    nodeBelowTheLine.setProperty(propertyKey, intPropertyValue);
    assertEquals(idBelow, nodeBelowTheLine.getId());
    Node nodeAboveTheLine = db.createNode();
    nodeAboveTheLine.setProperty(propertyKey, stringPropertyValue);
    Relationship relBelowTheLine = nodeBelowTheLine.createRelationshipTo(nodeAboveTheLine, this);
    relBelowTheLine.setProperty(propertyKey, arrayPropertyValue);
    assertEquals(idBelow, relBelowTheLine.getId());
    Relationship relAboveTheLine = nodeAboveTheLine.createRelationshipTo(nodeBelowTheLine, this);
    assertEquals(highMark, relAboveTheLine.getId());
    assertEquals(highMark, nodeAboveTheLine.getId());
    assertEquals(intPropertyValue, nodeBelowTheLine.getProperty(propertyKey));
    assertEquals(stringPropertyValue, nodeAboveTheLine.getProperty(propertyKey));
    assertTrue(Arrays.equals(arrayPropertyValue, (long[]) relBelowTheLine.getProperty(propertyKey)));
    tx.success();
    tx.close();
    for (int i = 0; i < 2; i++) {
        try (Transaction transaction = db.beginTx()) {
            assertEquals(nodeAboveTheLine, db.getNodeById(highMark));
            assertEquals(idBelow, nodeBelowTheLine.getId());
            assertEquals(highMark, nodeAboveTheLine.getId());
            assertEquals(idBelow, relBelowTheLine.getId());
            assertEquals(highMark, relAboveTheLine.getId());
            assertEquals(relBelowTheLine, db.getNodeById(idBelow).getSingleRelationship(this, Direction.OUTGOING));
            assertEquals(relAboveTheLine, db.getNodeById(idBelow).getSingleRelationship(this, Direction.INCOMING));
            assertEquals(idBelow, relBelowTheLine.getId());
            assertEquals(highMark, relAboveTheLine.getId());
            assertEquals(asSet(asList(relBelowTheLine, relAboveTheLine)), asSet(Iterables.asCollection(db.getNodeById(idBelow).getRelationships())));
            transaction.success();
        }
        if (i == 0) {
            db = dbRule.restartDatabase();
        }
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship)

Example 28 with Node

use of org.neo4j.graphdb.Node in project neo4j by neo4j.

the class ConcurrentCreateAndGetRelationshipsIT method createNode.

private Node createNode(GraphDatabaseService db) {
    try (Transaction tx = db.beginTx()) {
        Node node = db.createNode();
        tx.success();
        return node;
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node)

Example 29 with Node

use of org.neo4j.graphdb.Node in project neo4j by neo4j.

the class ConcurrentCreateAndGetRelationshipsIT method tryToReproduceTheIssue.

@Test
public void tryToReproduceTheIssue() throws Exception {
    // GIVEN
    GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
    CountDownLatch startSignal = new CountDownLatch(1);
    AtomicBoolean stopSignal = new AtomicBoolean();
    AtomicReference<Exception> failure = new AtomicReference<Exception>();
    Node parentNode = createNode(db);
    Collection<Worker> workers = createWorkers(db, startSignal, stopSignal, failure, parentNode);
    // WHEN
    startSignal.countDown();
    sleep(500);
    stopSignal.set(true);
    awaitWorkersToEnd(workers);
    // THEN
    if (failure.get() != null) {
        throw new Exception("A worker failed", failure.get());
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Node(org.neo4j.graphdb.Node) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 30 with Node

use of org.neo4j.graphdb.Node in project neo4j by neo4j.

the class NestedTransactionLocksIT method createNode.

private Node createNode() {
    try (Transaction tx = db.beginTx()) {
        Node n = db.createNode();
        tx.success();
        return n;
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node)

Aggregations

Node (org.neo4j.graphdb.Node)1271 Test (org.junit.Test)781 Transaction (org.neo4j.graphdb.Transaction)540 Relationship (org.neo4j.graphdb.Relationship)372 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)146 NotFoundException (org.neo4j.graphdb.NotFoundException)78 File (java.io.File)65 HashMap (java.util.HashMap)57 Label (org.neo4j.graphdb.Label)57 RelationshipType (org.neo4j.graphdb.RelationshipType)57 LinkedList (java.util.LinkedList)56 Path (org.neo4j.graphdb.Path)52 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)46 HashSet (java.util.HashSet)45 Map (java.util.Map)44 WeightedPath (org.neo4j.graphalgo.WeightedPath)37 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)35 ArrayList (java.util.ArrayList)30 List (java.util.List)27 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)26