public void testshouldRescanInterval() throws Exception { // set scan interval to 60 seconds, shouldRescan should now return false File basedir = new File(testdir, "testshouldRescan"); basedir.mkdirs(); final FileCache<ProviderLoader> loaderFileCache = new FileCache<ProviderLoader>(); // scan interval set to 60 seconds test scanner = new test(basedir, loaderFileCache, 60 * 1000); File testfile1 = new File(basedir, "service_provider"); assertTrue(testfile1.createNewFile()); File testfile2 = new File(basedir, "service2_provider"); assertTrue(testfile2.createNewFile()); final ProviderIdent ident = new ProviderIdent("service", "provider"); final ProviderIdent ident2 = new ProviderIdent("service2", "provider"); // initial pass should require scan assertTrue(scanner.shouldRescan()); // cause initial scan assertEquals(testfile1, scanner.scanForFile(ident)); assertFalse(scanner.shouldRescan()); // modify a file final FileOutputStream fileOutputStream = new FileOutputStream(testfile2); fileOutputStream.write("blah".getBytes()); fileOutputStream.close(); assertFalse(scanner.shouldRescan()); // rescan assertEquals(testfile2, scanner.scanForFile(ident2)); assertFalse(scanner.shouldRescan()); // delete a file testfile1.delete(); assertFalse(scanner.shouldRescan()); // rescan assertNull(scanner.scanForFile(ident)); assertFalse(scanner.shouldRescan()); }
public void testshouldRescan() throws Exception { // test rescan should return true if any file has been modified, and we are over the rescan // interval File basedir = new File(testdir, "testshouldRescan"); basedir.mkdirs(); final FileCache<ProviderLoader> loaderFileCache = new FileCache<ProviderLoader>(); test scanner = new test(basedir, loaderFileCache, 0); File testfile1 = new File(basedir, "service_provider"); assertTrue(testfile1.createNewFile()); File testfile2 = new File(basedir, "service2_provider"); assertTrue(testfile2.createNewFile()); final ProviderIdent ident = new ProviderIdent("service", "provider"); final ProviderIdent ident2 = new ProviderIdent("service2", "provider"); // initial pass should require scan assertTrue(scanner.shouldRescan()); // cause initial scan assertEquals(testfile1, scanner.scanForFile(ident)); assertFalse(scanner.shouldRescan()); // modify a file final FileOutputStream fileOutputStream = new FileOutputStream(testfile2); fileOutputStream.write("blah".getBytes()); fileOutputStream.close(); assertTrue(scanner.shouldRescan()); // rescan assertEquals(testfile2, scanner.scanForFile(ident2)); assertFalse(scanner.shouldRescan()); // delete a file testfile1.delete(); assertTrue(scanner.shouldRescan()); // rescan assertNull(scanner.scanForFile(ident)); assertFalse(scanner.shouldRescan()); }