jdk/test/javax/management/monitor/CounterMonitorTest.java
author coleenp
Wed, 17 Jun 2015 21:44:48 +0000
changeset 31362 8957ccbb5821
parent 30376 2ccf2cf7ea48
child 44423 306c020eb154
permissions -rw-r--r--
8098821: Crash in system dictionary initialization with shared strings Summary: map string regions after the compressed class base is known Reviewed-by: iklam, dcubed Contributed-by: coleen.phillimore@oracle.com, mikhailo.seledtsov@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
30376
2ccf2cf7ea48 8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents: 28054
diff changeset
     2
 * Copyright (c) 2004, 2015, 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 4981829
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Test that the counter monitor, when running in difference mode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *          emits a notification every time the threshold is exceeded.
27796
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
    29
 * @author Luis-Miguel Alventosa, Shanliang JIANG
30376
2ccf2cf7ea48 8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents: 28054
diff changeset
    30
 * @modules java.management
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * @run clean CounterMonitorTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * @run build CounterMonitorTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * @run main CounterMonitorTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.management.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.management.monitor.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
public class CounterMonitorTest implements NotificationListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    // threshold number
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    private Number threshold = new Integer(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    // modulus number
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private Number modulus = new Integer(7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    // difference mode flag
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private boolean differenceModeFlag = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    // notify flag
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private boolean notifyFlag = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    // granularity period
27796
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
    54
    private int granularityperiod = 10;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
27796
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
    56
    // derived gauge
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
    57
    private volatile int derivedGauge = 2;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    // flag to notify that a message has been received
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private volatile boolean messageReceived = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
27796
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
    62
    private volatile Object observedValue = null;
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
    63
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    // MBean class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    public class StdObservedObject implements StdObservedObjectMBean {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        public Object getNbObjects() {
27796
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
    67
            echo(">>> StdObservedObject.getNbObjects: " + count);
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
    68
            synchronized(CounterMonitorTest.class) {
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
    69
                observedValue = count;
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
    70
                CounterMonitorTest.class.notifyAll();
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
    71
            }
28054
8b0ef141b964 8066952: [TEST-BUG] javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 27796
diff changeset
    72
            return observedValue;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        public void setNbObjects(Object n) {
27796
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
    75
            echo(">>> StdObservedObject.setNbObjects: " + n);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            count = n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        }
27796
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
    78
        private volatile Object count= null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    // MBean interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    public interface StdObservedObjectMBean {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        public Object getNbObjects();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        public void setNbObjects(Object n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    // Notification handler
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public void handleNotification(Notification notification,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                                   Object handback) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        MonitorNotification n = (MonitorNotification) notification;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        echo("\tInside handleNotification...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        String type = n.getType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            if (type.equals(MonitorNotification.THRESHOLD_VALUE_EXCEEDED)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                echo("\t\t" + n.getObservedAttribute() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                     " has reached or exceeded the threshold");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                echo("\t\tDerived Gauge = " + n.getDerivedGauge());
26623
11289cf5c8fc 8042205: javax/management/monitor/*: some tests didn't get all the notifications
sjiang
parents: 5506
diff changeset
    98
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                synchronized (this) {
26623
11289cf5c8fc 8042205: javax/management/monitor/*: some tests didn't get all the notifications
sjiang
parents: 5506
diff changeset
   100
                    messageReceived = true;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                    notifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                echo("\t\tSkipping notification of type: " + type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            echo("\tError in handleNotification!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            e.printStackTrace(System.out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * Update the counter and check for notifications
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    public void thresholdNotification() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        CounterMonitor counterMonitor = new CounterMonitor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            MBeanServer server = MBeanServerFactory.newMBeanServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            String domain = server.getDefaultDomain();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            // Create a new CounterMonitor MBean and add it to the MBeanServer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            echo(">>> CREATE a new CounterMonitor MBean");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            ObjectName counterMonitorName = new ObjectName(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                            domain + ":type=" + CounterMonitor.class.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            server.registerMBean(counterMonitor, counterMonitorName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            echo(">>> ADD a listener to the CounterMonitor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            counterMonitor.addNotificationListener(this, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            // MANAGEMENT OF A STANDARD MBEAN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            echo(">>> CREATE a new StdObservedObject MBean");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            ObjectName stdObsObjName =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                new ObjectName(domain + ":type=StdObservedObject");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            StdObservedObject stdObsObj = new StdObservedObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            server.registerMBean(stdObsObj, stdObsObjName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            echo(">>> SET the attributes of the CounterMonitor:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            counterMonitor.addObservedObject(stdObsObjName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            echo("\tATTRIBUTE \"ObservedObject\"    = " + stdObsObjName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            counterMonitor.setObservedAttribute("NbObjects");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            echo("\tATTRIBUTE \"ObservedAttribute\" = NbObjects");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            counterMonitor.setNotify(notifyFlag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            echo("\tATTRIBUTE \"Notify\"            = " + notifyFlag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            counterMonitor.setInitThreshold(threshold);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            echo("\tATTRIBUTE \"Threshold\"         = " + threshold);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            counterMonitor.setGranularityPeriod(granularityperiod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            counterMonitor.setModulus(modulus);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            echo("\tATTRIBUTE \"Modulus\"           = " + modulus);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            counterMonitor.setDifferenceMode(differenceModeFlag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            echo("\tATTRIBUTE \"DifferenceMode\"    = " + differenceModeFlag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            echo(">>> START the CounterMonitor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            counterMonitor.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            // Set initial value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            Integer data = new Integer(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            echo(">>> Set data = " + data.intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            Attribute attrib = new Attribute("NbObjects", data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            server.setAttribute(stdObsObjName, attrib);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
27796
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
   178
            waitObservation(data);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            // Loop through the values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            //
27796
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
   182
            while (derivedGauge++ < 10) {
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
   183
                System.out.print(">>> Set data from " + data.intValue());
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
   184
                data = new Integer(data.intValue() + derivedGauge);
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
   185
                echo(" to " + data.intValue());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                attrib = new Attribute("NbObjects", data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                server.setAttribute(stdObsObjName, attrib);
27796
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
   189
                waitObservation(data);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                echo("\tdoWait in Counter Monitor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                doWait();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                // Check if notification was received
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                if (messageReceived) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                    echo("\tOKAY: Notification received");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                    echo("\tError: notification missed or not emitted");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                    throw new IllegalStateException("Notification lost");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                messageReceived = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            counterMonitor.stop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        echo(">>> Bye! Bye!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    /*
26623
11289cf5c8fc 8042205: javax/management/monitor/*: some tests didn't get all the notifications
sjiang
parents: 5506
diff changeset
   212
     * Wait messageReceived to be true
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     */
26623
11289cf5c8fc 8042205: javax/management/monitor/*: some tests didn't get all the notifications
sjiang
parents: 5506
diff changeset
   214
    synchronized void doWait() {
11289cf5c8fc 8042205: javax/management/monitor/*: some tests didn't get all the notifications
sjiang
parents: 5506
diff changeset
   215
        while (!messageReceived) {
11289cf5c8fc 8042205: javax/management/monitor/*: some tests didn't get all the notifications
sjiang
parents: 5506
diff changeset
   216
            try {
11289cf5c8fc 8042205: javax/management/monitor/*: some tests didn't get all the notifications
sjiang
parents: 5506
diff changeset
   217
                wait();
11289cf5c8fc 8042205: javax/management/monitor/*: some tests didn't get all the notifications
sjiang
parents: 5506
diff changeset
   218
            } catch (InterruptedException e) {
11289cf5c8fc 8042205: javax/management/monitor/*: some tests didn't get all the notifications
sjiang
parents: 5506
diff changeset
   219
                System.err.println("Got unexpected exception: " + e);
11289cf5c8fc 8042205: javax/management/monitor/*: some tests didn't get all the notifications
sjiang
parents: 5506
diff changeset
   220
                e.printStackTrace();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
27796
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
   226
    private void waitObservation(Object value) {
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
   227
        synchronized (CounterMonitorTest.class) {
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
   228
            while (value != observedValue) {
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
   229
                try {
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
   230
                    CounterMonitorTest.class.wait();
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
   231
                } catch (InterruptedException e) {
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
   232
                    System.err.println("Got unexpected exception: " + e);
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
   233
                    e.printStackTrace();
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
   234
                    break;
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
   235
                }
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
   236
            }
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
   237
        }
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
   238
    }
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
   239
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * Print message
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    void echo(String message) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        System.out.println(message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * Standalone entry point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * Run the test and report to stdout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    public static void main (String args[]) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        CounterMonitorTest test = new CounterMonitorTest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        test.thresholdNotification();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
}