-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#225 Improve tests and implementation
- Loading branch information
Showing
2 changed files
with
84 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
79 changes: 79 additions & 0 deletions
79
common/src/test/groovy/dvoraka/avservice/common/service/ExecutorServiceHelperSpec.groovy
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,79 @@ | ||
package dvoraka.avservice.common.service | ||
|
||
import org.apache.logging.log4j.Logger | ||
import spock.lang.Specification | ||
import spock.lang.Subject | ||
|
||
import java.util.concurrent.ExecutorService | ||
|
||
/** | ||
* ExecutorServiceHelperSpec | ||
*/ | ||
class ExecutorServiceHelperSpec extends Specification { | ||
|
||
@Subject | ||
ExecutorServiceHelper helper | ||
|
||
ExecutorService service | ||
Logger logger | ||
|
||
long seconds = 10 | ||
|
||
|
||
def setup() { | ||
helper = Spy() | ||
|
||
service = Mock() | ||
logger = Mock() | ||
} | ||
|
||
def "normal shutdown"() { | ||
when: | ||
helper.shutdownAndAwaitTermination(service, seconds, logger) | ||
|
||
then: | ||
1 * service.shutdown() | ||
1 * service.awaitTermination(_, _) >> true | ||
|
||
2 * logger._ | ||
} | ||
|
||
def "shutdown with troubles"() { | ||
when: | ||
helper.shutdownAndAwaitTermination(service, seconds, logger) | ||
|
||
then: | ||
1 * service.shutdown() | ||
2 * service.awaitTermination(_, _) >> false >> true | ||
1 * service.shutdownNow() | ||
|
||
2 * logger._ | ||
} | ||
|
||
def "shutdown with big troubles"() { | ||
when: | ||
helper.shutdownAndAwaitTermination(service, seconds, logger) | ||
|
||
then: | ||
1 * service.shutdown() | ||
2 * service.awaitTermination(_, _) >> false | ||
1 * service.shutdownNow() | ||
|
||
1 * logger.warn(_) | ||
1 * logger._ | ||
} | ||
|
||
def "shutdown with waiting troubles"() { | ||
when: | ||
helper.shutdownAndAwaitTermination(service, seconds, logger) | ||
|
||
then: | ||
1 * service.shutdown() | ||
1 * service.awaitTermination(_, _) >> { throw new InterruptedException() } | ||
|
||
1 * service.shutdownNow() | ||
|
||
1 * logger.warn(_, _) | ||
1 * logger._ | ||
} | ||
} |