[hg] main-silver: Added rnadom test for FileObjectCrawler.

  • From: Tomas Zezula < >
  • To:
  • Subject: [hg] main-silver: Added rnadom test for FileObjectCrawler.
  • Date: Wed, 16 Jan 2013 12:50:20 -0800

changeset 5eb0c8c4c547 in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/5eb0c8c4c547
description:
        Added rnadom test for FileObjectCrawler.

diffstat:

 
parsing.api/test/unit/src/org/netbeans/modules/parsing/impl/indexing/FileObjectCrawlerTest.java
 |  187 ++++++---
 1 files changed, 130 insertions(+), 57 deletions(-)

diffs (415 lines):

diff --git 
a/parsing.api/test/unit/src/org/netbeans/modules/parsing/impl/indexing/FileObjectCrawlerTest.java
 
b/parsing.api/test/unit/src/org/netbeans/modules/parsing/impl/indexing/FileObjectCrawlerTest.java
--- 
a/parsing.api/test/unit/src/org/netbeans/modules/parsing/impl/indexing/FileObjectCrawlerTest.java
+++ 
b/parsing.api/test/unit/src/org/netbeans/modules/parsing/impl/indexing/FileObjectCrawlerTest.java
@@ -55,6 +55,7 @@
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Random;
 import java.util.Set;
 import java.util.regex.Pattern;
 import org.netbeans.api.java.classpath.ClassPath;
@@ -65,6 +66,7 @@
 import org.netbeans.spi.java.classpath.support.ClassPathSupport;
 import org.openide.filesystems.FileObject;
 import org.openide.filesystems.FileStateInvalidException;
+import org.openide.filesystems.FileSystem;
 import org.openide.filesystems.FileUtil;
 
 /**
@@ -73,6 +75,13 @@
  */
 public class FileObjectCrawlerTest extends NbTestCase {
 
+    //Random test options
+    private static final boolean RUN_RANDOM_TESTS = false;
+    private static final int SINGLE_TEST_SET_SIZE = 5;
+    private static final int TEST_COUNT = 100000;
+    private static final int TREE_DEPTH = 5;
+    private static final int TREE_CHILD_COUNT = 3;
+
     private static final CancelRequest CR = new CancelRequest() {
         @Override
         public boolean isRaised() {
@@ -93,11 +102,16 @@
         CacheFolder.setCacheFolder(cache);
     }
 
+    @Override
+    protected void tearDown() throws IOException {
+        FileObjectCrawler.mockLinkTypes = null;
+    }
+
     public void testIncludesExcludes() throws IOException {
         final FileObject src = 
FileUtil.createFolder(FileUtil.toFileObject(getWorkDir()), "src");
         assertNotNull(src);
 
-        populateFolderStructure(new File(getWorkDir(), "src"),
+        populateFolderStructure(FileUtil.createFolder(new File(getWorkDir(), 
"src")),
             "p1/Included1.java",
             "p1/Included2.java",
             "p1/a/Included3.java",
@@ -147,7 +161,7 @@
     }
 
     public void testRelativePaths() throws IOException {
-        File root = new File(getWorkDir(), "src");
+        FileObject root = FileUtil.createFolder(new File(getWorkDir(), 
"src"));
         String [] paths = new String [] {
                 "org/pckg1/file1.txt",
                 "org/pckg1/pckg2/file1.txt",
@@ -156,12 +170,12 @@
         };
         populateFolderStructure(root, paths);
 
-        FileObjectCrawler crawler1 = new 
FileObjectCrawler(FileUtil.toFileObject(root), 
EnumSet.<Crawler.TimeStampAction>of(Crawler.TimeStampAction.UPDATE), null, 
CR, SuspendSupport.NOP);
+        FileObjectCrawler crawler1 = new FileObjectCrawler(root, 
EnumSet.<Crawler.TimeStampAction>of(Crawler.TimeStampAction.UPDATE), null, 
CR, SuspendSupport.NOP);
         assertCollectedFiles("Wrong files collected", 
crawler1.getResources(), paths);
         assertCollectedFiles("Wrong files collected", 
crawler1.getAllResources(), paths);
         
-        FileObject folder = FileUtil.toFileObject(new File(root, 
"org/pckg1/pckg2"));
-        FileObjectCrawler crawler2 = new 
FileObjectCrawler(FileUtil.toFileObject(root), new FileObject [] { folder }, 
EnumSet.<Crawler.TimeStampAction>of(Crawler.TimeStampAction.UPDATE), null, 
CR, SuspendSupport.NOP);
+        FileObject folder = root.getFileObject("org/pckg1/pckg2");
+        FileObjectCrawler crawler2 = new FileObjectCrawler(root, new 
FileObject [] { folder }, 
EnumSet.<Crawler.TimeStampAction>of(Crawler.TimeStampAction.UPDATE), null, 
CR, SuspendSupport.NOP);
         assertCollectedFiles("Wrong files collected from " + folder, 
crawler2.getResources(),
             "org/pckg1/pckg2/file1.txt",
             "org/pckg1/pckg2/file2.txt"
@@ -170,7 +184,7 @@
     }
 
     public void testDeletedFiles() throws IOException {
-        File root = new File(getWorkDir(), "src");
+        FileObject root = FileUtil.createFolder(new File(getWorkDir(), 
"src"));
         String [] paths = new String [] {
                 "org/pckg1/file1.txt",
                 "org/pckg1/pckg2/file1.txt",
@@ -179,26 +193,26 @@
         };
         populateFolderStructure(root, paths);
 
-        FileObjectCrawler crawler1 = new 
FileObjectCrawler(FileUtil.toFileObject(root), 
EnumSet.<Crawler.TimeStampAction>of(Crawler.TimeStampAction.UPDATE), null, 
CR, SuspendSupport.NOP);
+        FileObjectCrawler crawler1 = new FileObjectCrawler(root, 
EnumSet.<Crawler.TimeStampAction>of(Crawler.TimeStampAction.UPDATE), null, 
CR, SuspendSupport.NOP);
         assertCollectedFiles("Wrong files collected", 
crawler1.getResources(), paths);
         assertCollectedFiles("Wrong files collected", 
crawler1.getAllResources(), paths);
 
-        FileObject pckg2 = FileUtil.toFileObject(new File(root, 
"org/pckg1/pckg2"));
-        FileObject org = FileUtil.toFileObject(new File(root, "org"));
+        FileObject pckg2 = root.getFileObject("org/pckg1/pckg2");
+        FileObject org = root.getFileObject("org");
         org.delete();
 
-        FileObjectCrawler crawler2 = new 
FileObjectCrawler(FileUtil.toFileObject(root), new FileObject [] { pckg2 }, 
EnumSet.<Crawler.TimeStampAction>of(Crawler.TimeStampAction.UPDATE), null, 
CR, SuspendSupport.NOP);
+        FileObjectCrawler crawler2 = new FileObjectCrawler(root, new 
FileObject [] { pckg2 }, 
EnumSet.<Crawler.TimeStampAction>of(Crawler.TimeStampAction.UPDATE), null, 
CR, SuspendSupport.NOP);
         assertCollectedFiles("There should be no files in " + root, 
crawler2.getResources());
         assertNull("All resources should not be computed for subtree", 
crawler2.getAllResources());
 
-        FileObjectCrawler crawler3 = new 
FileObjectCrawler(FileUtil.toFileObject(root), 
EnumSet.<Crawler.TimeStampAction>of(Crawler.TimeStampAction.UPDATE), null, 
CR, SuspendSupport.NOP);
+        FileObjectCrawler crawler3 = new FileObjectCrawler(root, 
EnumSet.<Crawler.TimeStampAction>of(Crawler.TimeStampAction.UPDATE), null, 
CR, SuspendSupport.NOP);
         assertCollectedFiles("There should be no files in " + root, 
crawler3.getResources());
         assertCollectedFiles("There should be no files in " + root, 
crawler3.getAllResources());
         assertCollectedFiles("All files in " + root + " should be deleted", 
crawler3.getDeletedResources());
     }
 
     public void testAllFilesIndexing() throws Exception {
-        File root = new File(getWorkDir(), "src");
+        FileObject root = FileUtil.createFolder(new File(getWorkDir(), 
"src"));
         String [] paths = new String [] {
                 "org/pckg1/file1.txt",
                 "org/pckg1/pckg2/file1.txt",
@@ -208,7 +222,7 @@
         populateFolderStructure(root, paths);
 
         //First scan with timestamps enabled (project open)
-        FileObjectCrawler crawler1 = new 
FileObjectCrawler(FileUtil.toFileObject(root), 
EnumSet.<Crawler.TimeStampAction>of(Crawler.TimeStampAction.UPDATE, 
Crawler.TimeStampAction.CHECK), null, CR, SuspendSupport.NOP);
+        FileObjectCrawler crawler1 = new FileObjectCrawler(root, 
EnumSet.<Crawler.TimeStampAction>of(Crawler.TimeStampAction.UPDATE, 
Crawler.TimeStampAction.CHECK), null, CR, SuspendSupport.NOP);
         assertCollectedFiles("Wrong all files collected", 
crawler1.getAllResources(), paths);
         assertTrue(crawler1.getAllResources() != crawler1.getResources());
         assertEquals(crawler1.getAllResources().size(), 
crawler1.getResources().size());
@@ -216,36 +230,35 @@
         crawler1.storeTimestamps();
 
         //Second scan with timestamps enabled (project reopen)
-        FileObjectCrawler crawler2 = new 
FileObjectCrawler(FileUtil.toFileObject(root), 
EnumSet.<Crawler.TimeStampAction>of(Crawler.TimeStampAction.UPDATE, 
Crawler.TimeStampAction.CHECK), null, CR, SuspendSupport.NOP);
+        FileObjectCrawler crawler2 = new FileObjectCrawler(root, 
EnumSet.<Crawler.TimeStampAction>of(Crawler.TimeStampAction.UPDATE, 
Crawler.TimeStampAction.CHECK), null, CR, SuspendSupport.NOP);
         assertCollectedFiles("Wrong all files collected", 
crawler2.getAllResources(), paths);
         assertTrue(crawler2.getAllResources() != crawler2.getResources());
         assertEquals(0, crawler2.getResources().size());
         crawler2.storeTimestamps();
 
         //Rescan of root with force == false
-        FileObjectCrawler crawler3 = new 
FileObjectCrawler(FileUtil.toFileObject(root), 
EnumSet.<Crawler.TimeStampAction>of(Crawler.TimeStampAction.UPDATE, 
Crawler.TimeStampAction.CHECK), null, CR, SuspendSupport.NOP);
+        FileObjectCrawler crawler3 = new FileObjectCrawler(root, 
EnumSet.<Crawler.TimeStampAction>of(Crawler.TimeStampAction.UPDATE, 
Crawler.TimeStampAction.CHECK), null, CR, SuspendSupport.NOP);
         assertCollectedFiles("Wrong all files collected", 
crawler3.getAllResources(), paths);
         assertTrue(crawler3.getAllResources() != crawler3.getResources());
         assertEquals(0, crawler3.getResources().size());
         crawler3.storeTimestamps();
 
         //Rescan of root with force == true
-        FileObjectCrawler crawler4 = new 
FileObjectCrawler(FileUtil.toFileObject(root), 
EnumSet.<Crawler.TimeStampAction>of(Crawler.TimeStampAction.UPDATE), null, 
CR, SuspendSupport.NOP);
+        FileObjectCrawler crawler4 = new FileObjectCrawler(root, 
EnumSet.<Crawler.TimeStampAction>of(Crawler.TimeStampAction.UPDATE), null, 
CR, SuspendSupport.NOP);
         assertCollectedFiles("Wrong all files collected", 
crawler4.getAllResources(), paths);
         assertTrue(crawler4.getAllResources() == crawler4.getResources());
         crawler4.storeTimestamps();
 
         //Rescan of specified files (no timestamps)
-        final FileObject rootFo = FileUtil.toFileObject(root);
-        final FileObject expFile1 = 
rootFo.getFileObject("org/pckg1/pckg2/file1.txt");
-        final FileObject expFile2 = 
rootFo.getFileObject("org/pckg1/pckg2/file2.txt");
-        FileObjectCrawler crawler5 = new FileObjectCrawler(rootFo, new 
FileObject[] {expFile1, expFile2}, 
EnumSet.<Crawler.TimeStampAction>of(Crawler.TimeStampAction.UPDATE), null, 
CR, SuspendSupport.NOP);
+        final FileObject expFile1 = 
root.getFileObject("org/pckg1/pckg2/file1.txt");
+        final FileObject expFile2 = 
root.getFileObject("org/pckg1/pckg2/file2.txt");
+        FileObjectCrawler crawler5 = new FileObjectCrawler(root, new 
FileObject[] {expFile1, expFile2}, 
EnumSet.<Crawler.TimeStampAction>of(Crawler.TimeStampAction.UPDATE), null, 
CR, SuspendSupport.NOP);
         assertNull(crawler5.getAllResources());
         assertCollectedFiles("Wrong files collected", 
crawler5.getResources(), new String[] 
{"org/pckg1/pckg2/file1.txt","org/pckg1/pckg2/file2.txt"});
         crawler5.storeTimestamps();
 
         //Rescan of specified files with timestamps
-        FileObjectCrawler crawler6 = new FileObjectCrawler(rootFo, new 
FileObject[] {expFile1, expFile2}, 
EnumSet.<Crawler.TimeStampAction>of(Crawler.TimeStampAction.UPDATE, 
Crawler.TimeStampAction.CHECK), null, CR, SuspendSupport.NOP);
+        FileObjectCrawler crawler6 = new FileObjectCrawler(root, new 
FileObject[] {expFile1, expFile2}, 
EnumSet.<Crawler.TimeStampAction>of(Crawler.TimeStampAction.UPDATE, 
Crawler.TimeStampAction.CHECK), null, CR, SuspendSupport.NOP);
         assertNull(crawler6.getAllResources());
         assertEquals(0, crawler6.getResources().size());
         crawler6.storeTimestamps();
@@ -307,7 +320,7 @@
     }
 
     public void testDuplicateResults1() throws IOException {
-        File root = new File(getWorkDir(), "src");
+        FileObject root = FileUtil.createFolder(new File(getWorkDir(), 
"src"));
         String [] paths = new String [] {
                 "org/pckg1/file1.txt",
                 "org/pckg1/pckg2/file1.txt",
@@ -316,13 +329,12 @@
 
         populateFolderStructure(root, paths);
 
-        FileObject rootFO = FileUtil.toFileObject(root);
-        FileObjectCrawler crawler = new FileObjectCrawler(rootFO, new 
FileObject[] {rootFO.getFileObject("org/pckg1/pckg2/file1.txt"), 
rootFO.getFileObject("org/pckg1/pckg2")}, 
EnumSet.<Crawler.TimeStampAction>of(Crawler.TimeStampAction.UPDATE), null, 
CR, SuspendSupport.NOP);
+        FileObjectCrawler crawler = new FileObjectCrawler(root, new 
FileObject[] {root.getFileObject("org/pckg1/pckg2/file1.txt"), 
root.getFileObject("org/pckg1/pckg2")}, 
EnumSet.<Crawler.TimeStampAction>of(Crawler.TimeStampAction.UPDATE), null, 
CR, SuspendSupport.NOP);
         assertCollectedFiles("Wrong files collected", 
crawler.getResources(), new String[] {"org/pckg1/pckg2/file1.txt", 
"org/pckg1/pckg2/file2.txt"});
     }
 
     public void testDuplicateResults2() throws IOException {
-        File root = new File(getWorkDir(), "src");
+        FileObject root = FileUtil.createFolder(new File(getWorkDir(), 
"src"));
         String [] paths = new String [] {
                 "org/pckg1/file1.txt",
                 "org/pckg1/pckg2/file1.txt",
@@ -331,13 +343,12 @@
 
         populateFolderStructure(root, paths);
 
-        FileObject rootFO = FileUtil.toFileObject(root);
-        FileObjectCrawler crawler = new FileObjectCrawler(rootFO, new 
FileObject[] {rootFO.getFileObject("org/pckg1/pckg2/file1.txt"), 
rootFO.getFileObject("org/pckg1/pckg2/file2.txt")}, 
EnumSet.<Crawler.TimeStampAction>of(Crawler.TimeStampAction.UPDATE), null, 
CR, SuspendSupport.NOP);
+        FileObjectCrawler crawler = new FileObjectCrawler(root, new 
FileObject[] {root.getFileObject("org/pckg1/pckg2/file1.txt"), 
root.getFileObject("org/pckg1/pckg2/file2.txt")}, 
EnumSet.<Crawler.TimeStampAction>of(Crawler.TimeStampAction.UPDATE), null, 
CR, SuspendSupport.NOP);
         assertCollectedFiles("Wrong files collected", 
crawler.getResources(), new String[] {"org/pckg1/pckg2/file1.txt", 
"org/pckg1/pckg2/file2.txt"});
     }
 
     public void testDuplicateResults3() throws IOException {
-        File root = new File(getWorkDir(), "src");
+        FileObject root = FileUtil.createFolder(new File(getWorkDir(), 
"src"));
         String [] paths = new String [] {
                 "org/pckg1/file1.txt",
                 "org/pckg1/pckg2/file1.txt",
@@ -346,13 +357,12 @@
 
         populateFolderStructure(root, paths);
 
-        FileObject rootFO = FileUtil.toFileObject(root);
-        FileObjectCrawler crawler = new FileObjectCrawler(rootFO, new 
FileObject[] {rootFO.getFileObject("org/pckg1/pckg2/file1.txt"), 
rootFO.getFileObject("org/pckg1/pckg2/file1.txt")}, 
EnumSet.<Crawler.TimeStampAction>of(Crawler.TimeStampAction.UPDATE), null, 
CR, SuspendSupport.NOP);
+        FileObjectCrawler crawler = new FileObjectCrawler(root, new 
FileObject[] {root.getFileObject("org/pckg1/pckg2/file1.txt"), 
root.getFileObject("org/pckg1/pckg2/file1.txt")}, 
EnumSet.<Crawler.TimeStampAction>of(Crawler.TimeStampAction.UPDATE), null, 
CR, SuspendSupport.NOP);
         assertCollectedFiles("Wrong files collected", 
crawler.getResources(), new String[] {"org/pckg1/pckg2/file1.txt"});
     }
 
     public void testDuplicateResults4() throws IOException {
-        File root = new File(getWorkDir(), "src");
+        FileObject root = FileUtil.createFolder(new File(getWorkDir(), 
"src"));
         String [] paths = new String [] {
                 "org/bar/file1.txt",
                 "org/foo/file2.txt",
@@ -360,13 +370,12 @@
 
         populateFolderStructure(root, paths);
 
-        FileObject rootFO = FileUtil.toFileObject(root);
-        FileObjectCrawler crawler = new FileObjectCrawler(rootFO, new 
FileObject[] {rootFO.getFileObject("org/foo/file2.txt"), 
rootFO.getFileObject("org/bar")}, 
EnumSet.<Crawler.TimeStampAction>of(Crawler.TimeStampAction.UPDATE), null, 
CR, SuspendSupport.NOP);
+        FileObjectCrawler crawler = new FileObjectCrawler(root, new 
FileObject[] {root.getFileObject("org/foo/file2.txt"), 
root.getFileObject("org/bar")}, 
EnumSet.<Crawler.TimeStampAction>of(Crawler.TimeStampAction.UPDATE), null, 
CR, SuspendSupport.NOP);
         assertCollectedFiles("Wrong files collected", 
crawler.getResources(), new String[] 
{"org/bar/file1.txt","org/foo/file2.txt"});
     }
 
     public void testDuplicateResults5() throws IOException {
-        File root = new File(getWorkDir(), "src");
+        FileObject root = FileUtil.createFolder(new File(getWorkDir(), 
"src"));
         String [] paths = new String [] {
                 "org/bar/file1.txt",
                 "org/foo/file2.txt",
@@ -374,13 +383,12 @@
 
         populateFolderStructure(root, paths);
 
-        FileObject rootFO = FileUtil.toFileObject(root);
-        FileObjectCrawler crawler = new FileObjectCrawler(rootFO, new 
FileObject[] {rootFO.getFileObject("org/bar"), 
rootFO.getFileObject("org/foo/file2.txt")}, 
EnumSet.<Crawler.TimeStampAction>of(Crawler.TimeStampAction.UPDATE), null, 
CR, SuspendSupport.NOP);
+        FileObjectCrawler crawler = new FileObjectCrawler(root, new 
FileObject[] {root.getFileObject("org/bar"), 
root.getFileObject("org/foo/file2.txt")}, 
EnumSet.<Crawler.TimeStampAction>of(Crawler.TimeStampAction.UPDATE), null, 
CR, SuspendSupport.NOP);
         assertCollectedFiles("Wrong files collected", 
crawler.getResources(), new String[] 
{"org/bar/file1.txt","org/foo/file2.txt"});
     }
 
     public void testDuplicateResults6() throws IOException {
-        File root = new File(getWorkDir(), "src");
+        FileObject root = FileUtil.createFolder(new File(getWorkDir(), 
"src"));
         String [] paths = new String [] {
                 "org/me/prj/foo/file2.txt",
                 "org/me/prj/bar/file3.txt",
@@ -388,13 +396,12 @@
 
         populateFolderStructure(root, paths);
 
-        FileObject rootFO = FileUtil.toFileObject(root);
-        FileObjectCrawler crawler = new FileObjectCrawler(rootFO, new 
FileObject[] {rootFO.getFileObject("org/me/prj/bar/file3.txt"), 
rootFO.getFileObject("org/me/prj/foo"), 
rootFO.getFileObject("org/me/prj/bar")}, 
EnumSet.<Crawler.TimeStampAction>of(Crawler.TimeStampAction.UPDATE), null, 
CR, SuspendSupport.NOP);
+        FileObjectCrawler crawler = new FileObjectCrawler(root, new 
FileObject[] {root.getFileObject("org/me/prj/bar/file3.txt"), 
root.getFileObject("org/me/prj/foo"), root.getFileObject("org/me/prj/bar")}, 
EnumSet.<Crawler.TimeStampAction>of(Crawler.TimeStampAction.UPDATE), null, 
CR, SuspendSupport.NOP);
         assertCollectedFiles("Wrong files collected", 
crawler.getResources(), new String[] 
{"org/me/prj/foo/file2.txt","org/me/prj/bar/file3.txt"});
     }
 
     public void testDuplicateResults7() throws IOException {
-        File root = new File(getWorkDir(), "src");
+        FileObject root = FileUtil.createFolder(new File(getWorkDir(), 
"src"));
         String [] paths = new String [] {
                 "org/me/prj/foo/file2.txt",
                 "org/me/prj/bar/file3.txt",
@@ -402,13 +409,12 @@
 
         populateFolderStructure(root, paths);
 
-        FileObject rootFO = FileUtil.toFileObject(root);
-        FileObjectCrawler crawler = new FileObjectCrawler(rootFO, new 
FileObject[] {rootFO.getFileObject("org/me/prj/bar/file3.txt"), 
rootFO.getFileObject("org/me/prj/foo/file2.txt"), 
rootFO.getFileObject("org/me")}, 
EnumSet.<Crawler.TimeStampAction>of(Crawler.TimeStampAction.UPDATE), null, 
CR, SuspendSupport.NOP);
+        FileObjectCrawler crawler = new FileObjectCrawler(root, new 
FileObject[] {root.getFileObject("org/me/prj/bar/file3.txt"), 
root.getFileObject("org/me/prj/foo/file2.txt"), 
root.getFileObject("org/me")}, 
EnumSet.<Crawler.TimeStampAction>of(Crawler.TimeStampAction.UPDATE), null, 
CR, SuspendSupport.NOP);
         assertCollectedFiles("Wrong files collected", 
crawler.getResources(), new String[] 
{"org/me/prj/foo/file2.txt","org/me/prj/bar/file3.txt"});
     }
 
     public void testDuplicateResults8() throws IOException {
-        File root = new File(getWorkDir(), "src");
+        FileObject root = FileUtil.createFolder(new File(getWorkDir(), 
"src"));
         String [] paths = new String [] {
                 "org/me/lib/impl/file1.txt",
                 "org/me/prj/foo/file2.txt",
@@ -417,14 +423,13 @@
 
         populateFolderStructure(root, paths);
 
-        FileObject rootFO = FileUtil.toFileObject(root);
         FileObjectCrawler crawler = new FileObjectCrawler(
-                rootFO,
+                root,
                 new FileObject[] {
-                    rootFO.getFileObject("org/me/prj/bar/file3.txt"),
-                    rootFO.getFileObject("org/me/prj/foo/file2.txt"),
-                    rootFO.getFileObject("org/me/lib"),
-                    rootFO.getFileObject("org/me/prj")},
+                    root.getFileObject("org/me/prj/bar/file3.txt"),
+                    root.getFileObject("org/me/prj/foo/file2.txt"),
+                    root.getFileObject("org/me/lib"),
+                    root.getFileObject("org/me/prj")},
                 
EnumSet.<Crawler.TimeStampAction>of(Crawler.TimeStampAction.UPDATE),
                 null,
                 CR,
@@ -432,6 +437,79 @@
         assertCollectedFiles("Wrong files collected", 
crawler.getResources(), new String[] 
{"org/me/lib/impl/file1.txt","org/me/prj/foo/file2.txt","org/me/prj/bar/file3.txt"});
     }
 
+    public void testDuplicateRandomTest() throws IOException {
+        if (!RUN_RANDOM_TESTS) {
+            return;
+        }
+        final FileSystem fs = FileUtil.createMemoryFileSystem();
+        String[] paths = generateRandomTree(TREE_DEPTH,TREE_CHILD_COUNT);
+        FileObject root = fs.getRoot();
+        populateFolderStructure(root, paths);
+        Random r = new Random(System.currentTimeMillis());
+        for (int runCount=0; runCount<TEST_COUNT; runCount++) {
+            System.out.println("Run: " + runCount);
+            final Set<FileObject> testSet = new HashSet<FileObject>();
+            while (testSet.size() < SINGLE_TEST_SET_SIZE) {
+                final String s = paths[r.nextInt(paths.length)];
+                FileObject fo = root.getFileObject(s);
+                final int shift = r.nextInt(TREE_DEPTH);
+                for (int i = 0; i<shift; i++) {
+                    fo = fo.getParent();
+                }
+                testSet.add(fo);
+            }
+            FileObjectCrawler crawler = new FileObjectCrawler(
+                root,
+                testSet.toArray(new FileObject[testSet.size()]),
+                
EnumSet.<Crawler.TimeStampAction>of(Crawler.TimeStampAction.UPDATE),
+                null,
+                CR,
+                SuspendSupport.NOP);
+            assertCollectedFiles(
+                    "Wrong files collected for: " + testSet,
+                    crawler.getResources(),
+                    crawl(testSet, root));
+        }
+    }
+
+    private static String[] generateRandomTree(int depth, int childCount) {
+        final Collection<String> res = generateRandomTree("",depth, 
childCount);
+        return res.toArray(new String[res.size()]);
+    }
+
+    private static Collection<String> generateRandomTree(String prefix, int 
depth, int childCount) {
+        final Collection<String> res = new ArrayList<String>();
+        if (depth > 0) {
+            for (int i=0; i< childCount; i++) {
+                
res.addAll(generateRandomTree(String.format("%sdir%d/",prefix,i), depth-1, 
childCount));
+            }
+        } else {
+            for (int i=0; i< childCount; i++) {
+                res.add(String.format("%sfile%d.txt",prefix,i));
+            }
+        }
+        return res;
+    }
+
+    private static String[] crawl(final Set<FileObject> files, final 
FileObject root) {
+        final Set<String> collector = new HashSet<String>();
+        for (FileObject fo : files) {
+            crawl(fo, root, collector);
+        }
+        return collector.toArray(new String[collector.size()]);
+    }
+
+    private static void crawl(final FileObject file, final FileObject root, 
final Collection<? super String> collector) {
+        if (file.isData()) {
+            collector.add(FileUtil.getRelativePath(root,file));
+        } else {
+            for (FileObject fo : file.getChildren()) {
+                crawl(fo, root, collector);
+            }
+        }
+    }
+
+
     protected void assertCollectedFiles(String message, 
Collection<Indexable> resources, String... expectedPaths) throws IOException {
         List<String> collectedPaths = new ArrayList<String>();
         for(Indexable ii : resources) {
@@ -448,19 +526,14 @@
         assertEquals(message, expectedPathsFiltered, collectedPaths);
     }
 
-    private static void populateFolderStructure(File root, String... 
filesOrFolders) throws IOException {
-        root.mkdirs();
+    private static void populateFolderStructure(FileObject root, String... 
filesOrFolders) throws IOException {
         for(String fileOrFolder : filesOrFolders) {
             if (fileOrFolder.endsWith("/")) {
                 // folder
-                File folder = new File(root, fileOrFolder.substring(0, 
fileOrFolder.length() - 1));
-                folder.mkdirs();
+                FileObject folder = FileUtil.createFolder(root, 
fileOrFolder.substring(0, fileOrFolder.length() - 1));
             } else {
                 // file
-                File file = new File(root, fileOrFolder);
-                File folder = file.getParentFile();
-                folder.mkdirs();
-                FileUtil.createData(FileUtil.toFileObject(folder), 
file.getName());
+                FileObject file = FileUtil.createData(root, fileOrFolder);
             }
         }
     }

[hg] main-silver: Added rnadom test for FileObjectCrawler.

Tomas Zezula 01/16/2013

Project Features

About this Project

Editor was started in November 2009, is owned by Martin Ryzl, and has 147 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20131025.e7cbc9d). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close