jdk/test/com/sun/tools/attach/RunnerUtil.java
author sla
Mon, 23 Jun 2014 15:51:41 +0200
changeset 25155 8b98011eac74
parent 24268 43fb1c9e594c
child 25182 1f6766bac82c
permissions -rw-r--r--
8044772: TempDirTest.java still times out with -Xcomp Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21968
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
     1
/*
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
     4
 *
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
     7
 * published by the Free Software Foundation.
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
     8
 *
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    13
 * accompanied this code).
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    14
 *
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    18
 *
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    21
 * questions.
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    22
 */
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    23
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    24
import java.io.IOException;
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    25
import java.io.File;
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    26
import java.nio.file.Files;
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    27
import java.util.Arrays;
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    28
import java.util.regex.Pattern;
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    29
import java.util.regex.Matcher;
24268
43fb1c9e594c 8041979: sun/jvmstat/monitor/MonitoredVm/CR6672135.java failing on all platforms
sla
parents: 24120
diff changeset
    30
21968
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    31
import jdk.testlibrary.OutputAnalyzer;
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    32
import jdk.testlibrary.ProcessTools;
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    33
import jdk.testlibrary.Utils;
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    34
import jdk.testlibrary.ProcessThread;
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    35
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    36
/*
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    37
 * Utility functions for test runners.
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    38
 * (Test runner = class that launch a test)
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    39
 */
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    40
public class RunnerUtil {
24268
43fb1c9e594c 8041979: sun/jvmstat/monitor/MonitoredVm/CR6672135.java failing on all platforms
sla
parents: 24120
diff changeset
    41
21968
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    42
    /**
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    43
     * The Application process must be run concurrently with our tests since
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    44
     * the tests will attach to the Application.
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    45
     * We will run the Application process in a separate thread.
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    46
     *
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    47
     * The Application must be started with flag "-Xshare:off" for the Retransform
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    48
     * test in TestBasics to pass on all platforms.
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    49
     *
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    50
     * The Application will write its pid and shutdownPort in the given outFile.
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    51
     */
24268
43fb1c9e594c 8041979: sun/jvmstat/monitor/MonitoredVm/CR6672135.java failing on all platforms
sla
parents: 24120
diff changeset
    52
    public static ProcessThread startApplication(String outFile, String... additionalOpts) throws Throwable {
21968
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    53
        String classpath = System.getProperty("test.class.path", ".");
24268
43fb1c9e594c 8041979: sun/jvmstat/monitor/MonitoredVm/CR6672135.java failing on all platforms
sla
parents: 24120
diff changeset
    54
        String[] myArgs = concat(additionalOpts, new String [] { "-Dattach.test=true", "-classpath", classpath, "Application", outFile });
43fb1c9e594c 8041979: sun/jvmstat/monitor/MonitoredVm/CR6672135.java failing on all platforms
sla
parents: 24120
diff changeset
    55
        String[] args = Utils.addTestJavaOpts(myArgs);
21968
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    56
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(args);
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    57
        ProcessThread pt = new ProcessThread("runApplication", pb);
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    58
        pt.start();
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    59
        return pt;
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    60
    }
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    61
24268
43fb1c9e594c 8041979: sun/jvmstat/monitor/MonitoredVm/CR6672135.java failing on all platforms
sla
parents: 24120
diff changeset
    62
    public static String[] concat(String[] a, String[] b) {
43fb1c9e594c 8041979: sun/jvmstat/monitor/MonitoredVm/CR6672135.java failing on all platforms
sla
parents: 24120
diff changeset
    63
        if (a == null) {
43fb1c9e594c 8041979: sun/jvmstat/monitor/MonitoredVm/CR6672135.java failing on all platforms
sla
parents: 24120
diff changeset
    64
            return b;
43fb1c9e594c 8041979: sun/jvmstat/monitor/MonitoredVm/CR6672135.java failing on all platforms
sla
parents: 24120
diff changeset
    65
        }
43fb1c9e594c 8041979: sun/jvmstat/monitor/MonitoredVm/CR6672135.java failing on all platforms
sla
parents: 24120
diff changeset
    66
        if (b == null) {
43fb1c9e594c 8041979: sun/jvmstat/monitor/MonitoredVm/CR6672135.java failing on all platforms
sla
parents: 24120
diff changeset
    67
            return a;
43fb1c9e594c 8041979: sun/jvmstat/monitor/MonitoredVm/CR6672135.java failing on all platforms
sla
parents: 24120
diff changeset
    68
        }
43fb1c9e594c 8041979: sun/jvmstat/monitor/MonitoredVm/CR6672135.java failing on all platforms
sla
parents: 24120
diff changeset
    69
        int aLen = a.length;
43fb1c9e594c 8041979: sun/jvmstat/monitor/MonitoredVm/CR6672135.java failing on all platforms
sla
parents: 24120
diff changeset
    70
        int bLen = b.length;
43fb1c9e594c 8041979: sun/jvmstat/monitor/MonitoredVm/CR6672135.java failing on all platforms
sla
parents: 24120
diff changeset
    71
        String[] c = new String[aLen + bLen];
43fb1c9e594c 8041979: sun/jvmstat/monitor/MonitoredVm/CR6672135.java failing on all platforms
sla
parents: 24120
diff changeset
    72
        System.arraycopy(a, 0, c, 0, aLen);
43fb1c9e594c 8041979: sun/jvmstat/monitor/MonitoredVm/CR6672135.java failing on all platforms
sla
parents: 24120
diff changeset
    73
        System.arraycopy(b, 0, c, aLen, bLen);
43fb1c9e594c 8041979: sun/jvmstat/monitor/MonitoredVm/CR6672135.java failing on all platforms
sla
parents: 24120
diff changeset
    74
        return c;
43fb1c9e594c 8041979: sun/jvmstat/monitor/MonitoredVm/CR6672135.java failing on all platforms
sla
parents: 24120
diff changeset
    75
     }
43fb1c9e594c 8041979: sun/jvmstat/monitor/MonitoredVm/CR6672135.java failing on all platforms
sla
parents: 24120
diff changeset
    76
21968
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    77
    /**
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    78
     * Will stop the running Application.
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    79
     * First tries to shutdown nicely by connecting to the shut down port.
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    80
     * If that fails, the process will be killed hard with stopProcess().
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    81
     *
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    82
     * If the nice shutdown fails, then an Exception is thrown and the test should fail.
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    83
     *
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    84
     * @param port The shut down port.
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    85
     * @param processThread The process to stop.
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    86
     */
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    87
    public static void stopApplication(int port, ProcessThread processThread) throws Throwable {
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    88
        if (processThread == null) {
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    89
            System.out.println("RunnerUtil.stopApplication ignored since proc is null");
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    90
            return;
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    91
        }
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    92
        try {
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    93
            System.out.println("RunnerUtil.stopApplication waiting to for shutdown");
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    94
            OutputAnalyzer output = ProcessTools.executeTestJvm(
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    95
                    "-classpath",
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    96
                    System.getProperty("test.class.path", "."),
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    97
                    "Shutdown",
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    98
                    Integer.toString(port));
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
    99
            // Verify that both the Shutdown command and the Application finished ok.
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   100
            output.shouldHaveExitValue(0);
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   101
            processThread.joinAndThrow();
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   102
            processThread.getOutput().shouldHaveExitValue(0);
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   103
        } catch (Throwable t) {
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   104
            System.out.println("RunnerUtil.stopApplication failed. Will kill it hard: " + t);
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   105
            processThread.stopProcess();
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   106
            throw t;
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   107
        }
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   108
    }
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   109
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   110
    /**
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   111
     * Creates a jar file.
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   112
     * @param args Command to the jar tool.
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   113
     */
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   114
    public static void createJar(String... args) {
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   115
        System.out.println("Running: jar " + Arrays.toString(args));
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   116
        sun.tools.jar.Main jar = new sun.tools.jar.Main(System.out, System.err, "jar");
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   117
        if (!jar.run(args)) {
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   118
            throw new RuntimeException("jar failed: args=" + Arrays.toString(args));
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   119
        }
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   120
    }
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   121
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   122
    /**
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   123
     * Read process info for the running Application.
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   124
     * The Application writes its info to a file with this format:
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   125
     * shutdownPort=42994
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   126
     * pid=19597
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   127
     * done
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   128
     *
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   129
     * The final "done" is used to make sure the complete file has been written
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   130
     * before we try to read it.
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   131
     * This function will wait until the file is available.
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   132
     *
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   133
     * @param filename Path to file to read.
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   134
     * @return The ProcessInfo containing pid and shutdownPort.
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   135
     */
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   136
    public static ProcessInfo readProcessInfo(String filename) throws Throwable {
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   137
        System.out.println("Reading port and pid from file: " + filename);
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   138
        File file = new File(filename);
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   139
        String content = null;
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   140
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   141
        // Read file or wait for it to be created.
25155
8b98011eac74 8044772: TempDirTest.java still times out with -Xcomp
sla
parents: 24268
diff changeset
   142
        long startTime = System.currentTimeMillis();
8b98011eac74 8044772: TempDirTest.java still times out with -Xcomp
sla
parents: 24268
diff changeset
   143
        long lastWarningTime = 0;
21968
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   144
        while (true) {
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   145
            content = readFile(file);
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   146
            if (content != null && content.indexOf("done") >= 0) {
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   147
                break;
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   148
            }
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   149
            Thread.sleep(100);
25155
8b98011eac74 8044772: TempDirTest.java still times out with -Xcomp
sla
parents: 24268
diff changeset
   150
            long elapsedTime = (System.currentTimeMillis() - startTime) / 1000;
8b98011eac74 8044772: TempDirTest.java still times out with -Xcomp
sla
parents: 24268
diff changeset
   151
            if (elapsedTime > lastWarningTime) {
8b98011eac74 8044772: TempDirTest.java still times out with -Xcomp
sla
parents: 24268
diff changeset
   152
                lastWarningTime = elapsedTime;
8b98011eac74 8044772: TempDirTest.java still times out with -Xcomp
sla
parents: 24268
diff changeset
   153
                System.out.println("Waited " + elapsedTime + " seconds for file.");
8b98011eac74 8044772: TempDirTest.java still times out with -Xcomp
sla
parents: 24268
diff changeset
   154
            }
21968
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   155
        }
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   156
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   157
        ProcessInfo info = new ProcessInfo();
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   158
        // search for a line with format: key=nnn
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   159
        Pattern pattern = Pattern.compile("(\\w*)=([0-9]+)\\r?\\n");
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   160
        Matcher matcher = pattern.matcher(content);
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   161
        while (matcher.find()) {
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   162
            String key = matcher.group(1);
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   163
            int value  = Integer.parseInt(matcher.group(2));
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   164
            if ("pid".equals(key)) {
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   165
                info.pid = value;
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   166
            } else if ("shutdownPort".equals(key)) {
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   167
                info.shutdownPort = value;
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   168
            }
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   169
        }
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   170
        System.out.println("processInfo.pid:" + info.pid);
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   171
        System.out.println("processInfo.shutdownPort:" + info.shutdownPort);
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   172
        return info;
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   173
    }
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   174
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   175
    /**
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   176
     * Read the content of a file.
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   177
     * @param file The file to read.
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   178
     * @return The file content or null if file does not exists.
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   179
     */
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   180
    public static String readFile(File file) throws IOException {
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   181
        if (!file.exists()) {
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   182
            return null;
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   183
        }
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   184
        try {
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   185
            byte[] bytes = Files.readAllBytes(file.toPath());
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   186
            String content = new String(bytes);
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   187
            return content;
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   188
        } catch (IOException e) {
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   189
            e.printStackTrace();
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   190
            throw e;
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   191
        }
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   192
    }
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   193
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   194
    /**
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   195
     * Helper class with info of the running Application.
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   196
     */
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   197
    public static class ProcessInfo {
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   198
        public int pid = -1;
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   199
        public int shutdownPort = -1;
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   200
    }
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   201
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
diff changeset
   202
}