@Test public void testNotExistent() throws IOException { FileUtils.deleteFully(storageDir); // we will format the empty directory RaftStorage storage = new RaftStorage(storageDir, StartupOption.REGULAR); Assert.assertEquals(StorageState.NORMAL, storage.getState()); try { new RaftStorage(storageDir, StartupOption.FORMAT).close(); Assert.fail("the format should fail since the storage is still locked"); } catch (IOException e) { Assert.assertTrue(e.getMessage().contains("directory is already locked")); } storage.close(); FileUtils.deleteFully(storageDir); Assert.assertTrue(storageDir.createNewFile()); try { new RaftStorage(storageDir, StartupOption.REGULAR); Assert.fail(); } catch (IOException e) { Assert.assertTrue( e.getMessage().contains(StorageState.NON_EXISTENT.name())); } }
} catch (IOException e) { Assert.assertTrue( e.getMessage().contains(StorageState.NOT_FORMATTED.name()));
} catch (IOException e) { Assert.assertTrue( e.getMessage().contains(StorageState.NOT_FORMATTED.name()));
@Test public void testNotExistent() throws IOException { FileUtils.deleteFully(storageDir); // we will format the empty directory RaftStorage storage = new RaftStorage(storageDir, StartupOption.REGULAR); Assert.assertEquals(StorageState.NORMAL, storage.getState()); try { new RaftStorage(storageDir, StartupOption.FORMAT).close(); Assert.fail("the format should fail since the storage is still locked"); } catch (IOException e) { Assert.assertTrue(e.getMessage().contains("directory is already locked")); } storage.close(); FileUtils.deleteFully(storageDir); Assert.assertTrue(storageDir.createNewFile()); try { new RaftStorage(storageDir, StartupOption.REGULAR); Assert.fail(); } catch (IOException e) { Assert.assertTrue( e.getMessage().contains(StorageState.NON_EXISTENT.name())); } }