8332551: Test vmTestbase/nsk/monitoring/MemoryNotificationInfo/from/from001/TestDescription.java timed out

Reviewed-by: sspitsyn, lmesnik
This commit is contained in:
Kevin Walls 2024-07-22 16:40:34 +00:00
parent c740e1e3b0
commit 7ea7730564
2 changed files with 64 additions and 32 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2004, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -29,6 +29,7 @@ import javax.management.openmbean.*;
import java.util.List; import java.util.List;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.SynchronousQueue; import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.TimeUnit;
import nsk.share.*; import nsk.share.*;
import nsk.share.gc.Algorithms; import nsk.share.gc.Algorithms;
import nsk.share.gc.Memory; import nsk.share.gc.Memory;
@ -39,6 +40,7 @@ import nsk.share.test.Stresser;
public class from001 { public class from001 {
private static boolean testFailed = false; private static boolean testFailed = false;
private static final int MAX_TRIES = 6; // limit attempts to receive Notification data
public static void main(String[] args) { public static void main(String[] args) {
@ -62,8 +64,8 @@ public class from001 {
log.display("null CompositeData check passed."); log.display("null CompositeData check passed.");
// 2. Check CompositeData that doest not represnt // 2. Check CompositeData that does not represent MemoryNotificationInfo
// MemoryNotificationInfo - IllegalArgumentException must be thrown // throws IllegalArgumentException
ObjectName mbeanObjectName = null; ObjectName mbeanObjectName = null;
CompositeData cdata = null; CompositeData cdata = null;
@ -85,12 +87,13 @@ public class from001 {
testFailed = true; testFailed = true;
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
// Expected: CompositeData doest not represnt MemoryNotificationInfo // Expected: CompositeData does not represent MemoryNotificationInfo
} }
log.display("check for CompositeData doest not represnt MemoryNotificationInfo passed."); log.display("check that CompositeData does not represent MemoryNotificationInfo passed.");
// 3. Check correct CompositeData // 3. Check correct CompositeData usage:
// First try to provoke a Notification on a MemoryPool.
Object poolObject = null; Object poolObject = null;
try { try {
mbeanObjectName = new ObjectName(ManagementFactory.MEMORY_MXBEAN_NAME); mbeanObjectName = new ObjectName(ManagementFactory.MEMORY_MXBEAN_NAME);
@ -123,7 +126,11 @@ public class from001 {
throw new TestFailure("TEST FAILED. See log."); throw new TestFailure("TEST FAILED. See log.");
} }
// eat memory just to emmit notification if (poolObject == null) {
throw new TestFailure("No memory pool found to test.");
}
// eat memory just to emit notification
Stresser stresser = new Stresser(args) { Stresser stresser = new Stresser(args) {
@Override @Override
@ -133,18 +140,35 @@ public class from001 {
} }
}; };
stresser.start(0);// we use timeout, not iterations stresser.start(0);// we use timeout, not iterations
GarbageUtils.eatMemory(stresser); int oomCount = GarbageUtils.eatMemory(stresser);
log.display("eatMemory returns OOM count: " + oomCount);
boolean messageNotRecieved = true; // Check for the message. Poll on queue to avoid waiting forver on failure.
while(messageNotRecieved) { // Notification is known to fail, very rarely, with -Xcomp where the allocations
// do not affect the monitored pool. Possibly a timing issue, where the "eatMemory"
// is done before Notification/threshold processing happens.
// The Notification is quite immediate, other than that problem.
boolean messageReceived = false;
int tries = 0;
while (!messageReceived && ++tries < MAX_TRIES) {
try { try {
from001Listener.queue.take(); Object r = from001Listener.queue.poll(10000, TimeUnit.MILLISECONDS);
messageNotRecieved = false; if (r == null) {
log.display("poll for Notification data returns null...");
continue;
} else {
messageReceived = true;
break;
}
} catch (InterruptedException e) { } catch (InterruptedException e) {
messageNotRecieved = true; // ignored, continue
} }
} }
// If we got a Notification, test that the CompositeData can create a MemoryNotificationInfo
if (!messageReceived) {
throw new TestFailure("No Notification received.");
}
result = MemoryNotificationInfo.from(from001Listener.data.get()); result = MemoryNotificationInfo.from(from001Listener.data.get());
try { try {
ObjectName poolObjectName = new ObjectName(monitor.getName(poolObject)); ObjectName poolObjectName = new ObjectName(monitor.getName(poolObject));
@ -167,7 +191,6 @@ public class from001 {
e.printStackTrace(log.getOutStream()); e.printStackTrace(log.getOutStream());
testFailed = true; testFailed = true;
} }
if (testFailed) { if (testFailed) {
throw new TestFailure("TEST FAILED. See log."); throw new TestFailure("TEST FAILED. See log.");
} }
@ -183,9 +206,13 @@ class from001Listener implements NotificationListener {
static SynchronousQueue<Object> queue = new SynchronousQueue<Object>(); static SynchronousQueue<Object> queue = new SynchronousQueue<Object>();
public void handleNotification(Notification notification, Object handback) { public void handleNotification(Notification notification, Object handback) {
if (data.get() != null) if (data.get() != null) {
System.out.println("handleNotification: ignoring");
return; return;
data.set((CompositeData) notification.getUserData()); }
System.out.println("handleNotification: getting data");
CompositeData d = (CompositeData) notification.getUserData();
data.set(d);
boolean messageNotSent = true; boolean messageNotSent = true;
while(messageNotSent){ while(messageNotSent){
@ -193,7 +220,7 @@ class from001Listener implements NotificationListener {
queue.put(new Object()); queue.put(new Object());
messageNotSent = false; messageNotSent = false;
} catch(InterruptedException e) { } catch(InterruptedException e) {
messageNotSent = true; // ignore, retry
} }
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -34,15 +34,20 @@
* MemoryNotificationInfo.from(CompositeData) * MemoryNotificationInfo.from(CompositeData)
* returns correct results: * returns correct results:
* 1. null, if CompositeData is null; * 1. null, if CompositeData is null;
* 2. trows IllegalArgumentException, if CompositeData doest not represnt * 2. throws IllegalArgumentException, if CompositeData does not represent
* MemoryNotificationInfo; * MemoryNotificationInfo;
* 3. correct MemoryNotificationInfo object, if CompositeData is correst (i.e * 3. correct MemoryNotificationInfo object, if CompositeData is correct, i.e
* all attributes of the CompositeData must have correct values: pool name, * all attributes of the CompositeData must have correct values: pool name,
* count; init, used, committed, max (from MemoryUsage). * count; init, used, committed, max (from MemoryUsage).
* COMMENT * COMMENT
* Updated according to: * Updated according to:
* 5024531 Fix MBeans design flaw that restricts to use JMX CompositeData * 5024531 Fix MBeans design flaw that restricts to use JMX CompositeData
* *
* Avoid running with -Xcomp due to rare failure where the MemoryPool does not
* increase in usage and send Notification. Likely the timing changes so "eatMemory"
* completes before Notification/threshold processing.
*
* @requires vm.compMode != "Xcomp"
* @library /vmTestbase * @library /vmTestbase
* /test/lib * /test/lib
* @run main/othervm * @run main/othervm