@Test
void test() throws InterruptedException {

    final ClusterLockDbConnProvider clusterLockDbConnProvider = DbTestUtil.getTestDbDatasource(
            new ClusterLockDbModule(), new ClusterLockConfig());
    final DbClusterLock dbClusterLock = new DbClusterLock(clusterLockDbConnProvider);
    final DbClusterLockThreads dbClusterLockThreads = new DbClusterLockThreads(dbClusterLock);
    final CountDownLatch countDownLatch = new CountDownLatch(2);
    final List<Integer> sequence = new ArrayList<>(3);
    // This thread should acquire the lock first stopping the second thread
    // from adding to the sequence until after this thread completes.
    final Thread thread1 = new Thread(() -> {
        dbClusterLockThreads.thread1("TEST", sequence);
        countDownLatch.countDown();
    });
    final Thread thread2 = new Thread(() -> {
        dbClusterLockThreads.thread2("TEST", sequence);
        countDownLatch.countDown();
    });
    // Start the threads.
    thread1.start();
    thread2.start();
    // Now make sure the sequence is as expected.
    countDownLatch.await();
    assertThat(sequence.size()).isEqualTo(3);
    assertThat(sequence.get(0).intValue()).isEqualTo(1);
    assertThat(sequence.get(1).intValue()).isEqualTo(2);
    assertThat(sequence.get(2).intValue()).isEqualTo(3);
}