8283719: java/util/logging/CheckZombieLockTest.java failing intermittently
Reviewed-by: alanb
This commit is contained in:
parent
205cfb8496
commit
74835f7389
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -50,6 +50,8 @@ import java.util.UUID;
|
|||||||
import java.util.logging.FileHandler;
|
import java.util.logging.FileHandler;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.LogRecord;
|
import java.util.logging.LogRecord;
|
||||||
|
import static java.nio.file.StandardOpenOption.*;
|
||||||
|
|
||||||
public class CheckZombieLockTest {
|
public class CheckZombieLockTest {
|
||||||
|
|
||||||
private static final String WRITABLE_DIR = "writable-lockfile-dir";
|
private static final String WRITABLE_DIR = "writable-lockfile-dir";
|
||||||
@ -241,10 +243,9 @@ public class CheckZombieLockTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (supportsLocking) {
|
if (supportsLocking) {
|
||||||
FileChannel fc = FileChannel.open(Paths.get(lock.getAbsolutePath()),
|
handler2 = null;
|
||||||
StandardOpenOption.CREATE_NEW, StandardOpenOption.APPEND,
|
try (FileChannel fc = FileChannel.open(lock.toPath(), CREATE_NEW, APPEND, WRITE)) {
|
||||||
StandardOpenOption.WRITE);
|
|
||||||
try {
|
|
||||||
if (fc.tryLock() != null) {
|
if (fc.tryLock() != null) {
|
||||||
System.out.println("locked: " + lock);
|
System.out.println("locked: " + lock);
|
||||||
handler2 = createFileHandler(writableDir);
|
handler2 = createFileHandler(writableDir);
|
||||||
@ -261,6 +262,7 @@ public class CheckZombieLockTest {
|
|||||||
throw new RuntimeException("Failed to lock: " + lock);
|
throw new RuntimeException("Failed to lock: " + lock);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
if (handler2 != null) handler2.close();
|
||||||
delete(lock);
|
delete(lock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -320,17 +322,12 @@ public class CheckZombieLockTest {
|
|||||||
|
|
||||||
// try to determine whether file locking is supported
|
// try to determine whether file locking is supported
|
||||||
final String uniqueFileName = UUID.randomUUID().toString()+".lck";
|
final String uniqueFileName = UUID.randomUUID().toString()+".lck";
|
||||||
try {
|
try (FileChannel fc = FileChannel.open(Paths.get(writableDir.getAbsolutePath(),
|
||||||
FileChannel fc = FileChannel.open(Paths.get(writableDir.getAbsolutePath(),
|
uniqueFileName), CREATE_NEW, APPEND, DELETE_ON_CLOSE)) {
|
||||||
uniqueFileName),
|
|
||||||
StandardOpenOption.CREATE_NEW, StandardOpenOption.APPEND,
|
|
||||||
StandardOpenOption.DELETE_ON_CLOSE);
|
|
||||||
try {
|
try {
|
||||||
fc.tryLock();
|
fc.tryLock();
|
||||||
} catch(IOException x) {
|
} catch (IOException x) {
|
||||||
supportsLocking = false;
|
supportsLocking = false;
|
||||||
} finally {
|
|
||||||
fc.close();
|
|
||||||
}
|
}
|
||||||
} catch (IOException t) {
|
} catch (IOException t) {
|
||||||
// should not happen
|
// should not happen
|
||||||
|
Loading…
Reference in New Issue
Block a user