changeset 50225:2942ae532175

8201331: Better test cleanup for jdk/jfr/api/consumer/TestRecordingFile.java Reviewed-by: tbell, mgronlun
author egahlin
date Tue, 22 May 2018 23:27:54 +0200
parents 67066e7971e1
children 408021edf22f
files test/jdk/jdk/jfr/api/consumer/TestReadTwice.java test/jdk/jdk/jfr/api/consumer/TestRecordedEventGetThreadOther.java test/jdk/jdk/jfr/api/consumer/TestRecordedFullStackTrace.java test/jdk/jdk/jfr/api/consumer/TestRecordingFile.java test/jdk/jdk/jfr/api/metadata/annotations/TestInheritedAnnotations.java test/jdk/jdk/jfr/api/metadata/eventtype/TestUnloadingEventClass.java test/jdk/jdk/jfr/api/recorder/TestStartStopRecording.java test/jdk/jdk/jfr/cmd/ExecuteHelper.java test/jdk/jdk/jfr/cmd/TestPrint.java test/jdk/jdk/jfr/jcmd/TestJcmdLegacy.java test/jdk/jdk/jfr/jvm/TestUnsupportedVM.java test/lib/jdk/test/lib/Utils.java test/lib/jdk/test/lib/jfr/CommonHelper.java
diffstat 13 files changed, 54 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/test/jdk/jdk/jfr/api/consumer/TestReadTwice.java	Tue May 22 10:49:20 2018 -0700
+++ b/test/jdk/jdk/jfr/api/consumer/TestReadTwice.java	Tue May 22 23:27:54 2018 +0200
@@ -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.consumer.RecordedEvent;
 import jdk.jfr.consumer.RecordingFile;
 import jdk.test.lib.Asserts;
+import jdk.test.lib.Utils;
 
 
 /*
@@ -61,7 +62,7 @@
         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();
--- a/test/jdk/jdk/jfr/api/consumer/TestRecordedEventGetThreadOther.java	Tue May 22 10:49:20 2018 -0700
+++ b/test/jdk/jdk/jfr/api/consumer/TestRecordedEventGetThreadOther.java	Tue May 22 23:27:54 2018 +0200
@@ -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.RecordedThread;
 import jdk.jfr.consumer.RecordingFile;
 import jdk.test.lib.Asserts;
+import jdk.test.lib.Utils;
 
 /*
  * @test
@@ -99,7 +99,7 @@
         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();
--- a/test/jdk/jdk/jfr/api/consumer/TestRecordedFullStackTrace.java	Tue May 22 10:49:20 2018 -0700
+++ b/test/jdk/jdk/jfr/api/consumer/TestRecordedFullStackTrace.java	Tue May 22 23:27:54 2018 +0200
@@ -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.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 @@
             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();
--- a/test/jdk/jdk/jfr/api/consumer/TestRecordingFile.java	Tue May 22 10:49:20 2018 -0700
+++ b/test/jdk/jdk/jfr/api/consumer/TestRecordingFile.java	Tue May 22 23:27:54 2018 +0200
@@ -47,6 +47,7 @@
 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 @@
         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 @@
         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 @@
 
     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 @@
 
     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 @@
 
     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 @@
         } 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) {
--- a/test/jdk/jdk/jfr/api/metadata/annotations/TestInheritedAnnotations.java	Tue May 22 10:49:20 2018 -0700
+++ b/test/jdk/jdk/jfr/api/metadata/annotations/TestInheritedAnnotations.java	Tue May 22 23:27:54 2018 +0200
@@ -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.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 @@
             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);
--- a/test/jdk/jdk/jfr/api/metadata/eventtype/TestUnloadingEventClass.java	Tue May 22 10:49:20 2018 -0700
+++ b/test/jdk/jdk/jfr/api/metadata/eventtype/TestUnloadingEventClass.java	Tue May 22 23:27:54 2018 +0200
@@ -28,7 +28,6 @@
 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.Recording;
 import jdk.jfr.consumer.RecordingFile;
 import jdk.jfr.internal.JVM;
+import jdk.test.lib.Utils;
 
 /*
  * @test
@@ -164,7 +164,7 @@
     }
 
     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()) {
--- a/test/jdk/jdk/jfr/api/recorder/TestStartStopRecording.java	Tue May 22 10:49:20 2018 -0700
+++ b/test/jdk/jdk/jfr/api/recorder/TestStartStopRecording.java	Tue May 22 23:27:54 2018 +0200
@@ -32,6 +32,7 @@
 
 import jdk.jfr.Configuration;
 import jdk.jfr.Recording;
+import jdk.test.lib.Utils;
 
 /*
  * @test TestStartStopRecording
@@ -49,7 +50,7 @@
 
         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 @@
 
         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();
--- a/test/jdk/jdk/jfr/cmd/ExecuteHelper.java	Tue May 22 10:49:20 2018 -0700
+++ b/test/jdk/jdk/jfr/cmd/ExecuteHelper.java	Tue May 22 23:27:54 2018 +0200
@@ -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 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 @@
     }
 
     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();
--- a/test/jdk/jdk/jfr/cmd/TestPrint.java	Tue May 22 10:49:20 2018 -0700
+++ b/test/jdk/jdk/jfr/cmd/TestPrint.java	Tue May 22 23:27:54 2018 +0200
@@ -29,6 +29,7 @@
 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 @@
         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();
--- a/test/jdk/jdk/jfr/jcmd/TestJcmdLegacy.java	Tue May 22 10:49:20 2018 -0700
+++ b/test/jdk/jdk/jfr/jcmd/TestJcmdLegacy.java	Tue May 22 23:27:54 2018 +0200
@@ -27,12 +27,12 @@
 
 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 @@
     }
 
     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);
--- a/test/jdk/jdk/jfr/jvm/TestUnsupportedVM.java	Tue May 22 10:49:20 2018 -0700
+++ b/test/jdk/jdk/jfr/jvm/TestUnsupportedVM.java	Tue May 22 23:27:54 2018 +0200
@@ -62,6 +62,7 @@
 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 @@
         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())));
--- a/test/lib/jdk/test/lib/Utils.java	Tue May 22 10:49:20 2018 -0700
+++ b/test/lib/jdk/test/lib/Utils.java	Tue May 22 23:27:54 2018 +0200
@@ -35,6 +35,7 @@
 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 @@
         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);
+    }
 }
 
--- a/test/lib/jdk/test/lib/jfr/CommonHelper.java	Tue May 22 10:49:20 2018 -0700
+++ b/test/lib/jdk/test/lib/jfr/CommonHelper.java	Tue May 22 23:27:54 2018 +0200
@@ -37,6 +37,7 @@
 import jdk.jfr.consumer.RecordedEvent;
 import jdk.jfr.consumer.RecordingFile;
 import jdk.test.lib.Asserts;
+import jdk.test.lib.Utils;
 
 
 /**
@@ -90,7 +91,7 @@
                 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);