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());
}
}
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));
}
}
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);
}
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()));
}
}
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();
}
Aggregations