KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > loaders > CanYouQueryFromRenameTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.openide.loaders;
21 import java.io.IOException JavaDoc;
22 import java.io.InterruptedIOException JavaDoc;
23 import java.io.PrintWriter JavaDoc;
24 import java.io.StringWriter JavaDoc;
25 import java.lang.ref.WeakReference JavaDoc;
26 import java.util.Enumeration JavaDoc;
27 import java.util.List JavaDoc;
28 import java.util.logging.Handler JavaDoc;
29 import java.util.logging.Level JavaDoc;
30 import java.util.logging.Logger JavaDoc;
31 import javax.swing.JButton JavaDoc;
32 import javax.swing.JPanel JavaDoc;
33 import org.netbeans.junit.NbTestCase;
34 import org.openide.cookies.InstanceCookie;
35 import org.openide.filesystems.FileObject;
36 import org.openide.filesystems.FileUtil;
37 import org.openide.filesystems.Repository;
38 import org.openide.util.Enumerations;
39 import org.openide.util.Lookup;
40 import org.openide.util.RequestProcessor;
41 import org.openide.util.lookup.AbstractLookup;
42 import org.openide.util.lookup.InstanceContent;
43
44
45 import org.openide.loaders.CanYouQueryFolderLookupFromHandleFindTest.ErrManager;
46
47 /** To simulate and fix 70828.
48  * <pre>
49
50
51 "Folder recognizer" daemon prio=5 tid=0x03764658 nid=0x1644 in Object.wait() [49af000..49afd8c]
52         at java.lang.Object.wait(Native Method)
53         - waiting on <0x10cce880> (a org.openide.loaders.DataObjectPool)
54         at java.lang.Object.wait(Object.java:429)
55         at org.openide.loaders.DataObjectPool.enterRecognition(DataObjectPool.ja
56         - locked <0x10cce880> (a org.openide.loaders.DataObjectPool)
57         at org.openide.loaders.DataObjectPool.handleFindDataObject(DataObjectPoo
58         at org.openide.loaders.DataLoader.findDataObject(DataLoader.java:358)
59         at org.openide.loaders.DataLoaderPool.findDataObject(DataLoaderPool.java:402)
60         at org.openide.loaders.FolderList.createBoth(FolderList.java:701)
61         at org.openide.loaders.FolderList.access$600(FolderList.java:50)
62         at org.openide.loaders.FolderList$2.run(FolderList.java:334)
63         at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:493)
64         at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java
65
66 "OpenIDE-request-processor-0" daemon prio=2 tid=0x02df1388 nid=0x990 waiting for
67  monitor entry [402f000..402fd8c]
68         at org.openide.filesystems.AbstractFileObject.refresh(AbstractFileObject.java:780)
69         - waiting to lock <0x12ded7f8> (a org.openide.filesystems.AbstractFileOb
70         at org.openide.filesystems.AbstractFileObject.refresh(AbstractFileObject
71         at org.openide.filesystems.AbstractFolder.refresh(AbstractFolder.java:44
72         at org.openide.filesystems.AbstractFolder.refreshChildren(AbstractFolder
73         at org.openide.filesystems.AbstractFolder.refreshFolder(AbstractFolder.j
74         at org.openide.filesystems.AbstractFolder.refresh(AbstractFolder.java:87
75         at org.openide.filesystems.AbstractFileObject.refresh(AbstractFileObject
76         at org.openide.filesystems.AbstractFileObject.refresh(AbstractFileObject
77         at org.openide.filesystems.AbstractFolder.refresh(AbstractFolder.java:44
78         at org.openide.filesystems.FileObject.refresh(FileObject.java:725)
79         at org.netbeans.modules.vcscore.VcsFileSystem.doVirtualsRefresh(VcsFileS
80         at org.netbeans.modules.vcscore.util.virtuals.VcsRefreshRequest.doLoop(V
81         at org.netbeans.modules.vcscore.util.virtuals.VcsRefreshRequest.run(VcsR
82         at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:493)
83         at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java
84
85
86
87 "AWT-EventQueue-1" prio=7 tid=0x0369c900 nid=0x1350 in Object.wait() [3bcf000..3
88 bcfd8c]
89         at java.lang.Object.wait(Native Method)
90         - waiting on <0x1007cc88> (a org.openide.util.RequestProcessor$Task)
91         at org.openide.util.Task.waitFinished(Task.java:129)
92         - locked <0x1007cc88> (a org.openide.util.RequestProcessor$Task)
93         at org.openide.util.RequestProcessor$Task.waitFinished(RequestProcessor.java:723)
94         at org.openide.util.Task.waitFinished(Task.java:159)
95         at org.openide.loaders.FolderLookup$ProxyLkp.beforeLookup(FolderLookup.j
96         at org.openide.util.lookup.ProxyLookup$R.myBeforeLookup(ProxyLookup.java
97         at org.openide.util.lookup.ProxyLookup$R.beforeLookup(ProxyLookup.java:5
98         at org.openide.util.lookup.ProxyLookup$R.myBeforeLookup(ProxyLookup.java
99         at org.openide.util.lookup.ProxyLookup$R.computeResult(ProxyLookup.java:
100         at org.openide.util.lookup.ProxyLookup$R.allInstances(ProxyLookup.java:3
101         at org.netbeans.api.queries.SharabilityQuery.getSharability(SharabilityQ
102         at org.netbeans.modules.vcscore.VcsFileSystem.isImportant(VcsFileSystem.
103         at org.netbeans.modules.vcscore.VcsFileSystem.unlock(VcsFileSystem.java:
104         at org.openide.filesystems.AbstractFileObject.unlock(AbstractFileObject.
105         - locked <0x12ded7f8> (a org.openide.filesystems.AbstractFileObject)
106         at org.openide.filesystems.AbstractFileObject$AfLock.releaseLock(Abstrac
107         at org.netbeans.modules.masterfs.Delegate$FileLockImpl.releaseLock(Deleg
108         at org.openide.loaders.DefaultDataObject.handleRename(DefaultDataObject.
109         at org.openide.loaders.DataObject$1Op.run(DataObject.java:585)
110         at org.openide.loaders.DataObject$1WrapRun.run(DataObject.java:765)
111         - locked <0x10ccec70> (a java.lang.Object)
112         at org.openide.loaders.DataObjectPool$1WrapAtomicAction.run(DataObjectPo
113         at org.openide.filesystems.EventControl.runAtomicAction(EventControl.jav
114         at org.openide.filesystems.FileSystem.runAtomicAction(FileSystem.java:45
115         at org.openide.loaders.DataObjectPool.runAtomicAction(DataObjectPool.jav
116         at org.openide.loaders.DataObject.invokeAtomicAction(DataObject.java:785
117         at org.openide.loaders.DataObject.rename(DataObject.java:595)
118         at org.openide.loaders.DataNode.setName(DataNode.java:163)
119         at org.openide.loaders.DataNode.setName(DataNode.java:188)
120         at org.openide.nodes.FilterNode.setName(FilterNode.java:444)
121
122
123
124
125
126
127
128
129
130
131
132 "VCS Object Integrity Analyzer" daemon prio=2 tid=0x03856b50 nid=0x47c in Object
133 .wait() [3a8f000..3a8fd8c]
134         at java.lang.Object.wait(Native Method)
135         - waiting on <0x12e8b828> (a org.openide.util.RequestProcessor$Task)
136         at java.lang.Object.wait(Object.java:429)
137         at org.openide.util.Task.waitFinished(Task.java:102)
138         - locked <0x12e8b828> (a org.openide.util.RequestProcessor$Task)
139         at org.openide.util.RequestProcessor$Task.waitFinished(RequestProcessor.java:685)
140         at org.openide.loaders.FolderList.waitProcessingFinished(FolderList.java:250)
141         at org.openide.loaders.FolderInstance.waitProcessingFinished(FolderInstance.java:576)
142         at org.openide.loaders.FolderInstance.waitFinished(FolderInstance.java:279)
143         at org.openide.loaders.FolderInstance.waitFinished(FolderInstance.java:305)
144         at org.openide.loaders.FolderLookup$ProxyLkp.beforeLookup(FolderLookup.java:359)
145         at org.openide.util.lookup.ProxyLookup$R.myBeforeLookup(ProxyLookup.java:530)
146         at org.openide.util.lookup.ProxyLookup$R.beforeLookup(ProxyLookup.java:549)
147         at org.openide.util.lookup.ProxyLookup$R.myBeforeLookup(ProxyLookup.java:538)
148         at org.openide.util.lookup.ProxyLookup$R.computeResult(ProxyLookup.java:
149         at org.openide.util.lookup.ProxyLookup$R.allInstances(ProxyLookup.java:3
150         at org.netbeans.modules.vcscore.turbo.local.FileAttributeQuery.providers
151         at org.netbeans.modules.vcscore.turbo.local.FileAttributeQuery.loadAttri
152         at org.netbeans.modules.vcscore.turbo.local.FileAttributeQuery.readAttri
153         at org.netbeans.modules.vcscore.turbo.Turbo.getCachedMeta(Turbo.java:175
154         at org.netbeans.modules.vcscore.objectintegrity.VcsObjectIntegritySuppor
155         at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:493)
156         at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java
157
158 "FAQ Fetcher" daemon prio=2 tid=0x02ddee18 nid=0x834 in Object.wait() [357f000..
159 357fd8c]
160         at java.lang.Object.wait(Native Method)
161         - waiting on <0x10f127a8> (a java.util.Collections$SynchronizedSet)
162         at org.netbeans.modules.vcscore.turbo.local.FileAttributeQuery$PreparationTask.waitForRequests(FileAttributeQuery.java:441)
163         - locked <0x10f127a8> (a java.util.Collections$SynchronizedSet)
164         at org.netbeans.modules.vcscore.turbo.local.FileAttributeQuery$PreparationTask.run(FileAttributeQuery.java:378)
165         at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:493)
166         at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:926)
167  </pre>
168  *
169  * @author Jaroslav Tulach
170  */

171 public class CanYouQueryFromRenameTest extends LoggingTestCaseHid {
172     static {
173         Logger JavaDoc l = Logger.getLogger("");
174         Handler JavaDoc[] arr = l.getHandlers();
175         for (int i = 0; i < arr.length; i++) {
176             l.removeHandler(arr[i]);
177         }
178         l.addHandler(new ErrManager());
179         l.setLevel(Level.ALL);
180     }
181     
182     /** Creates a new instance of CanYouQueryFolderLookupFromHandleFindTest */
183     public CanYouQueryFromRenameTest(String JavaDoc s) {
184         super(s);
185     }
186     
187     protected int timeOut() {
188         return 57500;
189     }
190     
191     
192     protected void setUp() throws IOException JavaDoc {
193         registerIntoLookup(new Pool());
194         clearWorkDir();
195     }
196     
197     public void testTheDeadlock() throws Exception JavaDoc {
198         MyLoader m = (MyLoader)MyLoader.getLoader(MyLoader.class);
199         m.button = FileUtil.createFolder(Repository.getDefault().getDefaultFileSystem().getRoot(), "FolderLookup");
200         DataObject instance = InstanceDataObject.create(DataFolder.findFolder(m.button), "SomeName", JPanel JavaDoc.class);
201         m.initLookup(instance.getPrimaryFile());
202         
203         assertNotNull("There is the lookup", m.lookup.lookup(JPanel JavaDoc.class));
204         
205         DataLoaderPool.setPreferredLoader(m.instanceFile, m);
206         
207         FileObject any = Repository.getDefault().getDefaultFileSystem().getRoot().createData("Ahoj.txt");
208         DataObject obj = DataObject.find(any);
209         
210         assertEquals("The right object found", m, obj.getLoader());
211         assertEquals("Null value then", null, m.v);
212         
213         obj.rename("SomeStrangeName");
214         
215         //assertNull("It would not be bad if this would return non-null, but actually the button cannot be found right now: " + m.v, m.v);
216
}
217     
218     
219     public static final class MyLoader extends UniFileLoader
220     implements Runnable JavaDoc {
221         public FileObject button;
222         public Object JavaDoc v;
223         public Lookup lookup;
224         
225         public InstanceDataObject created;
226         
227         private FileObject instanceFile;
228         
229         private DataFolder middle;
230         private DataObject[] arr;
231         
232         public MyLoader() throws IOException JavaDoc {
233             super("org.openide.loaders.MultiDataObject");
234
235         }
236         
237         protected FileObject findPrimaryFile(FileObject fo) {
238             if (fo.hasExt("txt") || fo.equals(instanceFile)) {
239                 return fo;
240             }
241             return null;
242         }
243         
244         protected MultiDataObject createMultiObject(FileObject primaryFile) throws DataObjectExistsException, IOException JavaDoc {
245             return new MyObj(primaryFile, this);
246         }
247         
248         public void initLookup(FileObject inst) {
249             instanceFile = inst;
250             DataFolder f = DataFolder.findFolder(instanceFile.getParent());
251             FolderLookup l = new FolderLookup(f);
252             lookup = l.getLookup();
253             
254             assertNull("No button: ", lookup.lookup(JButton JavaDoc.class));
255         }
256
257         public void run() {
258             assertNotNull("Lookup exists: ", lookup);
259             
260             DataFolder f = DataFolder.findFolder(instanceFile.getParent());
261             try {
262                 f.getPrimaryFile().createData("javax-swing-JButton.instance");
263             } catch (IOException JavaDoc ex) {
264                 ex.printStackTrace();
265                 fail(ex.getMessage());
266             }
267             
268             middle = f;
269
270             // block here
271
arr = f.getChildren();
272         }
273         
274     }
275     
276     private static final class MyObj extends MultiDataObject {
277         public MyObj(FileObject fo, MyLoader l) throws DataObjectExistsException {
278             super(fo, l);
279         }
280
281         protected FileObject handleRename(String JavaDoc name) throws IOException JavaDoc {
282             FileObject retValue;
283             
284             MyLoader l = (MyLoader)getLoader();
285             try {
286                 RequestProcessor.getDefault().post(l).waitFinished(1000);
287             } catch (InterruptedException JavaDoc ex) {
288                 throw (InterruptedIOException JavaDoc)new InterruptedIOException JavaDoc(ex.getMessage()).initCause(ex);
289             }
290             
291             assertNotNull("In middle of creation", l.middle);
292
293             l.v = l.lookup.lookup(JButton JavaDoc.class);
294             
295             retValue = super.handleRename(name);
296             return retValue;
297         }
298     }
299     
300     private static final class Pool extends DataLoaderPool {
301         static List JavaDoc loaders;
302         
303         public Pool() {
304         }
305         
306         public Enumeration JavaDoc loaders() {
307             return Enumerations.singleton(DataLoader.getLoader(MyLoader.class));
308         }
309     }
310     
311 }
312
Popular Tags