jdk/test/com/sun/jmx/remote/NotificationMarshalVersions/Client/Client.java
author serb
Tue, 12 Nov 2013 20:24:25 +0400
changeset 21596 0e3a39f29dbc
parent 17720 2337b09003f5
permissions -rw-r--r--
8027696: Incorrect copyright header in the tests Reviewed-by: alanb, malenkov, mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21596
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 17720
diff changeset
     1
/*
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 17720
diff changeset
     2
 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 17720
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 17720
diff changeset
     4
 *
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 17720
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 17720
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 17720
diff changeset
     7
 * published by the Free Software Foundation.
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 17720
diff changeset
     8
 *
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 17720
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 17720
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 17720
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 17720
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 17720
diff changeset
    13
 * accompanied this code).
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 17720
diff changeset
    14
 *
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 17720
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 17720
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 17720
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 17720
diff changeset
    18
 *
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 17720
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 17720
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 17720
diff changeset
    21
 * questions.
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 17720
diff changeset
    22
 */
14916
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    23
17720
2337b09003f5 8005472: com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh failed on windows
jbachorik
parents: 14916
diff changeset
    24
import java.util.Collections;
2337b09003f5 8005472: com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh failed on windows
jbachorik
parents: 14916
diff changeset
    25
import java.util.HashSet;
2337b09003f5 8005472: com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh failed on windows
jbachorik
parents: 14916
diff changeset
    26
import java.util.Set;
2337b09003f5 8005472: com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh failed on windows
jbachorik
parents: 14916
diff changeset
    27
import java.util.concurrent.CountDownLatch;
2337b09003f5 8005472: com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh failed on windows
jbachorik
parents: 14916
diff changeset
    28
import java.util.concurrent.TimeUnit;
2337b09003f5 8005472: com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh failed on windows
jbachorik
parents: 14916
diff changeset
    29
import java.util.concurrent.atomic.AtomicBoolean;
14916
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    30
import javax.management.MBeanServerConnection;
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    31
import javax.management.Notification;
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    32
import javax.management.NotificationListener;
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    33
import javax.management.ObjectName;
17720
2337b09003f5 8005472: com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh failed on windows
jbachorik
parents: 14916
diff changeset
    34
import javax.management.remote.JMXConnectionNotification;
14916
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    35
import javax.management.remote.JMXConnector;
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    36
import javax.management.remote.JMXConnectorFactory;
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    37
import javax.management.remote.JMXServiceURL;
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    38
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    39
public class Client {
17720
2337b09003f5 8005472: com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh failed on windows
jbachorik
parents: 14916
diff changeset
    40
    public static void run(String url) throws Exception {
2337b09003f5 8005472: com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh failed on windows
jbachorik
parents: 14916
diff changeset
    41
        final int notifEmittedCnt = 10;
2337b09003f5 8005472: com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh failed on windows
jbachorik
parents: 14916
diff changeset
    42
        final CountDownLatch counter = new CountDownLatch(notifEmittedCnt);
2337b09003f5 8005472: com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh failed on windows
jbachorik
parents: 14916
diff changeset
    43
        final Set<Long> seqSet = Collections.synchronizedSet(new HashSet<Long>());
2337b09003f5 8005472: com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh failed on windows
jbachorik
parents: 14916
diff changeset
    44
        final AtomicBoolean duplNotification = new AtomicBoolean();
14916
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    45
17720
2337b09003f5 8005472: com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh failed on windows
jbachorik
parents: 14916
diff changeset
    46
        JMXServiceURL serverUrl = new JMXServiceURL(url);
14916
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    47
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    48
        ObjectName name = new ObjectName("test", "foo", "bar");
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    49
        JMXConnector jmxConnector = JMXConnectorFactory.connect(serverUrl);
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    50
        System.out.println("client connected");
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    51
        jmxConnector.addConnectionNotificationListener(new NotificationListener() {
17720
2337b09003f5 8005472: com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh failed on windows
jbachorik
parents: 14916
diff changeset
    52
            @Override
14916
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    53
            public void handleNotification(Notification notification, Object handback) {
17720
2337b09003f5 8005472: com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh failed on windows
jbachorik
parents: 14916
diff changeset
    54
                System.out.println("connection notification: " + notification);
2337b09003f5 8005472: com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh failed on windows
jbachorik
parents: 14916
diff changeset
    55
                if (!seqSet.add(notification.getSequenceNumber())) {
2337b09003f5 8005472: com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh failed on windows
jbachorik
parents: 14916
diff changeset
    56
                    duplNotification.set(true);
2337b09003f5 8005472: com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh failed on windows
jbachorik
parents: 14916
diff changeset
    57
                }
2337b09003f5 8005472: com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh failed on windows
jbachorik
parents: 14916
diff changeset
    58
                if (notification.getType().equals(JMXConnectionNotification.NOTIFS_LOST)) {
2337b09003f5 8005472: com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh failed on windows
jbachorik
parents: 14916
diff changeset
    59
                    long lostNotifs = ((Long)((JMXConnectionNotification)notification).getUserData()).longValue();
2337b09003f5 8005472: com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh failed on windows
jbachorik
parents: 14916
diff changeset
    60
                    for(int i=0;i<lostNotifs;i++) {
2337b09003f5 8005472: com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh failed on windows
jbachorik
parents: 14916
diff changeset
    61
                        counter.countDown();
2337b09003f5 8005472: com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh failed on windows
jbachorik
parents: 14916
diff changeset
    62
                    }
2337b09003f5 8005472: com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh failed on windows
jbachorik
parents: 14916
diff changeset
    63
                }
14916
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    64
            }
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    65
        }, null, null);
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    66
        MBeanServerConnection jmxServer = jmxConnector.getMBeanServerConnection();
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    67
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    68
        jmxServer.addNotificationListener(name, new NotificationListener() {
17720
2337b09003f5 8005472: com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh failed on windows
jbachorik
parents: 14916
diff changeset
    69
            @Override
14916
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    70
            public void handleNotification(Notification notification, Object handback) {
17720
2337b09003f5 8005472: com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh failed on windows
jbachorik
parents: 14916
diff changeset
    71
                System.out.println("client got: " + notification);
2337b09003f5 8005472: com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh failed on windows
jbachorik
parents: 14916
diff changeset
    72
                if (!seqSet.add(notification.getSequenceNumber())) {
2337b09003f5 8005472: com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh failed on windows
jbachorik
parents: 14916
diff changeset
    73
                    duplNotification.set(true);
2337b09003f5 8005472: com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh failed on windows
jbachorik
parents: 14916
diff changeset
    74
                }
2337b09003f5 8005472: com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh failed on windows
jbachorik
parents: 14916
diff changeset
    75
                counter.countDown();
14916
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    76
            }
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    77
        }, null, null);
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    78
17720
2337b09003f5 8005472: com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh failed on windows
jbachorik
parents: 14916
diff changeset
    79
        System.out.println("client invoking foo (" + notifEmittedCnt + " times)");
2337b09003f5 8005472: com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh failed on windows
jbachorik
parents: 14916
diff changeset
    80
        for(int i=0;i<notifEmittedCnt;i++) {
2337b09003f5 8005472: com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh failed on windows
jbachorik
parents: 14916
diff changeset
    81
            System.out.print(".");
14916
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    82
            jmxServer.invoke(name, "foo", new Object[]{}, new String[]{});
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    83
        }
17720
2337b09003f5 8005472: com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh failed on windows
jbachorik
parents: 14916
diff changeset
    84
        System.out.println();
2337b09003f5 8005472: com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh failed on windows
jbachorik
parents: 14916
diff changeset
    85
        try {
2337b09003f5 8005472: com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh failed on windows
jbachorik
parents: 14916
diff changeset
    86
            System.out.println("waiting for " + notifEmittedCnt + " notifications to arrive");
2337b09003f5 8005472: com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh failed on windows
jbachorik
parents: 14916
diff changeset
    87
            if (!counter.await(30, TimeUnit.SECONDS)) {
2337b09003f5 8005472: com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh failed on windows
jbachorik
parents: 14916
diff changeset
    88
                throw new InterruptedException();
2337b09003f5 8005472: com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh failed on windows
jbachorik
parents: 14916
diff changeset
    89
            }
2337b09003f5 8005472: com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh failed on windows
jbachorik
parents: 14916
diff changeset
    90
            if (duplNotification.get()) {
2337b09003f5 8005472: com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh failed on windows
jbachorik
parents: 14916
diff changeset
    91
                System.out.println("ERROR: received duplicated notifications");
2337b09003f5 8005472: com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh failed on windows
jbachorik
parents: 14916
diff changeset
    92
                throw new Error("received duplicated notifications");
2337b09003f5 8005472: com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh failed on windows
jbachorik
parents: 14916
diff changeset
    93
            }
2337b09003f5 8005472: com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh failed on windows
jbachorik
parents: 14916
diff changeset
    94
            System.out.println("\nshutting down client");
2337b09003f5 8005472: com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh failed on windows
jbachorik
parents: 14916
diff changeset
    95
        } catch (InterruptedException e) {
2337b09003f5 8005472: com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh failed on windows
jbachorik
parents: 14916
diff changeset
    96
            System.out.println("ERROR: notification processing thread interrupted");
2337b09003f5 8005472: com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh failed on windows
jbachorik
parents: 14916
diff changeset
    97
            throw new Error("notification thread interrupted unexpectedly");
2337b09003f5 8005472: com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh failed on windows
jbachorik
parents: 14916
diff changeset
    98
        }
14916
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
    99
    }
5e9eb5d9de14 8005309: Missed tests for 6783290,6937053,7009998
dsamersoff
parents:
diff changeset
   100
}