/** * Retrieve the number of files currently being tracked, and therefore * awaiting deletion. * * @return the number of files being tracked * @deprecated Use {@link FileCleaningTracker#getTrackCount()}. */ @Deprecated public static int getTrackCount() { return theInstance.getTrackCount(); }
/** * Retrieve the number of files currently being tracked, and therefore * awaiting deletion. * * @return the number of files being tracked */ public static int getTrackCount() { return theInstance.getTrackCount(); }
private void waitUntilTrackCount() throws Exception { System.gc(); TestUtils.sleep(500); int count = 0; while(theInstance.getTrackCount() != 0 && count++ < 5) { List<String> list = new ArrayList<>(); try { long i = 0; while (theInstance.getTrackCount() != 0) { list.add("A Big String A Big String A Big String A Big String A Big String A Big String A Big String A Big String A Big String A Big String " + (i++)); } } catch (final Throwable ignored) { } list = null; System.gc(); TestUtils.sleep(1000); } if (theInstance.getTrackCount() != 0) { throw new IllegalStateException("Your JVM is not releasing References, try running the testcase with less memory (-Xmx)"); } } }
@Test public void testFileCleanerFile() throws Exception { final String path = testFile.getPath(); assertFalse(testFile.exists()); RandomAccessFile r = new RandomAccessFile(testFile, "rw"); assertTrue(testFile.exists()); assertEquals(0, theInstance.getTrackCount()); theInstance.track(path, r); assertEquals(1, theInstance.getTrackCount()); r.close(); testFile = null; r = null; waitUntilTrackCount(); pauseForDeleteToComplete(new File(path)); assertEquals(0, theInstance.getTrackCount()); assertEquals(showFailures(), false, new File(path).exists()); }
@Test public void testFileCleanerDirectory_NullStrategy() throws Exception { TestUtils.createFile(testFile, 100); assertTrue(testFile.exists()); assertTrue(getTestDirectory().exists()); Object obj = new Object(); assertEquals(0, theInstance.getTrackCount()); theInstance.track(getTestDirectory(), obj, null); assertEquals(1, theInstance.getTrackCount()); obj = null; waitUntilTrackCount(); assertEquals(0, theInstance.getTrackCount()); assertTrue(testFile.exists()); // not deleted, as dir not empty assertTrue(testFile.getParentFile().exists()); // not deleted, as dir not empty }
@Test public void testFileCleanerDirectory() throws Exception { TestUtils.createFile(testFile, 100); assertTrue(testFile.exists()); assertTrue(getTestDirectory().exists()); Object obj = new Object(); assertEquals(0, theInstance.getTrackCount()); theInstance.track(getTestDirectory(), obj); assertEquals(1, theInstance.getTrackCount()); obj = null; waitUntilTrackCount(); assertEquals(0, theInstance.getTrackCount()); assertTrue(testFile.exists()); // not deleted, as dir not empty assertTrue(testFile.getParentFile().exists()); // not deleted, as dir not empty }
@Test public void testFileCleanerDirectory_ForceStrategy() throws Exception { if (!testFile.getParentFile().exists()) { throw new IOException("Cannot create file " + testFile + " as the parent directory does not exist"); } try (final BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(testFile))) { TestUtils.generateTestData(output, 100); } assertTrue(testFile.exists()); assertTrue(getTestDirectory().exists()); Object obj = new Object(); assertEquals(0, theInstance.getTrackCount()); theInstance.track(getTestDirectory(), obj, FileDeleteStrategy.FORCE); assertEquals(1, theInstance.getTrackCount()); obj = null; waitUntilTrackCount(); pauseForDeleteToComplete(testFile.getParentFile()); assertEquals(0, theInstance.getTrackCount()); assertEquals(showFailures(), false, new File(testFile.getPath()).exists()); assertEquals(showFailures(), false, testFile.getParentFile().exists()); }
@Test public void testFileCleanerExitWhenFinished1() throws Exception { final String path = testFile.getPath(); assertEquals("1-testFile exists: " + testFile, false, testFile.exists()); RandomAccessFile r = new RandomAccessFile(testFile, "rw"); assertEquals("2-testFile exists", true, testFile.exists()); assertEquals("3-Track Count", 0, theInstance.getTrackCount()); theInstance.track(path, r); assertEquals("4-Track Count", 1, theInstance.getTrackCount()); assertEquals("5-exitWhenFinished", false, theInstance.exitWhenFinished); assertEquals("6-reaper.isAlive", true, theInstance.reaper.isAlive()); assertEquals("7-exitWhenFinished", false, theInstance.exitWhenFinished); theInstance.exitWhenFinished(); assertEquals("8-exitWhenFinished", true, theInstance.exitWhenFinished); assertEquals("9-reaper.isAlive", true, theInstance.reaper.isAlive()); r.close(); testFile = null; r = null; waitUntilTrackCount(); pauseForDeleteToComplete(new File(path)); assertEquals("10-Track Count", 0, theInstance.getTrackCount()); assertEquals("11-testFile exists " + showFailures(), false, new File(path).exists()); assertEquals("12-exitWhenFinished", true, theInstance.exitWhenFinished); assertEquals("13-reaper.isAlive", false, theInstance.reaper.isAlive()); }
@Test public void testFileCleanerExitWhenFinished2() throws Exception { final String path = testFile.getPath(); assertFalse(testFile.exists()); RandomAccessFile r = new RandomAccessFile(testFile, "rw"); assertTrue(testFile.exists()); assertEquals(0, theInstance.getTrackCount()); theInstance.track(path, r); assertEquals(1, theInstance.getTrackCount()); assertFalse(theInstance.exitWhenFinished); assertTrue(theInstance.reaper.isAlive()); r.close(); testFile = null; r = null; waitUntilTrackCount(); pauseForDeleteToComplete(new File(path)); assertEquals(0, theInstance.getTrackCount()); assertEquals(showFailures(), false, new File(path).exists()); assertFalse(theInstance.exitWhenFinished); assertTrue(theInstance.reaper.isAlive()); assertFalse(theInstance.exitWhenFinished); theInstance.exitWhenFinished(); for (int i = 0; i < 20 && theInstance.reaper.isAlive(); i++) { TestUtils.sleep(500L); // allow reaper thread to die } assertTrue(theInstance.exitWhenFinished); assertFalse(theInstance.reaper.isAlive()); }
@Test public void testFileCleanerExitWhenFinishedFirst() throws Exception { assertFalse(theInstance.exitWhenFinished); theInstance.exitWhenFinished(); assertTrue(theInstance.exitWhenFinished); assertEquals(null, theInstance.reaper); waitUntilTrackCount(); assertEquals(0, theInstance.getTrackCount()); assertTrue(theInstance.exitWhenFinished); assertEquals(null, theInstance.reaper); }
/** * Retrieve the number of files currently being tracked, and therefore * awaiting deletion. * * @return the number of files being tracked * @deprecated Use {@link FileCleaningTracker#getTrackCount()}. */ public static int getTrackCount() { return theInstance.getTrackCount(); }
/** * Retrieve the number of files currently being tracked, and therefore * awaiting deletion. * * @return the number of files being tracked * @deprecated Use {@link FileCleaningTracker#getTrackCount()}. */ public static int getTrackCount() { return theInstance.getTrackCount(); }
/** * Retrieve the number of files currently being tracked, and therefore * awaiting deletion. * * @return the number of files being tracked * @deprecated Use {@link FileCleaningTracker#getTrackCount()}. */ @Deprecated public static int getTrackCount() { return theInstance.getTrackCount(); }
/** * Retrieve the number of files currently being tracked, and therefore * awaiting deletion. * * @return the number of files being tracked * @deprecated Use {@link FileCleaningTracker#getTrackCount()}. */ @Deprecated public static int getTrackCount() { return theInstance.getTrackCount(); }
/** * Retrieve the number of files currently being tracked, and therefore * awaiting deletion. * * @return the number of files being tracked * @deprecated Use {@link FileCleaningTracker#getTrackCount()}. */ @Deprecated public static int getTrackCount() { return theInstance.getTrackCount(); }
/** * Retrieve the number of files currently being tracked, and therefore * awaiting deletion. * * @return the number of files being tracked * @deprecated Use {@link FileCleaningTracker#getTrackCount()}. */ @Deprecated public static int getTrackCount() { return theInstance.getTrackCount(); }