1 19 20 package org.openide.loaders; 21 22 import java.lang.ref.WeakReference ; 23 import java.util.*; 24 import org.openide.filesystems.FileSystem; 25 import org.openide.filesystems.Repository; 26 import org.netbeans.junit.*; 27 import org.openide.filesystems.*; 28 29 33 public class DataShadowSlowness39981Test extends NbTestCase implements OperationListener { 34 35 private List shadows, brokenShadows; 36 37 private DataFolder folder; 38 39 private FileSystem lfs; 40 41 private long time; 42 43 private int createdObjects; 44 45 private DataObject[] arr; 46 47 public DataShadowSlowness39981Test (String name) { 48 super(name); 49 } 50 51 public static NbTestSuite suite () { 52 return NbTestSuite.speedSuite (DataShadowSlowness39981Test.class, 20, 5); 53 } 54 55 protected void setUp() throws Exception { 56 clearWorkDir(); 57 58 lfs = TestUtilHid.createLocalFileSystem(getWorkDir (), new String [] { 59 "shadows/", 60 "brokenshadows", 61 "folder/original.txt", 62 "folder/orig.txt", 63 "modify/" 64 }); 65 FileObject root = FileUtil.toFileObject(FileUtil.toFile(lfs.getRoot())); 66 67 int count = getTestNumber (); 68 69 shadows = createShadows ( 70 DataObject.find (root.getFileObject("folder/original.txt")), 71 DataFolder.findFolder (root.getFileObject("shadows")), 72 count 73 ); 74 75 brokenShadows = createShadows ( 76 DataObject.find (root.getFileObject("folder/orig.txt")), 77 DataFolder.findFolder (root.getFileObject("shadows")), 78 count 79 ); 80 81 DataObject.find (root.getFileObject("folder/orig.txt")).delete (); 82 83 ListIterator it = brokenShadows.listIterator (); 84 while (it.hasNext ()) { 85 DataObject obj = (DataObject)it.next (); 86 assertFalse ("Is not valid", obj.isValid ()); 87 assertTrue ("Used to be shadow", obj instanceof DataShadow); 88 DataObject newObj = DataObject.find (obj.getPrimaryFile ()); 89 assertTrue ("They are different", newObj != obj); 90 assertFalse ("It is not shadow, as it is broken", newObj instanceof DataShadow); 91 92 it.set (newObj); 93 } 94 95 FileObject files = root.getFileObject("modify"); 96 for (int i = 0; i < 200; i++) { 97 FileUtil.createData (files, "empty" + i + ".txt"); 98 } 99 100 assertEquals ("Children created", 200, files.getChildren ().length); 101 102 folder = DataFolder.findFolder (files); 103 time = System.currentTimeMillis (); 104 } 105 106 private static List createShadows (DataObject original, DataFolder target, int count) throws java.io.IOException { 107 ArrayList list = new ArrayList (count); 108 for (int i = 0; i < count; i++) { 109 DataShadow shad = DataShadow.create(target, original.getName()+i, original, "shadow"); 110 list.add (shad); 111 } 112 return list; 113 } 114 115 protected void tearDown() throws Exception { 116 ArrayList weaks = new ArrayList(); 117 addWeakRefs(Arrays.asList(arr), weaks); 118 addWeakRefs(brokenShadows, weaks); 119 addWeakRefs(shadows, weaks); 120 addWeakRefs(Collections.singleton(lfs), weaks); 121 addWeakRefs(Collections.singleton(folder), weaks); 122 123 arr = null; 124 brokenShadows = null; 125 shadows = null; 126 lfs = null; 127 folder = null; 128 129 130 WeakReference [] refArr = (WeakReference [])weaks.toArray(new WeakReference [0]); 131 for (int i = 0; i < refArr.length; i++) { 132 assertGC(i + " - gc(" + refArr[i].get() + "): ", refArr[i]); 133 } 134 135 136 } 137 138 private static void addWeakRefs(Collection objects, List weakRefsToAdd) { 139 Iterator it = objects.iterator(); 140 while (it.hasNext()) { 141 Object obj = it.next(); 142 weakRefsToAdd.add(new WeakReference (obj)); 143 } 144 } 145 146 private void createChildren () { 147 DataLoaderPool pool = DataLoaderPool.getDefault (); 148 pool.addOperationListener (this); 149 150 arr = folder.getChildren (); 151 152 pool.removeOperationListener (this); 153 154 if (arr.length > createdObjects) { 155 fail ("The children of the folder should not be created before the getChildren method is called. Children: " + arr.length + " created: " + createdObjects); 156 } 157 } 158 159 public void test0 () throws Exception { 160 createChildren (); 161 } 162 163 public void test10 () throws java.io.IOException { 164 createChildren (); 165 } 166 167 public void test99 () throws java.io.IOException { 168 createChildren (); 169 } 170 171 public void test245 () throws java.io.IOException { 172 createChildren (); 173 } 174 175 public void test552 () throws java.io.IOException { 176 createChildren (); 177 } 178 179 183 184 public void operationCopy (org.openide.loaders.OperationEvent.Copy ev) { 185 } 186 187 public void operationCreateFromTemplate (org.openide.loaders.OperationEvent.Copy ev) { 188 } 189 190 public void operationCreateShadow (org.openide.loaders.OperationEvent.Copy ev) { 191 } 192 193 public void operationDelete (OperationEvent ev) { 194 } 195 196 public void operationMove (org.openide.loaders.OperationEvent.Move ev) { 197 } 198 199 public void operationPostCreate (OperationEvent ev) { 200 createdObjects++; 201 } 202 203 public void operationRename (org.openide.loaders.OperationEvent.Rename ev) { 204 } 205 206 } 207 | Popular Tags |