KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > masterfs > Deadlock73332


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.netbeans.modules.masterfs;
21
22 import java.io.File JavaDoc;
23 import org.netbeans.junit.NbTestCase;
24 import org.netbeans.modules.masterfs.providers.AnnotationProvider;
25 import org.openide.filesystems.FileLock;
26 import org.openide.filesystems.FileObject;
27 import org.openide.filesystems.FileUtil;
28 import org.openide.util.Lookup;
29 import org.openide.util.RequestProcessor;
30 import org.openide.util.lookup.Lookups;
31 import org.openide.util.lookup.ProxyLookup;
32
33 /**
34  * @author Radek Matous
35  */

36 public class Deadlock73332 extends NbTestCase {
37     private static FileObject folder;
38     static {
39         System.setProperty("org.openide.util.Lookup", Deadlock73332.TestLookup.class.getName());
40         assertTrue(Lookup.getDefault().getClass().getName(),Lookup.getDefault() instanceof Deadlock73332.TestLookup);
41     }
42     
43     
44     public Deadlock73332(String JavaDoc testName) {
45         super(testName);
46     }
47     
48     public void testDeadLock() throws Exception JavaDoc {
49         assertNotNull(folder);
50         assertTrue(folder instanceof MasterFileObject);
51         FileObject data = FileUtil.createData(folder, "/a/b/c/data.txt");
52         assertNotNull(data);
53         FileLock lock = data.lock();
54         try {
55             data.move(lock,folder, data.getName(), data.getExt());
56         } finally {
57             lock.releaseLock();
58         }
59     }
60     
61     protected void setUp() throws Exception JavaDoc {
62         super.setUp();
63         clearWorkDir();
64         File JavaDoc f = this.getWorkDir();
65         folder = FileUtil.toFileObject(f);
66     }
67     
68     public static class TestLookup extends ProxyLookup {
69         public TestLookup() {
70             super();
71             setLookups(new Lookup[] {getMetaInfLookup()});
72         }
73         
74         private Lookup getMetaInfLookup() {
75             return Lookups.metaInfServices(Thread.currentThread().getContextClassLoader());
76         }
77         
78         protected void beforeLookup(Lookup.Template template) {
79             if (template.getType().isAssignableFrom(AnnotationProvider.class)) {
80                 RequestProcessor.Task task = RequestProcessor.getDefault().post(new Runnable JavaDoc() {
81                     public void run() {
82                         folder.getChildren(true);
83                     }
84                 });
85                 task.waitFinished();
86             }
87         }
88     }
89     
90 }
91
Popular Tags