private static File createTemporaryGraphStore() { try { Path path = Files.createTempDirectory("graph.db"); Path databaseDirectory = Paths.get(path.toFile().getAbsolutePath() + "/database"); Files.createDirectories(databaseDirectory); Runtime.getRuntime().addShutdownHook(new Thread(() -> { try { FileUtils.deleteDirectory(path); } catch (IOException e) { throw new RuntimeException("Failed to delete temporary files in " + path, e); } })); return databaseDirectory.toFile(); } catch (IOException e) { throw new RuntimeException(e); } }
private String createTemporaryFileStore() { try { Path path = Files.createTempDirectory("neo4jTmpEmbedded.db"); Path databasePath = Paths.get(path.toFile().getAbsolutePath() + "/database"); Files.createDirectories(databasePath); final File f = databasePath.toFile(); URI uri = f.toURI(); final String databaseUriValue = uri.toString(); logger.warn("Creating temporary file store: " + databaseUriValue); Runtime.getRuntime().addShutdownHook(new Thread(() -> { close(); try { logger.warn("Deleting temporary file store: " + databaseUriValue); deleteDirectory(path); } catch (IOException e) { throw new RuntimeException("Failed to delete temporary files in " + databaseUriValue, e); } })); return databaseUriValue; } catch (Exception e) { throw new RuntimeException(e); } }
@AfterClass public static void deleteEmbeddedStore() throws IOException { FileUtils.deleteDirectory(TMP_NEO4J); }
@Test // GH-169 public void shouldCreateDirectoryIfMissing() throws IOException { final String EMBEDDED_DIR = "/var/tmp/ogmEmbeddedDir"; Path path = Paths.get(EMBEDDED_DIR); if (Files.exists(path)) { FileUtils.deleteDirectory(path); } Configuration configuration = new Configuration.Builder().uri("file://" + EMBEDDED_DIR).build(); try (EmbeddedDriver driver = new EmbeddedDriver()) { driver.configure(configuration); assertThat(configuration.getURI()).isEqualTo("file://" + EMBEDDED_DIR); assertThat(driver.unwrap(GraphDatabaseService.class)).isNotNull(); assertThat(Files.exists(path)).isTrue(); } FileUtils.deleteDirectory(path); }