Skip to content

Commit

Permalink
#19725 more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wezell committed Dec 22, 2020
1 parent e8fde8f commit cd7e3b1
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions dotCMS/src/test/java/com/dotcms/concurrent/DebouncerTest.java
Expand Up @@ -12,7 +12,7 @@ public class DebouncerTest {


@Test
public void test() throws InterruptedException {
public void test_that_debouncer_prevents_multiple_runs() throws InterruptedException {
Debouncer debouncer = new Debouncer(0L);

// debounce for 10 seconds
Expand All @@ -24,15 +24,41 @@ public void test() throws InterruptedException {
debouncer.debounce("testingKey", ()->{Logger.info("DebouncerTest","running debouncer test" );}, 5, TimeUnit.SECONDS);
debouncer.debounce("testingKey", ()->{Logger.info("DebouncerTest","running debouncer test" );}, 5, TimeUnit.SECONDS);

//sleep 7 seconds
Thread.sleep(7*1000);


assertTrue("assert that we have only run once", debouncer.runCount==1);

}


@Test
public void test_that_debouncer_reschedules_the_runnable() throws InterruptedException {
Debouncer debouncer = new Debouncer(0L);


debouncer.debounce("testingKey", ()->{Logger.info("DebouncerTest","running debouncer test" );}, 1, TimeUnit.SECONDS);
Thread.sleep(300);
debouncer.debounce("testingKey", ()->{Logger.info("DebouncerTest","running debouncer test" );}, 1, TimeUnit.SECONDS);
Thread.sleep(2000);



debouncer.debounce("testingKey", ()->{Logger.info("DebouncerTest","running debouncer test" );}, 1, TimeUnit.SECONDS);
Thread.sleep(300);
debouncer.debounce("testingKey", ()->{Logger.info("DebouncerTest","running debouncer test" );}, 1, TimeUnit.SECONDS);
Thread.sleep(2000);



assertTrue("assert that we have run twice", debouncer.runCount==2);

}







}

0 comments on commit cd7e3b1

Please sign in to comment.