From 9950a4ceb13ff5be2ff61a506277a6d095df5f92 Mon Sep 17 00:00:00 2001 From: Andrea Cavalli Date: Sun, 24 Jan 2021 03:15:14 +0100 Subject: [PATCH] Update SnapshottableCollectionLockTest.java --- .../SnapshottableCollectionLockTest.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/test/java/org/warp/commonutils/locks/SnapshottableCollectionLockTest.java b/src/test/java/org/warp/commonutils/locks/SnapshottableCollectionLockTest.java index 23f0f86..fcc9130 100644 --- a/src/test/java/org/warp/commonutils/locks/SnapshottableCollectionLockTest.java +++ b/src/test/java/org/warp/commonutils/locks/SnapshottableCollectionLockTest.java @@ -1,6 +1,7 @@ package org.warp.commonutils.locks; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import org.junit.jupiter.api.Assertions; @@ -58,20 +59,22 @@ public class SnapshottableCollectionLockTest { private void checkSituation(SnapshottableCollectionLock lock, boolean fullReadAllow, boolean fullWriteAllow, boolean dataReadAllow, boolean dataWriteAllow) { + var pool = Executors.newWorkStealingPool(); + for (FullLockType readFullType : FullLockType.READ_FULL_TYPES) { if (fullReadAllow) { Assertions.assertDoesNotThrow(() -> { CompletableFuture.runAsync(() -> { lock.fullLock(null, readFullType); lock.fullUnlock(null, readFullType); - }).get(1, TimeUnit.SECONDS); + }, pool).get(2, TimeUnit.SECONDS); }); } else { Assertions.assertThrows(TimeoutException.class, () -> { CompletableFuture.runAsync(() -> { lock.fullLock(null, readFullType); lock.fullUnlock(null, readFullType); - }).get(50, TimeUnit.MILLISECONDS); + }, pool).get(50, TimeUnit.MILLISECONDS); }); } } @@ -82,14 +85,14 @@ public class SnapshottableCollectionLockTest { CompletableFuture.runAsync(() -> { lock.fullLock(null, writeFullType); lock.fullUnlock(null, writeFullType); - }).get(1, TimeUnit.SECONDS); + }, pool).get(2, TimeUnit.SECONDS); }); } else { Assertions.assertThrows(TimeoutException.class, () -> { CompletableFuture.runAsync(() -> { lock.fullLock(null, writeFullType); lock.fullUnlock(null, writeFullType); - }).get(50, TimeUnit.MILLISECONDS); + }, pool).get(50, TimeUnit.MILLISECONDS); }); } } @@ -99,14 +102,14 @@ public class SnapshottableCollectionLockTest { CompletableFuture.runAsync(() -> { lock.dataLock(null, DataLockType.READ, 1L); lock.dataUnlock(null, DataLockType.READ, 1L); - }).get(1, TimeUnit.SECONDS); + }, pool).get(2, TimeUnit.SECONDS); }); } else { Assertions.assertThrows(TimeoutException.class, () -> { CompletableFuture.runAsync(() -> { lock.dataLock(null, DataLockType.READ, 1L); lock.dataUnlock(null, DataLockType.READ, 1L); - }).get(50, TimeUnit.MILLISECONDS); + }, pool).get(50, TimeUnit.MILLISECONDS); }); } @@ -115,14 +118,14 @@ public class SnapshottableCollectionLockTest { CompletableFuture.runAsync(() -> { lock.dataLock(null, DataLockType.WRITE, 1L); lock.dataUnlock(null, DataLockType.WRITE, 1L); - }).get(1, TimeUnit.SECONDS); + }, pool).get(2, TimeUnit.SECONDS); }); } else { Assertions.assertThrows(TimeoutException.class, () -> { CompletableFuture.runAsync(() -> { lock.dataLock(null, DataLockType.WRITE, 1L); lock.dataUnlock(null, DataLockType.WRITE, 1L); - }).get(50, TimeUnit.MILLISECONDS); + }, pool).get(50, TimeUnit.MILLISECONDS); }); } }