test/jdk/java/awt/Frame/NonEDT_GUI_DeadlockTest/NonEDT_GUI_Deadlock.java
author serb
Wed, 27 Feb 2019 18:46:55 -0800
changeset 54231 e4813eded7cb
parent 50834 9cf279436b9d
permissions -rw-r--r--
8213110: Remove the use of applets in automatic tests Reviewed-by: prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31660
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
     1
/*
50834
9cf279436b9d 8205153: Delete "standard instructions" machinery in the open automated tests
serb
parents: 47216
diff changeset
     2
 * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
31660
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
     4
 *
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
     7
 * published by the Free Software Foundation.
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
     8
 *
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    13
 * accompanied this code).
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    14
 *
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    18
 *
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    21
 * questions.
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    22
 */
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    23
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    24
/*
54231
e4813eded7cb 8213110: Remove the use of applets in automatic tests
serb
parents: 50834
diff changeset
    25
  @test
e4813eded7cb 8213110: Remove the use of applets in automatic tests
serb
parents: 50834
diff changeset
    26
  @key headful
31660
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    27
  @bug 4828019
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    28
  @summary Frame/Window deadlock
54231
e4813eded7cb 8213110: Remove the use of applets in automatic tests
serb
parents: 50834
diff changeset
    29
  @run main/timeout=9999 NonEDT_GUI_Deadlock
31660
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    30
*/
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    31
54231
e4813eded7cb 8213110: Remove the use of applets in automatic tests
serb
parents: 50834
diff changeset
    32
import java.awt.*;
31660
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    33
54231
e4813eded7cb 8213110: Remove the use of applets in automatic tests
serb
parents: 50834
diff changeset
    34
public class NonEDT_GUI_Deadlock {
31660
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    35
    boolean bOK = false;
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    36
    Thread badThread = null;
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    37
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    38
    public void start ()
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    39
    {
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    40
        final Frame theFrame = new Frame("Window test");
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    41
        theFrame.setSize(240, 200);
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    42
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    43
        Thread thKiller = new Thread() {
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    44
           public void run() {
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    45
              try {
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    46
                 Thread.sleep( 9000 );
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    47
              }catch( Exception ex ) {
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    48
              }
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    49
              if( !bOK ) {
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    50
                 // oops,
50834
9cf279436b9d 8205153: Delete "standard instructions" machinery in the open automated tests
serb
parents: 47216
diff changeset
    51
                 //System.out.println("Deadlock!");
31660
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    52
                 Runtime.getRuntime().halt(0);
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    53
              }else{
50834
9cf279436b9d 8205153: Delete "standard instructions" machinery in the open automated tests
serb
parents: 47216
diff changeset
    54
                 //System.out.println("Passed ok.");
31660
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    55
              }
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    56
           }
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    57
        };
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    58
        thKiller.setName("Killer thread");
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    59
        thKiller.start();
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    60
        Window w = new TestWindow(theFrame);
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    61
        theFrame.toBack();
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    62
        theFrame.setVisible(true);
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    63
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    64
        theFrame.setLayout(new FlowLayout(FlowLayout.CENTER));
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    65
        EventQueue.invokeLater(new Runnable() {
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    66
           public void run() {
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    67
               bOK = true;
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    68
           }
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    69
        });
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    70
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    71
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    72
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    73
    }// start()
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    74
    class TestWindow extends Window implements Runnable {
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    75
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    76
        TestWindow(Frame f) {
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    77
            super(f);
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    78
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    79
            //setSize(240, 75);
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    80
            setLocation(0, 75);
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    81
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    82
            show();
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    83
            toFront();
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    84
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    85
            badThread = new Thread(this);
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    86
            badThread.setName("Bad Thread");
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    87
            badThread.start();
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    88
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    89
        }
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    90
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    91
        public void paint(Graphics g) {
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    92
            g.drawString("Deadlock or no deadlock?",20,80);
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    93
        }
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    94
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    95
        public void run() {
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    96
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    97
            long ts = System.currentTimeMillis();
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    98
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
    99
            while (true) {
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
   100
                if ((System.currentTimeMillis()-ts)>3000) {
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
   101
                    this.setVisible( false );
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
   102
                    dispose();
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
   103
                    break;
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
   104
                }
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
   105
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
   106
                toFront();
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
   107
                try {
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
   108
                    Thread.sleep(80);
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
   109
                } catch (Exception e) {
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
   110
                }
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
   111
            }
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
   112
        }
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
   113
    }
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
   114
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
   115
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
   116
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
   117
    public static void main(String args[]) {
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
   118
       NonEDT_GUI_Deadlock imt = new NonEDT_GUI_Deadlock();
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
   119
       imt.start();
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
   120
    }
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
   121
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
   122
1a4e2e5c15e1 8130125: [TEST_BUG] add @modules to the several client tests unaffected by the automated bulk update
yan
parents:
diff changeset
   123
}// class NonEDT_GUI_Deadlock