Skip to content
Permalink
Browse files
8279022: JCmdTestFileSafety.java should check file time stamp for tes…
…t result

Reviewed-by: ccheung
  • Loading branch information
yminqi committed Dec 22, 2021
1 parent a6903f8 commit 9a478b347e1ef7aecfc8bbc2e3c5e6ac7c23ba36
Showing 1 changed file with 27 additions and 10 deletions.
@@ -38,6 +38,9 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.attribute.FileTime;
import java.nio.file.Files;
import java.nio.file.Paths;
import jdk.test.lib.cds.CDSTestUtils;
import jdk.test.lib.apps.LingeredApp;
import jdk.test.lib.Platform;
@@ -61,6 +64,13 @@ static void checkContainAbsoluteLogPath(OutputAnalyzer output) throws Exception
}
}

private static void removeFile(String fileName) throws Exception {
File file = new File(fileName);
if (file.exists()) {
file.delete();
}
}

static void test() throws Exception {
buildJars();

@@ -75,17 +85,25 @@ static void test() throws Exception {
}
outputDirFile.setWritable(true);
String localFileName = subDir + File.separator + "MyStaticDump.jsa";
removeFile(localFileName);

setIsStatic(true/*static*/);
// Set target dir not writable, do static dump
print2ln(test_count++ + " Set target dir not writable, do static dump");
setKeepArchive(true);
app = createLingeredApp("-cp", allJars);
pid = app.getPid();
test(localFileName, pid, noBoot, EXPECT_PASS);
checkFileExistence(localFileName, true/*exist*/);
FileTime ft1 = Files.getLastModifiedTime(Paths.get(localFileName));
outputDirFile.setWritable(false);
test(localFileName, pid, noBoot, EXPECT_FAIL);
FileTime ft2 = Files.getLastModifiedTime(Paths.get(localFileName));
if (!ft2.equals(ft1)) {
throw new RuntimeException("Archive file " + localFileName + " should not be updated");
}
removeFile(localFileName);
outputDirFile.setWritable(true);
checkFileExistence(localFileName, true/*exist*/);

// Illegal character in file name
localFileName = "mystatic:.jsa";
@@ -103,18 +121,17 @@ static void test() throws Exception {
pid = app.getPid();
localFileName = subDir + File.separator + "MyDynamicDump.jsa";
test(localFileName, pid, noBoot, EXPECT_PASS);
app.stopApp();
// cannot dynamically dump twice, restart
app = createLingeredApp("-cp", allJars, "-XX:+RecordDynamicDumpInfo");
pid = app.getPid();
checkFileExistence(localFileName, true/*exist*/);
ft1 = Files.getLastModifiedTime(Paths.get(localFileName));
outputDirFile.setWritable(false);
test(localFileName, pid, noBoot, EXPECT_FAIL);
outputDirFile.setWritable(true);
ft2 = Files.getLastModifiedTime(Paths.get(localFileName));
if (!ft2.equals(ft1)) {
throw new RuntimeException("Archive file " + localFileName + " should not be updated");
}
app.stopApp();
// MyDynamicDump.jsa should exist
checkFileExistence(localFileName, true);
File rmFile = new File(localFileName);
rmFile.delete();
removeFile(localFileName);
outputDirFile.setWritable(true);
outputDirFile.delete();
}

1 comment on commit 9a478b3

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 9a478b3 Dec 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.