提交 64e12c67 编写于 作者: D Denghui Dong 提交者: D-D-H

[Backport] 8234703: JFR TestOutOfProcessMigration.java should clean up files

Summary:

Test Plan: jdk/jfr

Reviewed-by: yuleil

Issue: https://github.com/alibaba/dragonwell8/issues/112
上级 bc43f3fe
......@@ -44,7 +44,7 @@ public class TestJVMCrash {
public static void main(String... args) throws Exception {
int id = 1;
while (true) {
TestProcess process = new TestProcess("crash-application-" + id++);
try (TestProcess process = new TestProcess("crash-application-" + id++)) {
AtomicInteger eventCounter = new AtomicInteger();
try (EventStream es = EventStream.openRepository(process.getRepository())) {
// Start from first event in repository
......@@ -64,4 +64,5 @@ public class TestJVMCrash {
}
}
}
}
}
......@@ -41,7 +41,7 @@ import jdk.jfr.consumer.EventStream;
public class TestJVMExit {
public static void main(String... args) throws Exception {
TestProcess process = new TestProcess("exit-application");
try (TestProcess process = new TestProcess("exit-application")) {
AtomicInteger eventCounter = new AtomicInteger();
try (EventStream es = EventStream.openRepository(process.getRepository())) {
// Start from first event in repository
......@@ -54,4 +54,5 @@ public class TestJVMExit {
es.start();
}
}
}
}
......@@ -33,7 +33,6 @@ import java.util.concurrent.atomic.AtomicInteger;
import jdk.jfr.consumer.EventStream;
import jdk.test.lib.dcmd.CommandExecutor;
import jdk.test.lib.dcmd.PidJcmdExecutor;
import jdk.test.lib.process.OutputAnalyzer;
/**
* @test
......@@ -46,10 +45,9 @@ import jdk.test.lib.process.OutputAnalyzer;
*/
public class TestOutOfProcessMigration {
public static void main(String... args) throws Exception {
Path newRepo = Paths.get("new-repository").toAbsolutePath();
TestProcess process = new TestProcess("application");
try (TestProcess process = new TestProcess("application")) {
AtomicInteger eventCounter = new AtomicInteger();
Path newRepo = Paths.get("new-repository").toAbsolutePath();
try (EventStream es = EventStream.openRepository(process.getRepository())) {
// Start from first event in repository
es.setStartTime(Instant.EPOCH);
......@@ -58,11 +56,14 @@ public class TestOutOfProcessMigration {
System.out.println("Changing repository to " + newRepo + " ...");
CommandExecutor executor = new PidJcmdExecutor(String.valueOf(process.pid()));
// This should close stream
OutputAnalyzer oa = executor.execute("JFR.configure repositorypath=" + newRepo);
System.out.println(oa);
executor.execute("JFR.configure repositorypath=" + newRepo);
}
});
es.start();
process.exit();
// Wait for process to die, so files are cleaned up
process.awaitDeath();
}
}
}
}
......@@ -33,6 +33,7 @@ import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Properties;
......@@ -49,7 +50,7 @@ import com.sun.tools.attach.VirtualMachine;
* Requires jdk.attach module.
*
*/
public final class TestProcess {
public final class TestProcess implements AutoCloseable {
private static class TestEvent extends Event {
}
......@@ -173,4 +174,21 @@ public final class TestProcess {
public long pid() {
return pid;
}
@Override
public void close() throws Exception {
try {
if (path != null) {
Files.delete(path);
}
} catch(NoSuchFileException nfe) {
// ignore
}
}
public void awaitDeath() {
while (process.isAlive()) {
takeNap();
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册