[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/passivation ...

Ben Wang bwang at jboss.com
Thu Sep 28 20:42:54 EDT 2006


  User: bwang   
  Date: 06/09/28 20:42:54

  Added:       tests/functional/org/jboss/cache/passivation 
                        ReplicatedPassivationIntegrationTest.java
  Log:
  added
  
  Revision  Changes    Path
  1.1      date: 2006/09/29 00:42:54;  author: bwang;  state: Exp;JBossCache/tests/functional/org/jboss/cache/passivation/ReplicatedPassivationIntegrationTest.java
  
  Index: ReplicatedPassivationIntegrationTest.java
  ===================================================================
  /*
   * JBoss, Home of Professional Open Source.
   * Copyright 2006, Red Hat Middleware LLC, and individual contributors
   * as indicated by the @author tags. See the copyright.txt file in the
   * distribution for a full listing of individual contributors.
   *
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
   * the License, or (at your option) any later version.
   *
   * This software is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
   * License along with this software; if not, write to the Free
   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
   */
  
  package org.jboss.cache.passivation;
  
  import junit.framework.TestCase;
  import org.jboss.cache.TreeCache;
  import org.jboss.cache.AbstractCacheListener;
  import org.jboss.cache.Fqn;
  import org.jboss.cache.misc.TestingUtil;
  import org.jboss.cache.factories.XmlConfigurationParser;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  import java.util.Map;
  
  /**
   * @author Ben Wang, Feb 11, 2004
   */
  public class ReplicatedPassivationIntegrationTest extends TestCase
  {
     TreeCache cache_;
     TreeCache cache1_;
     protected final static Log log = LogFactory.getLog(ReplicatedPassivationIntegrationTest.class);
     int wakeupIntervalMillis_ = 0;
     ReplicatedPassivationIntegrationTest.PassivationListener listener_;
  
     public ReplicatedPassivationIntegrationTest(String s)
     {
        super(s);
        listener_ = new ReplicatedPassivationIntegrationTest.PassivationListener();
     }
  
     public void setUp() throws Exception
     {
        super.setUp();
        cache_ = new TreeCache();
        initCaches(cache_);
        cache_.getConfiguration().setUseRegionBasedMarshalling(true);
        cache_.start();
        cache_.getNotifier().addCacheListener(listener_);
  
  
        cache1_ = new TreeCache();
        initCaches(cache1_);
        cache1_.getConfiguration().setUseRegionBasedMarshalling(true);
  
        cache1_.start();
        cache1_.getNotifier().addCacheListener(listener_);
        listener_.resetCounter();
  
        wakeupIntervalMillis_ = cache1_.getEvictionThreadWakeupIntervalSeconds() * 1000;
        log("wakeupInterval is " + wakeupIntervalMillis_);
        if (wakeupIntervalMillis_ <= 0)
        {
           fail("testEviction(): eviction thread wake up interval is illegal " + wakeupIntervalMillis_);
        }
     }
  
     void initCaches(TreeCache cache) throws Exception
     {
        cache.setConfiguration(new XmlConfigurationParser().parseFile("META-INF/replSync-passivation-service.xml")); // read in generic local xml
        cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
     }
  
     public void tearDown() throws Exception
     {
        super.tearDown();
        cache_.stop();
        cache1_.stop();
     }
  
     /**
      */
     public void testActivationEvent() throws Exception
     {
        String rootStr = "/org/jboss/test/data/";
        String str = rootStr + "0";
        cache_.remove("/");
        listener_.resetCounter();
  
        cache_.put(str, str, str);
  
        TestingUtil.sleepThread(20000);
        assertFalse("NodeImpl should not exist", cache1_.exists(str, str));
        String val = (String) cache1_.get(str, str);
        assertNotNull("DataNode should be activated ", val);
        assertEquals("Eviction counter ", 1, listener_.getCounter());
     }
  
     void log(String msg)
     {
        System.out.println("-- " + msg);
     }
  
     class PassivationListener extends AbstractCacheListener
     {
        int counter = 0;
        int loadedCounter = 0;
  
        public int getCounter()
        {
           return counter;
        }
  
        public void resetCounter()
        {
           counter = 0;
           loadedCounter = 0;
        }
  
        public void nodeActivated(Fqn fqn, boolean pre)
        {
           if (!pre)
           {
              counter++;
              System.out.println("nodeActivate(): counter: " + counter);
           }
        }
  
        public void nodePassivated(Fqn fqn, boolean pre)
        {
           if (pre)
           {
              System.out.println("nodePassivate(): " +fqn);
           }
        }
  
        public void nodeLoaded(Fqn f, boolean pre, Map data)
        {
           if (!pre)
           {
              loadedCounter++;
           }
        }
  
     }
  }
  
  
  



More information about the jboss-cvs-commits mailing list