forked from iluwatar/java-design-patterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Intermittent failure was due to Thread.sleep in the code. While perfo…
…rming unit test cases there was race condition between two threads, so it was not guaranteed to work every time. Used an interface DelayProvider for simulating delay, and while unit testing fake delay provider is used that eradicates the use of Threads in unit test cases, which is not a good practice.
- Loading branch information
Showing
3 changed files
with
59 additions
and
28 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
balking/src/main/java/com/iluwatar/balking/DelayProvider.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,10 @@ | ||
package com.iluwatar.balking; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* An interface to simulate delay while executing some work. | ||
*/ | ||
public interface DelayProvider { | ||
void executeAfterDelay(long interval, TimeUnit timeUnit, Runnable task); | ||
} |
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
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