Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Though simply testing the job (without waiting for the scheduler to run it for you) would do the trick in most (read this as: probably all) situations, there are some in which it might be interesting to not have to trigger it manually.</p> <p>For instance, you have a cluster of play apps that share a common configuration set. Change one config in one slave, all the others take note and do the same. Let's say the configuration is kept in memcached. One useful unit test is to manually change some setting using Cache.set, wait for the amount of time it takes for the configurationObserver job to run, then check that the internal config has been updated. This would be even more helpful if there would be a series of jobs updating the configuration, etc.</p> <p>To do that, you must remember that play in DEV mode uses one thread (this helps debugging a lot, btw). You can simply add this line to your application.conf: %test.application.mode=prod and you'll have multiple threads.</p> <p>Later edit: It appears that setting the mode to prod doesn't really help in this case. What does help is this: use some "await" magic.</p> <pre><code>@Test public void myTest() { final Lock lock = new ReentrantLock(); final Condition goAhead = lock.newCondition(); /* Here goes everything you need to do before "pausing" */ lock.lock(); try { /** * Set whatever time limit you want/need * You can also use notifiers like goAhead.signal(), from within another thread */ goAhead.await(5, TimeUnit.SECONDS); } catch (InterruptedException e) { assertTrue(whateverINeedToTest); } finally { lock.unlock(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload