author | Jaroslav Tulach <jtulach@netbeans.org> |
Sat, 14 Jun 2008 18:51:38 +0200 | |
changeset 263 | 7e8e995065c5 |
parent 154 | 0fd5e9c500b9 |
permissions | -rw-r--r-- |
jtulach@105 | 1 |
package org.apidesign.deadlock; |
jtulach@105 | 2 |
|
jtulach@105 | 3 |
import java.awt.Dimension; |
jtulach@105 | 4 |
import java.util.logging.Level; |
jtulach@105 | 5 |
import java.util.logging.Logger; |
jtulach@105 | 6 |
import javax.swing.JFrame; |
jtulach@105 | 7 |
import javax.swing.JLabel; |
jtulach@105 | 8 |
import javax.swing.SwingUtilities; |
jtulach@105 | 9 |
import org.netbeans.junit.NbTestCase; |
jtulach@105 | 10 |
import static org.junit.Assert.*; |
jtulach@105 | 11 |
|
jtulach@105 | 12 |
// BEGIN: deadlock.test |
jtulach@105 | 13 |
public class DeadlockTest extends NbTestCase { |
jtulach@154 | 14 |
static final Logger LOG = Logger.getLogger( |
jtulach@154 | 15 |
DeadlockTest.class.getName() |
jtulach@154 | 16 |
); |
jtulach@105 | 17 |
|
jtulach@105 | 18 |
public DeadlockTest(String n) { |
jtulach@105 | 19 |
super(n); |
jtulach@105 | 20 |
} |
jtulach@105 | 21 |
|
jtulach@105 | 22 |
@Override |
jtulach@105 | 23 |
protected int timeOut() { |
jtulach@105 | 24 |
return 10000; |
jtulach@105 | 25 |
} |
jtulach@105 | 26 |
|
jtulach@105 | 27 |
|
jtulach@105 | 28 |
public static class StrangePanel extends LabelProvider { |
jtulach@105 | 29 |
@Override |
jtulach@105 | 30 |
public Dimension getPreferredSize () { |
jtulach@105 | 31 |
try { |
jtulach@105 | 32 |
Thread.sleep(1000); |
jtulach@105 | 33 |
JLabel sampleLabel = createLabel(); |
jtulach@105 | 34 |
return sampleLabel.getPreferredSize(); |
jtulach@105 | 35 |
} catch (InterruptedException ex) { |
jtulach@154 | 36 |
Logger l = Logger.getLogger( |
jtulach@154 | 37 |
DeadlockTest.class.getName() |
jtulach@154 | 38 |
); |
jtulach@154 | 39 |
l.log(Level.SEVERE, null, ex); |
jtulach@105 | 40 |
return super.getPreferredSize(); |
jtulach@105 | 41 |
} |
jtulach@105 | 42 |
} |
jtulach@105 | 43 |
} |
jtulach@105 | 44 |
|
jtulach@105 | 45 |
|
jtulach@105 | 46 |
|
jtulach@105 | 47 |
|
jtulach@105 | 48 |
public void testCreateLabel() throws Exception { |
jtulach@263 | 49 |
if (Boolean.getBoolean("no.failures")) return; |
jtulach@105 | 50 |
final LabelProvider instance = new StrangePanel(); |
jtulach@105 | 51 |
|
jtulach@105 | 52 |
class R implements Runnable { |
jtulach@105 | 53 |
public void run() { |
jtulach@105 | 54 |
JFrame f = new JFrame(); |
jtulach@105 | 55 |
f.add(instance); |
jtulach@105 | 56 |
f.setVisible(true); |
jtulach@105 | 57 |
f.pack(); |
jtulach@105 | 58 |
} |
jtulach@105 | 59 |
} |
jtulach@105 | 60 |
|
jtulach@105 | 61 |
R showFrame = new R(); |
jtulach@105 | 62 |
SwingUtilities.invokeLater(showFrame); |
jtulach@105 | 63 |
|
jtulach@105 | 64 |
Thread.sleep(500); |
jtulach@105 | 65 |
JLabel result = instance.createLabel(); |
jtulach@105 | 66 |
assertNotNull("Creates the result", result); |
jtulach@105 | 67 |
} |
jtulach@105 | 68 |
|
jtulach@105 | 69 |
} |
jtulach@105 | 70 |
// END: deadlock.test |
jtulach@105 | 71 |