KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > Deadlock64710Test


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;
21
22 import org.netbeans.junit.NbTestCase;
23 import org.openide.ErrorManager;
24 import org.openide.util.Lookup;
25 import org.openide.util.RequestProcessor;
26 import org.openide.util.lookup.AbstractLookup;
27
28 /**
29  *
30  * @author Jaroslav Tulach
31  */

32 public class Deadlock64710Test extends NbTestCase {
33     private Lkp lookup;
34
35     public Deadlock64710Test(String JavaDoc name) {
36         super(name);
37     }
38
39     protected void setUp() throws Exception JavaDoc {
40         System.setProperty("org.openide.util.Lookup", "org.netbeans.Deadlock64710Test$Lkp");
41
42         Lookup l = Lookup.getDefault();
43         
44         ErrorManager.getDefault();
45         
46         if (! (l instanceof Lkp)) {
47             fail("From lookup: " + l);
48         }
49         
50         lookup = (Lkp)l;
51         
52         
53         String JavaDoc c = "org.openide.util.Cancellable";
54         
55         lookup.query = new JarClassLoaderTest.OneClassLoader (
56             "cancel loader", getClass().getClassLoader(), getClass().getClassLoader().getParent(), c
57         );
58         lookup.another = new JarClassLoaderTest.OneClassLoader (
59             "another loader", getClass().getClassLoader(), getClass().getClassLoader().getParent(), c
60         );
61         
62     }
63     
64     public void testProxyClassLoaderAsksForLookup() throws Exception JavaDoc {
65         lookup.lookup(Module.class);
66     }
67     
68     public static final class Lkp extends AbstractLookup implements Runnable JavaDoc {
69         ProxyClassLoader query, another;
70         ProxyClassLoader toAdd;
71         
72         public Lkp () {
73             this (new org.openide.util.lookup.InstanceContent ());
74         }
75         
76         private Lkp (org.openide.util.lookup.InstanceContent ic) {
77             super (ic);
78         }
79
80         protected synchronized void beforeLookup(org.openide.util.Lookup.Template template) {
81             if (query != null) {
82                 ProxyClassLoader p = query;
83                 toAdd = p;
84 // query = null;
85
try {
86                     synchronized (this) {
87                         RequestProcessor.getDefault().post(this);
88                         wait(200);
89                     }
90                     p.loadClass("java.lang.String", false);
91                 } catch (Exception JavaDoc ex) {
92                     fail(ex.getMessage());
93                 }
94                 return;
95             }
96             
97         }
98
99         public void run() {
100             toAdd.append(new ClassLoader JavaDoc[] { another });
101         }
102         
103         
104     }
105     
106 }
107
Popular Tags