use of java.util.logging.FileHandler in project robovm by robovm.
the class OldFileHandlerTest method testFileHandler_3params.
public void testFileHandler_3params() throws Exception {
int limit = 120;
int count = 1;
handler = new FileHandler("%t/log/string", limit, count);
assertEquals("character encoding is non equal to actual value", "iso-8859-1", handler.getEncoding());
assertNotNull("Filter is null", handler.getFilter());
assertNotNull("Formatter is null", handler.getFormatter());
assertEquals("is non equal to actual value", Level.FINE, handler.getLevel());
assertNotNull("ErrorManager is null", handler.getErrorManager());
handler.publish(r);
handler.close();
// append mode is true
for (int i = 0; i < 3; i++) {
handler = new FileHandler("%t/log/string", limit, count);
handler.publish(r);
handler.close();
}
assertFileContent(TEMPPATH + SEP + "log", "/string", new LogRecord[] { r, null, r, null, r, null, r }, new MockFormatter());
try {
new FileHandler("", limit, count);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException e) {
//expected
}
try {
new FileHandler("%t/log/string", -1, count);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException e) {
//expected
}
try {
new FileHandler("%t/log/string", limit, 0);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException e) {
//expected
}
}
use of java.util.logging.FileHandler in project robovm by robovm.
the class OldFileHandlerTest method testClose.
public void testClose() throws Exception {
FileHandler h = new FileHandler("%t/log/stringPublish");
h.publish(r);
h.close();
assertFileContent(TEMPPATH + SEP + "log", "stringPublish", h.getFormatter());
}
use of java.util.logging.FileHandler in project robovm by robovm.
the class OldFileHandlerTest method testFileHandler.
public void testFileHandler() throws Exception {
assertEquals("character encoding is non equal to actual value", "iso-8859-1", handler.getEncoding());
assertNotNull("Filter is null", handler.getFilter());
assertNotNull("Formatter is null", handler.getFormatter());
assertEquals("is non equal to actual value", Level.FINE, handler.getLevel());
assertNotNull("ErrorManager is null", handler.getErrorManager());
handler.publish(r);
handler.close();
// append mode is true
for (int i = 0; i < 3; i++) {
handler = new FileHandler();
handler.publish(r);
handler.close();
}
assertFileContent(TEMPPATH + SEP + "log", "java0.test.0", new LogRecord[] { r, null, r, null, r, null, r }, new MockFormatter());
}
use of java.util.logging.FileHandler in project jdk8u_jdk by JetBrains.
the class CheckZombieLockTest method testFileHandlerClose.
private static void testFileHandlerClose(File writableDir) throws IOException {
File fakeLock = new File(writableDir, "log.log.lck");
if (!createFile(fakeLock, false)) {
throw new IOException("Can't create fake lock file: " + fakeLock);
}
try {
List<File> before = listLocks(writableDir, true);
System.out.println("before: " + before.size() + " locks found");
FileHandler handler = createFileHandler(writableDir);
System.out.println("handler created: " + handler);
List<File> after = listLocks(writableDir, true);
System.out.println("after creating handler: " + after.size() + " locks found");
handler.close();
System.out.println("handler closed: " + handler);
List<File> afterClose = listLocks(writableDir, true);
System.out.println("after closing handler: " + afterClose.size() + " locks found");
afterClose.removeAll(before);
if (!afterClose.isEmpty()) {
throw new RuntimeException("Zombie lock file detected: " + afterClose);
}
} finally {
if (fakeLock.canRead())
delete(fakeLock);
}
List<File> finalLocks = listLocks(writableDir, false);
System.out.println("After cleanup: " + finalLocks.size() + " locks found");
}
use of java.util.logging.FileHandler in project jdk8u_jdk by JetBrains.
the class CheckZombieLockTest method testFileHandlerCreate.
private static void testFileHandlerCreate(File writableDir, boolean first) throws IOException {
List<File> before = listLocks(writableDir, true);
System.out.println("before: " + before.size() + " locks found");
try {
if (first && !before.isEmpty()) {
throw new RuntimeException("Expected no lock file! Found: " + before);
} else if (!first && before.size() != 1) {
throw new RuntimeException("Expected a single lock file! Found: " + before);
}
} finally {
before.stream().forEach(CheckZombieLockTest::delete);
}
FileHandler handler = createFileHandler(writableDir);
System.out.println("handler created: " + handler);
List<File> after = listLocks(writableDir, true);
System.out.println("after creating handler: " + after.size() + " locks found");
if (after.size() != 1) {
throw new RuntimeException("Unexpected number of lock files found for " + handler + ": " + after);
}
}
Aggregations