Skip to content

Commit ecf21a9

Browse files
author
Alan Bateman
committed
8301767: Convert virtual thread tests to JUnit
Reviewed-by: cstein, lancea, jpai
1 parent 9af2ea2 commit ecf21a9

34 files changed

+1378
-1253
lines changed

test/hotspot/jtreg/serviceability/dcmd/thread/ThreadDumpToFileTest.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 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
@@ -26,7 +26,7 @@
2626
* @bug 8284161 8287008
2727
* @summary Basic test for jcmd Thread.dump_to_file
2828
* @library /test/lib
29-
* @run testng/othervm ThreadDumpToFileTest
29+
* @run junit/othervm ThreadDumpToFileTest
3030
*/
3131

3232
import java.io.IOException;
@@ -37,16 +37,16 @@
3737
import jdk.test.lib.process.OutputAnalyzer;
3838
import jdk.test.lib.threaddump.ThreadDump;
3939

40-
import org.testng.annotations.Test;
41-
import static org.testng.Assert.*;
40+
import org.junit.jupiter.api.Test;
41+
import static org.junit.jupiter.api.Assertions.*;
4242

43-
public class ThreadDumpToFileTest {
43+
class ThreadDumpToFileTest {
4444

4545
/**
4646
* Test thread dump, should be in plain text format.
4747
*/
4848
@Test
49-
public void testThreadDump() throws IOException {
49+
void testThreadDump() throws IOException {
5050
Path file = genThreadDumpPath(".txt");
5151
testPlainThreadDump(file);
5252
}
@@ -55,7 +55,7 @@ public void testThreadDump() throws IOException {
5555
* Test thread dump in plain text format.
5656
*/
5757
@Test
58-
public void testPlainThreadDump() throws IOException {
58+
void testPlainThreadDump() throws IOException {
5959
Path file = genThreadDumpPath(".txt");
6060
testPlainThreadDump(file, "-format=plain");
6161
}
@@ -64,7 +64,7 @@ public void testPlainThreadDump() throws IOException {
6464
* Test thread dump in JSON format.
6565
*/
6666
@Test
67-
public void testJsonThreadDump() throws IOException {
67+
void testJsonThreadDump() throws IOException {
6868
Path file = genThreadDumpPath(".json");
6969
threadDump(file, "-format=json").shouldMatch("Created");
7070

@@ -85,21 +85,21 @@ public void testJsonThreadDump() throws IOException {
8585
* Test that an existing file is not overwritten.
8686
*/
8787
@Test
88-
public void testDoNotOverwriteFile() throws IOException {
88+
void testDoNotOverwriteFile() throws IOException {
8989
Path file = genThreadDumpPath(".txt");
9090
Files.writeString(file, "xxx");
9191

9292
threadDump(file, "").shouldMatch("exists");
9393

9494
// file should not be overridden
95-
assertEquals(Files.readString(file), "xxx");
95+
assertEquals("xxx", Files.readString(file));
9696
}
9797

9898
/**
9999
* Test overwriting an existing file.
100100
*/
101101
@Test
102-
public void testOverwriteFile() throws IOException {
102+
void testOverwriteFile() throws IOException {
103103
Path file = genThreadDumpPath(".txt");
104104
Files.writeString(file, "xxx");
105105
testPlainThreadDump(file, "-overwrite");

test/jdk/com/sun/management/HotSpotDiagnosticMXBean/DumpThreads.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 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
@@ -27,10 +27,10 @@
2727
* @summary Basic test for com.sun.management.HotSpotDiagnosticMXBean.dumpThreads
2828
* @enablePreview
2929
* @library /test/lib
30-
* @run testng/othervm DumpThreads
31-
* @run testng/othervm -Djdk.trackAllThreads DumpThreads
32-
* @run testng/othervm -Djdk.trackAllThreads=true DumpThreads
33-
* @run testng/othervm -Djdk.trackAllThreadds=false DumpThreads
30+
* @run junit/othervm DumpThreads
31+
* @run junit/othervm -Djdk.trackAllThreads DumpThreads
32+
* @run junit/othervm -Djdk.trackAllThreads=true DumpThreads
33+
* @run junit/othervm -Djdk.trackAllThreadds=false DumpThreads
3434
*/
3535

3636
import java.lang.management.ManagementFactory;
@@ -47,10 +47,10 @@
4747
import com.sun.management.HotSpotDiagnosticMXBean.ThreadDumpFormat;
4848
import jdk.test.lib.threaddump.ThreadDump;
4949

50-
import org.testng.annotations.Test;
51-
import static org.testng.Assert.*;
50+
import org.junit.jupiter.api.Test;
51+
import static org.junit.jupiter.api.Assertions.*;
5252

53-
public class DumpThreads {
53+
class DumpThreads {
5454
private static final boolean TRACK_ALL_THREADS;
5555
static {
5656
String s = System.getProperty("jdk.trackAllThreads");
@@ -61,7 +61,7 @@ public class DumpThreads {
6161
* Thread dump in plain text format.
6262
*/
6363
@Test
64-
public void testPlainText() throws Exception {
64+
void testPlainText() throws Exception {
6565
var mbean = ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class);
6666
Path file = genOutputPath("txt");
6767
try (var executor = Executors.newVirtualThreadPerTaskExecutor()) {
@@ -98,7 +98,7 @@ public void testPlainText() throws Exception {
9898
* Thread dump in JSON format.
9999
*/
100100
@Test
101-
public void testJson() throws Exception {
101+
void testJson() throws Exception {
102102
var mbean = ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class);
103103
Path file = genOutputPath("json");
104104
try (var executor = Executors.newVirtualThreadPerTaskExecutor()) {
@@ -118,7 +118,7 @@ public void testJson() throws Exception {
118118
ZonedDateTime.parse(threadDump.time());
119119

120120
// test threadDump/runtimeVersion
121-
assertEquals(threadDump.runtimeVersion(), Runtime.version().toString());
121+
assertEquals(Runtime.version().toString(), threadDump.runtimeVersion());
122122

123123
// test root container
124124
var rootContainer = threadDump.rootThreadContainer();
@@ -150,7 +150,7 @@ public void testJson() throws Exception {
150150
* Test that dumpThreads throws if the output file already exists.
151151
*/
152152
@Test
153-
public void testFileAlreadyExsists() throws Exception {
153+
void testFileAlreadyExsists() throws Exception {
154154
var mbean = ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class);
155155
String file = Files.createFile(genOutputPath("txt")).toString();
156156
assertThrows(FileAlreadyExistsException.class,
@@ -163,7 +163,7 @@ public void testFileAlreadyExsists() throws Exception {
163163
* Test that dumpThreads throws if the file path is relative.
164164
*/
165165
@Test
166-
public void testRelativePath() throws Exception {
166+
void testRelativePath() throws Exception {
167167
var mbean = ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class);
168168
assertThrows(IllegalArgumentException.class,
169169
() -> mbean.dumpThreads("threads.txt", ThreadDumpFormat.TEXT_PLAIN));
@@ -175,7 +175,7 @@ public void testRelativePath() throws Exception {
175175
* Test that dumpThreads throws with null parameters.
176176
*/
177177
@Test
178-
public void testNull() throws Exception {
178+
void testNull() throws Exception {
179179
var mbean = ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class);
180180
assertThrows(NullPointerException.class,
181181
() -> mbean.dumpThreads(null, ThreadDumpFormat.TEXT_PLAIN));

0 commit comments

Comments
 (0)