提交 55b8911c 编写于 作者: M Matt Sicker

Use CountDownLatch instead of Object

Signed-off-by: NMatt Sicker <boards@gmail.com>
上级 f71bf079
......@@ -34,6 +34,7 @@ import org.junit.rules.Timeout;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
......@@ -196,14 +197,14 @@ public class PathRemoverTest {
mkdirs(d1, d2);
touchWithFileName(f1, d1f1, d2f2);
locker.acquireLock(d2f2);
Object readyToUnlockSignal = new Object();
Object readyToDeleteSignal = new Object();
CountDownLatch unlockLatch = new CountDownLatch(1);
CountDownLatch deleteLatch = new CountDownLatch(1);
AtomicBoolean lockedFileExists = new AtomicBoolean();
Thread thread = new Thread(() -> {
try {
readyToUnlockSignal.wait();
unlockLatch.await();
locker.releaseLock(d2f2);
readyToDeleteSignal.notifyAll();
deleteLatch.countDown();
} catch (Exception ignored) {
}
});
......@@ -211,9 +212,9 @@ public class PathRemoverTest {
PathRemover remover = PathRemover.newRemoverWithStrategy(retriesAttempted -> {
if (retriesAttempted == 0) {
lockedFileExists.set(d2f2.exists());
readyToUnlockSignal.notifyAll();
unlockLatch.countDown();
try {
readyToDeleteSignal.wait();
deleteLatch.await();
return true;
} catch (InterruptedException e) {
return false;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册