You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2014/07/24 11:50:06 UTC
[1/2] git commit: Fortify the async nature of the FilesTest tests.
Repository: wicket
Updated Branches:
refs/heads/wicket-6.x e02c3ac5b -> a94cba36a
Fortify the async nature of the FilesTest tests.
We should null-ify the file/folder to be deleted so it is eligible for GC.
(cherry picked from commit 649f9d2538f30677d7231afb749d509383989f2b)
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/6460905f
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/6460905f
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/6460905f
Branch: refs/heads/wicket-6.x
Commit: 6460905fe6f2d9aaa13489c2bfcebbed93513d70
Parents: e02c3ac
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Thu Jul 24 12:47:51 2014 +0300
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Thu Jul 24 12:49:13 2014 +0300
----------------------------------------------------------------------
.../org/apache/wicket/util/file/FilesTest.java | 49 ++++++++++++++++----
1 file changed, 40 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/6460905f/wicket-util/src/test/java/org/apache/wicket/util/file/FilesTest.java
----------------------------------------------------------------------
diff --git a/wicket-util/src/test/java/org/apache/wicket/util/file/FilesTest.java b/wicket-util/src/test/java/org/apache/wicket/util/file/FilesTest.java
index 90534bb..74bcd30 100644
--- a/wicket-util/src/test/java/org/apache/wicket/util/file/FilesTest.java
+++ b/wicket-util/src/test/java/org/apache/wicket/util/file/FilesTest.java
@@ -27,7 +27,6 @@ import org.junit.Test;
*/
public class FilesTest extends Assert
{
-
/**
* Tests for {@link Files#remove(java.io.File)}
*
@@ -39,9 +38,10 @@ public class FilesTest extends Assert
assertFalse("'null' files are not deleted.", Files.remove(null));
assertFalse("Non existing files are not deleted.", Files.remove(new File(
- "/somethingThatDoesntExistsOnMostMachines-111111111111111111111111111111")));
+ "/somethingThatDoesntExistsOnMostMachines-111111111111111111111111111111")));
- java.io.File file = java.io.File.createTempFile("wicket-test--", ".tmp");
+ java.io.File file = getFile();
+ file.createNewFile();
assertTrue("The just created file should exist!", file.isFile());
boolean removed = Files.remove(file);
@@ -54,7 +54,7 @@ public class FilesTest extends Assert
assertFalse("Files.remove(file) should not remove the file", removed);
// try to remove a folder
- java.io.File folder = new File(System.getProperty("java.io.tmpdir"), "wicket-test-folder");
+ java.io.File folder = getFolder();
Files.mkdirs(folder);
assertTrue(folder.isDirectory());
assertFalse("Should not be able to delete a folder, even empty one.", Files.remove(folder));
@@ -103,19 +103,25 @@ public class FilesTest extends Assert
Files.removeFolderAsync(nonExistingFile, fileCleaner));
assertFalse(nonExistingFile.exists());
- java.io.File file = java.io.File.createTempFile("wicket-test--", ".tmp");
- assertTrue("The just created file should exist!", file.exists());
+ java.io.File file = getFile();
file.createNewFile();
+ assertTrue("The just created file should exist!", file.exists());
assertTrue(file.isFile());
assertTrue("The file is scheduled for deletion.", Files.removeAsync(file, fileCleaner));
+
+ // remove the reference to the file to be deleted
+ // this way the FileCleaningTracker's ReferenceQueue will mark it as eligible for GC
+ file = null;
+
// give chance to the file cleaner to run and delete the folder
System.gc();
boolean exists = true;
for (int i = 0; i < 10; i++)
{
Thread.sleep(5);
- if (!file.exists())
+ java.io.File newFileReference = getFile();
+ if (!newFileReference.exists())
{
exists = false;
break;
@@ -142,7 +148,7 @@ public class FilesTest extends Assert
Files.removeFolderAsync(nonExistingFolder, fileCleaner));
assertFalse(nonExistingFolder.exists());
- java.io.File folder = new File(System.getProperty("java.io.tmpdir"), "wicket-test-folder");
+ java.io.File folder = getFolder();
Files.mkdirs(folder);
assertTrue(folder.isDirectory());
File file = new File(folder, "child");
@@ -151,10 +157,16 @@ public class FilesTest extends Assert
assertTrue("The folder is scheduled for deletion.",
Files.removeFolderAsync(folder, fileCleaner));
+
+ // remove the reference to the folder to be deleted
+ // this way the FileCleaningTracker's ReferenceQueue will mark it as eligible for GC
+ folder = null;
+
// give chance to the file cleaner to run and delete the folder
System.gc();
Thread.sleep(5);
- assertFalse("", folder.exists());
+ java.io.File newFolderReference = getFolder();
+ assertFalse("The folder still exists", newFolderReference.exists());
}
/**
@@ -169,4 +181,23 @@ public class FilesTest extends Assert
assertEquals( java.io.File.separator + "file with whitespace", Files.getLocalFileFromUrl(url).getPath());
}
+
+ /**
+ * @return a reference to a folder, without creating it !
+ */
+ private java.io.File getFolder()
+ {
+ File folder = new File(System.getProperty("java.io.tmpdir"), "wicket-7.x-test-folder");
+ return folder;
+ }
+
+ /**
+ * @return a reference to a file, without creating it !
+ * @throws IOException
+ */
+ private java.io.File getFile() throws IOException
+ {
+ return new java.io.File(System.getProperty("java.io.tmpdir"), "wicket-7.x-test-file");
+ }
+
}
[2/2] git commit: Use 6.x in the file/folder names
Posted by mg...@apache.org.
Use 6.x in the file/folder names
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/a94cba36
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/a94cba36
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/a94cba36
Branch: refs/heads/wicket-6.x
Commit: a94cba36a0bebb474a848448b5bc224766209398
Parents: 6460905
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Thu Jul 24 12:49:36 2014 +0300
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Thu Jul 24 12:49:36 2014 +0300
----------------------------------------------------------------------
.../src/test/java/org/apache/wicket/util/file/FilesTest.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/a94cba36/wicket-util/src/test/java/org/apache/wicket/util/file/FilesTest.java
----------------------------------------------------------------------
diff --git a/wicket-util/src/test/java/org/apache/wicket/util/file/FilesTest.java b/wicket-util/src/test/java/org/apache/wicket/util/file/FilesTest.java
index 74bcd30..2c124c7 100644
--- a/wicket-util/src/test/java/org/apache/wicket/util/file/FilesTest.java
+++ b/wicket-util/src/test/java/org/apache/wicket/util/file/FilesTest.java
@@ -187,7 +187,7 @@ public class FilesTest extends Assert
*/
private java.io.File getFolder()
{
- File folder = new File(System.getProperty("java.io.tmpdir"), "wicket-7.x-test-folder");
+ File folder = new File(System.getProperty("java.io.tmpdir"), "wicket-6.x-test-folder");
return folder;
}
@@ -197,7 +197,7 @@ public class FilesTest extends Assert
*/
private java.io.File getFile() throws IOException
{
- return new java.io.File(System.getProperty("java.io.tmpdir"), "wicket-7.x-test-file");
+ return new java.io.File(System.getProperty("java.io.tmpdir"), "wicket-6.x-test-file");
}
}