ChangedListBackupManager implements Runnable { public ChangedListBackupManager(ChangedList changedList, File backupDir, long backupFrequency, List<File> contentDirs) { this.backupDir = new File(backupDir, "changeList"); if (!this.backupDir.exists()) { this.backupDir.mkdir(); } this.backupFrequency = backupFrequency; this.changedList = changedList; this.contentDirs = contentDirs; continueBackup = true; } ChangedListBackupManager(ChangedList changedList,
                                    File backupDir,
                                    long backupFrequency, List<File> contentDirs); long loadBackup(); void run(); void clear(); void endBackup(); boolean hasBackups(); static final int SAVED_BACKUPS; }
@Test public void testChangedListBackupManager() throws Exception { long backupFrequency = 100; ChangedListBackupManager bkMan = new ChangedListBackupManager(changedList, tempDir, backupFrequency, new LinkedList<File>()); new Thread(bkMan).start(); String testFileName = "testfile" + System.currentTimeMillis(); File file = new File(tempDir, testFileName); file.createNewFile(); file.deleteOnExit(); changedList.addChangedFile(file); Thread.sleep((backupFrequency * 3) + ChangedListBackupManager.DEFAULT_SLEEP_TIME); bkMan.endBackup(); ChangedFile changedFile = changedList.reserve(); changedFile.remove(); assertNotNull(changedFile); assertEquals(testFileName, changedFile.getFile().getName()); assertNull(changedList.reserve()); assertTrue(bkMan.loadBackup() > 0); changedFile = changedList.reserve(); assertNotNull(changedFile); assertEquals(testFileName, changedFile.getFile().getName()); assertNull(changedList.reserve()); }