6384N/A/*
6384N/A * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
6384N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6384N/A *
6384N/A * This code is free software; you can redistribute it and/or modify it
6384N/A * under the terms of the GNU General Public License version 2 only, as
6384N/A * published by the Free Software Foundation.
6384N/A *
6384N/A * This code is distributed in the hope that it will be useful, but WITHOUT
6384N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6384N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
6384N/A * version 2 for more details (a copy is included in the LICENSE file that
6384N/A * accompanied this code).
6384N/A *
6384N/A * You should have received a copy of the GNU General Public License version
6384N/A * 2 along with this work; if not, write to the Free Software Foundation,
6384N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6384N/A *
6384N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6384N/A * or visit www.oracle.com if you need additional information or have any
6384N/A * questions.
6384N/A */
6384N/A
6384N/A/*
6384N/A * @test
6384N/A * @bug 8012933
6384N/A * @summary Tests (although somewhat indirectly) that createNewAppContext()
6384N/A * immediately followed by dispose() works correctly
6384N/A * @author Leonid Romanov
6384N/A */
6384N/A
6384N/Aimport sun.awt.SunToolkit;
6384N/Aimport sun.awt.AppContext;
6384N/A
6384N/Apublic class Test8012933 {
6384N/A private AppContext appContext = null;
6384N/A final ThreadGroup threadGroup = new ThreadGroup("test thread group");
6384N/A final Object lock = new Object();
6384N/A boolean isCreated = false;
6384N/A
6384N/A public static void main(String[] args) throws Exception {
6384N/A SunToolkit.createNewAppContext();
6384N/A new Test8012933().test();
6384N/A }
6384N/A
6384N/A private void test() throws Exception {
6384N/A createAppContext();
6384N/A long startTime = System.currentTimeMillis();
6384N/A appContext.dispose();
6384N/A long endTime = System.currentTimeMillis();
6384N/A
6384N/A // In case of the bug, calling dispose() when there is no EQ
6384N/A // dispatch thread running fails to create it, so it takes
6384N/A // almost 10 sec to return from dispose(), which is spent
6384N/A // waiting on the notificationLock.
6384N/A if ((endTime - startTime) > 9000) {
6384N/A throw new RuntimeException("Returning from dispose() took too much time, probably a bug");
6384N/A }
6384N/A }
6384N/A
6384N/A private void createAppContext() {
6384N/A isCreated = false;
6384N/A final Runnable runnable = new Runnable() {
6384N/A public void run() {
6384N/A appContext = SunToolkit.createNewAppContext();
6384N/A synchronized (lock) {
6384N/A isCreated = true;
6384N/A lock.notifyAll();
6384N/A }
6384N/A }
6384N/A };
6384N/A
6384N/A final Thread thread = new Thread(threadGroup, runnable, "creates app context");
6384N/A synchronized (lock) {
6384N/A thread.start();
6384N/A while (!isCreated) {
6384N/A try {
6384N/A lock.wait();
6384N/A } catch (InterruptedException ie) {
6384N/A ie.printStackTrace();
6384N/A }
6384N/A }
6384N/A }
6384N/A
6384N/A if (appContext == null) {
6384N/A throw new RuntimeException("failed to create app context.");
6384N/A } else {
6384N/A System.out.println("app context was created.");
6384N/A }
6384N/A }
6384N/A
6384N/A}