1 19 20 package org.openide.loaders; 21 22 import java.io.File ; 23 import java.io.FileOutputStream ; 24 import java.io.IOException ; 25 import java.util.*; 26 import java.lang.ref.WeakReference ; 27 import javax.swing.event.ChangeEvent ; 28 import javax.swing.event.ChangeListener ; 29 import org.openide.ErrorManager; 30 31 import org.openide.filesystems.*; 32 33 import org.netbeans.junit.*; 34 import org.openide.nodes.Node; 35 import org.openide.nodes.Children; 36 import org.openide.util.RequestProcessor; 37 38 39 public class FolderChildrenGCRaceConditionTest extends LoggingTestCaseHid { 40 public FolderChildrenGCRaceConditionTest() { 41 super(""); 42 } 43 44 public FolderChildrenGCRaceConditionTest(java.lang.String testName) { 45 super(testName); 46 } 47 48 protected void setUp() throws Exception { 49 super.setUp(); 50 clearWorkDir(); 51 52 FileObject[] arr = Repository.getDefault().getDefaultFileSystem().getRoot().getChildren(); 53 for (int i = 0; i < arr.length; i++) { 54 arr[i].delete(); 55 } 56 } 57 58 public void testChildrenCanBeSetToNullIfGCKicksIn () throws Exception { 59 FileObject f = FileUtil.createData(Repository.getDefault().getDefaultFileSystem().getRoot(), "folder/node.txt"); 60 61 DataFolder df = DataFolder.findFolder(f.getParent()); 62 Node n = df.getNodeDelegate(); 63 64 Node[] arr = n.getChildren().getNodes(true); 65 assertEquals("Ok, one", 1, arr.length); 66 final WeakReference ref = new WeakReference (arr[0]); 67 arr = null; 68 69 class R implements Runnable { 70 public void run() { 71 ErrorManager.getDefault().log("Ready to GC"); 72 assertGC("Node can go away in the worst possible moment", ref); 73 ErrorManager.getDefault().log("Gone"); 74 } 75 } 76 R r = new R(); 77 RequestProcessor.Task t = new RequestProcessor("Inter", 1, true).post(r); 78 79 registerSwitches( 80 "THREAD:FolderChildren_Refresh MSG:Children computed" + 81 "THREAD:FolderChildren_Refresh MSG:notifyFinished.*" + 82 "THREAD:Inter MSG:Gone.*" + 83 "THREAD:Finalizer MSG:RMV.*" + 84 "THREAD:FolderChildren_Refresh MSG:Clearing the ref.*" + 85 "", 200); 86 87 int cnt = n.getChildren().getNodes(true).length; 88 89 t.cancel(); 90 91 assertEquals("Count is really one", 1, cnt); 92 } 93 94 } | Popular Tags |