This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 156829
Collapse All | Expand All

(-)test/unit/src/org/netbeans/api/db/explorer/node/BaseNodeTest.java (+119 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 *
35
 * Contributor(s):
36
 *
37
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.api.db.explorer.node;
41
42
import java.awt.EventQueue;
43
import java.util.ResourceBundle;
44
import javax.swing.JComponent;
45
import javax.swing.JPanel;
46
import org.netbeans.junit.NbTestCase;
47
import org.netbeans.modules.db.explorer.node.DriverNode;
48
import static org.junit.Assert.*;
49
import org.openide.util.Exceptions;
50
import org.openide.util.lookup.Lookups;
51
52
/** Simulates deadlock as in issue 156829, the AWT tree lock is accessed outside
53
 * of AWT by BaseNode and its action support initialization:
54
  <pre>
55
  java.awt.KeyboardFocusManager.clearMostRecentFocusOwner:1777
56
  java.awt.Component.setFocusable:6635
57
  javax.swing.JSeparator.<init>:88
58
  javax.swing.JSeparator.<init>:70
59
  java.lang.reflect.Constructor.newInstance:513
60
  java.lang.Class.newInstance0:355
61
  java.lang.Class.newInstance:308
62
  org.openide.loaders.InstanceSupport.instanceCreate:219
63
  org.openide.loaders.InstanceDataObject$Ser.instanceCreate:1265
64
  org.openide.loaders.InstanceDataObject.instanceCreate:749
65
  org.openide.loaders.FolderLookup$ICItem.getInstance:584
66
  org.openide.util.lookup.AbstractLookup$R.allInstances:974
67
  org.openide.util.lookup.ProxyLookup$R.computeResult:548
68
  org.openide.util.lookup.ProxyLookup$R.allInstances:489
69
  org.openide.util.lookup.ProxyLookup$R.computeResult:548
70
  org.openide.util.lookup.ProxyLookup$R.allInstances:489
71
  org.netbeans.modules.db.explorer.action.ActionRegistry.initActions:108
72
  org.netbeans.modules.db.explorer.action.ActionRegistry.loadActions:93
73
  org.netbeans.modules.db.explorer.action.ActionRegistry.<init>:80
74
  org.netbeans.api.db.explorer.node.BaseNode.<init>:156
75
  org.netbeans.api.db.explorer.node.BaseNode.<init>:131
76
  org.netbeans.modules.db.explorer.node.DriverNode.<init>:76
77
  org.netbeans.modules.db.explorer.node.DriverNode.create:70
78
  </pre>
79
 *
80
 * @author Jaroslav Tulach
81
 */
82
public class BaseNodeTest extends NbTestCase {
83
84
    public BaseNodeTest(String n) {
85
        super(n);
86
    }
87
88
    @Override
89
    protected int timeOut() {
90
        return 5000;
91
    }
92
93
    @Override
94
    protected void setUp() throws Exception {
95
        assertNotNull("Lookup is created", Lookups.forPath("initialize"));
96
    }
97
98
    public void testDeadlock156829() {
99
        assertFalse("Not in AWT", EventQueue.isDispatchThread());
100
        class R implements Runnable {
101
            JComponent c = new JPanel();
102
            public void run() {
103
                synchronized (c.getTreeLock()) {
104
                    try {
105
                        Thread.sleep(10000);
106
                    } catch (InterruptedException ex) {
107
                        Exceptions.printStackTrace(ex);
108
                    }
109
                }
110
            }
111
        }
112
        R run = new R();
113
        EventQueue.invokeLater(run);
114
115
        BaseNode n = DriverNode.create(null, null);
116
        assertNotNull("Really created without deadlock", n);
117
    }
118
119
}

Return to bug 156829