Skip to content

Commit

Permalink
8341316: [macos] javax/swing/ProgressMonitor/ProgressMonitorEscapeKey…
Browse files Browse the repository at this point in the history
…Press.java fails sometimes in macos

Reviewed-by: prr
  • Loading branch information
Manukumar V S authored and prrace committed Oct 3, 2024
1 parent e89fd1d commit 6bc3971
Showing 1 changed file with 59 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,66 +29,64 @@
* @run main ProgressMonitorEscapeKeyPress
*/

import java.awt.AWTException;
import java.awt.EventQueue;
import java.awt.Robot;
import java.awt.event.KeyEvent;

import javax.swing.JFrame;
import javax.swing.ProgressMonitor;
import javax.swing.SwingUtilities;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

public class ProgressMonitorEscapeKeyPress {

static volatile int counter = 0;
static ProgressMonitor monitor;
static int counter = 0;
static TestThread robotThread;
static TestThread testThread;
static JFrame frame;
static CountDownLatch progressLatch;
static Robot robot;


public static void main(String[] args) throws Exception {

createTestUI();

monitor = new ProgressMonitor(frame, "Progress", null, 0, 100);

robotThread = new TestThread();
robotThread.start();

for (counter = 0; counter <= 100; counter += 10) {
Thread.sleep(1000);

EventQueue.invokeAndWait(new Runnable() {
@Override
public void run() {
if (!monitor.isCanceled()) {
monitor.setProgress(counter);
System.out.println("Progress bar is in progress");
}
}
});

if (monitor.isCanceled()) {
break;
try {
progressLatch = new CountDownLatch(20);
createTestUI();
robot = new Robot();
robot.setAutoDelay(50);
robot.setAutoWaitForIdle(true);
testThread = new TestThread();
testThread.start();
Thread.sleep(100);
if (progressLatch.await(15, TimeUnit.SECONDS)) {
System.out.println("Progress monitor completed 20%, lets press Esc...");
robot.keyPress(KeyEvent.VK_ESCAPE);
robot.keyRelease(KeyEvent.VK_ESCAPE);
System.out.println("ESC pressed....");
} else {
System.out.println("Failure : No status available from Progress monitor...");
throw new RuntimeException(
"Can't get the status from Progress monitor even after waiting too long..");
}
}

disposeTestUI();

if (counter >= monitor.getMaximum()) {
throw new RuntimeException("Escape key did not cancel the ProgressMonitor");
if (counter >= monitor.getMaximum()) {
throw new RuntimeException("Escape key did not cancel the ProgressMonitor");
}
System.out.println("Test Passed...");
} finally {
disposeTestUI();
}
}

private static void createTestUI() throws Exception {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
frame = new JFrame("Test");
frame.setSize(300, 300);
frame.setLocationByPlatform(true);
frame.setVisible(true);
}});
}
private static void createTestUI() throws Exception {
SwingUtilities.invokeAndWait(() -> {
frame = new JFrame("Test");
frame.setSize(300, 300);
monitor = new ProgressMonitor(frame, "Progress", "1", 0, 100);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setLocationByPlatform(true);
});
}


private static void disposeTestUI() throws Exception {
Expand All @@ -100,26 +98,25 @@ private static void disposeTestUI() throws Exception {


class TestThread extends Thread {

Robot testRobot;

TestThread() throws AWTException {
super();
testRobot = new Robot();
}

@Override
public void run() {
try {
// Sleep for 5 seconds - so that the ProgressMonitor starts
Thread.sleep(5000);

// Press and release Escape key
testRobot.keyPress(KeyEvent.VK_ESCAPE);
testRobot.delay(20);
testRobot.keyRelease(KeyEvent.VK_ESCAPE);
} catch (InterruptedException ex) {
throw new RuntimeException("Exception in TestThread");
System.out.println("TestThread started.........");
for (ProgressMonitorEscapeKeyPress.counter = 0;
ProgressMonitorEscapeKeyPress.counter <= 100;
ProgressMonitorEscapeKeyPress.counter += 1) {
ProgressMonitorEscapeKeyPress.robot.delay(100);
ProgressMonitor monitor = ProgressMonitorEscapeKeyPress.monitor;
if (!monitor.isCanceled()) {
monitor.setNote("" + ProgressMonitorEscapeKeyPress.counter);
monitor.setProgress(ProgressMonitorEscapeKeyPress.counter);
ProgressMonitorEscapeKeyPress.progressLatch.countDown();
System.out.println("Progress bar is in progress....."
+ ProgressMonitorEscapeKeyPress.counter + "%");
}
if (monitor.isCanceled()) {
System.out.println("$$$$$$$$$$$$$$$ Monitor canceled");
break;
}
}
}
}
Expand Down

5 comments on commit 6bc3971

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

@GoeLin
Copy link
Member

@GoeLin GoeLin commented on 6bc3971 Jan 17, 2025

Choose a reason for hiding this comment

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

/backport jdk21u-dev

@GoeLin
Copy link
Member

@GoeLin GoeLin commented on 6bc3971 Jan 17, 2025

Choose a reason for hiding this comment

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

/backport jdk17u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 6bc3971 Jan 17, 2025

Choose a reason for hiding this comment

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

@GoeLin the backport was successfully created on the branch backport-GoeLin-6bc3971f-master in my personal fork of openjdk/jdk21u-dev. To create a pull request with this backport targeting openjdk/jdk21u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 6bc3971f from the openjdk/jdk repository.

The commit being backported was authored by Manukumar V S on 3 Oct 2024 and was reviewed by Phil Race.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk21u-dev:

$ git fetch https://github.com/openjdk-bots/jdk21u-dev.git backport-GoeLin-6bc3971f-master:backport-GoeLin-6bc3971f-master
$ git checkout backport-GoeLin-6bc3971f-master
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk21u-dev.git backport-GoeLin-6bc3971f-master

@openjdk
Copy link

@openjdk openjdk bot commented on 6bc3971 Jan 17, 2025

Choose a reason for hiding this comment

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

@GoeLin the backport was successfully created on the branch backport-GoeLin-6bc3971f-master in my personal fork of openjdk/jdk17u-dev. To create a pull request with this backport targeting openjdk/jdk17u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 6bc3971f from the openjdk/jdk repository.

The commit being backported was authored by Manukumar V S on 3 Oct 2024 and was reviewed by Phil Race.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk17u-dev:

$ git fetch https://github.com/openjdk-bots/jdk17u-dev.git backport-GoeLin-6bc3971f-master:backport-GoeLin-6bc3971f-master
$ git checkout backport-GoeLin-6bc3971f-master
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk17u-dev.git backport-GoeLin-6bc3971f-master

Please sign in to comment.