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