Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
runtime-core: Guard from multiple invocations, fix #708
- Loading branch information
Showing
2 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...eedment/runtime/core/internal/component/StatisticsReporterSchedulerComponentImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.speedment.runtime.core.internal.component; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class StatisticsReporterSchedulerComponentImplTest { | ||
|
||
@Test | ||
void guardedCallStalled() { | ||
|
||
final AtomicBoolean called = new AtomicBoolean(); | ||
final StatisticsReporterSchedulerComponentImpl instance = new StatisticsReporterSchedulerComponentImpl(); | ||
|
||
final Thread t0 = new Thread(() -> { instance.guardedCall(() -> dly(1000)); }); | ||
final Thread t1 = new Thread(() -> { called.set(true); }); | ||
|
||
t0.start(); | ||
dly(100); | ||
t1.start(); | ||
|
||
assertFalse(called.get()); | ||
} | ||
|
||
|
||
@Test | ||
void guardedCallClean() { | ||
|
||
final AtomicBoolean called = new AtomicBoolean(); | ||
final StatisticsReporterSchedulerComponentImpl instance = new StatisticsReporterSchedulerComponentImpl(); | ||
|
||
instance.guardedCall(() -> {}); | ||
instance.guardedCall(() -> called.set(true)); | ||
|
||
assertTrue(called.get()); | ||
} | ||
|
||
|
||
|
||
private void dly(long ms) { | ||
try { | ||
Thread.sleep(ms); | ||
} catch (InterruptedException ignored) { | ||
|
||
} | ||
} | ||
|
||
} |