jdk/test/sun/management/jmxremote/startstop/JMXStartStopDoSomething.java
author sjiang
Wed, 19 Dec 2012 11:06:51 +0100
changeset 14907 ac3160bdc1bd
parent 14013 10f55dd791e1
child 22349 2aa385c1c4d8
permissions -rw-r--r--
7158614: JMXStartStopTest.sh failing intermittently Summary: fixed 3 problems here: 1) checked the lock file too eary 2) never got the process id of a java test 3) some shell commands were not supported in some Solaris machines. Reviewed-by: dsamersoff, alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11991
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents:
diff changeset
     1
/*
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents:
diff changeset
     2
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents:
diff changeset
     4
 *
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents:
diff changeset
     7
 * published by the Free Software Foundation.
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents:
diff changeset
     8
 *
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents:
diff changeset
    13
 * accompanied this code).
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents:
diff changeset
    14
 *
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents:
diff changeset
    18
 *
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents:
diff changeset
    21
 * questions.
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents:
diff changeset
    22
 */
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents:
diff changeset
    23
14013
10f55dd791e1 7186723: TEST_BUG: Race condition in sun/management/jmxremote/startstop/JMXStartStopTest.sh
dsamersoff
parents: 11991
diff changeset
    24
import java.io.File;
11991
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents:
diff changeset
    25
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents:
diff changeset
    26
public class JMXStartStopDoSomething {
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents:
diff changeset
    27
14013
10f55dd791e1 7186723: TEST_BUG: Race condition in sun/management/jmxremote/startstop/JMXStartStopTest.sh
dsamersoff
parents: 11991
diff changeset
    28
    private static final String lockFileName = "JMXStartStop.lck";
11991
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents:
diff changeset
    29
14013
10f55dd791e1 7186723: TEST_BUG: Race condition in sun/management/jmxremote/startstop/JMXStartStopTest.sh
dsamersoff
parents: 11991
diff changeset
    30
    public static void doSomething() {
11991
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents:
diff changeset
    31
        try {
14013
10f55dd791e1 7186723: TEST_BUG: Race condition in sun/management/jmxremote/startstop/JMXStartStopTest.sh
dsamersoff
parents: 11991
diff changeset
    32
            File lockFile = new File(lockFileName);
10f55dd791e1 7186723: TEST_BUG: Race condition in sun/management/jmxremote/startstop/JMXStartStopTest.sh
dsamersoff
parents: 11991
diff changeset
    33
            lockFile.createNewFile();
10f55dd791e1 7186723: TEST_BUG: Race condition in sun/management/jmxremote/startstop/JMXStartStopTest.sh
dsamersoff
parents: 11991
diff changeset
    34
10f55dd791e1 7186723: TEST_BUG: Race condition in sun/management/jmxremote/startstop/JMXStartStopTest.sh
dsamersoff
parents: 11991
diff changeset
    35
            while(lockFile.exists()) {
10f55dd791e1 7186723: TEST_BUG: Race condition in sun/management/jmxremote/startstop/JMXStartStopTest.sh
dsamersoff
parents: 11991
diff changeset
    36
                long datetime = lockFile.lastModified();
10f55dd791e1 7186723: TEST_BUG: Race condition in sun/management/jmxremote/startstop/JMXStartStopTest.sh
dsamersoff
parents: 11991
diff changeset
    37
                long epoch = System.currentTimeMillis()/1000;
10f55dd791e1 7186723: TEST_BUG: Race condition in sun/management/jmxremote/startstop/JMXStartStopTest.sh
dsamersoff
parents: 11991
diff changeset
    38
10f55dd791e1 7186723: TEST_BUG: Race condition in sun/management/jmxremote/startstop/JMXStartStopTest.sh
dsamersoff
parents: 11991
diff changeset
    39
                // Don't allow test app to run more than an hour
10f55dd791e1 7186723: TEST_BUG: Race condition in sun/management/jmxremote/startstop/JMXStartStopTest.sh
dsamersoff
parents: 11991
diff changeset
    40
                if (epoch - datetime > 3600) {
10f55dd791e1 7186723: TEST_BUG: Race condition in sun/management/jmxremote/startstop/JMXStartStopTest.sh
dsamersoff
parents: 11991
diff changeset
    41
                    System.err.println("Lock is too old. Aborting");
10f55dd791e1 7186723: TEST_BUG: Race condition in sun/management/jmxremote/startstop/JMXStartStopTest.sh
dsamersoff
parents: 11991
diff changeset
    42
                    return;
10f55dd791e1 7186723: TEST_BUG: Race condition in sun/management/jmxremote/startstop/JMXStartStopTest.sh
dsamersoff
parents: 11991
diff changeset
    43
                }
14907
ac3160bdc1bd 7158614: JMXStartStopTest.sh failing intermittently
sjiang
parents: 14013
diff changeset
    44
                Thread.sleep(500);
11991
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents:
diff changeset
    45
            }
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents:
diff changeset
    46
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents:
diff changeset
    47
        } catch (Throwable e) {
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents:
diff changeset
    48
            System.err.println("Something bad happens:" +e);
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents:
diff changeset
    49
        }
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents:
diff changeset
    50
    }
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents:
diff changeset
    51
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents:
diff changeset
    52
    public static void main(String args[]) throws Exception {
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents:
diff changeset
    53
        System.err.println("main enter");
14013
10f55dd791e1 7186723: TEST_BUG: Race condition in sun/management/jmxremote/startstop/JMXStartStopTest.sh
dsamersoff
parents: 11991
diff changeset
    54
        doSomething();
10f55dd791e1 7186723: TEST_BUG: Race condition in sun/management/jmxremote/startstop/JMXStartStopTest.sh
dsamersoff
parents: 11991
diff changeset
    55
        System.err.println("main exit");
11991
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents:
diff changeset
    56
    }
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents:
diff changeset
    57
}