2327N/A/*
2362N/A * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
2327N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2327N/A *
2327N/A * This code is free software; you can redistribute it and/or modify it
2327N/A * under the terms of the GNU General Public License version 2 only, as
2327N/A * published by the Free Software Foundation.
2327N/A *
2327N/A * This code is distributed in the hope that it will be useful, but WITHOUT
2327N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2327N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2327N/A * version 2 for more details (a copy is included in the LICENSE file that
2327N/A * accompanied this code).
2327N/A *
2327N/A * You should have received a copy of the GNU General Public License version
2327N/A * 2 along with this work; if not, write to the Free Software Foundation,
2327N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2327N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
2327N/A */
2327N/A
2327N/A/* @test
2327N/A * @bug 6880336
2327N/A * @summary Test for nested SwingWorkers, i.e. when the second worker is
2327N/Astarted from the first's doInBackground() method. A timeout when running
2327N/A* this test is an indication of failure.
2327N/A * @author Artem Ananiev
2327N/A * @run main/timeout=32 NestedWorkers
2327N/A */
2327N/A
2327N/Aimport javax.swing.*;
2327N/A
2327N/Apublic class NestedWorkers extends SwingWorker<String, Void> {
2327N/A
2327N/A private final static int MAX_LEVEL = 2;
2327N/A
2327N/A private int level;
2327N/A
2327N/A public NestedWorkers(int level) {
2327N/A super();
2327N/A this.level = level;
2327N/A }
2327N/A
2327N/A @Override
2327N/A public String doInBackground() throws Exception {
2327N/A if (level < MAX_LEVEL) {
2327N/A SwingWorker<String, Void> nested = new NestedWorkers(level + 1);
2327N/A nested.execute();
2327N/A nested.get();
2327N/A }
2327N/A System.out.println("doInBackground " + level + " is complete");
2327N/A return String.valueOf(level);
2327N/A }
2327N/A
2327N/A public static void main(String[] args) throws Exception {
2327N/A SwingUtilities.invokeAndWait(new Runnable() {
2327N/A @Override
2327N/A public void run() {
2327N/A SwingWorker<String, Void> sw = new NestedWorkers(0);
2327N/A sw.execute();
2327N/A try {
2327N/A System.err.println(sw.get());
2327N/A } catch (Exception z) {
2327N/A throw new RuntimeException(z);
2327N/A }
2327N/A }
2327N/A });
2327N/A }
2327N/A
2327N/A}