Dealing with random failures on overloaded machines: preload JLabel and its classes; increase the timeOut
1 package org.apidesign.deadlock;
3 import java.awt.Dimension;
4 import java.util.logging.Level;
5 import java.util.logging.Logger;
6 import javax.swing.JFrame;
7 import javax.swing.JLabel;
8 import javax.swing.SwingUtilities;
9 import org.netbeans.junit.NbTestCase;
10 import static org.junit.Assert.*;
12 public class DeadlockSyncOnTest extends NbTestCase {
13 static final Logger LOG = Logger.getLogger(DeadlockSyncOnTest.class.getName());
14 private static final JLabel preLoadClasses = new JLabel();
16 public DeadlockSyncOnTest(String n) {
21 protected int timeOut() {
26 public static class StrangePanel extends LabelProviderSyncOnTreeLock {
28 public Dimension getPreferredSize () {
31 JLabel sampleLabel = createLabel();
32 return sampleLabel.getPreferredSize();
33 } catch (InterruptedException ex) {
34 Logger.getLogger(DeadlockSyncOnTest.class.getName()).log(Level.SEVERE, null, ex);
35 return super.getPreferredSize();
43 public void testCreateLabel() throws Exception {
44 final LabelProviderSyncOnTreeLock instance = new StrangePanel();
46 class R implements Runnable {
48 JFrame f = new JFrame();
55 R showFrame = new R();
56 SwingUtilities.invokeLater(showFrame);
59 JLabel result = instance.createLabel();
60 assertNotNull("Creates the result", result);