KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > explorer > view > TreeView72765Test


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.explorer.view;
21
22 import java.awt.Dimension JavaDoc;
23 import java.awt.EventQueue JavaDoc;
24 import java.awt.event.ActionEvent JavaDoc;
25 import java.lang.reflect.InvocationTargetException JavaDoc;
26 import javax.swing.AbstractAction JavaDoc;
27 import javax.swing.Action JavaDoc;
28 import javax.swing.JFrame JavaDoc;
29 import javax.swing.JScrollBar JavaDoc;
30 import javax.swing.JScrollPane JavaDoc;
31 import org.netbeans.junit.NbTestCase;
32 import org.openide.explorer.ExplorerManager;
33 import org.openide.nodes.AbstractNode;
34 import org.openide.nodes.Children;
35 import org.openide.nodes.FilterNode;
36 import org.openide.nodes.Node;
37 import org.openide.util.HelpCtx;
38 import org.openide.util.Lookup;
39 import org.openide.util.RequestProcessor;
40 import org.openide.util.actions.NodeAction;
41 import org.openide.util.actions.SystemAction;
42
43 /** Simulate a deadlock.
44  *
45  * @author Jaroslav Tulach
46  */

47 public final class TreeView72765Test extends NbTestCase {
48     private TreeView ttv;
49
50     public TreeView72765Test(String JavaDoc testName) {
51         super(testName);
52     }
53
54     protected void setUp() throws Exception JavaDoc {
55         ttv = new BeanTreeView();
56     }
57
58     protected boolean runInEQ() {
59         return true;
60     }
61
62
63
64     public void testRedrawWhenOtherThreadHasChildrenLock() throws InterruptedException JavaDoc {
65
66         class Block implements Runnable JavaDoc {
67             public synchronized void run() {
68                 if (!Children.MUTEX.isWriteAccess()) {
69                     Children.MUTEX.writeAccess(this);
70                     return;
71                 }
72
73                 notifyAll();
74                 try {
75                     wait(500);
76                 } catch (InterruptedException JavaDoc ex) {
77                     ex.printStackTrace();
78                 }
79
80                 synchronized (ttv.getTreeLock()) {
81                 }
82             }
83         }
84
85
86         Block block = new Block();
87         RequestProcessor.Task t;
88         synchronized (block) {
89             t = RequestProcessor.getDefault().post(block);
90             block.wait();
91         }
92
93         ttv.addNotify();
94
95         assertNotNull("Initialize peer", ttv.getPeer());
96
97         ttv.invalidate();
98         ttv.validate();
99
100     }
101 }
102
Popular Tags