@Test
public void testLock() throws InterruptedException {

    String LOCK_NAME = "test-lock";
    int WAIT = 20;
    List<String> list = Collections.synchronizedList(new ArrayList<>());
    // Define the concurrent tasks
    Callable<Object> task1 = () -> {
        Lock lock = cache.acquireLock(LOCK_NAME);
        Thread.sleep(WAIT);
        list.add("a1");
        Thread.sleep(WAIT);
        list.add("b1");
        Thread.sleep(WAIT);
        list.add("c1");
        lock.unlock();
        return null;
    };
    Callable<Object> task2 = () -> {
        Lock lock = cache.acquireLock(LOCK_NAME);
        Thread.sleep(WAIT);
        list.add("a2");
        Thread.sleep(WAIT);
        list.add("b2");
        Thread.sleep(WAIT);
        list.add("c2");
        lock.unlock();
        return null;
    };
    List<Callable<Object>> tasks = new ArrayList<>();
    tasks.add(task1);
    tasks.add(task2);
    // Execute the tasks concurrently
    ExecutorService executorService = Executors.newFixedThreadPool(2);
    executorService.invokeAll(tasks);
    // Verify that the tasks updated the shared list in sequence
    String result = String.join(",", list);
    assertTrue(result.equals("a1,b1,c1,a2,b2,c2") || result.equals("a2,b2,c2,a1,b1,c1"));
}