test/java/util/logging/CheckLockLocationTest.java
Print this page
rev 6154 : 8003596: TEST_BUG: java/util/logging/CheckLockLocationTest.java failing [win]
Summary: Remove test that requires setWritable when running on Windows
Reviewed-by: alanb
*** 40,60 ****
private static final String NON_WRITABLE_DIR = "non-writable-dir";
private static final String NOT_A_DIR = "not-a-dir";
private static final String WRITABLE_DIR = "writable-dir";
private static final String NON_EXISTENT_DIR = "non-existent-dir";
public static void main(String... args) throws IOException {
// we'll base all file creation attempts on the system temp directory,
// %t and also try specifying non-existent directories and plain files
// that should be directories, and non-writable directories,
// to exercise all code paths of checking the lock location
File writableDir = setup();
// we now have three files/directories to work with:
// writableDir
// notAdir
! // nonWritableDir
// nonExistentDir (which doesn't exist)
runTests(writableDir);
}
/**
--- 40,65 ----
private static final String NON_WRITABLE_DIR = "non-writable-dir";
private static final String NOT_A_DIR = "not-a-dir";
private static final String WRITABLE_DIR = "writable-dir";
private static final String NON_EXISTENT_DIR = "non-existent-dir";
+ private static boolean runNonWritableDirTest;
public static void main(String... args) throws IOException {
// we'll base all file creation attempts on the system temp directory,
// %t and also try specifying non-existent directories and plain files
// that should be directories, and non-writable directories,
// to exercise all code paths of checking the lock location
+ // Note that on platforms like Windows that don't support
+ // setWritable() on a directory, we'll skip the non-writable
+ // directory test if setWritable(false) returns false.
+ //
File writableDir = setup();
// we now have three files/directories to work with:
// writableDir
// notAdir
! // nonWritableDir (may not be possible on some platforms)
// nonExistentDir (which doesn't exist)
runTests(writableDir);
}
/**
*** 77,95 ****
// files created and the directory
delete(writableDir);
}
// Test 2: creating FileHandler in non-writable directory should fail
try {
new FileHandler("%t/" + NON_WRITABLE_DIR + "/log.log");
throw new RuntimeException("Test failed: should not have been able"
+ " to create FileHandler for " + "%t/" + NON_WRITABLE_DIR
+ "/log.log in non-writable directory.");
} catch (IOException ex) {
// check for the right exception
if (!(ex instanceof AccessDeniedException)) {
! throw new RuntimeException("Test failed: Expected exception was not an AccessDeniedException", ex);
}
}
// Test 3: creating FileHandler in non-directory should fail
try {
--- 82,104 ----
// files created and the directory
delete(writableDir);
}
// Test 2: creating FileHandler in non-writable directory should fail
+ if (runNonWritableDirTest) {
try {
new FileHandler("%t/" + NON_WRITABLE_DIR + "/log.log");
throw new RuntimeException("Test failed: should not have been able"
+ " to create FileHandler for " + "%t/" + NON_WRITABLE_DIR
+ "/log.log in non-writable directory.");
} catch (IOException ex) {
// check for the right exception
if (!(ex instanceof AccessDeniedException)) {
! throw new RuntimeException(
! "Test failed: Expected exception was not an "
! + "AccessDeniedException", ex);
! }
}
}
// Test 3: creating FileHandler in non-directory should fail
try {
*** 97,108 ****
throw new RuntimeException("Test failed: should not have been able"
+ " to create FileHandler for " + "%t/" + NOT_A_DIR
+ "/log.log in non-directory.");
} catch (IOException ex) {
// check for the right exception
! if (!(ex instanceof FileSystemException && ex.getMessage().contains("Not a directory"))) {
! throw new RuntimeException("Test failed: Expected exception was not a FileSystemException", ex);
}
}
// Test 4: make sure we can't create a FileHandler in a non-existent dir
try {
--- 106,120 ----
throw new RuntimeException("Test failed: should not have been able"
+ " to create FileHandler for " + "%t/" + NOT_A_DIR
+ "/log.log in non-directory.");
} catch (IOException ex) {
// check for the right exception
! if (!(ex instanceof FileSystemException
! && ex.getMessage().contains("Not a directory"))) {
! throw new RuntimeException(
! "Test failed: Expected exception was not a "
! + "FileSystemException", ex);
}
}
// Test 4: make sure we can't create a FileHandler in a non-existent dir
try {
*** 111,121 ****
+ " to create FileHandler for " + "%t/" + NON_EXISTENT_DIR
+ "/log.log in a non-existent directory.");
} catch (IOException ex) {
// check for the right exception
if (!(ex instanceof NoSuchFileException)) {
! throw new RuntimeException("Test failed: Expected exception was not a NoSuchFileException", ex);
}
}
}
/**
--- 123,134 ----
+ " to create FileHandler for " + "%t/" + NON_EXISTENT_DIR
+ "/log.log in a non-existent directory.");
} catch (IOException ex) {
// check for the right exception
if (!(ex instanceof NoSuchFileException)) {
! throw new RuntimeException("Test failed: Expected exception "
! + "was not a NoSuchFileException", ex);
}
}
}
/**
*** 160,173 ****
+ nonWritableDir.getAbsolutePath() );
}
nonWritableDir.deleteOnExit();
// make it non-writable
! if (!nonWritableDir.setWritable(false)) {
! throw new RuntimeException("Test setup failed: unable to make"
+ " working directory " + nonWritableDir.getAbsolutePath()
! + " non-writable.");
}
// make sure non-existent directory really doesn't exist
File nonExistentDir = new File(tmpOrHomeDir, NON_EXISTENT_DIR);
if (nonExistentDir.exists()) {
--- 173,190 ----
+ nonWritableDir.getAbsolutePath() );
}
nonWritableDir.deleteOnExit();
// make it non-writable
! if (nonWritableDir.setWritable(false)) {
! runNonWritableDirTest = true;
! } else {
! runNonWritableDirTest = false;
! System.out.println( "Test Setup WARNING: unable to make"
+ " working directory " + nonWritableDir.getAbsolutePath()
! + " non-writable on platform " + System.getProperty("os.name"));
!
}
// make sure non-existent directory really doesn't exist
File nonExistentDir = new File(tmpOrHomeDir, NON_EXISTENT_DIR);
if (nonExistentDir.exists()) {