use of org.neo4j.test.TestGraphDatabaseFactory in project neo4j by neo4j.
the class TestIndexDelectionFs method doBefore.
@BeforeClass
public static void doBefore() throws IOException {
File directory = new File("target/test-data/deletion");
FileUtils.deleteRecursively(directory);
db = (GraphDatabaseAPI) new TestGraphDatabaseFactory().newEmbeddedDatabase(directory);
}
use of org.neo4j.test.TestGraphDatabaseFactory in project neo4j by neo4j.
the class TestAutoIndexReopen method startDb.
@Before
public void startDb() {
graphDb = (GraphDatabaseAPI) new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig(new HashMap<>()).newGraphDatabase();
try (Transaction tx = graphDb.beginTx()) {
// Create the node and relationship auto-indexes
graphDb.index().getNodeAutoIndexer().setEnabled(true);
graphDb.index().getNodeAutoIndexer().startAutoIndexingProperty("nodeProp");
graphDb.index().getRelationshipAutoIndexer().setEnabled(true);
graphDb.index().getRelationshipAutoIndexer().startAutoIndexingProperty("type");
tx.success();
}
try (Transaction tx = graphDb.beginTx()) {
Node node1 = graphDb.createNode();
Node node2 = graphDb.createNode();
Node node3 = graphDb.createNode();
id1 = node1.getId();
id2 = node2.getId();
id3 = node3.getId();
Relationship rel = node1.createRelationshipTo(node2, RelationshipType.withName("FOO"));
rel.setProperty("type", "FOO");
tx.success();
}
}
use of org.neo4j.test.TestGraphDatabaseFactory in project neo4j by neo4j.
the class LuceneRecoveryIT method testHardCoreRecovery.
@Test
public void testHardCoreRecovery() throws Exception {
String path = "target/hcdb";
File hcdb = new File(path);
FileUtils.deleteRecursively(hcdb);
Process process = Runtime.getRuntime().exec(new String[] { ProcessUtil.getJavaExecutable().toString(), "-cp", ProcessUtil.getClassPath(), Inserter.class.getName(), path });
// Let it run for a while and then kill it, and wait for it to die
awaitFile(new File(path, "started"));
Thread.sleep(5000);
process.destroy();
process.waitFor();
final GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabase(hcdb);
try (Transaction transaction = db.beginTx()) {
assertTrue(db.index().existsForNodes("myIndex"));
Index<Node> index = db.index().forNodes("myIndex");
for (Node node : db.getAllNodes()) {
for (String key : node.getPropertyKeys()) {
String value = (String) node.getProperty(key);
boolean found = false;
for (Node indexedNode : index.get(key, value)) {
if (indexedNode.equals(node)) {
found = true;
break;
}
}
if (!found) {
throw new IllegalStateException(node + " has property '" + key + "'='" + value + "', but not in index");
}
}
}
} catch (Throwable e) {
if (Exceptions.contains(e, CorruptIndexException.class) || exceptionContainsStackTraceElementFromPackage(e, "org.apache.lucene")) {
// On some machines and during some circumstances a lucene index may become
// corrupted during a crash. This is out of our control and since this test
// is about a legacy (a.k.a. manual index) the db cannot just re-populate the
// index automatically. We have to consider this an OK scenario and we cannot
// verify the index any further if it happens.
System.err.println("Lucene exception happened during recovery after a real crash. " + "It may be that the index is corrupt somehow and this is out of control and not " + "something this test can reall improve on right now. Printing the exception for reference");
e.printStackTrace();
return;
}
// This was another unknown exception, throw it so that the test fails with it
throw e;
}
// Added due to a recovery issue where the lucene data source write wasn't released properly after recovery.
Thread t = new Thread() {
@Override
public void run() {
try (Transaction tx = db.beginTx()) {
Index<Node> index = db.index().forNodes("myIndex");
index.add(db.createNode(), "one", "two");
tx.success();
}
}
};
t.start();
t.join();
db.shutdown();
}
use of org.neo4j.test.TestGraphDatabaseFactory in project neo4j by neo4j.
the class CypherSessionTest method shouldReturnASingleNode.
@Test
public void shouldReturnASingleNode() throws Throwable {
GraphDatabaseFacade graphdb = (GraphDatabaseFacade) new TestGraphDatabaseFactory().newImpermanentDatabase();
Database database = new WrappedDatabase(graphdb);
CypherExecutor executor = new CypherExecutor(database, NullLogProvider.getInstance());
executor.start();
HttpServletRequest request = mock(HttpServletRequest.class);
when(request.getScheme()).thenReturn("http");
when(request.getRemoteAddr()).thenReturn("127.0.0.1");
when(request.getRemotePort()).thenReturn(5678);
when(request.getServerName()).thenReturn("127.0.0.1");
when(request.getServerPort()).thenReturn(7474);
when(request.getRequestURI()).thenReturn("/");
try {
CypherSession session = new CypherSession(executor, NullLogProvider.getInstance(), request);
Pair<String, String> result = session.evaluate("create (a) return a");
assertThat(result.first(), containsString("Node[0]"));
} finally {
graphdb.shutdown();
}
}
use of org.neo4j.test.TestGraphDatabaseFactory in project neo4j by neo4j.
the class RestfulGraphDatabaseTest method doBefore.
@BeforeClass
public static void doBefore() throws IOException {
graph = (GraphDatabaseFacade) new TestGraphDatabaseFactory().newImpermanentDatabase();
database = new WrappedDatabase(graph);
helper = new GraphDbHelper(database);
output = new EntityOutputFormat(new JsonFormat(), URI.create(BASE_URI), null);
service = new TransactionWrappingRestfulGraphDatabase(graph, new RestfulGraphDatabase(new JsonFormat(), output, new DatabaseActions(new LeaseManager(Clocks.fakeClock()), true, database.getGraph()), new ConfigAdapter(Config.embeddedDefaults())));
}
Aggregations