8201331: Better test cleanup for jdk/jfr/api/consumer/TestRecordingFile.java
Reviewed-by: tbell, mgronlun
This commit is contained in:
parent
09be3efb39
commit
6e9b05acb2
test
jdk/jdk/jfr
api
consumer
TestReadTwice.javaTestRecordedEventGetThreadOther.javaTestRecordedFullStackTrace.javaTestRecordingFile.java
metadata
recorder
cmd
jcmd
jvm
lib/jdk/test/lib
@ -25,8 +25,8 @@
|
||||
|
||||
package jdk.jfr.api.consumer;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
@ -35,6 +35,7 @@ import jdk.jfr.Recording;
|
||||
import jdk.jfr.consumer.RecordedEvent;
|
||||
import jdk.jfr.consumer.RecordingFile;
|
||||
import jdk.test.lib.Asserts;
|
||||
import jdk.test.lib.Utils;
|
||||
|
||||
|
||||
/*
|
||||
@ -61,7 +62,7 @@ public class TestReadTwice {
|
||||
r.stop();
|
||||
|
||||
// Dump the recording to a file
|
||||
Path path = Files.createTempFile("recording", ".jfr");
|
||||
Path path = Utils.createTempFile("read-twice", ".jfr");
|
||||
System.out.println("Dumping to " + path);
|
||||
r.dump(path);
|
||||
r.close();
|
||||
|
@ -25,7 +25,6 @@
|
||||
|
||||
package jdk.jfr.api.consumer;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
@ -35,6 +34,7 @@ import jdk.jfr.consumer.RecordedEvent;
|
||||
import jdk.jfr.consumer.RecordedThread;
|
||||
import jdk.jfr.consumer.RecordingFile;
|
||||
import jdk.test.lib.Asserts;
|
||||
import jdk.test.lib.Utils;
|
||||
|
||||
/*
|
||||
* @test
|
||||
@ -99,7 +99,7 @@ public class TestRecordedEventGetThreadOther {
|
||||
TestEvent t = new TestEvent();
|
||||
t.commit();
|
||||
r.stop();
|
||||
Path path = Files.createTempFile("recording", ".jfr");
|
||||
Path path = Utils.createTempFile("event-thread", ".jfr");
|
||||
System.out.println("Created path: " + path);
|
||||
r.dump(path);
|
||||
r.close();
|
||||
|
@ -24,7 +24,6 @@
|
||||
*/
|
||||
package jdk.jfr.api.consumer;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
@ -36,6 +35,7 @@ import jdk.jfr.consumer.RecordedFrame;
|
||||
import jdk.jfr.consumer.RecordedStackTrace;
|
||||
import jdk.jfr.consumer.RecordingFile;
|
||||
import jdk.test.lib.Asserts;
|
||||
import jdk.test.lib.Utils;
|
||||
import jdk.test.lib.jfr.EventNames;
|
||||
import jdk.test.lib.jfr.Events;
|
||||
import jdk.test.lib.jfr.RecurseThread;
|
||||
@ -84,7 +84,7 @@ public class TestRecordedFullStackTrace {
|
||||
Thread.sleep(500);
|
||||
recording.stop();
|
||||
// Dump the recording to a file
|
||||
path = Files.createTempFile("recording", ".jfr");
|
||||
path = Utils.createTempFile("execution-stack-trace", ".jfr");
|
||||
System.out.println("Dumping to " + path);
|
||||
recording.dump(path);
|
||||
recording.close();
|
||||
|
@ -47,6 +47,7 @@ import jdk.jfr.Registered;
|
||||
import jdk.jfr.consumer.RecordedEvent;
|
||||
import jdk.jfr.consumer.RecordingFile;
|
||||
import jdk.test.lib.Asserts;
|
||||
import jdk.test.lib.Utils;
|
||||
|
||||
/*
|
||||
* @test
|
||||
@ -86,7 +87,7 @@ public class TestRecordingFile {
|
||||
TestEvent3 t3 = new TestEvent3();
|
||||
t3.commit();
|
||||
r.stop();
|
||||
Path valid = Files.createTempFile("three-event-recording", ".jfr");
|
||||
Path valid = Utils.createTempFile("three-event-recording", ".jfr");
|
||||
r.dump(valid);
|
||||
r.close();
|
||||
|
||||
@ -145,7 +146,7 @@ public class TestRecordingFile {
|
||||
System.out.println("Should exist: " + Arrays.toString(shouldExist));
|
||||
System.out.println("Should not exist: " + Arrays.toString(shouldNotExist));
|
||||
|
||||
Path p = Files.createTempFile(sb.toString(), ".jfr");
|
||||
Path p = Utils.createTempFile(sb.toString(), ".jfr");
|
||||
System.out.println("Filename: " + p);
|
||||
try (Recording r = new Recording()) {
|
||||
r.start();
|
||||
@ -180,8 +181,8 @@ public class TestRecordingFile {
|
||||
|
||||
private static void testReadEventTypesMultiChunk() throws Exception {
|
||||
|
||||
Path twoEventTypes = Files.createTempFile("two-event-types", ".jfr");
|
||||
Path threeEventTypes = Files.createTempFile("three-event-types", ".jfr");
|
||||
Path twoEventTypes = Utils.createTempFile("two-event-types", ".jfr");
|
||||
Path threeEventTypes = Utils.createTempFile("three-event-types", ".jfr");
|
||||
try (Recording r1 = new Recording()) {
|
||||
r1.start();
|
||||
FlightRecorder.register(Event1.class);
|
||||
@ -251,7 +252,7 @@ public class TestRecordingFile {
|
||||
|
||||
private static Path createBrokenWIthZeros(Path valid) throws Exception {
|
||||
try {
|
||||
Path broken = Files.createTempFile("broken-events", ".jfr");
|
||||
Path broken = Utils.createTempFile("broken-events", ".jfr");
|
||||
Files.delete(broken);
|
||||
Files.copy(valid, broken);
|
||||
RandomAccessFile raf = new RandomAccessFile(broken.toFile(), "rw");
|
||||
@ -271,7 +272,7 @@ public class TestRecordingFile {
|
||||
|
||||
private static Path createBrokenMetadata(Path valid) throws Exception {
|
||||
try {
|
||||
Path broken = Files.createTempFile("broken-metadata", ".jfr");
|
||||
Path broken = Utils.createTempFile("broken-metadata", ".jfr");
|
||||
Files.delete(broken);
|
||||
Files.copy(valid, broken);
|
||||
RandomAccessFile raf = new RandomAccessFile(broken.toFile(), "rw");
|
||||
@ -324,7 +325,7 @@ public class TestRecordingFile {
|
||||
} catch (FileNotFoundException npe) {
|
||||
// OK
|
||||
}
|
||||
Path testFile = Files.createTempFile("test-file", ".jfr");
|
||||
Path testFile = Utils.createTempFile("test-empty-file", ".jfr");
|
||||
try (RecordingFile r = new RecordingFile(testFile)) {
|
||||
throw new Exception("Expected IOException if file is empty");
|
||||
} catch (IOException e) {
|
||||
|
@ -25,7 +25,6 @@
|
||||
|
||||
package jdk.jfr.api.metadata.annotations;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@ -45,6 +44,7 @@ import jdk.jfr.Threshold;
|
||||
import jdk.jfr.consumer.RecordedEvent;
|
||||
import jdk.jfr.consumer.RecordingFile;
|
||||
import jdk.test.lib.Asserts;
|
||||
import jdk.test.lib.Utils;
|
||||
import jdk.test.lib.jfr.EventNames;
|
||||
import jdk.test.lib.jfr.Events;
|
||||
|
||||
@ -110,7 +110,7 @@ public class TestInheritedAnnotations {
|
||||
c.commit();
|
||||
|
||||
r.stop();
|
||||
Path p = Files.createTempFile("temp", ".jfr");
|
||||
Path p = Utils.createTempFile("inherited-annotations", ".jfr");
|
||||
r.dump(p);
|
||||
List<RecordedEvent> events = RecordingFile.readAllEvents(p);
|
||||
assertNoGrandFather(events);
|
||||
|
@ -28,7 +28,6 @@ package jdk.jfr.api.metadata.eventtype;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import jdk.jfr.Event;
|
||||
@ -37,6 +36,7 @@ import jdk.jfr.FlightRecorder;
|
||||
import jdk.jfr.Recording;
|
||||
import jdk.jfr.consumer.RecordingFile;
|
||||
import jdk.jfr.internal.JVM;
|
||||
import jdk.test.lib.Utils;
|
||||
|
||||
/*
|
||||
* @test
|
||||
@ -164,7 +164,7 @@ public class TestUnloadingEventClass {
|
||||
}
|
||||
|
||||
private static Object getEventType(Recording r, long id, String eventName) throws IOException {
|
||||
Path p = Files.createTempFile("recording-" + id + "_", ".jfr");
|
||||
Path p = Utils.createTempFile("unloading-event-class-recording-" + id + "_", ".jfr");
|
||||
r.dump(p);
|
||||
try (RecordingFile rf = new RecordingFile(p)) {
|
||||
for (EventType et : rf.readEventTypes()) {
|
||||
|
@ -32,6 +32,7 @@ import java.nio.file.Path;
|
||||
|
||||
import jdk.jfr.Configuration;
|
||||
import jdk.jfr.Recording;
|
||||
import jdk.test.lib.Utils;
|
||||
|
||||
/*
|
||||
* @test TestStartStopRecording
|
||||
@ -49,7 +50,7 @@ public class TestStartStopRecording {
|
||||
|
||||
inMemory.start();
|
||||
|
||||
Path memoryFile = Files.createTempFile("memory-recording", ".jfr");
|
||||
Path memoryFile = Utils.createTempFile("start-stop-memory-recording", ".jfr");
|
||||
inMemory.dump(memoryFile);
|
||||
assertValid(memoryFile, "Not a valid memory file.");
|
||||
inMemory.stop();
|
||||
@ -60,7 +61,7 @@ public class TestStartStopRecording {
|
||||
|
||||
toDisk.start();
|
||||
toDisk.stop();
|
||||
Path diskFile = Files.createTempFile("disk-recording", ".jfr");
|
||||
Path diskFile = Utils.createTempFile("start-stop-disk-recording", ".jfr");
|
||||
toDisk.dump(diskFile);
|
||||
assertValid(diskFile, "Not a valid disk file.");
|
||||
toDisk.close();
|
||||
|
@ -25,7 +25,6 @@
|
||||
|
||||
package jdk.jfr.cmd;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.regex.Matcher;
|
||||
@ -34,6 +33,7 @@ import java.util.regex.Pattern;
|
||||
import jdk.jfr.Configuration;
|
||||
import jdk.jfr.Event;
|
||||
import jdk.jfr.Recording;
|
||||
import jdk.test.lib.Utils;
|
||||
import jdk.test.lib.process.OutputAnalyzer;
|
||||
import jdk.test.lib.process.ProcessTools;;
|
||||
|
||||
@ -99,7 +99,7 @@ final class ExecuteHelper {
|
||||
}
|
||||
|
||||
public static Path createProfilingRecording() throws Exception {
|
||||
Path file = Files.createTempFile("recording", ".jfr");
|
||||
Path file = Utils.createTempFile("profiling-recording", ".jfr");
|
||||
// Create a recording with some data
|
||||
try (Recording r = new Recording(Configuration.getConfiguration("profile"))) {
|
||||
r.start();
|
||||
|
@ -29,6 +29,7 @@ import java.io.FileWriter;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import jdk.test.lib.Utils;
|
||||
import jdk.test.lib.process.OutputAnalyzer;
|
||||
|
||||
/*
|
||||
@ -51,7 +52,7 @@ public class TestPrint {
|
||||
output = ExecuteHelper.run("print", "missing.jfr", "option1", "option2");
|
||||
output.shouldContain("Too many arguments");
|
||||
|
||||
Path file = Files.createTempFile("faked-print-file", ".jfr");
|
||||
Path file = Utils.createTempFile("faked-print-file", ".jfr");
|
||||
FileWriter fw = new FileWriter(file.toFile());
|
||||
fw.write('d');
|
||||
fw.close();
|
||||
|
@ -27,12 +27,12 @@ package jdk.jfr.jcmd;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import jdk.jfr.Recording;
|
||||
import jdk.jfr.consumer.RecordedEvent;
|
||||
import jdk.jfr.consumer.RecordingFile;
|
||||
import jdk.test.lib.Utils;
|
||||
import jdk.test.lib.jfr.EventNames;
|
||||
import jdk.test.lib.jfr.FileHelper;
|
||||
import jdk.test.lib.process.OutputAnalyzer;
|
||||
@ -68,7 +68,7 @@ public class TestJcmdLegacy {
|
||||
}
|
||||
|
||||
private static void testAPI() throws IOException, Exception {
|
||||
Path p = Files.createTempFile("recording", ".jfr");
|
||||
Path p = Utils.createTempFile("enable-legacy-event", ".jfr");
|
||||
|
||||
try (Recording r = new Recording()) {
|
||||
r.enable(LEGACY_EVENT);
|
||||
|
@ -62,6 +62,7 @@ import jdk.management.jfr.EventTypeInfo;
|
||||
import jdk.management.jfr.FlightRecorderMXBean;
|
||||
import jdk.management.jfr.RecordingInfo;
|
||||
import jdk.management.jfr.SettingDescriptorInfo;
|
||||
import jdk.test.lib.Utils;
|
||||
|
||||
/*
|
||||
* @test TestUnsupportedVM
|
||||
@ -144,7 +145,7 @@ public class TestUnsupportedVM {
|
||||
if (!Configuration.getConfigurations().isEmpty()) {
|
||||
throw new AssertionError("Configuration files should not exist on an unsupported VM");
|
||||
}
|
||||
Path jfcFile = Files.createTempFile("my", ".jfr");
|
||||
Path jfcFile = Utils.createTempFile("empty", ".jfr");
|
||||
assertIOException(() -> Configuration.getConfiguration("default"));
|
||||
assertIOException(() -> Configuration.create(jfcFile));
|
||||
assertIOException(() -> Configuration.create(new FileReader(jfcFile.toFile())));
|
||||
|
@ -35,6 +35,7 @@ import java.net.UnknownHostException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.attribute.FileAttribute;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -770,5 +771,26 @@ public final class Utils {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an empty file in "user.dir" if the property set.
|
||||
* <p>
|
||||
* This method is meant as a replacement for {@code Files#createTempFile(String, String, FileAttribute...)}
|
||||
* that doesn't leave files behind in /tmp directory of the test machine
|
||||
* <p>
|
||||
* If the property "user.dir" is not set, "." will be used.
|
||||
*
|
||||
* @param prefix
|
||||
* @param suffix
|
||||
* @param attrs
|
||||
* @return the path to the newly created file that did not exist before this
|
||||
* method was invoked
|
||||
* @throws IOException
|
||||
*
|
||||
* @see {@link Files#createTempFile(String, String, FileAttribute...)}
|
||||
*/
|
||||
public static Path createTempFile(String prefix, String suffix, FileAttribute<?>... attrs) throws IOException {
|
||||
Path dir = Paths.get(System.getProperty("user.dir", "."));
|
||||
return Files.createTempFile(dir, prefix, suffix);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,6 +37,7 @@ import jdk.jfr.RecordingState;
|
||||
import jdk.jfr.consumer.RecordedEvent;
|
||||
import jdk.jfr.consumer.RecordingFile;
|
||||
import jdk.test.lib.Asserts;
|
||||
import jdk.test.lib.Utils;
|
||||
|
||||
|
||||
/**
|
||||
@ -90,7 +91,7 @@ public final class CommonHelper {
|
||||
r.enable(EventNames.CPUTimeStampCounter);
|
||||
r.start();
|
||||
r.stop();
|
||||
Path p = Files.createTempFile("timestamo", ".jfr");
|
||||
Path p = Utils.createTempFile("timestamo", ".jfr");
|
||||
r.dump(p);
|
||||
List<RecordedEvent> events = RecordingFile.readAllEvents(p);
|
||||
Files.deleteIfExists(p);
|
||||
|
Loading…
x
Reference in New Issue
Block a user