8216565: Specifying the same path creates a new directory in JFR.configure

Reviewed-by: ysuenaga, egahlin
This commit is contained in:
Chihiro Ito 2019-01-26 15:47:50 +09:00
parent 52f9024232
commit df9591f47d
3 changed files with 55 additions and 1 deletions

View File

@ -56,6 +56,11 @@ public final class Repository {
}
public synchronized void setBasePath(SafePath baseLocation) throws Exception {
if(baseLocation.equals(this.baseLocation)) {
Logger.log(LogTag.JFR, LogLevel.INFO, "Same base repository path " + baseLocation.toString() + " is set");
return;
}
// Probe to see if repository can be created, needed for fail fast
// during JVM startup or JFR.configure
this.repository = createRepository(baseLocation);

View File

@ -171,6 +171,19 @@ public final class SecuritySupport {
public String toString() {
return text;
}
@Override
public boolean equals(Object other) {
if(other != null && other instanceof SafePath){
return this.toPath().equals(((SafePath) other).toPath());
}
return false;
}
@Override
public int hashCode() {
return this.toPath().hashCode();
}
}
private interface RunnableWithCheckedException {

View File

@ -26,9 +26,12 @@
package jdk.jfr.jcmd;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import jdk.jfr.internal.Repository;
import jdk.jfr.internal.SecuritySupport.SafePath;
import jdk.jfr.internal.Options;
import jdk.test.lib.Asserts;
import jdk.test.lib.Utils;
@ -40,7 +43,7 @@ import jdk.test.lib.Utils;
* @requires vm.hasJFR
* @library /test/lib /test/jdk
* @modules jdk.jfr/jdk.jfr.internal
* @run main/othervm jdk.jfr.jcmd.TestJcmdConfigure
* @run main/othervm -Xlog:jfr=info:file=jfr_info.txt jdk.jfr.jcmd.TestJcmdConfigure
*/
public class TestJcmdConfigure {
@ -53,6 +56,13 @@ public class TestJcmdConfigure {
private static final String SAMPLE_THREADS = "samplethreads";
private static final String UNSUPPORTED_OPTION = "unsupportedoption";
private static final String REPOSITORYPATH_1 = "./repo1";
private static final String REPOSITORYPATH_2 = "./repo2";
private static final String REPOSITORYPATH_SETTING_1 = "repositorypath="+REPOSITORYPATH_1;
private static final String REPOSITORYPATH_SETTING_2 = "repositorypath="+REPOSITORYPATH_2;
private static final String JFR_UNIFIED_LOG_FILE = "jfr_info.txt";
public static void main(String[] args) throws Exception {
//
// Simple sanity tests against what is available in Java,
@ -76,6 +86,8 @@ public class TestJcmdConfigure {
testNegative(UNSUPPORTED_OPTION, 100000);
testNegative(MAX_CHUNK_SIZE, -500);
testRepository();
if (!testExceptions.isEmpty()) {
for (Exception e : testExceptions) {
System.out.println("Error: " + e.getMessage());
@ -118,4 +130,28 @@ public class TestJcmdConfigure {
default: throw new RuntimeException("Unknown option " + name);
}
}
private static void testRepository(){
final String findWhat = "[info][jfr] Same base repository path " + REPOSITORYPATH_1 + " is set";
try {
JcmdHelper.jcmd("JFR.configure", REPOSITORYPATH_SETTING_1);
SafePath initialPath = Repository.getRepository().getRepositoryPath();
JcmdHelper.jcmd("JFR.configure", REPOSITORYPATH_SETTING_1);
SafePath samePath = Repository.getRepository().getRepositoryPath();
Asserts.assertTrue(samePath.equals(initialPath));
List<String> lines = Files.readAllLines(Paths.get(JFR_UNIFIED_LOG_FILE));
Asserts.assertTrue(lines.stream().anyMatch(l->l.contains(findWhat)));
JcmdHelper.jcmd("JFR.configure", REPOSITORYPATH_SETTING_2);
SafePath changedPath = Repository.getRepository().getRepositoryPath();
Asserts.assertFalse(changedPath.equals(initialPath));
} catch(Exception e) {
testExceptions.add(e);
}
}
}