1 19 20 package org.openide.loaders; 21 22 import java.lang.ref.WeakReference ; 23 import java.util.*; 24 import java.util.logging.Level ; 25 import java.util.logging.Logger ; 26 import junit.framework.AssertionFailedError; 27 import junit.textui.TestRunner; 28 import org.openide.filesystems.FileSystem; 29 import java.util.Enumeration ; 30 import org.openide.nodes.Node; 31 import org.openide.cookies.InstanceCookie; 32 import org.openide.filesystems.Repository; 33 import org.netbeans.junit.*; 34 import org.openide.filesystems.*; 35 36 40 public class DataShadowBrokenSlownessTest extends NbTestCase { 41 42 private List shadows, brokenShadows; 43 44 private DataFolder folder; 45 46 private FileObject root; 47 48 private FileObject[] arr; 49 50 public DataShadowBrokenSlownessTest (String name) { 51 super(name); 52 } 53 54 public static NbTestSuite suite () { 55 return NbTestSuite.speedSuite (DataShadowBrokenSlownessTest.class, 10, 5); 56 } 57 58 protected Level logLevel() { 59 return Level.INFO; 60 } 61 62 protected void setUp() throws Exception { 63 clearWorkDir(); 64 FileSystem lfs = TestUtilHid.createLocalFileSystem(getWorkDir (), new String [] { 65 "shadows/", 66 "brokenshadows", 67 "folder/original.txt", 68 "folder/orig.txt", 69 "modify/" 70 }); 71 72 73 root = FileUtil.toFileObject(FileUtil.toFile(lfs.getRoot())); 74 75 int count = getTestNumber (); 76 77 shadows = createShadows ( 78 DataObject.find (root.getFileObject("folder/original.txt")), 79 DataFolder.findFolder (lfs.findResource ("shadows")), 80 count 81 ); 82 83 brokenShadows = createShadows ( 84 DataObject.find (root.getFileObject("folder/orig.txt")), 85 DataFolder.findFolder (lfs.findResource ("shadows")), 86 count 87 ); 88 89 DataObject.find (root.getFileObject("folder/orig.txt")).delete (); 90 91 ListIterator it = brokenShadows.listIterator (); 92 while (it.hasNext ()) { 93 DataObject obj = (DataObject)it.next (); 94 assertFalse ("Is not valid", obj.isValid ()); 95 assertTrue ("Used to be shadow", obj instanceof DataShadow); 96 DataObject newObj = DataObject.find (obj.getPrimaryFile ()); 97 assertTrue ("They are different", newObj != obj); 98 assertFalse ("It is not shadow, as it is broken", newObj instanceof DataShadow); 99 100 it.set (newObj); 101 } 102 103 FileObject files = lfs.findResource ("modify"); 104 for (int i = 0; i < 200; i++) { 105 FileUtil.createData (files, "empty" + i + ".txt"); 106 } 107 108 arr = files.getChildren (); 109 assertEquals ("Children created", 200, arr.length); 110 111 folder = DataFolder.findFolder (files); 112 } 113 114 private static List createShadows (DataObject original, DataFolder target, int count) throws java.io.IOException { 115 ArrayList list = new ArrayList (count); 116 for (int i = 0; i < count; i++) { 117 DataShadow shad = DataShadow.create(target, original.getName()+i, original, "shadow"); 118 list.add (shad); 119 } 120 return list; 121 } 122 123 protected void tearDown() throws Exception { 124 DataShadow.waitUpdatesProcessed(); 125 126 WeakReference ref = new WeakReference (root); 127 this.root = null; 128 this.brokenShadows = null; 129 this.folder = null; 130 this.shadows = null; 131 this.arr = null; 132 try { 133 assertGC("Make sure the filesystem is gone", ref); 134 } catch (AssertionFailedError ex) { 135 Logger.getAnonymousLogger().log(Level.WARNING, null, ex); 136 } 137 } 138 public void test0 () throws java.io.IOException { 139 folder.delete (); 140 } 141 142 public void test10 () throws java.io.IOException { 143 folder.delete (); 144 } 145 146 public void test99 () throws java.io.IOException { 147 folder.delete (); 148 } 149 150 public void test245 () throws java.io.IOException { 151 folder.delete (); 152 } 153 public void test987 () throws java.io.IOException { 154 folder.delete (); 155 } 156 } 157 | Popular Tags |