spock icon indicating copy to clipboard operation
spock copied to clipboard

Add ReusableBlockingVariable to allow reset the state of the variable…

Open guenhter opened this issue 8 years ago • 2 comments

Often it's needed to use the same BlockingVariable again but reset it. E.g. when the variable is used for Messaging and is contained in a consumer. Than it isn't always that easy to replace the existing variable with a new instance. So I added a simple reset method which resets the value and the CountDownLatch of the BlockingVariable.

This also was suggested in #312

So it is now possible to do:

BlockingVariable<String> b = ...
// do something async with the var

when:
sender.send("val1")
then:
b.get() == "val1"

when:
b.reset()
sender.send("val2")
then:
b.get() == "val2"

when:
b.reset()
sender.error();
b.get()
then:
thrown(SpockTimeoutError)

(I know, this samples can be split up to own tests, but there are other circumstances where such cases are needed)


This change is Reviewable

guenhter avatar Apr 18 '17 08:04 guenhter

Codecov Report

Merging #721 into master will increase coverage by 0.02%. The diff coverage is 92.85%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #721      +/-   ##
============================================
+ Coverage     73.16%   73.18%   +0.02%     
- Complexity     3088     3094       +6     
============================================
  Files           341      342       +1     
  Lines          9639     9653      +14     
  Branches       1201     1201              
============================================
+ Hits           7052     7065      +13     
- Misses         2144     2145       +1     
  Partials        443      443
Impacted Files Coverage Δ Complexity Δ
...ock/util/concurrent/ReuseableBlockingVariable.java 92.85% <92.85%> (ø) 6 <6> (?)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update e9d7edc...d52ea1b. Read the comment docs.

codecov[bot] avatar Apr 18 '17 08:04 codecov[bot]

FYI, we won't merge any new features until 1.1 is released.

leonard84 avatar Apr 25 '17 08:04 leonard84