@Test public void shouldPerformRecoveryIfNecessary() throws Exception { // Given StoreRecoverer recoverer = new StoreRecoverer(); Configuration config = buildProperties(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); new GraphDatabaseFactory().newEmbeddedDatabase(STORE_DIRECTORY).shutdown(); // Make this look incorrectly shut down new File(STORE_DIRECTORY, "nioneo_logical.log.active").delete(); assertThat( "Store should not be recovered", recoverer.recoveryNeededAt(new File(STORE_DIRECTORY), new HashMap<String, String>()), is(true)); // Run recovery PerformRecoveryIfNecessary task = new PerformRecoveryIfNecessary( config, new HashMap<String, String>(), new PrintStream(outputStream)); assertThat("Recovery task should run successfully.", task.run(), is(true)); assertThat("Database should exist.", new File(STORE_DIRECTORY).exists(), is(true)); assertThat( "Recovery should print status message.", outputStream.toString(), is("Detected incorrectly shut down database, performing recovery.." + LINEBREAK)); assertThat( "Store should be recovered", recoverer.recoveryNeededAt(new File(STORE_DIRECTORY), new HashMap<String, String>()), is(false)); }
@Test public void shouldNotDoAnythingIfNoDBPresent() throws Exception { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); Configuration config = buildProperties(); PerformRecoveryIfNecessary task = new PerformRecoveryIfNecessary( config, new HashMap<String, String>(), new PrintStream(outputStream)); assertThat("Recovery task runs successfully.", task.run(), is(true)); assertThat( "No database should have been created.", new File(STORE_DIRECTORY).exists(), is(false)); assertThat("Recovery task should not print anything.", outputStream.toString(), is("")); }
@Test public void doesNotPrintAnythingIfDatabaseWasCorrectlyShutdown() throws Exception { // Given Configuration config = buildProperties(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); new GraphDatabaseFactory().newEmbeddedDatabase(STORE_DIRECTORY).shutdown(); PerformRecoveryIfNecessary task = new PerformRecoveryIfNecessary( config, new HashMap<String, String>(), new PrintStream(outputStream)); assertThat("Recovery task should run successfully.", task.run(), is(true)); assertThat("Database should exist.", new File(STORE_DIRECTORY).exists(), is(true)); assertThat("Recovery should not print anything.", outputStream.toString(), is("")); }