[jbosscache-dev] Writing parallel-execution-ready test

Dominik Pospisil dpospisi at redhat.com
Fri Aug 8 15:47:00 EDT 2008


The process of paralellizing JBossCache testsuite is underway and here are 
some guidelines to help write new tests which could be ran using parallel 
TestNG testsuite runner.

1. Declare the test class as sequential using @Test annotation or 
(preferrably) write the test class thread safe so the test methods could be 
ran simultaneously.

Example of @Test annotation to be used in a non thread-safe test class:
@Test(groups = {"functional", "transaction", "optimistic"}, sequential = true)

2. In the case the test class needs replicated cache use UnitTestCacheFactory 
class to instantiate the cache. The UnitTestCacheFactory will ensure that the 
cache will use different mcast_addr and mcast_port than other tests running in 
different threads. Also, create the cache configuration before invoking 
createCache factory method and pass the configuration as an argument.

Example:

Configuration c = new Configuration();
c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
c.setNodeLockingScheme(Configuration.NodeLockingScheme.OPTIMISTIC);
c.setCacheMode(Configuration.CacheMode.REPL_SYNC);      
Cache cache = new UnitTestCacheFactory<Object, Object>().createCache(c, 
false));

3. At the end of the test (or test method if not sequential), all the cache 
instances must be destroyed. The cleanUp method of the UnitTestCacheFactory 
could be used for this purpose. Note that the method relies on the fact that 
it is executed in the same thread as the thread in which the cache(s) were 
created.

4. That's it!

Thanks,

- Dominik




More information about the jbosscache-dev mailing list