@Test public void testConstructorReaderTimeElapsedDirectory() throws Exception { String uuid = UUID.randomUUID().toString(); File directory = new File(System.getProperty("java.io.tmpdir"), uuid); memoizer = new Memoizer(reader, 0, directory); // Check non-existing memo directory returns null assertEquals(memoizer.getMemoFile(id), null); // Create memoizer directory and memoizer reader directory.mkdirs(); String memoDir = idDir.getAbsolutePath(); memoDir = memoDir.substring(memoDir.indexOf(File.separator) + 1); File memoFile = new File(directory, memoDir); memoFile = new File(memoFile, "." + TEST_FILE + ".bfmemo"); File f = memoizer.getMemoFile(id); assertEquals(f.getAbsolutePath(), memoFile.getAbsolutePath()); // Test multiple setId invocations memoizer.setId(id); assertFalse(memoizer.isLoadedFromMemo()); assertTrue(memoizer.isSavedToMemo()); memoizer.close(); memoizer.setId(id); assertTrue(memoizer.isLoadedFromMemo()); assertFalse(memoizer.isSavedToMemo()); memoizer.close(); }
@Test public void testConstructorReaderTimeElapsed() throws Exception { memoizer = new Memoizer(reader, 0); File f = memoizer.getMemoFile(id); File memoFile = new File(idDir, "." + TEST_FILE + ".bfmemo"); assertEquals(f.getAbsolutePath(), memoFile.getAbsolutePath()); // Test multiple setId invocations memoizer.setId(id); assertFalse(memoizer.isLoadedFromMemo()); assertTrue(memoizer.isSavedToMemo()); memoizer.close(); memoizer.setId(id); assertTrue(memoizer.isLoadedFromMemo()); assertFalse(memoizer.isSavedToMemo()); memoizer.close(); }
@Test public void testRelocate() throws Exception { // Create an in-place memo file memoizer = new Memoizer(reader, 0); memoizer.setId(id); memoizer.close(); assertFalse(memoizer.isLoadedFromMemo()); assertTrue(memoizer.isSavedToMemo()); // Rename the directory (including the file and the memo file) String uuid = UUID.randomUUID().toString(); File newidDir = new File(System.getProperty("java.io.tmpdir"), uuid); idDir.renameTo(newidDir); File newtempFile = new File(newidDir, TEST_FILE); String newid = newtempFile.getAbsolutePath(); // Try to reopen the file with the Memoizer memoizer.setId(newid); memoizer.close(); assertFalse(memoizer.isLoadedFromMemo()); assertTrue(memoizer.isSavedToMemo()); }
@Test public void testConstructorReaderTimeElapsedNull() throws Exception { memoizer = new Memoizer(reader, 0, null); // Check null memo directory returns null assertEquals(memoizer.getMemoFile(id), null); // Test setId invocation memoizer.setId(id); assertFalse(memoizer.isLoadedFromMemo()); assertFalse(memoizer.isSavedToMemo()); memoizer.close(); }