Search in sources :

Example 11 with NotFoundException

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

the class TestNode 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 e) {
    } 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) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test)

Example 12 with NotFoundException

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

the class TestNeo4jConstrains method testIllegalPropertyType.

@Test
public void testIllegalPropertyType() {
    Logger log = Logger.getLogger(NodeManager.class.getName());
    Level level = log.getLevel();
    log.setLevel(Level.OFF);
    try {
        Node node1 = getGraphDb().createNode();
        try {
            node1.setProperty(key, new Object());
            fail("Shouldn't validate");
        } catch (Exception e) {
        // good
        }
        try {
            Transaction tx = getTransaction();
            tx.success();
            tx.finish();
            fail("Shouldn't validate");
        } catch (Exception e) {
        }
        // good
        setTransaction(getGraphDb().beginTx());
        try {
            getGraphDb().getNodeById(node1.getId());
            fail("Node should not exist, previous tx didn't rollback");
        } catch (NotFoundException e) {
        // good
        }
        node1 = getGraphDb().createNode();
        Node node2 = getGraphDb().createNode();
        Relationship rel = node1.createRelationshipTo(node2, MyRelTypes.TEST);
        try {
            rel.setProperty(key, new Object());
            fail("Shouldn't validate");
        } catch (Exception e) {
        // good
        }
        try {
            Transaction tx = getTransaction();
            tx.success();
            tx.finish();
            fail("Shouldn't validate");
        } catch (Exception e) {
        }
        // good
        setTransaction(getGraphDb().beginTx());
        try {
            getGraphDb().getNodeById(node1.getId());
            fail("Node should not exist, previous tx didn't rollback");
        } catch (NotFoundException e) {
        // good
        }
        try {
            getGraphDb().getNodeById(node2.getId());
            fail("Node should not exist, previous tx didn't rollback");
        } catch (NotFoundException e) {
        // good
        }
    } finally {
        log.setLevel(level);
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) NotFoundException(org.neo4j.graphdb.NotFoundException) Level(java.util.logging.Level) Logger(java.util.logging.Logger) NotFoundException(org.neo4j.graphdb.NotFoundException) Test(org.junit.Test)

Example 13 with NotFoundException

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

the class TestRelationship method testRelGetProperties.

@Test
public void testRelGetProperties() {
    Integer int1 = new Integer(1);
    Integer int2 = new Integer(2);
    String string = new String("3");
    Node node1 = getGraphDb().createNode();
    Node node2 = getGraphDb().createNode();
    Relationship rel1 = node1.createRelationshipTo(node2, MyRelTypes.TEST);
    try {
        rel1.getProperty(key1);
        fail("get non existing property din't throw exception");
    } catch (NotFoundException e) {
    }
    try {
        rel1.getProperty(null);
        fail("get of null key din't throw exception");
    } catch (IllegalArgumentException e) {
    }
    assertTrue(!rel1.hasProperty(key1));
    assertTrue(!rel1.hasProperty(null));
    rel1.setProperty(key1, int1);
    rel1.setProperty(key2, int2);
    rel1.setProperty(key3, string);
    assertTrue(rel1.hasProperty(key1));
    assertTrue(rel1.hasProperty(key2));
    assertTrue(rel1.hasProperty(key3));
    try {
        rel1.removeProperty(key3);
    } catch (NotFoundException e) {
        fail("Remove of property failed.");
    }
    assertTrue(!rel1.hasProperty(key3));
    assertTrue(!rel1.hasProperty(null));
    rel1.delete();
    node2.delete();
    node1.delete();
}
Also used : Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) NotFoundException(org.neo4j.graphdb.NotFoundException) Test(org.junit.Test)

Example 14 with NotFoundException

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

the class GraphDbHelper method getFirstNode.

public long getFirstNode() {
    try (Transaction tx = database.getGraph().beginTransaction(implicit, AnonymousContext.write())) {
        try {
            Node referenceNode = database.getGraph().getNodeById(0L);
            tx.success();
            return referenceNode.getId();
        } catch (NotFoundException e) {
            Node newNode = database.getGraph().createNode();
            tx.success();
            return newNode.getId();
        }
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Node(org.neo4j.graphdb.Node) NotFoundException(org.neo4j.graphdb.NotFoundException)

Example 15 with NotFoundException

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

the class LegacyIndexAddDropConcurrently method shouldHandleConcurrentIndexDropping.

@Test
public void shouldHandleConcurrentIndexDropping() throws Exception {
    // Given
    ExecutorService exec = Executors.newFixedThreadPool(4);
    final GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
    List<Callable<Object>> jobs = new ArrayList<>();
    for (int i = 0; i < 4; i++) {
        jobs.add(new Callable<Object>() {

            private final Random rand = ThreadLocalRandom.current();

            @Override
            public Object call() throws Exception {
                for (int j = 0; j < 1000; j++) {
                    switch(rand.nextInt(5)) {
                        case 4:
                            // 1 in 5 chance, drop the index
                            try (Transaction tx = db.beginTx()) {
                                db.index().forNodes("users").delete();
                                tx.success();
                            } catch (NotFoundException e) {
                            // Occasionally expected
                            }
                            break;
                        default:
                            // Otherwise, write to it
                            try (Transaction tx = db.beginTx()) {
                                db.index().forNodes("users").add(db.createNode(), "name", "steve");
                                tx.success();
                            } catch (NotFoundException e) {
                            // Occasionally expected
                            }
                            break;
                    }
                }
                return null;
            }
        });
    }
    // When
    for (Future<Object> objectFuture : exec.invokeAll(jobs)) {
        objectFuture.get();
    }
// Then no errors should have occurred.
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) ArrayList(java.util.ArrayList) NotFoundException(org.neo4j.graphdb.NotFoundException) Callable(java.util.concurrent.Callable) NotFoundException(org.neo4j.graphdb.NotFoundException) Random(java.util.Random) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Transaction(org.neo4j.graphdb.Transaction) ExecutorService(java.util.concurrent.ExecutorService) 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