improve test. Assert new ISO 8601 format

This commit is contained in:
Ivan Bereziuk 2026-01-21 17:22:48 +01:00
parent 4fca769a67
commit c702901d78

View File

@ -26,31 +26,30 @@ import java.time.format.DateTimeFormatter;
import java.time.Duration;
import jdk.test.lib.Asserts;
import jdk.test.lib.dcmd.FileJcmdExecutor;
import jdk.test.lib.dcmd.PidJcmdExecutor;
import jdk.test.lib.dcmd.JcmdExecutor;
import jdk.test.lib.process.OutputAnalyzer;
/*
* @test
* @summary test jcmd generic flag "-T" to make sure dignostic coommand is timestamped
*
* @library /test/lib
*
* @run main/othervm TestJcmdTimestamp
*/
public class TestJcmdTimestamp {
public static void main(String[] args) throws Exception {
TestJcmdTimestamp("VM.version", true /* -T */, true /* expectTimestamp */);
TestJcmdTimestamp("VM.version", false /* -T */, false /* expectTimestamp */);
// "Thread.print" should be unconditionally timestamped
TestJcmdTimestamp("Thread.print", true /* -T */, true /* expectTimestamp */);
TestJcmdTimestamp("Thread.print", false /* -T */, true /* expectTimestamp */);
TestJcmdTimestamp(new PidJcmdExecutor(), "-T VM.version", true /* expectTimestamp */);
TestJcmdTimestamp(new PidJcmdExecutor(), "VM.version", false /* expectTimestamp */);
TestJcmdTimestamp(new FileJcmdExecutor(), "-T VM.version", true /* expectTimestamp */);
TestJcmdTimestamp(new FileJcmdExecutor(), "VM.version", false /* expectTimestamp */);
}
// timestamp should be there and it should be recent
public static void assertTimestamp(final String line) throws java.time.format.DateTimeParseException {
final String timePattern = "yyyy-MM-dd HH:mm:ss";
// ISO 8601. Example "2026-01-21T16:58:49.518+0100"
final String timePattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(timePattern);
final LocalDateTime parsedDateTime = LocalDateTime.parse(line, formatter);
@ -59,11 +58,11 @@ public class TestJcmdTimestamp {
}
private static void TestJcmdTimestamp(final String command, boolean flaged, boolean expectTimestamp) throws Exception {
final OutputAnalyzer output = flaged
? JcmdBase.jcmd(new String[] {"-T", command})
: JcmdBase.jcmd(new String[] {command});
private static void TestJcmdTimestamp(final JcmdExecutor executor,
final String command,
final boolean expectTimestamp) throws Exception {
OutputAnalyzer output = executor.execute(command);
output.shouldHaveExitValue(0);
final String secondLine = output.getOutput().split("\\r?\\n")[1];