Search in sources :

Example 71 with NotFoundException

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

the class TestRecoveryScenarios method shouldRecoverTransactionWhereNodeIsDeletedInTheFuture.

@Test
public void shouldRecoverTransactionWhereNodeIsDeletedInTheFuture() throws Exception {
    // GIVEN
    Node node = createNodeWithProperty("key", "value", label);
    checkPoint();
    setProperty(node, "other-key", 1);
    deleteNode(node);
    flush.flush(db);
    // WHEN
    crashAndRestart(indexProvider);
    // -- really the problem was that recovery threw exception, so mostly assert that.
    try (Transaction tx = db.beginTx()) {
        node = db.getNodeById(node.getId());
        tx.success();
        fail("Should not exist");
    } catch (NotFoundException e) {
        assertEquals("Node " + node.getId() + " not found", e.getMessage());
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) NotFoundException(org.neo4j.graphdb.NotFoundException) Test(org.junit.Test)

Example 72 with NotFoundException

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

the class DatabaseActions method pagedTraverse.

public ListRepresentation pagedTraverse(String traverserId, TraverserReturnType returnType) {
    Lease lease = leases.getLeaseById(traverserId);
    if (lease == null) {
        throw new NotFoundException(String.format("The traverser with id [%s] was not found", traverserId));
    }
    PagedTraverser traverser = lease.getLeasedItemAndRenewLease();
    List<Path> paths = traverser.next();
    if (paths != null) {
        return toListPathRepresentation(paths, returnType);
    } else {
        leases.remove(traverserId);
        // Yuck.
        throw new NotFoundException(String.format("The results for paged traverser with id [%s] have been fully enumerated", traverserId));
    }
}
Also used : Path(org.neo4j.graphdb.Path) WeightedPath(org.neo4j.graphalgo.WeightedPath) Lease(org.neo4j.server.rest.paging.Lease) StartNodeNotFoundException(org.neo4j.server.rest.domain.StartNodeNotFoundException) NotFoundException(org.neo4j.graphdb.NotFoundException) EndNodeNotFoundException(org.neo4j.server.rest.domain.EndNodeNotFoundException) PagedTraverser(org.neo4j.server.rest.paging.PagedTraverser)

Example 73 with NotFoundException

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

the class DatabaseActions method getIndexedNodesByQuery.

public ListRepresentation getIndexedNodesByQuery(String indexName, String key, String query, String sort) {
    if (!graphDb.index().existsForNodes(indexName)) {
        throw new NotFoundException();
    }
    if (query == null) {
        return toListNodeRepresentation();
    }
    Index<Node> index = graphDb.index().forNodes(indexName);
    IndexResultOrder order = getOrdering(sort);
    QueryContext queryCtx = order.updateQueryContext(new QueryContext(query));
    IndexHits<Node> result = index.query(key, queryCtx);
    return toListNodeRepresentation(result, order);
}
Also used : Node(org.neo4j.graphdb.Node) StartNodeNotFoundException(org.neo4j.server.rest.domain.StartNodeNotFoundException) NotFoundException(org.neo4j.graphdb.NotFoundException) EndNodeNotFoundException(org.neo4j.server.rest.domain.EndNodeNotFoundException) QueryContext(org.neo4j.index.lucene.QueryContext)

Example 74 with NotFoundException

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

the class IndexRestartIT method shouldBeAbleToDropIndexWhileItIsPopulating.

/* This is somewhat difficult to test since dropping an index while it's populating forces it to be cancelled
     * first (and also awaiting cancellation to complete). So this is a best-effort to have the timing as close
     * as possible. If this proves to be flaky, remove it right away.
     */
@Test
public void shouldBeAbleToDropIndexWhileItIsPopulating() throws Exception {
    // GIVEN
    startDb();
    DoubleLatch populationCompletionLatch = provider.installPopulationJobCompletionLatch();
    IndexDefinition index = createIndex();
    // await population job to start
    populationCompletionLatch.waitForAllToStart();
    // WHEN
    dropIndex(index, populationCompletionLatch);
    // THEN
    assertThat(getIndexes(db, myLabel), inTx(db, hasSize(0)));
    try {
        getIndexState(db, index);
        fail("This index should have been deleted");
    } catch (NotFoundException e) {
        assertThat(e.getMessage(), CoreMatchers.containsString(myLabel.name()));
    }
}
Also used : IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) NotFoundException(org.neo4j.graphdb.NotFoundException) DoubleLatch(org.neo4j.test.DoubleLatch) Test(org.junit.Test)

Example 75 with NotFoundException

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

the class NodeTest method testNodeGetProperties.

@Test
public void testNodeGetProperties() {
    String key1 = "key1";
    String key2 = "key2";
    String key3 = "key3";
    Integer int1 = new Integer(1);
    Integer int2 = new Integer(2);
    String string = new String("3");
    Node node1 = getGraphDb().createNode();
    try {
        node1.getProperty(key1);
        fail("get non existing property din't throw exception");
    } catch (NotFoundException ignored) {
    }
    try {
        node1.getProperty(null);
        fail("get of null key din't throw exception");
    } catch (IllegalArgumentException ignored) {
    }
    assertTrue(!node1.hasProperty(key1));
    assertTrue(!node1.hasProperty(null));
    node1.setProperty(key1, int1);
    node1.setProperty(key2, int2);
    node1.setProperty(key3, string);
    Iterator<String> keys = node1.getPropertyKeys().iterator();
    keys.next();
    keys.next();
    keys.next();
    Map<String, Object> properties = node1.getAllProperties();
    assertTrue(properties.get(key1).equals(int1));
    assertTrue(properties.get(key2).equals(int2));
    assertTrue(properties.get(key3).equals(string));
    properties = node1.getProperties(key1, key2);
    assertTrue(properties.get(key1).equals(int1));
    assertTrue(properties.get(key2).equals(int2));
    assertFalse(properties.containsKey(key3));
    properties = node1.getProperties();
    assertTrue(properties.isEmpty());
    try {
        String[] names = null;
        node1.getProperties(names);
        fail();
    } catch (NullPointerException e) {
    // Ok
    }
    try {
        String[] names = new String[] { null };
        node1.getProperties(names);
        fail();
    } catch (NullPointerException e) {
    // Ok
    }
    try {
        node1.removeProperty(key3);
    } catch (NotFoundException e) {
        fail("Remove of property failed.");
    }
    assertTrue(!node1.hasProperty(key3));
    assertTrue(!node1.hasProperty(null));
    node1.delete();
}
Also used : 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