Search in sources :

Example 1 with NotFoundException

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

the class NodeProxyTest method shouldThrowHumaneExceptionsWhenPropertyDoesNotExistOnNode.

@Test
public void shouldThrowHumaneExceptionsWhenPropertyDoesNotExistOnNode() throws Exception {
    // Given a database with PROPERTY_KEY in it
    createNodeWith(PROPERTY_KEY);
    // When trying to get property from node without it
    try (Transaction ignored = db.beginTx()) {
        Node node = db.createNode();
        node.getProperty(PROPERTY_KEY);
        fail("Expected exception to have been thrown");
    }// Then
     catch (NotFoundException exception) {
        assertThat(exception.getMessage(), containsString(PROPERTY_KEY));
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) NotFoundException(org.neo4j.graphdb.NotFoundException) Test(org.junit.Test)

Example 2 with NotFoundException

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

the class NodeTest method testNodeChangeProperty.

@Test
public void testNodeChangeProperty() {
    String key1 = "key1";
    String key2 = "key2";
    String key3 = "key3";
    Integer int1 = new Integer(1);
    Integer int2 = new Integer(2);
    String string1 = new String("1");
    String string2 = new String("2");
    Boolean bool1 = new Boolean(true);
    Boolean bool2 = new Boolean(false);
    Node node1 = getGraphDb().createNode();
    Node node2 = getGraphDb().createNode();
    node1.setProperty(key1, int1);
    node2.setProperty(key1, string1);
    node1.setProperty(key2, string2);
    node2.setProperty(key2, int2);
    try {
        node1.setProperty(null, null);
        fail("Null argument should result in exception.");
    } catch (IllegalArgumentException ignored) {
    } catch (NotFoundException e) {
        fail("wrong exception");
    }
    // test change property
    node1.setProperty(key1, int2);
    node2.setProperty(key1, string2);
    assertEquals(string2, node2.getProperty(key1));
    node1.setProperty(key3, bool1);
    node1.setProperty(key3, bool2);
    assertEquals(string2, node2.getProperty(key1));
    node1.delete();
    node2.delete();
}
Also used : Node(org.neo4j.graphdb.Node) NotFoundException(org.neo4j.graphdb.NotFoundException) Test(org.junit.Test)

Example 3 with NotFoundException

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

the class RelationshipCreateDeleteLockOrderingIT method shouldNotDeadlockWhenConcurrentCreateAndDeleteRelationships.

@Test
public void shouldNotDeadlockWhenConcurrentCreateAndDeleteRelationships() throws Throwable {
    // GIVEN (A) -[R]-> (B)
    final Node a;
    final Node b;
    try (Transaction tx = db.beginTx()) {
        (a = db.createNode()).createRelationshipTo(b = db.createNode(), MyRelTypes.TEST);
        tx.success();
    }
    // WHEN
    Race race = new Race();
    // a bunch of deleters
    for (int i = 0; i < 30; i++) {
        race.addContestant(new Runnable() {

            @Override
            public void run() {
                try (Transaction tx = db.beginTx()) {
                    Node node = random.nextBoolean() ? a : b;
                    for (Relationship relationship : node.getRelationships()) {
                        try {
                            relationship.delete();
                        } catch (NotFoundException e) {
                            // This is OK and expected since there are multiple threads deleting
                            assertTrue(e.getMessage().contains("already deleted"));
                        }
                    }
                    tx.success();
                }
            }
        });
    }
    // a bunch of creators
    for (int i = 0; i < 30; i++) {
        race.addContestant(new Runnable() {

            @Override
            public void run() {
                try (Transaction tx = db.beginTx()) {
                    boolean order = random.nextBoolean();
                    Node start = order ? a : b;
                    Node end = order ? b : a;
                    start.createRelationshipTo(end, MyRelTypes.TEST);
                    tx.success();
                }
            }
        });
    }
    // THEN there should be no thread throwing exception, especially DeadlockDetectedException
    race.go();
}
Also used : 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 4 with NotFoundException

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

the class ValueNode method pack.

public static void pack(Neo4jPack.Packer packer, Node node) throws IOException {
    //TODO: We should mark deleted nodes properly but that requires updates to protocol and
    //clients. Until that we merely don't fail and return a node with neither labels nor properties
    packer.packStructHeader(STRUCT_FIELD_COUNT, Neo4jPack.NODE);
    packer.pack(node.getId());
    try {
        //read labels and properties, will fail if node has been deleted
        Collection<Label> collectedLabels = Iterables.asList(node.getLabels());
        Map<String, Object> props = node.getAllProperties();
        packer.packListHeader(collectedLabels.size());
        for (Label label : collectedLabels) {
            packer.pack(label.name());
        }
        packer.packRawMap(props);
    } catch (NotFoundException e) {
        //node is deleted, just send along an empty node
        packer.packListHeader(0);
        packer.packRawMap(Collections.emptyMap());
    }
}
Also used : Label(org.neo4j.graphdb.Label) NotFoundException(org.neo4j.graphdb.NotFoundException)

Example 5 with NotFoundException

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

the class TestRelationship method testRelationshipRemoveProperty.

@Test
public void testRelationshipRemoveProperty() {
    Integer int1 = new Integer(1);
    Integer int2 = new Integer(2);
    String string1 = new String("1");
    String string2 = new String("2");
    Node node1 = getGraphDb().createNode();
    Node node2 = getGraphDb().createNode();
    Relationship rel1 = node1.createRelationshipTo(node2, MyRelTypes.TEST);
    Relationship rel2 = node2.createRelationshipTo(node1, MyRelTypes.TEST);
    // verify that we can rely on PL to reomve non existing properties
    try {
        if (rel1.removeProperty(key1) != null) {
            fail("Remove of non existing property should return null");
        }
    } catch (NotFoundException e) {
    // OK
    }
    try {
        rel1.removeProperty(null);
        fail("Remove null property should throw exception.");
    } catch (IllegalArgumentException e) {
    // OK
    }
    rel1.setProperty(key1, int1);
    rel2.setProperty(key1, string1);
    rel1.setProperty(key2, string2);
    rel2.setProperty(key2, int2);
    try {
        rel1.removeProperty(null);
        fail("Null argument should result in exception.");
    } catch (IllegalArgumentException e) {
    // OK
    }
    // test remove property
    assertEquals(int1, rel1.removeProperty(key1));
    assertEquals(string1, rel2.removeProperty(key1));
    // test remove of non existing property
    try {
        if (rel2.removeProperty(key1) != null) {
            fail("Remove of non existing property should return null");
        }
    } catch (NotFoundException e) {
        // have to set rollback only here
        getTransaction().failure();
    }
    rel1.delete();
    rel2.delete();
    node1.delete();
    node2.delete();
}
Also used : Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) 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