Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 76   Methods: 5
NCLOC: 56   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ReplicateToInactiveRegionTest.java - 100% 100% 100%
coverage
 1    package org.jboss.cache.marshall;
 2   
 3    import junit.framework.TestCase;
 4    import org.jboss.cache.CacheImpl;
 5    import org.jboss.cache.DefaultCacheFactory;
 6    import org.jboss.cache.Fqn;
 7    import org.jboss.cache.Region;
 8    import org.jboss.cache.misc.TestingUtil;
 9   
 10    public class ReplicateToInactiveRegionTest extends TestCase
 11    {
 12    CacheImpl[] caches;
 13   
 14  1 protected void setUp() throws Exception
 15    {
 16  1 super.setUp();
 17  1 caches = new CacheImpl[]{createCache(), createCache()};
 18  1 TestingUtil.blockUntilViewsReceived(caches, 10000);
 19    }
 20   
 21  1 protected void tearDown() throws Exception
 22    {
 23  1 super.tearDown();
 24  1 destroyCache(caches[0]);
 25  1 destroyCache(caches[1]);
 26  1 caches = null;
 27    }
 28   
 29  2 private void destroyCache(CacheImpl c)
 30    {
 31  2 c.stop();
 32    }
 33   
 34  2 private CacheImpl createCache() throws Exception
 35    {
 36  2 CacheImpl c = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
 37  2 c.getConfiguration().setCacheMode("REPL_SYNC");
 38  2 c.getConfiguration().setUseRegionBasedMarshalling(true);
 39  2 c.start();
 40  2 return c;
 41    }
 42   
 43  1 public void testTransferToInactiveRegion()
 44    {
 45  1 Fqn f = Fqn.fromString("/a/b");
 46   
 47  1 caches[0].put(f, "k", "v");
 48   
 49  1 assertEquals("v", caches[0].get(f, "k"));
 50  1 assertEquals("v", caches[1].get(f, "k"));
 51   
 52    // create the region on cache 0, make sure it is marked as a MARSHALLING region by attaching a class loader to it.
 53  1 Region region0 = caches[0].getRegionManager().getRegion(f, true);
 54  1 region0.registerContextClassLoader(this.getClass().getClassLoader()); // just to make sure this is recognised as a marshalling region.
 55  1 assertTrue("Should be active by default", region0.isActive());
 56    // make sure this newly created region is "recognised" as a marshalling region.
 57  1 assertTrue(caches[0].getRegionManager().getAllRegions(Region.Type.MARSHALLING).contains(region0));
 58   
 59    // now create a region on cache 1, as above.
 60  1 Region region1 = caches[1].getRegionManager().getRegion(f, true);
 61  1 region1.registerContextClassLoader(this.getClass().getClassLoader()); // just to make sure this is recognised as a marshalling region.
 62  1 assertTrue("Should be active by default", region1.isActive());
 63    // make sure this newly created region is "recognised" as a marshalling region.
 64  1 assertTrue(caches[1].getRegionManager().getAllRegions(Region.Type.MARSHALLING).contains(region1));
 65   
 66    // now deactivate the region on cache 1.
 67  1 region1.deactivate();
 68  1 assertFalse("Should be have deactivated", region1.isActive());
 69   
 70  1 caches[0].put(f, "k", "v2");
 71  1 assertEquals("v2", caches[0].get(f, "k"));
 72  1 assertNull(caches[1].get(f, "k"));
 73   
 74    }
 75    }
 76