author | serb |
Tue, 12 Nov 2013 20:24:25 +0400 | |
changeset 21596 | 0e3a39f29dbc |
parent 17720 | 2337b09003f5 |
permissions | -rw-r--r-- |
21596 | 1 |
/* |
2 |
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
14916 | 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 | 30 |
import javax.management.MBeanServerConnection; |
31 |
import javax.management.Notification; |
|
32 |
import javax.management.NotificationListener; |
|
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 | 35 |
import javax.management.remote.JMXConnector; |
36 |
import javax.management.remote.JMXConnectorFactory; |
|
37 |
import javax.management.remote.JMXServiceURL; |
|
38 |
||
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 | 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 | 47 |
|
48 |
ObjectName name = new ObjectName("test", "foo", "bar"); |
|
49 |
JMXConnector jmxConnector = JMXConnectorFactory.connect(serverUrl); |
|
50 |
System.out.println("client connected"); |
|
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 | 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 | 64 |
} |
65 |
}, null, null); |
|
66 |
MBeanServerConnection jmxServer = jmxConnector.getMBeanServerConnection(); |
|
67 |
||
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 | 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 | 76 |
} |
77 |
}, null, null); |
|
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 | 82 |
jmxServer.invoke(name, "foo", new Object[]{}, new String[]{}); |
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 | 99 |
} |
100 |
} |