jdk/test/javax/management/monitor/GaugeMonitorDeadlockTest.java
author stefank
Fri, 17 Apr 2015 17:10:38 +0000 (2015-04-17)
changeset 30266 ef82cd1f2db3
parent 26636 8638e7d8ebf5
child 30376 2ccf2cf7ea48
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug 6303187
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Test that no locks are held when a monitor attribute is sampled
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * or notif delivered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * @author Eamonn McManus
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * @run clean GaugeMonitorDeadlockTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * @run build GaugeMonitorDeadlockTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * @run main GaugeMonitorDeadlockTest 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * @run main GaugeMonitorDeadlockTest 2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * @run main GaugeMonitorDeadlockTest 3
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * @run main GaugeMonitorDeadlockTest 4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.lang.management.ManagementFactory;
26636
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
    39
import java.lang.management.ThreadInfo;
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
    40
import java.lang.management.ThreadMXBean;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.util.concurrent.atomic.AtomicInteger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import javax.management.JMX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import javax.management.MBeanServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import javax.management.Notification;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import javax.management.NotificationListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import javax.management.ObjectName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import javax.management.monitor.GaugeMonitor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import javax.management.monitor.GaugeMonitorMBean;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
public class GaugeMonitorDeadlockTest {
26636
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
    51
    private static enum When {IN_GET_ATTRIBUTE, IN_NOTIFY};
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
    52
    private static long checkingTime;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        if (args.length != 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            throw new Exception("Arg should be test number");
26636
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
    57
        double factor = Double.parseDouble(System.getProperty("test.timeout.factor", "1.0"));
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
    58
        checkingTime = (long)factor*1000;
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
    59
        System.out.println("=== checkingTime = " + checkingTime + "ms");
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
    60
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        int testNo = Integer.parseInt(args[0]) - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        TestCase test = testCases[testNo];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        System.out.println("Test: " + test.getDescription());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        test.run();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        System.out.println("Test passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private static abstract class TestCase {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        TestCase(String description, When when) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            this.description = description;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            this.when = when;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        void run() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            final ObjectName observedName = new ObjectName("a:b=c");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            final ObjectName monitorName = new ObjectName("a:type=Monitor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            mbs.registerMBean(new GaugeMonitor(), monitorName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            final GaugeMonitorMBean monitorProxy =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                JMX.newMBeanProxy(mbs, monitorName, GaugeMonitorMBean.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            final TestMBean observedProxy =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                JMX.newMBeanProxy(mbs, observedName, TestMBean.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            final Runnable sensitiveThing = new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                    doSensitiveThing(monitorProxy, observedName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            final Runnable nothing = new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                public void run() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            final Runnable withinGetAttribute =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                (when == When.IN_GET_ATTRIBUTE) ? sensitiveThing : nothing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            mbs.registerMBean(new Test(withinGetAttribute), observedName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            monitorProxy.addObservedObject(observedName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            monitorProxy.setObservedAttribute("Thing");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            monitorProxy.setThresholds(105, 100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            monitorProxy.setGranularityPeriod(10L); // 10 ms
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            monitorProxy.setNotifyHigh(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            monitorProxy.setNotifyLow(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            monitorProxy.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
26636
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   106
            System.out.println("=== Waiting observedProxy.getGetCount() to be "
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   107
                    + "changed, presumable deadlock if timeout?");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            final int initGetCount = observedProxy.getGetCount();
26636
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   109
            long checkedTime = System.currentTimeMillis();
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   110
            long nowTime;
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   111
            ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   112
            while (observedProxy.getGetCount() == initGetCount) {
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   113
                Thread.sleep(100);
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   114
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   115
                nowTime = System.currentTimeMillis();
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   116
                if (nowTime - checkedTime >= checkingTime) {
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   117
                    System.out.println("=== Checking deadlocked ...");
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   118
                    if (threadMXBean.findDeadlockedThreads() != null) {
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   119
                        for (ThreadInfo info : threadMXBean.dumpAllThreads(true, true)) {
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   120
                            System.out.println(info);
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   121
                        }
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   122
                        throw new Error("Found deadlocked threads: "
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   123
                                + threadMXBean.findDeadlockedThreads().length);
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   124
                    }
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   125
                    checkedTime = System.currentTimeMillis();
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   126
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            }
26636
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   128
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            // This won't show up as a deadlock in CTRL-\ or in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            // ThreadMXBean.findDeadlockedThreads(), because they don't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            // see that thread A is waiting for thread B (B.join()), and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            // thread B is waiting for a lock held by thread A
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            // Now we know the monitor has observed the initial value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            // so if we want to test notify behaviour we can trigger by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            // exceeding the threshold.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            if (when == When.IN_NOTIFY) {
26636
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   138
                final Thread testedThread = new Thread(sensitiveThing);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                final AtomicInteger notifCount = new AtomicInteger();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                final NotificationListener listener = new NotificationListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                    public void handleNotification(Notification n, Object h) {
26636
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   142
                        testedThread.start();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                        try {
26636
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   144
                            testedThread.join();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                        } catch (InterruptedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                            throw new RuntimeException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                        notifCount.incrementAndGet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                mbs.addNotificationListener(monitorName, listener, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                observedProxy.setThing(1000);
26636
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   153
                System.out.println("=== Waiting notifications, presumable "
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   154
                        + "deadlock if timeout?");
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   155
                long startTime = System.currentTimeMillis();
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   156
                checkedTime = startTime;
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   157
                while (notifCount.get() == 0) {
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   158
                    Thread.sleep(100);
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   159
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   160
                    nowTime = System.currentTimeMillis();
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   161
                    if (nowTime - checkedTime >= checkingTime) {
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   162
                        System.out.println("=== Checking the thread state ...");
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   163
                        if (testedThread.isAlive()) {
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   164
                            System.out.println("=== Waiting testedThread to die "
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   165
                                    + "after " + (nowTime - startTime) + "ms");
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   166
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   167
                            ThreadInfo tinfo = threadMXBean.getThreadInfo(testedThread.getId());
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   168
                            if (Thread.State.BLOCKED.equals(tinfo.getThreadState())) {
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   169
                                for (ThreadInfo info : threadMXBean.dumpAllThreads(true, true)) {
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   170
                                    System.out.println(info);
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   171
                                }
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   172
                            } else {
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   173
                                System.out.println(tinfo);
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   174
                            }
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   175
                        } else {
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   176
                            System.out.println("=== The testedThread is dead as wished, "
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   177
                                    + "the test must be passed soon.");
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   178
                        }
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   179
                        checkedTime = System.currentTimeMillis();
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   180
                    }
8638e7d8ebf5 8050115: javax/management/monitor/GaugeMonitorDeadlockTest.java fails intermittently
sjiang
parents: 5506
diff changeset
   181
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        abstract void doSensitiveThing(GaugeMonitorMBean monitorProxy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                                       ObjectName observedName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        String getDescription() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            return description;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        private final String description;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        private final When when;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    private static final TestCase[] testCases = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        new TestCase("Remove monitored MBean within monitored getAttribute",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                     When.IN_GET_ATTRIBUTE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            void doSensitiveThing(GaugeMonitorMBean monitorProxy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                                  ObjectName observedName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                monitorProxy.removeObservedObject(observedName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        new TestCase("Stop monitor within monitored getAttribute",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                     When.IN_GET_ATTRIBUTE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            void doSensitiveThing(GaugeMonitorMBean monitorProxy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                                  ObjectName observedName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                monitorProxy.stop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        new TestCase("Remove monitored MBean within threshold listener",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                     When.IN_NOTIFY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            void doSensitiveThing(GaugeMonitorMBean monitorProxy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                                  ObjectName observedName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                monitorProxy.removeObservedObject(observedName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        new TestCase("Stop monitor within threshold listener",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                     When.IN_NOTIFY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            void doSensitiveThing(GaugeMonitorMBean monitorProxy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                                  ObjectName observedName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                monitorProxy.stop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    public static interface TestMBean {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        public int getThing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        public void setThing(int thing);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        public int getGetCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    public static class Test implements TestMBean {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        public Test(Runnable runWithinGetAttribute) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            this.runWithinGetAttribute = runWithinGetAttribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        public int getThing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            Thread t = new Thread(runWithinGetAttribute);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            t.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                t.join();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            } catch (InterruptedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                throw new RuntimeException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            getCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            return thing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        public void setThing(int thing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            this.thing = thing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        public int getGetCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            return getCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        private final Runnable runWithinGetAttribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        private volatile int getCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        private volatile int thing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
}