8223396: [TESTBUG] several jfr tests do not clean up files created in /tmp

Using test utils to create temp files and directories

Reviewed-by: dholmes, erikj, hseigel, lmesnik
This commit is contained in:
Mikhailo Seledtsov 2019-06-04 07:53:12 -07:00
parent 4b01aa4f71
commit 7d3aebccc0
11 changed files with 50 additions and 26 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -38,6 +38,7 @@ import java.net.ServerSocket;
import java.net.Socket;
import java.security.ProtectionDomain;
import java.util.concurrent.CountDownLatch;
import jdk.test.lib.Utils;
/**
@ -87,7 +88,7 @@ public class EvilInstrument {
}
public static File createScratchFile() throws IOException {
return File.createTempFile("EvilTransformer", null, new File(".")).getAbsoluteFile();
return Utils.createTempFile("EvilTransformer", null).toFile();
}
class EvilTransformer implements ClassFileTransformer {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -37,6 +37,7 @@ import java.nio.channels.FileChannel;
import jdk.jfr.Recording;
import jdk.jfr.consumer.RecordedEvent;
import jdk.test.lib.Utils;
import jdk.test.lib.jfr.Events;
/**
@ -55,8 +56,7 @@ public class TestDisabledEvents {
private static final byte[] writeBuf = { 'B', 'C', 'D' };
public static void main(String[] args) throws Throwable {
File tmp = File.createTempFile("TestDisabledEvents", ".tmp", new File("."));
tmp.deleteOnExit();
File tmp = Utils.createTempFile("TestDisabledEvents", ".tmp").toFile();
Recording recording = new Recording();
recording.disable(IOEvent.EVENT_FILE_READ);
recording.disable(IOEvent.EVENT_FILE_WRITE);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -37,6 +37,7 @@ import java.util.List;
import jdk.jfr.Recording;
import jdk.jfr.consumer.RecordedEvent;
import jdk.test.lib.Utils;
import jdk.test.lib.jfr.Events;
/**
@ -48,8 +49,7 @@ import jdk.test.lib.jfr.Events;
*/
public class TestFileChannelEvents {
public static void main(String[] args) throws Throwable {
File tmp = File.createTempFile("TestFileChannelEvents", ".tmp", new File("."));
tmp.deleteOnExit();
File tmp = Utils.createTempFile("TestFileChannelEvents", ".tmp").toFile();
Recording recording = new Recording();
List<IOEvent> expectedEvents = new ArrayList<>();

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -38,6 +38,7 @@ import java.util.List;
import jdk.jfr.Recording;
import jdk.jfr.consumer.RecordedEvent;
import jdk.test.lib.Utils;
import jdk.test.lib.jfr.Events;
/**
@ -50,8 +51,7 @@ import jdk.test.lib.jfr.Events;
public class TestFileReadOnly {
public static void main(String[] args) throws Throwable {
File tmp = File.createTempFile("TestFileReadOnly", ".tmp", new File("."));
tmp.deleteOnExit();
File tmp = Utils.createTempFile("TestFileReadOnly", ".tmp").toFile();
Recording recording = new Recording();
List<IOEvent> expectedEvents = new ArrayList<>();

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -36,6 +36,7 @@ import java.util.List;
import jdk.jfr.Recording;
import jdk.jfr.consumer.RecordedEvent;
import jdk.test.lib.Utils;
import jdk.test.lib.jfr.Events;
/**
@ -48,8 +49,7 @@ import jdk.test.lib.jfr.Events;
public class TestFileStreamEvents {
public static void main(String[] args) throws Throwable {
File tmp = File.createTempFile("TestFileStreamEvents", ".tmp", new File("."));
tmp.deleteOnExit();
File tmp = Utils.createTempFile("TestFileStreamEvents", ".tmp").toFile();
Recording recording = new Recording();
List<IOEvent> expectedEvents = new ArrayList<>();

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -35,6 +35,7 @@ import java.util.List;
import jdk.jfr.Recording;
import jdk.jfr.consumer.RecordedEvent;
import jdk.test.lib.Utils;
import jdk.test.lib.jfr.Events;
/**
@ -47,8 +48,7 @@ import jdk.test.lib.jfr.Events;
public class TestRandomAccessFileEvents {
public static void main(String[] args) throws Throwable {
File tmp = File.createTempFile("TestRandomAccessFileEvents", ".tmp", new File("."));
tmp.deleteOnExit();
File tmp = Utils.createTempFile("TestRandomAccessFileEvents", ".tmp").toFile();
Recording recording = new Recording();
List<IOEvent> expectedEvents = new ArrayList<>();

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -37,6 +37,7 @@ import java.util.List;
import jdk.jfr.Recording;
import jdk.jfr.consumer.RecordedEvent;
import jdk.test.lib.Asserts;
import jdk.test.lib.Utils;
import jdk.test.lib.jfr.Events;
import jdk.test.lib.thread.TestThread;
import jdk.test.lib.thread.XRun;
@ -62,8 +63,7 @@ public class TestRandomAccessFileThread {
private static volatile int writeCount = 0; // Number of writes executed.
public static void main(String[] args) throws Throwable {
File tmp = File.createTempFile("TestRandomAccessFileThread", ".tmp", new File("."));
tmp.deleteOnExit();
File tmp = Utils.createTempFile("TestRandomAccessFileThread", ".tmp").toFile();
Recording recording = new Recording();
recording.enable(IOEvent.EVENT_FILE_READ).withThreshold(Duration.ofMillis(0));

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -31,6 +31,7 @@ import java.util.List;
import jdk.jfr.internal.Options;
import jdk.test.lib.Asserts;
import jdk.test.lib.Utils;
/**
* @test
@ -62,7 +63,7 @@ public class TestJcmdConfigure {
// - where feasible, check if they are respected
//
String dumpPath = Files.createTempDirectory("dump-path").toAbsolutePath().toString();
String dumpPath = Utils.createTempDirectory("dump-path-").toAbsolutePath().toString();
test(DUMPPATH, dumpPath);
test(STACK_DEPTH, 15);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -48,6 +48,7 @@ import jdk.management.jfr.FlightRecorderMXBean;
import jdk.management.jfr.RecordingInfo;
import jdk.management.jfr.SettingDescriptorInfo;
import jdk.test.lib.Asserts;
import jdk.test.lib.Utils;
import jdk.test.lib.jfr.CommonHelper;
import jdk.test.lib.jfr.Events;
@ -127,7 +128,7 @@ public class JmxHelper {
}
static File dump(long streamId, FlightRecorderMXBean bean) throws IOException {
File f = File.createTempFile("stream_" + streamId + "_", ".jfr", new File("."));
File f = Utils.createTempFile("stream_" + streamId + "_", ".jfr").toFile();
try (FileOutputStream fos = new FileOutputStream(f); BufferedOutputStream bos = new BufferedOutputStream(fos)) {
while (true) {
byte[] data = bean.readStream(streamId);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -39,6 +39,7 @@ import jdk.jfr.Recording;
import jdk.jfr.ValueDescriptor;
import jdk.jfr.consumer.RecordedEvent;
import jdk.jfr.consumer.RecordingFile;
import jdk.test.lib.Utils;
/**
* @test TestGetThreadId
@ -117,7 +118,7 @@ public class TestJavaEvent {
r.stop();
// prettyPrint();
File file = File.createTempFile("test", ".jfr");
File file = Utils.createTempFile("test", ".jfr").toFile();
r.dump(file.toPath());
int eventCount = 0;
for (RecordedEvent e : RecordingFile.readAllEvents(file.toPath())) {

View File

@ -815,4 +815,24 @@ public final class Utils {
Path dir = Paths.get(System.getProperty("user.dir", "."));
return Files.createTempFile(dir, prefix, suffix);
}
/**
* Creates an empty directory in "user.dir" or "."
* <p>
* This method is meant as a replacement for {@code Files#createTempDirectory(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 attrs
* @return the path to the newly created directory
* @throws IOException
*
* @see {@link Files#createTempDirectory(String, String, FileAttribute...)}
*/
public static Path createTempDirectory(String prefix, FileAttribute<?>... attrs) throws IOException {
Path dir = Paths.get(System.getProperty("user.dir", "."));
return Files.createTempDirectory(dir, prefix);
}
}