jdk/test/javax/management/remote/mandatory/connection/IdleTimeoutTest.java
author dbuck
Tue, 18 Aug 2015 04:29:28 -0700
changeset 32417 6859107fc6c3
parent 30376 2ccf2cf7ea48
child 43503 bc7f8619ab70
permissions -rw-r--r--
8133666: OperatingSystemMXBean reports abnormally high machine CPU consumption on Linux Reviewed-by: sla, mgronlun
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: 23010
diff changeset
     2
 * Copyright (c) 2003, 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: 4156
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
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
20768
d7bfaa88e290 8025204: Intermittent test failure: javax/management/remote/mandatory/connection/IdleTimeoutTest.java
sjiang
parents: 14917
diff changeset
    26
 * @bug 4886838 4886830 8025204
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Tests that idle timeouts happen at appropriate times
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: 23010
diff changeset
    29
 * @modules java.management/com.sun.jmx.remote.util
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * @run clean IdleTimeoutTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * @run build IdleTimeoutTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * @run main IdleTimeoutTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.Arrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.management.MBeanServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import javax.management.MBeanServerConnection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import javax.management.MBeanServerFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import javax.management.MBeanServerNotification;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import javax.management.Notification;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import javax.management.NotificationListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import javax.management.ObjectName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import javax.management.remote.JMXConnector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import javax.management.remote.JMXConnectorFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import javax.management.remote.JMXConnectorServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import javax.management.remote.JMXConnectorServerFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import javax.management.remote.JMXServiceURL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import com.sun.jmx.remote.util.EnvHelp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
public class IdleTimeoutTest {
14917
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 5506
diff changeset
    56
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 5506
diff changeset
    57
    static boolean isPresent(String cn) {
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 5506
diff changeset
    58
        try {
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 5506
diff changeset
    59
            Class.forName(cn);
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 5506
diff changeset
    60
            return true;
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 5506
diff changeset
    61
        } catch (ClassNotFoundException x) {
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 5506
diff changeset
    62
            return false;
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 5506
diff changeset
    63
        }
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 5506
diff changeset
    64
    }
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 5506
diff changeset
    65
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        boolean ok = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        List protos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        if (args.length > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            protos = Arrays.asList(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        else {
14917
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 5506
diff changeset
    72
            protos = new ArrayList(Arrays.asList(new String[] {"rmi"}));
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 5506
diff changeset
    73
            if (isPresent("javax.management.remote.rmi._RMIConnectionImpl_Tie"))
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 5506
diff changeset
    74
                protos.add("iiop");
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 5506
diff changeset
    75
            if (isPresent("javax.management.remote.jmxmp.JMXMPConnectorServer"))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                protos.add("jmxmp");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        for (Iterator it = protos.iterator(); it.hasNext(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            String proto = (String) it.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            int liCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            if (proto.equals("jmxmp")) liCount=1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            else liCount=2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            if (test(proto,4,liCount))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                System.out.println("Test for protocol " + proto + " passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                System.out.println("Test for protocol " + proto + " FAILED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        if (!ok) {
14917
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 5506
diff changeset
    91
            throw new RuntimeException("Some tests failed - see log for details");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    private static long getIdleTimeout(MBeanServer mbs, JMXServiceURL url)
14917
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 5506
diff changeset
    96
        throws Exception
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 5506
diff changeset
    97
    {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        JMXConnectorServer server =
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1247
diff changeset
    99
            JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        server.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            url = server.getAddress();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            // Force initialization (class loading, JIT, etc...)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            JMXConnector client = JMXConnectorFactory.connect(url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                String connId = client.getConnectionId();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                MBeanServerConnection conn = client.getMBeanServerConnection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                client.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            // Do the time measurement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            final long firstTime = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            final long endtime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            client = JMXConnectorFactory.connect(url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                String connId = client.getConnectionId();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                MBeanServerConnection conn = client.getMBeanServerConnection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                endtime = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                client.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            // multipled by 10 for a slow machine, plus 1500 for a fast one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            return 10*(endtime - firstTime) + 1500;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            server.stop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    private static class NotificationCounter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        implements NotificationListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        private final int[]  listenerCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        private final String listenerName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        NotificationCounter(int[] counter, String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            listenerCount=counter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            listenerName=name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        public void handleNotification(Notification n,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                                       Object h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            MBeanServerNotification mbsn =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                (MBeanServerNotification) n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            System.out.println(listenerName + " got notification: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                               + mbsn.getMBeanName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            synchronized (listenerCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                listenerCount[0]++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                listenerCount.notify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            return listenerName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    private static boolean test(String proto,int opCount,int liCount)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        System.out.println("Idle timeout test for protocol " + proto);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        ObjectName delegateName =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            ObjectName.getInstance("JMImplementation:" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                                   "type=MBeanServerDelegate");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        MBeanServer mbs = MBeanServerFactory.createMBeanServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        JMXServiceURL url = new JMXServiceURL("service:jmx:" + proto + "://");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        final long timeout = getIdleTimeout(mbs,url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        System.out.println("Timeout for " + proto + " is: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                           timeout + " ms");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        Map idleMap = new HashMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        idleMap.put(EnvHelp.SERVER_CONNECTION_TIMEOUT, new Long(timeout));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        JMXConnectorServer server =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            JMXConnectorServerFactory.newJMXConnectorServer(url,idleMap,mbs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        final int[] listenerCount = new int[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        final NotificationListener countListeners[] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            new NotificationListener[liCount];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        for (i=0; i<countListeners.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            countListeners[i] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                new NotificationCounter(listenerCount,"Listener"+i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        server.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            url = server.getAddress();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            final long firstTime = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            JMXConnector client = JMXConnectorFactory.connect(url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            long elapsed, startIdle=0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                String connId = client.getConnectionId();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                MBeanServerConnection conn =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                    client.getMBeanServerConnection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                elapsed   = System.currentTimeMillis() - firstTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                System.out.println("Idle Time: " + elapsed + "ms");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                for (i=0; i<countListeners.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                    System.out.println("add " + countListeners[i] +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                                       ": starting at " + elapsed + "ms");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                    conn.addNotificationListener(delegateName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                                                 countListeners[i],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                                                 null,null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                System.out.println("connId=" + connId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                for (i = 0; i < opCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                    elapsed   = System.currentTimeMillis() - firstTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                    System.out.println("Operation[" + (i+1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                                       +"]: starting at " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                                       elapsed + "ms");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                    final String name = "d:type=mlet,instance=" + i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                    mbs.createMBean("javax.management.loading.MLet",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                                    new ObjectName(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                    if (i == (opCount-1))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                        startIdle = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                    Thread.sleep(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                // Wait for notifs to arrive before doing removeNListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                long startTime = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                long deadline = startTime + 10000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                System.out.println("Waiting for notifs: starting at " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                                   (startTime - firstTime) + "ms");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                final int expectedCount = opCount*countListeners.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                while (System.currentTimeMillis() < deadline) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                    synchronized (listenerCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                        if (listenerCount[0] >= expectedCount)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                        listenerCount.wait();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                long elapsedWait = System.currentTimeMillis() - startTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                System.out.println("Waited " + elapsedWait +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                                   "ms for notifs to arrive");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                if (listenerCount[0] != expectedCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                    System.out.println("Did not get expected " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                                       expectedCount + " notifications: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                                       + listenerCount[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                elapsed   = System.currentTimeMillis() - firstTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                System.out.println("idle time since last operation: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                                   (elapsed + firstTime - startIdle) + "ms");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                System.out.println("Requesting conn id at: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                                   elapsed + "ms");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                final String cid = client.getConnectionId();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                elapsed   = System.currentTimeMillis() - firstTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                System.out.println("Got conn id <" + cid + "> at: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                                   elapsed + "ms");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                if (!connId.equals(cid)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                    System.out.println("Client id changed: <" + connId +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                                       "> -> <" + cid +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                                       ">");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                List ids = Arrays.asList(server.getConnectionIds());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                if (!ids.contains(connId)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                    System.out.println("Server ids don't contain our id: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                                       ids + " - " + connId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                for (i=0;i<countListeners.length;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                    System.out.println("Removing notification listener: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                                       countListeners[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                    conn.removeNotificationListener(delegateName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                                                    countListeners[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                System.out.println("Waiting for id list to drop ours");
20768
d7bfaa88e290 8025204: Intermittent test failure: javax/management/remote/mandatory/connection/IdleTimeoutTest.java
sjiang
parents: 14917
diff changeset
   282
                // pass or timed out by test harness - see 8025204
d7bfaa88e290 8025204: Intermittent test failure: javax/management/remote/mandatory/connection/IdleTimeoutTest.java
sjiang
parents: 14917
diff changeset
   283
                do {
d7bfaa88e290 8025204: Intermittent test failure: javax/management/remote/mandatory/connection/IdleTimeoutTest.java
sjiang
parents: 14917
diff changeset
   284
                   Thread.sleep(100);
d7bfaa88e290 8025204: Intermittent test failure: javax/management/remote/mandatory/connection/IdleTimeoutTest.java
sjiang
parents: 14917
diff changeset
   285
                   ids = Arrays.asList(server.getConnectionIds());
d7bfaa88e290 8025204: Intermittent test failure: javax/management/remote/mandatory/connection/IdleTimeoutTest.java
sjiang
parents: 14917
diff changeset
   286
                } while (ids.contains(connId));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                conn.getDefaultDomain();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                if (connId.equals(client.getConnectionId())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                    System.out.println("Client id did not change: <" + connId +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                                       ">: idle timeout did not happen?");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                    System.out.println("Client id changed as expected: <" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                                       connId + "> -> <" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                                       client.getConnectionId() + ">");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                client.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                System.out.println("Connection id list on server after " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                                   "client close: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                                   Arrays.asList(server.getConnectionIds()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            server.stop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        System.out.println("*** ------------------------------------------");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        System.out.println("*** Test passed for " + proto);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        System.out.println("*** ------------------------------------------");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
}