Search in sources :

Example 86 with NotFoundException

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

the class NeoStoresIT method shouldWriteOutThePropertyRecordBeforeReferencingItFromARelationshipRecord.

@Test
public void shouldWriteOutThePropertyRecordBeforeReferencingItFromARelationshipRecord() throws Throwable {
    final long node1Id;
    final long node2Id;
    try (Transaction tx = db.beginTx()) {
        Node node1 = db.createNode();
        node1Id = node1.getId();
        Node node2 = db.createNode();
        node2Id = node2.getId();
        tx.success();
    }
    Race race = new Race();
    final long[] latestRelationshipId = new long[1];
    AtomicLong writes = new AtomicLong();
    AtomicLong reads = new AtomicLong();
    long endTime = currentTimeMillis() + SECONDS.toMillis(2);
    race.withEndCondition(() -> (writes.get() > 100 && reads.get() > 10_000) || currentTimeMillis() > endTime);
    race.addContestant(() -> {
        try (Transaction tx = db.beginTx()) {
            Node node1 = db.getGraphDatabaseAPI().getNodeById(node1Id);
            Node node2 = db.getGraphDatabaseAPI().getNodeById(node2Id);
            Relationship rel = node1.createRelationshipTo(node2, FRIEND);
            latestRelationshipId[0] = rel.getId();
            rel.setProperty("largeProperty", LONG_STRING_VALUE);
            tx.success();
        }
        writes.incrementAndGet();
    });
    race.addContestant(() -> {
        try (Transaction tx = db.getGraphDatabaseAPI().beginTx()) {
            Relationship rel = db.getGraphDatabaseAPI().getRelationshipById(latestRelationshipId[0]);
            for (String propertyKey : rel.getPropertyKeys()) {
                rel.getProperty(propertyKey);
            }
            tx.success();
        } catch (NotFoundException e) {
            if (Exceptions.contains(e, InvalidRecordException.class)) {
                throw e;
            }
        }
        reads.incrementAndGet();
    });
    race.go();
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Race(org.neo4j.test.Race) Relationship(org.neo4j.graphdb.Relationship) NotFoundException(org.neo4j.graphdb.NotFoundException) Test(org.junit.Test)

Example 87 with NotFoundException

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

the class NeoStoresIT method shouldWriteOutTheDynamicChainBeforeUpdatingThePropertyRecord.

@Test
public void shouldWriteOutTheDynamicChainBeforeUpdatingThePropertyRecord() throws Throwable {
    Race race = new Race();
    long[] latestNodeId = new long[1];
    AtomicLong writes = new AtomicLong();
    AtomicLong reads = new AtomicLong();
    long endTime = currentTimeMillis() + SECONDS.toMillis(2);
    race.withEndCondition(() -> (writes.get() > 100 && reads.get() > 10_000) || currentTimeMillis() > endTime);
    race.addContestant(() -> {
        try (Transaction tx = db.beginTx()) {
            Node node = db.createNode();
            latestNodeId[0] = node.getId();
            node.setProperty("largeProperty", LONG_STRING_VALUE);
            tx.success();
        }
        writes.incrementAndGet();
    });
    race.addContestant(() -> {
        try (Transaction tx = db.getGraphDatabaseAPI().beginTx()) {
            Node node = db.getGraphDatabaseAPI().getNodeById(latestNodeId[0]);
            for (String propertyKey : node.getPropertyKeys()) {
                node.getProperty(propertyKey);
            }
            tx.success();
        } catch (NotFoundException e) {
        // This will catch nodes not found (expected) and also PropertyRecords not found (shouldn't happen
        // but handled in shouldWriteOutThePropertyRecordBeforeReferencingItFromANodeRecord)
        }
        reads.incrementAndGet();
    });
    race.go();
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) Transaction(org.neo4j.graphdb.Transaction) Race(org.neo4j.test.Race) Node(org.neo4j.graphdb.Node) NotFoundException(org.neo4j.graphdb.NotFoundException) Test(org.junit.Test)

Aggregations

NotFoundException (org.neo4j.graphdb.NotFoundException)87 Node (org.neo4j.graphdb.Node)43 Test (org.junit.Test)36 Relationship (org.neo4j.graphdb.Relationship)24 Transaction (org.neo4j.graphdb.Transaction)24 Statement (org.neo4j.kernel.api.Statement)18 EntityNotFoundException (org.neo4j.kernel.api.exceptions.EntityNotFoundException)14 PropertyNotFoundException (org.neo4j.kernel.api.exceptions.PropertyNotFoundException)13 ReentrantLock (java.util.concurrent.locks.ReentrantLock)8 EndNodeNotFoundException (org.neo4j.server.rest.domain.EndNodeNotFoundException)7 StartNodeNotFoundException (org.neo4j.server.rest.domain.StartNodeNotFoundException)7 RelationshipType (org.neo4j.graphdb.RelationshipType)5 ReadOperations (org.neo4j.kernel.api.ReadOperations)4 SchemaRuleNotFoundException (org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException)4 KeyReadOperations (org.neo4j.kernel.impl.api.operations.KeyReadOperations)4 InvalidRecordException (org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)4 Race (org.neo4j.test.Race)4 ArrayList (java.util.ArrayList)3 ConstraintViolationException (org.neo4j.graphdb.ConstraintViolationException)3 StatementTokenNameLookup (org.neo4j.kernel.api.StatementTokenNameLookup)3