[jboss-cvs] JBossCache/old/tests/functional/org/jboss/cache/aop/eviction ...
Ben Wang
bwang at jboss.com
Tue Oct 31 03:01:15 EST 2006
User: bwang
Date: 06/10/31 03:01:15
Added: old/tests/functional/org/jboss/cache/aop/eviction
AopLRUPolicyUpdateEvictionTest.java
AopLRUPolicyTest.java PojoEvictionTest.java
Log:
Deprecated files moved to old dir.
Revision Changes Path
1.1 date: 2006/10/31 08:01:15; author: bwang; state: Exp;JBossCache/old/tests/functional/org/jboss/cache/aop/eviction/AopLRUPolicyUpdateEvictionTest.java
Index: AopLRUPolicyUpdateEvictionTest.java
===================================================================
/*
* JBoss, Home of Professional Open Source
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.cache.aop.eviction;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.jboss.cache.Fqn;
import org.jboss.cache.aop.AOPInstance;
import org.jboss.cache.aop.InternalDelegate;
import org.jboss.cache.aop.PojoCache;
import org.jboss.cache.factories.XmlConfigurationParser;
import org.jboss.cache.misc.TestingUtil;
/**
* @author Ben Wang, Feb 11, 2004
* @version $Revision: 1.1 $
*/
public class AopLRUPolicyUpdateEvictionTest extends TestCase
{
PojoCache cache_;
int wakeupIntervalMillis_ = 0;
public AopLRUPolicyUpdateEvictionTest(String s)
{
super(s);
}
public void setUp() throws Exception
{
super.setUp();
initCaches();
wakeupIntervalMillis_ = cache_.getEvictionThreadWakeupIntervalSeconds() * 1000;
log("wakeupInterval is " + wakeupIntervalMillis_);
// if (wakeupIntervalMillis_ <= 0)
// fail("testEviction(): eviction thread wake up interval is illegal " + wakeupIntervalMillis_);
}
void initCaches() throws Exception
{
// sleep(10000);
cache_ = new PojoCache();
// cache_.setConfiguration(new XmlConfigurationParser().parseFile("META-INF/local-aop-eviction-service.xml")); // read in generic local xml
cache_.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
cache_.start();
}
public void tearDown() throws Exception
{
super.tearDown();
cache_.stop();
}
public void testDummy()
{
// nothing
}
public void XtestUpdateEviction()
{
String rootStr = "/aop/";
AOPInstance aop = new AOPInstance();
try
{
for (int i = 0; i < 4; i++)
{
String stri = rootStr + i;
Fqn fqni = Fqn.fromString(stri);
cache_.put(fqni, stri, stri);
cache_.put(fqni, AOPInstance.KEY, aop); // signals that this is an aop node.
cache_.put(fqni, InternalDelegate.CLASS_INTERNAL, String.class); // signals that this is an aop node.
for (int j = 0; j < 2; j++)
{
String strj = stri + "/" + j;
Fqn fqnj = Fqn.fromString(strj);
cache_.put(fqnj, strj, strj);
}
}
}
catch (Exception e)
{
e.printStackTrace();
fail("Failed to insert data" + e);
}
int period = (wakeupIntervalMillis_ + 500);
log("period is " + period);
TestingUtil.sleepThread(period); // it really depends on the eviction thread time.
String str = rootStr + "3";
Fqn fqn = Fqn.fromString(str);
try
{
cache_.get(fqn, str); // just to keep it fresh
TestingUtil.sleepThread(period); // it really depends the eviction thread time.
cache_.get(fqn, str); // just to keep it fresh
TestingUtil.sleepThread(period); // it really depends the eviction thread time.
String val = (String) cache_.get(rootStr + "3/1", rootStr + "3/1");
assertNotNull("DataNode should not be empty ", val);
TestingUtil.sleepThread(period);
val = (String) cache_.get(rootStr + "3", rootStr + "3");
assertNull("Known failure. See JBCACHE-462; DataNode should be empty. But this is broken because of TreeCache._removeData() has disabled " +
"sendNodeEvent. See the FIXME. ", val);
}
catch (Exception e)
{
e.printStackTrace();
fail("Failed to evict" + e);
}
}
void log(String msg)
{
System.out.println("-- " + msg);
}
public static Test suite()
{
return new TestSuite(AopLRUPolicyUpdateEvictionTest.class);
}
public static void main(String[] args)
{
junit.textui.TestRunner.run(AopLRUPolicyUpdateEvictionTest.suite());
}
}
1.1 date: 2006/10/31 08:01:15; author: bwang; state: Exp;JBossCache/old/tests/functional/org/jboss/cache/aop/eviction/AopLRUPolicyTest.java
Index: AopLRUPolicyTest.java
===================================================================
package org.jboss.cache.aop.eviction;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.jboss.cache.Fqn;
import org.jboss.cache.aop.AOPInstance;
import org.jboss.cache.aop.InternalDelegate;
import org.jboss.cache.aop.PojoCache;
import org.jboss.cache.factories.XmlConfigurationParser;
import org.jboss.cache.misc.TestingUtil;
/**
* @author Ben Wang, Feb 11, 2004
* @version $Revision: 1.1 $
*/
public class AopLRUPolicyTest extends TestCase
{
PojoCache cache_;
int wakeupIntervalMillis_ = 0;
public AopLRUPolicyTest(String s)
{
super(s);
}
public void setUp() throws Exception
{
super.setUp();
initCaches();
wakeupIntervalMillis_ = cache_.getEvictionThreadWakeupIntervalSeconds() * 1000;
log("wakeupInterval is " + wakeupIntervalMillis_);
// if (wakeupIntervalMillis_ <= 0)
// fail("testEviction(): eviction thread wake up interval is illegal " + wakeupIntervalMillis_);
}
void initCaches() throws Exception
{
// sleep(10000);
cache_ = new PojoCache();
// cache_.setConfiguration(new XmlConfigurationParser().parseFile("META-INF/pojocache-service.xml")); // read in generic local xml
cache_.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
cache_.start();
}
public void tearDown() throws Exception
{
super.tearDown();
cache_.stop();
}
public void testDummy()
{
// nothing
}
/**
* We are disabling these tests now becuase of the switch to EvictionInterceptor makes these
* tests obslete.
*/
public void XtestSimpleEviction()
{
String rootStr = "/aop/";
AOPInstance aop = new AOPInstance();
Fqn internalFqn = new Fqn(InternalDelegate.JBOSS_INTERNAL, "test");
try
{
for (int i = 0; i < 4; i++)
{
String stri = rootStr + i;
Fqn fqni = Fqn.fromString(stri);
cache_.put(fqni, stri, stri);
cache_.put(fqni, AOPInstance.KEY, aop); // signals that this is an aop node.
cache_.put(fqni, InternalDelegate.CLASS_INTERNAL, String.class); // signals that this is an aop node.
cache_.put(internalFqn, "test", "test"); // this will always be around since it is internal.
for (int j = 0; j < 3; j++)
{
String strj = stri + "/" + j;
Fqn fqnj = Fqn.fromString(strj);
cache_.put(fqnj, strj, strj);
}
}
}
catch (Exception e)
{
e.printStackTrace();
fail("Failed to insert data" + e);
}
int period = (wakeupIntervalMillis_ + 500);
log("period is " + period);
TestingUtil.sleepThread(period); // it really depends on the eviction thread time.
try
{
String str = rootStr + "0";
String val = (String) cache_.get(Fqn.fromString(str), str);
assertNull("DataNode should be empty ", val);
str = rootStr + "3";
val = (String) cache_.get(Fqn.fromString(str), str);
assertNotNull("DataNode should not be empty if maxElements is 4 ", val);
}
catch (Exception e)
{
e.printStackTrace();
fail("Failed to evict" + e);
}
}
public void XtestRemoveEviction()
{
String rootStr = "/aop/";
AOPInstance aop = new AOPInstance();
try
{
for (int i = 0; i < 4; i++)
{
String stri = rootStr + i;
Fqn fqni = Fqn.fromString(stri);
cache_.put(fqni, stri, stri);
cache_.put(fqni, AOPInstance.KEY, aop); // signals that this is an aop node.
for (int j = 0; j < 2; j++)
{
String strj = stri + "/" + j;
Fqn fqnj = Fqn.fromString(strj);
cache_.put(fqnj, strj, strj);
}
}
}
catch (Exception e)
{
e.printStackTrace();
fail("Failed to insert data" + e);
}
int period = (wakeupIntervalMillis_ + 500);
log("period is " + period);
TestingUtil.sleepThread(period); // it really depends on the eviction thread time.
String str = rootStr + "3";
Fqn fqn = Fqn.fromString(str);
try
{
cache_.get(fqn, str); // just to keep it fresh
TestingUtil.sleepThread(period); // it really depends the eviction thread time.
cache_.get(fqn, str); // just to keep it fresh
TestingUtil.sleepThread(period); // it really depends the eviction thread time.
String val = (String) cache_.get(rootStr + "3/1", rootStr + "3/1");
assertNotNull("DataNode should not be empty ", val);
cache_.remove(rootStr + "3");
val = (String) cache_.get(rootStr + "3", rootStr + "3");
assertNull("DataNode should be empty ", val);
TestingUtil.sleepThread(wakeupIntervalMillis_ + 500);
}
catch (Exception e)
{
e.printStackTrace();
fail("Failed to evict" + e);
}
}
void log(String msg)
{
System.out.println("-- " + msg);
}
public static Test suite()
{
return new TestSuite(AopLRUPolicyTest.class);
}
public static void main(String[] args)
{
junit.textui.TestRunner.run(suite());
}
}
1.1 date: 2006/10/31 08:01:15; author: bwang; state: Exp;JBossCache/old/tests/functional/org/jboss/cache/aop/eviction/PojoEvictionTest.java
Index: PojoEvictionTest.java
===================================================================
/*
* JBoss, Home of Professional Open Source
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.cache.aop.eviction;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.aop.PojoCache;
import org.jboss.cache.aop.test.Address;
import org.jboss.cache.aop.test.Person;
import org.jboss.cache.aop.test.Student;
import org.jboss.cache.factories.XmlConfigurationParser;
import org.jboss.cache.misc.TestingUtil;
import java.util.ArrayList;
import java.util.List;
/**
* Test for pojo eviction, i.e., eviction on pojo level.
* @author Ben Wang
*/
public class PojoEvictionTest extends TestCase
{
Log log_= LogFactory.getLog(PojoEvictionTest.class);
PojoCache cache_;
int wakeupIntervalMillis_ = 0;
public PojoEvictionTest(String name)
{
super(name);
}
protected void setUp() throws Exception
{
super.setUp();
log_.info("setUp() ....");
String configFile = "META-INF/pojocache-service.xml";
cache_ = new PojoCache();
// cache_.setConfiguration(new XmlConfigurationParser().parseFile(configFile));
cache_.start();
wakeupIntervalMillis_ = cache_.getEvictionThreadWakeupIntervalSeconds() * 1000;
log_.info("wakeupInterval is " + wakeupIntervalMillis_);
// if (wakeupIntervalMillis_ <= 0)
// fail("setup(): eviction thread wake up interval is illegal " + wakeupIntervalMillis_);
}
protected void tearDown() throws Exception
{
super.tearDown();
cache_.stop();
}
public void testDummy()
{
// nothing
}
public void XtestPutAndEvict() throws Exception
{
log_.info("testPutAndEvict() ....");
Person test = new Person();
test.setName("Ben");
test.setAge(10);
cache_.putObject("/pojo", test);
Person result = (Person)cache_.getObject("/pojo");
assertEquals(" ", test, result);
result.setAge(20);
int period = (wakeupIntervalMillis_ *2+ 500);
log_.info("period is " + period);
TestingUtil.sleepThread(period*2); // it really depends on the eviction thread time.
assertFalse("pojo node should not exist ", cache_.exists("/pojo"));
assertEquals("Age should still be after eviction/detachment: ", 20, test.getAge());
}
/**
* THis is not working properly now for maxNode becuase we should evict based on the while graph instead of
* just children. E.g., in this case, we should evict Student as a whole. But we also need to consider the
* object graph scenario. We will refactor the eviction policy in 2.0 release to address these.
*/
public void XtestPutAndMaxNodeEvict() throws Exception
{
log_.info("testPutAndMaxNodeEvict() ....");
String fqn = "/testMaxNode";
Student test = new Student();
test.setName("Ben");
test.setAge(10);
Address addr = new Address();
addr.setZip(95123);
List lang = new ArrayList();
lang.add("English");
lang.add("French");
lang.add("Mandarin");
test.setLanguages(lang);
cache_.putObject(fqn, test);
Person result = (Person)cache_.getObject(fqn);
assertEquals(" ", test, result);
result.setAge(20);
int period = (wakeupIntervalMillis_ *2+ 500);
log_.info("period is " + period);
TestingUtil.sleepThread(period*2); // it really depends on the eviction thread time.
assertFalse("pojo node should not exist ", cache_.exists(fqn));
assertEquals("Age should still be after eviction/detachment: ", 20, test.getAge());
}
/**
* This test is passing but still incomplete. We should take the object graph into consideration when
* trying to evict a pojo. In theory, if a sub-pojo has been refreshed, should we evict the parent object?
* @throws Exception
*/
public void XtestPutObjectGraphAndEvict() throws Exception
{
log_.info("testPutGraphAndEvict() ....");
Person ben = new Person();
ben.setName("Ben");
ben.setAge(10);
Person mary = new Person();
mary.setName("Mary");
mary.setAge(20);
Address addr = new Address();
addr.setCity("Sunnyvale");
addr.setZip(95123);
ben.setAddress(addr);
mary.setAddress(addr);
cache_.putObject("/pojo/ben", ben);
cache_.putObject("/pojo/mary", mary);
Person result = (Person)cache_.getObject("/pojo/ben");
assertEquals(" ", ben, result);
result.setAge(20);
int period = (wakeupIntervalMillis_);
log_.info("period is " + period);
TestingUtil.sleepThread(period/2); // it really depends on the eviction thread time.
addr.getZip();
TestingUtil.sleepThread(period/2);
addr.getZip();
TestingUtil.sleepThread(period/2);
addr.getZip();
TestingUtil.sleepThread(period/2);
// It is failing now but need to fix.
assertFalse("pojo node should not exist ", cache_.exists("/pojo/mary"));
assertFalse("pojo node should exist ", cache_.exists("/pojo/ben"));
assertEquals("Age should still be after eviction/detachment: ", 20, ben.getAge());
}
public static Test suite() throws Exception
{
return new TestSuite(PojoEvictionTest.class);
}
public static void main(String[] args) throws Exception
{
junit.textui.TestRunner.run(PojoEvictionTest.suite());
}
}
More information about the jboss-cvs-commits
mailing list