mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-14 18:03:44 +00:00
8242239: [Graal] javax/management/generified/GenericTest.java fails: FAILED: queryMBeans sets same
Reviewed-by: cjplummer, sspitsyn
This commit is contained in:
parent
d84e4f1fd6
commit
c2d3ff3bf8
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2004, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2004, 2020, 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
|
||||
@ -35,6 +35,7 @@
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.reflect.*;
|
||||
import java.util.*;
|
||||
import java.util.stream.Stream;
|
||||
import javax.management.*;
|
||||
import javax.management.openmbean.*;
|
||||
import javax.management.relation.*;
|
||||
@ -70,33 +71,52 @@ public class GenericTest {
|
||||
check("ArrayList<MBeanServer> findMBeanServer", mbsList1.size() == 1);
|
||||
check("ArrayList findMBeanServer", mbsList1.equals(mbsList2));
|
||||
|
||||
Set<ObjectName> names1 =
|
||||
checked(mbs.queryNames(null, null), ObjectName.class);
|
||||
Set names2 = mbs.queryNames(null, null);
|
||||
Set<ObjectName> names3 =
|
||||
checked(((MBeanServerConnection) mbs).queryNames(null, null),
|
||||
ObjectName.class);
|
||||
check("Set<ObjectName> MBeanServer.queryNames", names1.size() >= 1);
|
||||
check("Set MBeanServer.queryNames", names2.size() >= 1);
|
||||
check("Set<ObjectName> MBeanServerConnection.queryNames",
|
||||
names3.size() >= 1);
|
||||
check("queryNames sets same",
|
||||
names1.equals(names2) && names2.equals(names3));
|
||||
|
||||
Set<ObjectInstance> mbeans1 =
|
||||
checked(mbs.queryMBeans(null, null), ObjectInstance.class);
|
||||
Set mbeans2 = mbs.queryMBeans(null, null);
|
||||
Set<ObjectInstance> mbeans3 =
|
||||
checked(((MBeanServerConnection) mbs).queryMBeans(null, null),
|
||||
ObjectInstance.class);
|
||||
check("Set<ObjectInstsance> MBeanServer.queryMBeans",
|
||||
mbeans1.size() >= 1);
|
||||
check("Set MBeanServer.queryMBeans", mbeans2.size() >= 1);
|
||||
check("Set<ObjectInstsance> MBeanServerConnection.queryMBeans",
|
||||
mbeans3.size() >= 1);
|
||||
check("queryMBeans sets same",
|
||||
mbeans1.equals(mbeans2) && mbeans2.equals(mbeans3));
|
||||
boolean isSecondAttempt = false;
|
||||
Set<ObjectName> names1 = null;
|
||||
while (true) {
|
||||
names1 = checked(mbs.queryNames(null, null), ObjectName.class);
|
||||
Set names2 = mbs.queryNames(null, null);
|
||||
Set<ObjectName> names3 =
|
||||
checked(((MBeanServerConnection) mbs).queryNames(null, null),
|
||||
ObjectName.class);
|
||||
// If new MBean (e.g. Graal MBean) is registered while the test is running, names1,
|
||||
// names2, and names3 will have different sizes. Repeat the test in this case.
|
||||
if (sameSize(names1, names2, names3) || isSecondAttempt) {
|
||||
check("Set<ObjectName> MBeanServer.queryNames", names1.size() >= 1);
|
||||
check("Set MBeanServer.queryNames", names2.size() >= 1);
|
||||
check("Set<ObjectName> MBeanServerConnection.queryNames",
|
||||
names3.size() >= 1);
|
||||
check("queryNames sets same",
|
||||
names1.equals(names2) && names2.equals(names3));
|
||||
break;
|
||||
}
|
||||
isSecondAttempt = true;
|
||||
System.out.println("queryNames sets have different size, retrying...");
|
||||
}
|
||||
|
||||
isSecondAttempt = false;
|
||||
while (true) {
|
||||
Set<ObjectInstance> mbeans1 =
|
||||
checked(mbs.queryMBeans(null, null), ObjectInstance.class);
|
||||
Set mbeans2 = mbs.queryMBeans(null, null);
|
||||
Set<ObjectInstance> mbeans3 =
|
||||
checked(((MBeanServerConnection) mbs).queryMBeans(null, null),
|
||||
ObjectInstance.class);
|
||||
// If new MBean (e.g. Graal MBean) is registered while the test is running, mbeans1,
|
||||
// mbeans2, and mbeans3 will have different sizes. Repeat the test in this case.
|
||||
if (sameSize(mbeans1, mbeans2, mbeans3) || isSecondAttempt) {
|
||||
check("Set<ObjectInstance> MBeanServer.queryMBeans",
|
||||
mbeans1.size() >= 1);
|
||||
check("Set MBeanServer.queryMBeans", mbeans2.size() >= 1);
|
||||
check("Set<ObjectInstance> MBeanServerConnection.queryMBeans",
|
||||
mbeans3.size() >= 1);
|
||||
check("queryMBeans sets same",
|
||||
mbeans1.equals(mbeans2) && mbeans2.equals(mbeans3));
|
||||
break;
|
||||
}
|
||||
isSecondAttempt = true;
|
||||
System.out.println("queryMBeans sets have different size, retrying...");
|
||||
}
|
||||
|
||||
AttributeChangeNotificationFilter acnf =
|
||||
new AttributeChangeNotificationFilter();
|
||||
@ -482,4 +502,8 @@ public class GenericTest {
|
||||
failures++;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean sameSize(Set ... sets) {
|
||||
return Stream.of(sets).map(s -> s.size()).distinct().count() == 1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2020, 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
|
||||
@ -89,21 +89,36 @@ public class CustomQueryTest {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
|
||||
mbs.registerMBean(new Count(), countName);
|
||||
int mbeanCount = mbs.getMBeanCount();
|
||||
QueryExp query = new IncrQuery();
|
||||
Set<ObjectName> names = mbs.queryNames(null, query);
|
||||
assertEquals(mbeanCount, names.size());
|
||||
assertEquals(mbeanCount, mbs.getAttribute(countName, "Count"));
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oout = new ObjectOutputStream(bout);
|
||||
oout.writeObject(query);
|
||||
oout.close();
|
||||
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
|
||||
ObjectInputStream oin = new ObjectInputStream(bin);
|
||||
query = (QueryExp) oin.readObject();
|
||||
names = mbs.queryNames(null, query);
|
||||
assertEquals(mbeanCount * 2, mbs.getAttribute(countName, "Count"));
|
||||
boolean isSecondAttempt = false;
|
||||
// The test may fail if some new MBean is registered while the test
|
||||
// is running (e.g. Graal MBean). In this case just retry the test.
|
||||
while (true) {
|
||||
mbs.registerMBean(new Count(), countName);
|
||||
int mbeanCount = mbs.getMBeanCount();
|
||||
QueryExp query = new IncrQuery();
|
||||
Set<ObjectName> names = mbs.queryNames(null, query);
|
||||
assertEquals(mbeanCount, names.size());
|
||||
assertEquals(mbeanCount, mbs.getAttribute(countName, "Count"));
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oout = new ObjectOutputStream(bout);
|
||||
oout.writeObject(query);
|
||||
oout.close();
|
||||
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
|
||||
ObjectInputStream oin = new ObjectInputStream(bin);
|
||||
query = (QueryExp) oin.readObject();
|
||||
names = mbs.queryNames(null, query);
|
||||
int counterCount = (int)mbs.getAttribute(countName, "Count");
|
||||
if (mbeanCount * 2 == counterCount) {
|
||||
break;
|
||||
}
|
||||
if (isSecondAttempt) {
|
||||
assertEquals(mbeanCount * 2, counterCount);
|
||||
break;
|
||||
}
|
||||
isSecondAttempt = true;
|
||||
System.out.println("New MBean was registered. Retrying...");
|
||||
mbs.unregisterMBean(countName);
|
||||
}
|
||||
}
|
||||
|
||||
private static void assertEquals(Object expected, Object actual)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user