From 57adf64ab4e50fd1739eb8ed14331d49f943b5e5 Mon Sep 17 00:00:00 2001 From: Kevin Walls Date: Mon, 16 Dec 2024 17:18:20 +0000 Subject: [PATCH] 8346261: Cleanup in JDP tests Reviewed-by: cjplummer --- .../jdk/sun/management/jdp/ClientConnection.java | 6 +++--- test/jdk/sun/management/jdp/DynamicLauncher.java | 8 ++------ test/jdk/sun/management/jdp/JdpDefaultsTest.java | 4 ++-- .../jdp/JdpJmxRemoteDynamicPortTest.java | 4 ++-- .../jdp/JdpJmxRemoteDynamicPortTestCase.java | 4 ++-- test/jdk/sun/management/jdp/JdpOffTest.java | 4 ++-- test/jdk/sun/management/jdp/JdpOffTestCase.java | 6 +++--- test/jdk/sun/management/jdp/JdpOnTestCase.java | 6 +++--- .../management/jdp/JdpSpecificAddressTest.java | 4 ++-- test/jdk/sun/management/jdp/JdpTestCase.java | 16 +++++++++------- 10 files changed, 30 insertions(+), 32 deletions(-) diff --git a/test/jdk/sun/management/jdp/ClientConnection.java b/test/jdk/sun/management/jdp/ClientConnection.java index 9c74517e49a..77d133106be 100644 --- a/test/jdk/sun/management/jdp/ClientConnection.java +++ b/test/jdk/sun/management/jdp/ClientConnection.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2024, 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 @@ -53,10 +53,10 @@ public class ClientConnection { } - public MulticastSocket connectWithTimeout(int msTimeOut) throws IOException { + public MulticastSocket connectWithTimeout(int msTimeout) throws IOException { MulticastSocket socket = new MulticastSocket(port); socket.joinGroup(address); - socket.setSoTimeout(msTimeOut); + socket.setSoTimeout(msTimeout); return socket; } } diff --git a/test/jdk/sun/management/jdp/DynamicLauncher.java b/test/jdk/sun/management/jdp/DynamicLauncher.java index b79672211b1..8f29e774893 100644 --- a/test/jdk/sun/management/jdp/DynamicLauncher.java +++ b/test/jdk/sun/management/jdp/DynamicLauncher.java @@ -37,7 +37,7 @@ import java.util.UUID; */ public abstract class DynamicLauncher { - private static final int MAX_RETRY_ATTEMPTS = 10; + private static final int MAX_PORT_RETRY_ATTEMPTS = 10; final String jdpName = UUID.randomUUID().toString(); OutputAnalyzer output; @@ -54,7 +54,7 @@ public abstract class DynamicLauncher { try { output.shouldNotContain("Port already in use"); } catch (RuntimeException e) { - if (retries < MAX_RETRY_ATTEMPTS) { + if (retries < MAX_PORT_RETRY_ATTEMPTS) { retries++; tryAgain = true; } @@ -77,8 +77,4 @@ public abstract class DynamicLauncher { } protected abstract String[] options(); - - protected OutputAnalyzer getProcessOutpoutAnalyzer() { - return output; - } } diff --git a/test/jdk/sun/management/jdp/JdpDefaultsTest.java b/test/jdk/sun/management/jdp/JdpDefaultsTest.java index 1cf76aa58b7..7c17efe0fd0 100644 --- a/test/jdk/sun/management/jdp/JdpDefaultsTest.java +++ b/test/jdk/sun/management/jdp/JdpDefaultsTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2024, 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 @@ -58,7 +58,7 @@ public class JdpDefaultsTest extends DynamicLauncher { "-Dcom.sun.management.jmxremote.autodiscovery=true", "-Dcom.sun.management.jdp.pause=1", "-Dcom.sun.management.jdp.name=" + jdpName, - "-Djava.util.logging.SimpleFormatter.format='%1$tF %1$tT %4$-7s %5$s %n'", + "-Djava.util.logging.SimpleFormatter.format=%1$tF %1$tT %4$-7s %5$s %n", testName }; return options; diff --git a/test/jdk/sun/management/jdp/JdpJmxRemoteDynamicPortTest.java b/test/jdk/sun/management/jdp/JdpJmxRemoteDynamicPortTest.java index edf65a79b19..55558a5d88e 100644 --- a/test/jdk/sun/management/jdp/JdpJmxRemoteDynamicPortTest.java +++ b/test/jdk/sun/management/jdp/JdpJmxRemoteDynamicPortTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2018, 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. * * This code is free software; you can redistribute it and/or modify it @@ -52,7 +52,7 @@ public class JdpJmxRemoteDynamicPortTest extends DynamicLauncher { "-Dcom.sun.management.jmxremote.autodiscovery=true", "-Dcom.sun.management.jdp.pause=1", "-Dcom.sun.management.jdp.name=" + jdpName, - "-Djava.util.logging.SimpleFormatter.format='%1$tF %1$tT %4$-7s %5$s %n'", + "-Djava.util.logging.SimpleFormatter.format=%1$tF %1$tT %4$-7s %5$s %n", testName }; return options; diff --git a/test/jdk/sun/management/jdp/JdpJmxRemoteDynamicPortTestCase.java b/test/jdk/sun/management/jdp/JdpJmxRemoteDynamicPortTestCase.java index bb5485ed073..fbc8087a7a5 100644 --- a/test/jdk/sun/management/jdp/JdpJmxRemoteDynamicPortTestCase.java +++ b/test/jdk/sun/management/jdp/JdpJmxRemoteDynamicPortTestCase.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 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. * * This code is free software; you can redistribute it and/or modify it @@ -64,7 +64,7 @@ public class JdpJmxRemoteDynamicPortTestCase extends JdpTestCase { * It is set to wait for 10 times the defined pause between Jdp packet. See JdpOnTestCase.TIME_OUT_FACTOR. */ @Override - protected void onSocketTimeOut(SocketTimeoutException e) throws Exception { + protected void onSocketTimeout(SocketTimeoutException e) throws Exception { String message = "Timed out waiting for JDP packet. Should arrive within " + connection.pauseInSeconds + " seconds, but waited for " + timeOut + " seconds."; diff --git a/test/jdk/sun/management/jdp/JdpOffTest.java b/test/jdk/sun/management/jdp/JdpOffTest.java index c5f9af4984d..b52222562fe 100644 --- a/test/jdk/sun/management/jdp/JdpOffTest.java +++ b/test/jdk/sun/management/jdp/JdpOffTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2024, 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 @@ -60,7 +60,7 @@ public class JdpOffTest extends DynamicLauncher { "-Dcom.sun.management.jmxremote.autodiscovery=false", "-Dcom.sun.management.jdp.pause=1", "-Dcom.sun.management.jdp.name=" + jdpName, - "-Djava.util.logging.SimpleFormatter.format='%1$tF %1$tT %4$-7s %5$s %n'", + "-Djava.util.logging.SimpleFormatter.format=%1$tF %1$tT %4$-7s %5$s %n", testName }; return options; diff --git a/test/jdk/sun/management/jdp/JdpOffTestCase.java b/test/jdk/sun/management/jdp/JdpOffTestCase.java index 54bb2bd3c31..6ddeebb8d00 100644 --- a/test/jdk/sun/management/jdp/JdpOffTestCase.java +++ b/test/jdk/sun/management/jdp/JdpOffTestCase.java @@ -49,8 +49,8 @@ public class JdpOffTestCase extends JdpTestCase { * The socket has not received anything, and this is the expected behavior. */ @Override - protected void onSocketTimeOut(SocketTimeoutException e) throws Exception { - log.fine("No packages received. Test passed!"); + protected void onSocketTimeout(SocketTimeoutException e) throws Exception { + log.fine("No packets received. Test passed!"); testPassed = true; } @@ -77,7 +77,7 @@ public class JdpOffTestCase extends JdpTestCase { /** - * The test should stop after the socket has timed out. See onSocketTimeOut {@link}. + * The test should stop after the socket has timed out. See onSocketTimeout {@link}. */ @Override protected boolean shouldContinue() { diff --git a/test/jdk/sun/management/jdp/JdpOnTestCase.java b/test/jdk/sun/management/jdp/JdpOnTestCase.java index c6d2c30a162..00856bb4f5d 100644 --- a/test/jdk/sun/management/jdp/JdpOnTestCase.java +++ b/test/jdk/sun/management/jdp/JdpOnTestCase.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2024, 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 @@ -64,10 +64,10 @@ public class JdpOnTestCase extends JdpTestCase { /** * The socket should not timeout. - * It is set to wait for 10 times the defined pause between Jdp packet. See JdpOnTestCase.TIME_OUT_FACTOR. + * It is set to wait for a multiple of the defined pause between Jdp packets. See JdpTestCase.TIME_OUT_FACTOR. */ @Override - protected void onSocketTimeOut(SocketTimeoutException e) throws Exception { + protected void onSocketTimeout(SocketTimeoutException e) throws Exception { String message = "Timed out waiting for JDP packet. Should arrive within " + connection.pauseInSeconds + " seconds, but waited for " + timeOut + " seconds."; diff --git a/test/jdk/sun/management/jdp/JdpSpecificAddressTest.java b/test/jdk/sun/management/jdp/JdpSpecificAddressTest.java index 1bc0cd01dcc..5134321a5c2 100644 --- a/test/jdk/sun/management/jdp/JdpSpecificAddressTest.java +++ b/test/jdk/sun/management/jdp/JdpSpecificAddressTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2024, 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 @@ -61,7 +61,7 @@ public class JdpSpecificAddressTest extends DynamicLauncher { "-Dcom.sun.management.jdp.name=" + jdpName, "-Dcom.sun.management.jdp.address=224.0.1.2", "-Dcom.sun.management.jdp.port=1234", - "-Djava.util.logging.SimpleFormatter.format='%1$tF %1$tT %4$-7s %5$s %n'", + "-Djava.util.logging.SimpleFormatter.format=%1$tF %1$tT %4$-7s %5$s %n", testName }; return options; diff --git a/test/jdk/sun/management/jdp/JdpTestCase.java b/test/jdk/sun/management/jdp/JdpTestCase.java index f9178b5f07c..71277e1d2ad 100644 --- a/test/jdk/sun/management/jdp/JdpTestCase.java +++ b/test/jdk/sun/management/jdp/JdpTestCase.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2024, 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 @@ -40,10 +40,12 @@ import java.util.logging.Level; import java.util.logging.Logger; public abstract class JdpTestCase { + + private static final int MAGIC = 0xC0FFEE42; // Jdp magic number. + private static final int BUFFER_LENGTH = 64 * 1024; // max UDP size, except for IPv6 jumbograms. + private static final int TIME_OUT_FACTOR = 10; // Socket times out after a multiple of the jdp pause. + final Logger log = Logger.getLogger("sun.management.jdp"); - final int MAGIC = 0xC0FFEE42; // Jdp magic number. - private static final int BUFFER_LENGTH = 64 * 1024; // max UDP size, except for IPv6 jumbograms. - private final int TIME_OUT_FACTOR = 10; // Socket times out after 10 times the jdp pause. protected int timeOut; private long startTime; protected ClientConnection connection; @@ -74,7 +76,7 @@ public abstract class JdpTestCase { socket.receive(datagram); onReceived(extractUDPpayload(datagram)); } catch (SocketTimeoutException e) { - onSocketTimeOut(e); + onSocketTimeout(e); } if (!shouldContinue()) { @@ -117,7 +119,7 @@ public abstract class JdpTestCase { /** * This method is executed when the socket has not received any packet for timeOut seconds. */ - abstract protected void onSocketTimeOut(SocketTimeoutException e) throws Exception; + abstract protected void onSocketTimeout(SocketTimeoutException e) throws Exception; /** * This method is executed after a correct Jdp packet has been received. @@ -156,7 +158,7 @@ public abstract class JdpTestCase { * The test should stop if it has been 12 times the jdp.pause. * jdp.pause is how many seconds in between packets. *

- * This timeout (12 times)is slightly longer than the socket timeout (10 times) on purpose. + * This timeout (12 times) is slightly longer than the socket timeout (10 times) on purpose. * In the off test case, the socket should time out first. * * @return