Clover coverage report -
Coverage timestamp: Wed Jan 31 2007 15:38:53 EST
file stats: LOC: 161   Methods: 11
NCLOC: 113   Classes: 2
 
 Source file Conditionals Statements Methods TOTAL
ReplicatedPassivationIntegrationTest.java 87.5% 97.9% 100% 97%
coverage coverage
 1    /*
 2    * JBoss, Home of Professional Open Source.
 3    * Copyright 2006, Red Hat Middleware LLC, and individual contributors
 4    * as indicated by the @author tags. See the copyright.txt file in the
 5    * distribution for a full listing of individual contributors.
 6    *
 7    * This is free software; you can redistribute it and/or modify it
 8    * under the terms of the GNU Lesser General Public License as
 9    * published by the Free Software Foundation; either version 2.1 of
 10    * the License, or (at your option) any later version.
 11    *
 12    * This software is distributed in the hope that it will be useful,
 13    * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 15    * Lesser General Public License for more details.
 16    *
 17    * You should have received a copy of the GNU Lesser General Public
 18    * License along with this software; if not, write to the Free
 19    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 20    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 21    */
 22   
 23    package org.jboss.cache.passivation;
 24   
 25    import junit.framework.TestCase;
 26    import org.apache.commons.logging.Log;
 27    import org.apache.commons.logging.LogFactory;
 28    import org.jboss.cache.AbstractCacheListener;
 29    import org.jboss.cache.CacheImpl;
 30    import org.jboss.cache.DefaultCacheFactory;
 31    import org.jboss.cache.Fqn;
 32    import org.jboss.cache.factories.XmlConfigurationParser;
 33    import org.jboss.cache.misc.TestingUtil;
 34   
 35    import java.util.Map;
 36   
 37    /**
 38    * @author Ben Wang, Feb 11, 2004
 39    */
 40    public class ReplicatedPassivationIntegrationTest extends TestCase
 41    {
 42    CacheImpl cache_;
 43    CacheImpl cache1_;
 44    protected final static Log log = LogFactory.getLog(ReplicatedPassivationIntegrationTest.class);
 45    int wakeupIntervalMillis_ = 0;
 46    ReplicatedPassivationIntegrationTest.PassivationListener listener_;
 47   
 48  1 public ReplicatedPassivationIntegrationTest(String s)
 49    {
 50  1 super(s);
 51  1 listener_ = new ReplicatedPassivationIntegrationTest.PassivationListener();
 52    }
 53   
 54  1 public void setUp() throws Exception
 55    {
 56  1 super.setUp();
 57  1 cache_ = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
 58  1 initCaches(cache_);
 59  1 cache_.getConfiguration().setUseRegionBasedMarshalling(true);
 60  1 cache_.start();
 61   
 62  1 cache1_ = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
 63  1 initCaches(cache1_);
 64  1 cache1_.getConfiguration().setUseRegionBasedMarshalling(true);
 65   
 66  1 cache1_.start();
 67  1 cache1_.getNotifier().addCacheListener(listener_);
 68  1 listener_.resetCounter();
 69   
 70  1 wakeupIntervalMillis_ = cache1_.getConfiguration().getEvictionConfig().getWakeupIntervalSeconds() * 1000;
 71  1 log("wakeupInterval is " + wakeupIntervalMillis_);
 72  1 if (wakeupIntervalMillis_ <= 0)
 73    {
 74  0 fail("testEviction(): eviction thread wake up interval is illegal " + wakeupIntervalMillis_);
 75    }
 76    }
 77   
 78  2 void initCaches(CacheImpl cache) throws Exception
 79    {
 80  2 cache.setConfiguration(new XmlConfigurationParser().parseFile("META-INF/replSync-passivation-service.xml"));// read in generic local xml
 81  2 cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
 82    }
 83   
 84  1 public void tearDown() throws Exception
 85    {
 86  1 super.tearDown();
 87  1 cache_.stop();
 88  1 cache1_.stop();
 89    }
 90   
 91    /**
 92    */
 93  1 public void testActivationEvent() throws Exception
 94    {
 95  1 String rootStr = "/org/jboss/test/data/";
 96  1 String rootStr1 = "/__JBossInternal__/5c4o12-pzhlhj-esnuy3sg-1-esnuy3sg-2";
 97  1 String str = rootStr + "0";
 98  1 cache_.remove("/");
 99  1 listener_.resetCounter();
 100   
 101  1 cache_.put(str, str, str);
 102  1 cache_.put(rootStr1, str, str);
 103   
 104  1 TestingUtil.sleepThread(11000);
 105  1 assertFalse("UnversionedNode should not exist", cache1_.exists(str, str));
 106  1 String val;
 107  1 val = (String) cache1_.get(str, str);
 108  1 val = (String) cache1_.get(rootStr1, str);
 109  1 assertNotNull("DataNode should be activated ", val);
 110  1 assertEquals("Eviction counter ", 2, listener_.getCounter());
 111    }
 112   
 113  1 void log(String msg)
 114    {
 115  1 System.out.println("-- " + msg);
 116    }
 117   
 118    class PassivationListener extends AbstractCacheListener
 119    {
 120    int counter = 0;
 121    int loadedCounter = 0;
 122   
 123  1 public int getCounter()
 124    {
 125  1 return counter;
 126    }
 127   
 128  2 public void resetCounter()
 129    {
 130  2 counter = 0;
 131  2 loadedCounter = 0;
 132    }
 133   
 134  7 public void nodeActivated(Fqn fqn, boolean pre)
 135    {
 136  7 if (!pre)
 137    {
 138  2 counter++;
 139  2 System.out.println("nodeActivate(): counter: " + counter);
 140  2 System.out.println("nodeActivate(): " + fqn);
 141    }
 142    }
 143   
 144  4 public void nodePassivated(Fqn fqn, boolean pre)
 145    {
 146  4 if (pre)
 147    {
 148  2 System.out.println("nodePassivate(): " + fqn);
 149    }
 150    }
 151   
 152  4 public void nodeLoaded(Fqn f, boolean pre, Map data)
 153    {
 154  4 if (!pre)
 155    {
 156  2 loadedCounter++;
 157    }
 158    }
 159   
 160    }
 161    }