Skip to content

Commit

Permalink
8302069: javax/management/remote/mandatory/notif/NotifReconnectDeadlo…
Browse files Browse the repository at this point in the history
…ckTest.java update

Backport-of: 1c7b09bc23ac37f83b9043de35b71bea7e814da5
  • Loading branch information
Amos Shi committed Apr 23, 2024
1 parent 295a8cd commit 7491ed4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
2 changes: 0 additions & 2 deletions test/jdk/ProblemList.txt
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,6 @@ java/lang/management/ThreadMXBean/ThreadMXBeanStateTest.java 8247426 generic-

javax/management/MBeanServer/OldMBeanServerTest.java 8030957 aix-all

javax/management/remote/mandatory/notif/NotifReconnectDeadlockTest.java 8042215 generic-all

############################################################################

# jdk_net
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -87,7 +87,10 @@ public static void main(String[] args) throws Exception {
JMXServiceURL addr = server.getAddress();
JMXConnector client = JMXConnectorFactory.connect(addr, env);

Thread.sleep(100); // let pass the first client open notif if there is
// Sleeping here was an attempt to avoid seeing an initial notification.
// This does not work, but does not matter.
// Thread.sleep(100);

client.getMBeanServerConnection().addNotificationListener(oname,
listener,
null,
Expand All @@ -100,12 +103,13 @@ public static void main(String[] args) throws Exception {

synchronized(lock) {
while(clientState == null && System.currentTimeMillis() < end) {
System.out.println("Calling sendNotifications");
mbs.invoke(oname, "sendNotifications",
new Object[] {new Notification("MyType", "", 0)},
new String[] {"javax.management.Notification"});

try {
lock.wait(10);
lock.wait(1000); // sleep as no point in constant notifications
} catch (Exception e) {}
}
}
Expand Down Expand Up @@ -143,10 +147,10 @@ public interface NotificationEmitterMBean {
private final static NotificationListener listener = new NotificationListener() {
public void handleNotification(Notification n, Object hb) {

// treat the client notif to know the end
System.out.println("handleNotification: " + n);
if (n instanceof JMXConnectionNotification) {
if (!JMXConnectionNotification.NOTIFS_LOST.equals(n.getType())) {

// Expected: [type=jmx.remote.connection.opened][message=Reconnected to server]
clientState = n.getType();
System.out.println(
">>> The client state has been changed to: "+clientState);
Expand All @@ -159,7 +163,7 @@ public void handleNotification(Notification n, Object hb) {
return;
}

System.out.println(">>> Do sleep to make reconnection.");
System.out.println(">>> sleeping in NotificationListener to force reconnection.");
synchronized(lock) {
try {
lock.wait(listenerSleep);
Expand All @@ -170,9 +174,11 @@ public void handleNotification(Notification n, Object hb) {
}
};

private static final long serverTimeout = 1000;
// serverTimeout increased to avoid occasional problems with initial connect.
// Not using Utils.adjustTimeout to avoid accidentally making it too long.
private static final long serverTimeout = 2000;
private static final long listenerSleep = serverTimeout*6;

private static String clientState = null;
private volatile static String clientState = null;
private static final int[] lock = new int[0];
}

1 comment on commit 7491ed4

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.