Skip to content

Commit 8275262

Browse files
kevinjwallspull[bot]
authored andcommitted
8319238: JMX ThreadPoolAccTest.java is too verbose and should fail before timeout
Reviewed-by: sspitsyn
1 parent a3a6076 commit 8275262

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

test/jdk/javax/management/monitor/ThreadPoolAccTest.java

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -49,6 +49,8 @@
4949

5050
public class ThreadPoolAccTest {
5151

52+
public static final int MAX_TRIES = 30;
53+
5254
// MBean class
5355
public static class ObservedObject implements ObservedObjectMBean {
5456
public volatile String principal;
@@ -137,8 +139,18 @@ public Void run() {
137139
Subject.doAs(subject, action);
138140
}
139141

140-
while(!testPrincipals(monitored, monitorNames, monitor, principals));
141-
142+
sleep(500); // wait for getX method to be called, which calls setPrincipal
143+
boolean ok = false;
144+
for (int i = 0; i < MAX_TRIES; i++) {
145+
ok = testPrincipals(monitored, monitorNames, monitor, principals);
146+
if (ok) {
147+
break;
148+
}
149+
sleep(1000);
150+
}
151+
if (!ok) {
152+
throw new Exception("Failed: testPrincipals fails repeatedly.");
153+
}
142154
} finally {
143155
for (int i = 0; i < 6; i++)
144156
if (monitor[i] != null)
@@ -151,6 +163,9 @@ private static boolean testPrincipals(ObservedObject[] monitored, ObjectName[] m
151163
for (int i = 0; i < 6; i++) {
152164
String principal = monitored[i].principal;
153165
String expected = principals[i / 3];
166+
167+
echo("testPrincipals: monitored: " + monitored[i] + " principal: " + principal + " expected: " + expected);
168+
154169
if (principal == null) {
155170
echo("Task not submitted " + new Date() + ". RETRY");
156171
return false;
@@ -172,4 +187,12 @@ private static boolean testPrincipals(ObservedObject[] monitored, ObjectName[] m
172187
private static void echo(String message) {
173188
System.out.println(message);
174189
}
190+
191+
public static void sleep(int ms) {
192+
try {
193+
Thread.currentThread().sleep(ms);
194+
} catch (InterruptedException ie) {
195+
// ignore
196+
}
197+
}
175198
}

0 commit comments

Comments
 (0)