jdk/test/javax/management/monitor/MultiMonitorTest.java
author asapre
Fri, 24 Feb 2017 14:59:39 +0530
changeset 44100 a5803b63fc79
parent 30376 2ccf2cf7ea48
child 44423 306c020eb154
permissions -rw-r--r--
7132577: javax/management/monitor/MultiMonitorTest.java fails in JDK8-B22 Summary: Changed test’s own timeout mechanism to jtreg’s default timeout Reviewed-by: dholmes, egahlin Contributed-by: amit.sapre@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
44100
a5803b63fc79 7132577: javax/management/monitor/MultiMonitorTest.java fails in JDK8-B22
asapre
parents: 30376
diff changeset
     2
 * Copyright (c) 2004, 2017, 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 4984057
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Test that monitors can sample a large number of attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @author Eamonn McManus
30376
2ccf2cf7ea48 8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents: 30046
diff changeset
    29
 * @modules java.management
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * @run clean MultiMonitorTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * @run build MultiMonitorTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * @run main MultiMonitorTest
30046
cf2c86e1819e 8078334: Mark regression tests using randomness
darcy
parents: 5506
diff changeset
    33
 * @key randomness
2
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 java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.management.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.management.monitor.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/* We create N MBeans and three monitors, one for each different
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
   monitor type.  Each monitor monitors a single attribute in each of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
   the N MBeans.  We arrange for the trigger condition to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
   satisfied, so the listener we register on each monitor should get N
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
   notifications.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
public class MultiMonitorTest {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    static final int N = 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    static final ObjectName[] mbeanNames = new ObjectName[N];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    static final Monitored[] monitored = new Monitored[N];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    static final int COUNTER_THRESHOLD = 1000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    static final int OVER_COUNTER_THRESHOLD = 2000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    static final double GAUGE_THRESHOLD = 1000.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    static final double OVER_GAUGE_THRESHOLD = 2000.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    static final String STRING_TO_COMPARE = "chou";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    static final String DIFFERENT_STRING = "chevre";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        System.out.println("Test that monitors can sample a large " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
                           "number of attributes");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        final MBeanServer mbs = MBeanServerFactory.createMBeanServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        for (int i = 0; i < N; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            mbeanNames[i] = new ObjectName(":type=Monitored,instance=" + i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            monitored[i] = new Monitored();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            mbs.registerMBean(monitored[i], mbeanNames[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        final ObjectName counterMonitor =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            new ObjectName(":type=CounterMonitor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        final ObjectName gaugeMonitor =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            new ObjectName(":type=GaugeMonitor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        final ObjectName stringMonitor =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            new ObjectName(":type=StringMonitor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        final ObjectName[] monitorNames =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            new ObjectName[] {counterMonitor, gaugeMonitor, stringMonitor};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        final String[] attrNames =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            new String[] {"CounterValue", "GaugeValue", "StringValue"};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        mbs.createMBean(CounterMonitor.class.getName(), counterMonitor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        mbs.createMBean(GaugeMonitor.class.getName(), gaugeMonitor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        mbs.createMBean(StringMonitor.class.getName(), stringMonitor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        final CounterMonitorMBean counterProxy = (CounterMonitorMBean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            MBeanServerInvocationHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            .newProxyInstance(mbs, counterMonitor, CounterMonitorMBean.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                              false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        final GaugeMonitorMBean gaugeProxy = (GaugeMonitorMBean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            MBeanServerInvocationHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            .newProxyInstance(mbs, gaugeMonitor, GaugeMonitorMBean.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                              false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        final StringMonitorMBean stringProxy = (StringMonitorMBean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            MBeanServerInvocationHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            .newProxyInstance(mbs, stringMonitor, StringMonitorMBean.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                              false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        final MonitorMBean[] proxies = new MonitorMBean[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            counterProxy, gaugeProxy, stringProxy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        for (int i = 0; i < 3; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            proxies[i].setGranularityPeriod(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            proxies[i].setObservedAttribute(attrNames[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            for (int j = 0; j < N; j++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                proxies[i].addObservedObject(mbeanNames[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        final CountListener[] listeners = new CountListener[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            new CountListener(), new CountListener(), new CountListener()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        for (int i = 0; i < 3; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            mbs.addNotificationListener(monitorNames[i], listeners[i],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                                        null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        counterProxy.setInitThreshold(new Integer(COUNTER_THRESHOLD));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        counterProxy.setNotify(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        gaugeProxy.setThresholds(new Double(GAUGE_THRESHOLD), new Double(0.0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        gaugeProxy.setNotifyHigh(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        stringProxy.setStringToCompare(STRING_TO_COMPARE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        stringProxy.setNotifyDiffer(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        // A couple of granularity periods to detect bad behaviour
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        Thread.sleep(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
44100
a5803b63fc79 7132577: javax/management/monitor/MultiMonitorTest.java fails in JDK8-B22
asapre
parents: 30376
diff changeset
   119
        System.out.println("Checking for all listeners to be 0");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        if (!listenersAreAll(0, listeners)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            System.out.println("TEST FAILED: listeners not all 0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            System.exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        for (int i = 0; i < 3; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            proxies[i].start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
44100
a5803b63fc79 7132577: javax/management/monitor/MultiMonitorTest.java fails in JDK8-B22
asapre
parents: 30376
diff changeset
   128
        System.out.println("Waiting for listeners to all : " + N);
a5803b63fc79 7132577: javax/management/monitor/MultiMonitorTest.java fails in JDK8-B22
asapre
parents: 30376
diff changeset
   129
        int iterations = 0;
a5803b63fc79 7132577: javax/management/monitor/MultiMonitorTest.java fails in JDK8-B22
asapre
parents: 30376
diff changeset
   130
        while (!listenersAreAll(N, listeners)) {
a5803b63fc79 7132577: javax/management/monitor/MultiMonitorTest.java fails in JDK8-B22
asapre
parents: 30376
diff changeset
   131
            Thread.sleep(500);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
44100
a5803b63fc79 7132577: javax/management/monitor/MultiMonitorTest.java fails in JDK8-B22
asapre
parents: 30376
diff changeset
   133
            if (++iterations == 10) {
a5803b63fc79 7132577: javax/management/monitor/MultiMonitorTest.java fails in JDK8-B22
asapre
parents: 30376
diff changeset
   134
               for (int i = 0; i < listeners.length; i++) {
a5803b63fc79 7132577: javax/management/monitor/MultiMonitorTest.java fails in JDK8-B22
asapre
parents: 30376
diff changeset
   135
                   System.out.print(" " + listeners[i].getCount());
a5803b63fc79 7132577: javax/management/monitor/MultiMonitorTest.java fails in JDK8-B22
asapre
parents: 30376
diff changeset
   136
               }
a5803b63fc79 7132577: javax/management/monitor/MultiMonitorTest.java fails in JDK8-B22
asapre
parents: 30376
diff changeset
   137
               System.out.println();
a5803b63fc79 7132577: javax/management/monitor/MultiMonitorTest.java fails in JDK8-B22
asapre
parents: 30376
diff changeset
   138
               iterations = 0;
a5803b63fc79 7132577: javax/management/monitor/MultiMonitorTest.java fails in JDK8-B22
asapre
parents: 30376
diff changeset
   139
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        for (int i = 0; i < 3; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            proxies[i].stop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            for (int j = 0; j < N; j++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                proxies[i].removeObservedObject(mbeanNames[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            ObjectName[] observed = proxies[i].getObservedObjects();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            if (observed.length != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                System.out.println("TEST FAILED: not all observed objects " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                                   "removed: " + Arrays.asList(observed));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                System.exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        System.out.println("Test passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    public static interface MonitoredMBean {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        public int getCounterValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        public double getGaugeValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        public String getStringValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    public static class Monitored implements MonitoredMBean {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        /* We give a small random number of normal readings (possibly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
           zero) before giving a reading that provokes a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
           notification.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        private int okCounter = randomInt(5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        private int okGauge = randomInt(5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        private int okString = randomInt(5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        public synchronized int getCounterValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            if (--okCounter >= 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                return OVER_COUNTER_THRESHOLD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        public synchronized double getGaugeValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            if (--okGauge >= 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                return 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                return OVER_GAUGE_THRESHOLD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        public synchronized String getStringValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            if (--okString >= 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                return STRING_TO_COMPARE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                return DIFFERENT_STRING;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    public static class CountListener implements NotificationListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        private int count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        public synchronized void handleNotification(Notification n, Object h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            if (!(n instanceof MonitorNotification)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                System.out.println("TEST FAILED: bad notif: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                                   n.getClass().getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                System.exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            if (n.getType().indexOf("error") >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                System.out.println("TEST FAILED: error notif: " + n.getType());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                System.exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        public synchronized int getCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            return count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    private static boolean listenersAreAll(int n, CountListener[] listeners) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        for (int i = 0; i < listeners.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            if (listeners[i].getCount() != n)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    private static final Random random = new Random();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    static synchronized int randomInt(int n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        return random.nextInt(n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
}