jdk/test/java/awt/EventQueue/InvocationEventTest/InvocationEventTest.java
author jjg
Wed, 04 Jan 2017 18:33:20 -0800
changeset 43029 1cd1c816581e
parent 25108 cbf21a81a738
permissions -rw-r--r--
8172260: remove tests from ProblemList Reviewed-by: rfield
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25108
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
     1
/*
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
     4
 *
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
     7
 * published by the Free Software Foundation.
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
     8
 *
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    13
 * accompanied this code).
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    14
 *
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    18
 *
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    21
 * questions.
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    22
 */
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    23
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    24
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    25
import java.awt.*;
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    26
import java.awt.event.*;
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    27
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    28
/*
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    29
 * @test
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    30
 * @summary  To Test the following assertions in InvovationEvent.
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    31
 * 1.InvocationEvent when dispatched, should invoke the
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    32
 *   run() method of the Runnable Interface.
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    33
 * 2.If catchExceptions is false, Exception should be
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    34
 *   propagated up to the EventDispatchThread's dispatch loop.
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    35
 * 3.If catchExceptions is true, InvocationEvent.getExceptions()
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    36
 *   should return the exception thrown inside thr run() method.
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    37
 * 4.When InvocationEvent object is posted on to the EventQueue,
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    38
 *   InvocationEvent.dispatch() method should be invoked by the
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    39
 *   EventQueue.
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    40
 * 5.If the notifier object is not null, notifyAll() of the
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    41
 *   notifier object should be invoked when the run() method returns.
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    42
 * 6.To test whether the threads are invoked in the right order
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    43
 *   When InvocationEvents are nested.
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    44
 * 7.The getWhen method should return timestamp which is less than
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    45
 *   current System time and greater than the time before it has
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    46
 *   actually happened
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    47
 * @author Dmitriy Ermashov (dmitriy.ermashov@oracle.com)
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    48
 * @run main InvocationEventTest
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    49
 */
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    50
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    51
public class InvocationEventTest {
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    52
    EventQueue eventQ1 = new EventQueue();
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    53
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    54
    Object lock = new Object();
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    55
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    56
    static final int delay = 5000;
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    57
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    58
    public volatile boolean notifierStatus = false;
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    59
    public Object notifierLock = new Object();
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    60
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    61
    public volatile boolean threadStatus = false;
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    62
    public volatile boolean childInvoked = false;
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    63
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    64
    public synchronized void doTest() throws Exception {
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    65
        // Testing assertions 1, 2 and 7:
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    66
        // 1.InvocationEvent when dispatched, should invoke the
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    67
        //   run() method of the Runnable Interface.
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    68
        // 2.If catchExceptions is false, Exception should be
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    69
        //   propagated up to the EventDispatchThread's dispatch loop.
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    70
        // 7.The getWhen method should return timestamp which is less than
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    71
        //   current System time and greater than the time before it has
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    72
        //   actually happened
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    73
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    74
        long timeBeforeInvoking = System.currentTimeMillis();
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    75
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    76
        Thread.sleep(10);
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    77
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    78
        InvocationEvent invoc = new InvocationEvent(this, () -> { threadStatus = true; }, lock, false);
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    79
        invoc.dispatch();
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    80
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    81
        Thread.sleep(10);
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    82
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    83
        if (!threadStatus) {
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    84
            synchronized (lock) {
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    85
                lock.wait(delay);
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    86
            }
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    87
        }
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    88
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    89
        // testing getException() when no exception is thrown
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    90
        if (invoc.getWhen() <= timeBeforeInvoking ||
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    91
                invoc.getWhen() >= System.currentTimeMillis()) {
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    92
            throw new RuntimeException("getWhen method is not getting the time at which event occured");
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    93
        }
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    94
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    95
        if (invoc.getException() != null) {
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    96
            throw new RuntimeException("InvocationEvent.getException() does not return null " +
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    97
                    "when catchException is false");
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    98
        }
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
    99
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   100
        // testing the normal behaviour of InvocationEvent
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   101
        if (!threadStatus) {
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   102
            throw new RuntimeException("InvocationEvent when dispatched, did not" +
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   103
                    " invoke the run() of the Runnable interface  ");
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   104
        }
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   105
        threadStatus = false;
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   106
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   107
        // Testing assertion 3:
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   108
        // 3.If catchExceptions is true, InvocationEvent.getExceptions()
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   109
        //   should return the exception thrown inside the run() method.
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   110
        RuntimeException sampleExn = new RuntimeException(" test exception");
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   111
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   112
        invoc = new InvocationEvent(this, () -> { threadStatus = true; throw sampleExn; }, lock, true);
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   113
        invoc.dispatch();
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   114
        if (!threadStatus) {
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   115
            synchronized (lock) {
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   116
                lock.wait(delay);
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   117
            }
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   118
        }
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   119
        // testing getException() when exception is thrown
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   120
        // Should return the same exception thrown inside the run() method
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   121
        if (!invoc.getException().equals(sampleExn)) {
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   122
            throw new RuntimeException("getException() does not return " +
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   123
                    "the same Exception thrown inside the run() method ");
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   124
        }
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   125
        threadStatus = false;
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   126
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   127
        // Testing assertions 4 and 5:
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   128
        // 4.When InvocationEvent object is posted on to the EventQueue,
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   129
        //   InvocationEvent.dispatch() method should be invoked by the
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   130
        //   EventQueue.
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   131
        // 5.If the notifier object is not null, notifyAll() of the
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   132
        //   notifier object should be invoked when the run() method returns.
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   133
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   134
        Thread notify = new Thread(){
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   135
            public void run() {
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   136
                synchronized (this) {
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   137
                    try { wait(); } catch (InterruptedException e) { throw new RuntimeException(e); }
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   138
                }
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   139
                notifierStatus = true;
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   140
                synchronized (notifierLock) {
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   141
                    notifierLock.notifyAll();
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   142
                }
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   143
            }
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   144
        };
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   145
        notify.start();
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   146
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   147
        while (notify.getState() != Thread.State.WAITING)
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   148
            Thread.sleep(delay/5);
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   149
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   150
        InvocationEvent invocation = new InvocationEvent(this, () -> { }, (Object) notify, false);
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   151
        eventQ1.postEvent(invocation);
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   152
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   153
        while(!invocation.isDispatched())
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   154
            synchronized (notifierLock) {
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   155
                notifierLock.wait(delay);
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   156
            }
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   157
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   158
        while (notify.getState() != Thread.State.TERMINATED)
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   159
            Thread.sleep(delay/5);
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   160
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   161
        if (!notifierStatus) {
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   162
            throw new RuntimeException("Notifier object did not get notified" +
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   163
                    " When the run method of the Runnable returns ");
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   164
        }
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   165
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   166
        // Testing assertion 6:
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   167
        // 6.To test whether the threads are invoked in the right order
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   168
        //   When InvocationEvents are nested.
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   169
        Thread thread = new Thread(){
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   170
            public void run() {
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   171
                InvocationEvent evt = new InvocationEvent(this, () -> { childInvoked = true; }, (Object) this, false);
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   172
                new EventQueue().postEvent(evt);
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   173
                synchronized (this) {
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   174
                    try {
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   175
                        wait(delay);
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   176
                    } catch (InterruptedException e) {
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   177
                        throw new RuntimeException(e);
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   178
                    }
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   179
                }
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   180
                threadStatus = true;
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   181
            }
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   182
        };
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   183
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   184
        invocation = new InvocationEvent(this, thread, lock, false);
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   185
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   186
        eventQ1.postEvent(invocation);
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   187
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   188
        while (!invocation.isDispatched())
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   189
            synchronized (lock) {
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   190
                lock.wait(delay);
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   191
            }
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   192
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   193
        if (!threadStatus || !childInvoked) {
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   194
            throw new RuntimeException("Nesting of InvocationEvents when dispatched," +
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   195
                    " did not invoke the run() of the Runnables properly ");
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   196
        }
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   197
    }
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   198
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   199
    public static void main(String[] args) throws Exception {
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   200
        new InvocationEventTest().doTest();
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   201
    }
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   202
}
cbf21a81a738 8041915: Move 8 awt tests to OpenJDK regression tests tree
yan
parents:
diff changeset
   203