Note: Please see The Green Report for latest recommendations in writing DistributedTests.
Updating Old Client/Server DUnit Test to Use Rules
These tests typically use a Cache instead of ClientCache. They also typically use NORMAL or DISTRIBUTED_ACK Region. The following example updates the test to use Rules without upgrading the client APIs.
Example: CacheRegionClearStatsDUnitTest
1) change "extends JUnit4DistributedTestCase" to "implements Serializable"
Code Block |
---|
@Category(DistributedTest.class)
@SuppressWarnings("serial")
public class CacheRegionClearStatsDUnitTest implements Serializable {
|
...
4) (optional) remove any other uses of @SuppressWarnings
5) add DistributedTestRule add DistributedRule (and optionally CacheRule and ClientCacheRule)
Code Block |
---|
@ClassRule@Rule public staticDistributedRule DistributedTestRule distributedTestRuledistributedRule = new DistributedTestRuleDistributedRule(); @Rule public CacheRule cacheRule = new CacheRule(); |
...
Code Block |
---|
@Before public void setUp() throws Exception { server1 = getHost(0).getVM(0); client1 = getHost(0).getVM(1); } |
7) delete any lines that instantiate CacheRegionClearStatsDUnitTest
...
14) replace any WaitCriterion with AwailityAwaitility
15) delete any dead code or commented out code
...
24) reorganize test so that vars and Rules are at the top, Before and After methods come before tests, Test methods come next, then any private methods used by the tests and finally any inner classes at the bottom of the class
25) (optional) rename the test to be more descriptive and prefer *DistributedTest to *DUnitTest
I renamed to CacheRegionClearStatsDUnitTest to RegionClearStatsDistributedTest.