[infinispan-dev] eventually...
Manik Surtani
manik at jboss.org
Thu Sep 2 06:53:24 EDT 2010
Is there a max wait period? I wouldn't want conditions blocking indefinitely...
On 2 Sep 2010, at 11:31, Mircea Markus wrote:
> Hi,
>
> While testing, especially on async behaviour, one needs to wait until a certain state is reached.
> E.g. let's say we want to test _async_ repl works fine, one way to do it is:
>
> 1. first approach
> cache1.put(k,v);
>
> //now expect this to be replicated at some point in future on cache2
> for (int i=0; i < 10; i++) {
> if (v.equals(cache2.get(k)) break;
> Thread.sleep(1000);
> }
> assert v.equals(cache2.get(k));
>
> the code bellow waits 10 seconds for the replication to occur, if not fails the test.
> Problem with this code is that it is rather hard to read, and not reusable.
> This code can be found in many paces in our tests.
>
> 2. second approach.
> I've added AbstractInfinispanTest.eventually(Condition ec) method that does the same.
> Code bellow now looks like:
>
> eventually(new Condition() {
> public boolean isSatisfied() throws Exception {
> return v.equals(cache2.get(k));
> }
> });
> While the amount of code itself hasn't change significantly, the second approach is more readable and much more quicker to write as it is generated by the IDE.
>
> I've added this in 4.2, let me know your thoughts around it.
>
> Cheers,
> Mircea
>
>
>
>
>
>
> _______________________________________________
> infinispan-dev mailing list
> infinispan-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/infinispan-dev
--
Manik Surtani
manik at jboss.org
Lead, Infinispan
Lead, JBoss Cache
http://www.infinispan.org
http://www.jbosscache.org
More information about the infinispan-dev
mailing list