[jboss-cvs] JBossCache/tests-50/functional/org/jboss/cache/pojo/passivation ...
Ben Wang
bwang at jboss.com
Mon Nov 6 22:58:58 EST 2006
User: bwang
Date: 06/11/06 22:58:58
Modified: tests-50/functional/org/jboss/cache/pojo/passivation
ReplicatedTest.java LocalTest.java
Log:
pojocache passivation tests
Revision Changes Path
1.8 +239 -53 JBossCache/tests-50/functional/org/jboss/cache/pojo/passivation/ReplicatedTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ReplicatedTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests-50/functional/org/jboss/cache/pojo/passivation/ReplicatedTest.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- ReplicatedTest.java 2 Nov 2006 13:58:52 -0000 1.7
+++ ReplicatedTest.java 7 Nov 2006 03:58:58 -0000 1.8
@@ -1,8 +1,23 @@
/*
- * JBoss, Home of Professional Open Source
+ * 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.
*
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
+ * 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.pojo.passivation;
@@ -12,50 +27,61 @@
import junit.framework.TestSuite;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.pojo.*;
+import org.jboss.cache.pojo.PojoCache;
+import org.jboss.cache.pojo.PojoCacheFactory;
import org.jboss.cache.pojo.test.Person;
+import org.jboss.cache.pojo.test.Address;
+import org.jboss.cache.pojo.test.Link;
import org.jboss.cache.Fqn;
-import org.jboss.cache.AbstractCacheListener;
import org.jboss.cache.CacheListener;
import org.jboss.cache.CacheSPI;
+import org.jgroups.View;
import java.util.Map;
/**
+ * Replicated passivation test.
*
* @author Ben Wang
*/
+
public class ReplicatedTest extends TestCase
{
Log log = LogFactory.getLog(ReplicatedTest.class);
- PojoCache cache, cache1;
- CacheListener listener;
+ PojoCache cache_, cache1_;
+ MyCacheListener listener_;
public ReplicatedTest(String name)
{
super(name);
- listener = new PassivationListener();
}
protected void setUp() throws Exception
{
super.setUp();
log.info("setUp() ....");
- String configFile = "META-INF/replSync-passivation-service.xml";
+ String configFile = "META-INF/pojocache-passivation-service.xml";
boolean toStart = false;
- cache = PojoCacheFactory.createCache(configFile, toStart);
- cache.start();
- cache1 = PojoCacheFactory.createCache(configFile, toStart);
- cache1.start();
- ((CacheSPI)cache1.getCache()).getNotifier().addCacheListener(listener);
+ cache_ = PojoCacheFactory.createCache(configFile, toStart);
+ cache_.getCache().getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.BatchModeTransactionManagerLookup");
+
+ cache_.start();
+
+ cache1_ = PojoCacheFactory.createCache(configFile, toStart);
+ cache1_.getCache().getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.BatchModeTransactionManagerLookup");
+
+ listener_ = new MyCacheListener();
+ cache1_.getCache().addCacheListener(listener_);
+
+ cache1_.start();
}
protected void tearDown() throws Exception
{
super.tearDown();
- cache.getCache().getRoot().remove(Fqn.fromString("/"));
- cache.stop();
- cache1.stop();
+ cache_.getCache().removeNode(Fqn.fromString("/"));
+ cache_.stop();
+ cache1_.stop();
}
// public void testDummy() {}
@@ -65,85 +91,245 @@
Person p = new Person();
p.setName(name);
p.setAge(age);
+ Address add = new Address();
+ add.setZip(95123);
+ add.setCity("San Jose");
+ p.setAddress(add);
return p;
}
- public void testSimple() throws Exception
+ private void sanityCheck() throws InterruptedException
+ {
+ Thread.sleep(100);
+ if(listener_.getActivationCount() == 0 || listener_.getPassivationCount() == 0)
+ {
+ fail("Sanity checking for passivation failed. Counters: activation - " +listener_.getActivationCount()
+ + " passivation - " +listener_.getPassivationCount());
+ }
+
+ listener_.reset();
+ }
+
+ public void testFindAfterPassivation() throws Exception
{
- log.info("testSimple() ....");
- String id = "/person/test1";
- Person ben = createPerson("Ben Wang", 40);
- cache.attach(id, ben);
- cache1.find(id);
+ log.info("testFindAfterPassivation() ....");
+ String id = "person";
+ Person joe = createPerson("Joe Black", 20);
+ cache_.attach(id, joe);
+ Thread.sleep(9100); // default is 3 seconds so joe should have been passivated.
- Thread.sleep(11000);
assertFalse("Node should be evicted ",
- cache.getCache().hasChild(new Fqn(id)));
+ cache_.getCache().hasChild(new Fqn(id)));
+
+ Person p = (Person)cache1_.find(id);
+ assertNotNull("Person on remote node ", p);
+
+ sanityCheck();
+ }
+
+ public void testRemoteSetAfterPassivation() throws Exception
+ {
+ log.info("testFindAfterPassivation() ....");
+ String id = "person";
+ Person joe = createPerson("Joe Black", 20);
+ cache_.attach(id, joe);
+
+ Person p = (Person)cache1_.find(id);
+ assertNotNull("Person on remote node ", p);
+
+ Thread.sleep(9100); // default is 3 seconds so joe should have been passivated.
+
+ assertFalse("Node should be evicted ",
+ cache_.getCache().hasChild(new Fqn(id)));
+
+ Address addr = new Address();
+ addr.setCity("Taipei");
+ addr.setZip(106);
+
+ p.setAddress(addr);
+
+ sanityCheck();
+ }
+
+ public void testMultipleReference() throws Exception
+ {
+ log.info("testMultipleReference() ...");
+ String id1 = "/person/ben";
+ cache_.attach(id1, createPerson("Ben Hogan", 51));
+ Person joe = (Person) cache_.find(id1);
+ String id = "/person/joe";
+ cache_.attach(id, createPerson("Joe Black", 31));
+ Person ben = (Person) cache_.find(id);
+
+ Address addr = new Address();
+ addr.setStreet("123 Albert Ave.");
+ addr.setCity("Sunnyvale");
+ addr.setZip(94087);
+
+ // They share the sub-object: address
+ log.info("testMultipleReference(): set Joe address");
+ joe.setAddress(addr);
+ log.info("testMultipleReference(): set Ben address");
+ ben.setAddress(addr);
+
+ log.info("testMultipleReference(): verify");
+ Address add1 = (Address) ((Person) cache1_.find(id)).getAddress();
+ Address add2 = (Address) ((Person) cache1_.find(id)).getAddress();
+ assertEquals(add1.getCity(), add2.getCity());
+ addr.setCity("Santa Clara");
+ assertEquals(add1.getCity(), add2.getCity());
+
+ Thread.sleep(9100); // default is 3 seconds so joe should have been passivated.
assertFalse("Node should be evicted ",
- cache1.getCache().hasChild(new Fqn(id)));
+ cache_.getCache().hasChild(new Fqn(id)));
- // Note that we can't run this line becuase two caches are still sharing the
- // same cache loader file from junit.
-// assertEquals("Ben Wang", ben.getName());
+ assertEquals("City is ", "Santa Clara", add2.getCity());
- assertEquals("Ben Wang", ((Person) cache1.find(id)).getName());
- cache.detach(id);
+ Thread.sleep(9100); // default is 3 seconds so joe should have been passivated.
+ assertEquals("City is ", "Santa Clara", joe.getAddress().getCity());
+
+ cache_.detach(id);
+ cache_.detach(id1);
+ }
+
+ public void testRemoveObject1() throws Exception
+ {
+ log.info("testRemoveObject1() ...");
+ cache_.attach("/person/joe", createPerson("Joe Black", 31));
+ Person joe = (Person) cache_.find("/person/joe");
+ cache_.attach("/person/ben", createPerson("Ben Hogan", 51));
+ Person ben = (Person) cache_.find("/person/ben");
+
+ Address addr = new Address();
+ addr.setStreet("123 Albert Ave.");
+ addr.setCity("Sunnyvale");
+ addr.setZip(94087);
+
+ // They share the sub-object: address
+ log.info("testMultipleReference(): set Joe address");
+ joe.setAddress(addr);
+ log.info("testMultipleReference(): set Ben address");
+ ben.setAddress(addr);
+
+ Address add1 = (Address) ((Person) cache1_.find("/person/joe")).getAddress();
+ Address add2 = (Address) ((Person) cache1_.find("/person/ben")).getAddress();
+ assertEquals(add1.getCity(), add2.getCity());
+ addr.setCity("Santa Clara");
+ assertEquals(add1.getCity(), add2.getCity());
+
+ Thread.sleep(9100);
+ // Remove pojo joe will relocate the address field to ben's
+ cache_.detach("/person/joe");
+ add2 = (Address) ((Person) cache1_.find("/person/ben")).getAddress();
+ assertEquals("City ", "Santa Clara", add2.getCity());
+ }
+
+ public void testCircularReference1() throws Exception
+ {
+ log.info("testCircularReference1() ...");
+ Link parent = new Link("parent");
+ Link child = new Link("child");
+ parent.setLink(child);
+ child.setLink(parent);
+ cache_.attach("/link/parent", parent);
+
+ Thread.sleep(9100);
+ assertEquals("parent", ((Link) cache1_.find("/link/parent")).getName());
+ assertEquals("child", ((Link) cache1_.find("/link/parent")).getLink().getName());
}
public static Test suite() throws Exception
{
- return new TestSuite(org.jboss.cache.pojo.passivation.ReplicatedTest.class);
+ return new TestSuite(ReplicatedTest.class);
}
public static void main(String[] args) throws Exception
{
- junit.textui.TestRunner.run(org.jboss.cache.pojo.passivation.ReplicatedTest.suite());
+ junit.textui.TestRunner.run(suite());
+ }
+
+ public class MyCacheListener implements CacheListener
+ {
+ int activation = 0;
+ int passivation = 0;
+
+ public int getActivationCount() { return activation;}
+
+ public int getPassivationCount() { return passivation;}
+
+ public void reset()
+ {
+ activation = 0;
+ passivation = 0;
+ }
+
+ public void nodeCreated(Fqn fqn, boolean pre, boolean isLocal)
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
}
+ public void nodeModified(Fqn fqn, boolean pre, boolean isLocal, Map data)
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void nodeRemoved(Fqn fqn, boolean pre, boolean isLocal, Map data)
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
- class PassivationListener extends AbstractCacheListener
+ public void nodeVisited(Fqn fqn, boolean pre)
{
- int counter = 0;
- int loadedCounter = 0;
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
- public int getCounter()
+ public void nodeEvicted(Fqn fqn, boolean pre, boolean isLocal)
{
- return counter;
}
- public void resetCounter()
+ public void nodeLoaded(Fqn fqn, boolean pre, Map data)
{
- counter = 0;
- loadedCounter = 0;
+ }
+
+ public void nodeMoved(Fqn from, Fqn to, boolean pre)
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
}
public void nodeActivated(Fqn fqn, boolean pre)
{
- if (!pre)
+ if(!pre)
{
- counter++;
- System.out.println("nodeActivate(): counter: " + counter);
- System.out.println("nodeActivate(): " + fqn);
+ System.out.println("nodeActivated: " + fqn);
+ activation++;
}
}
public void nodePassivated(Fqn fqn, boolean pre)
{
- if (pre)
+ if(pre)
{
- System.out.println("nodePassivate(): " +fqn);
+ System.out.println("nodePassivated: " + fqn);
+ passivation++;
}
}
- public void nodeLoaded(Fqn f, boolean pre, Map data)
- {
- if (!pre)
+ public void cacheStarted(CacheSPI cache)
{
- loadedCounter++;
+ //To change body of implemented methods use File | Settings | File Templates.
}
+
+ public void cacheStopped(CacheSPI cache)
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
}
+ public void viewChange(View new_view) // might be MergeView after merging
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
}
+
}
1.8 +127 -38 JBossCache/tests-50/functional/org/jboss/cache/pojo/passivation/LocalTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: LocalTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests-50/functional/org/jboss/cache/pojo/passivation/LocalTest.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- LocalTest.java 31 Oct 2006 11:07:18 -0000 1.7
+++ LocalTest.java 7 Nov 2006 03:58:58 -0000 1.8
@@ -18,10 +18,14 @@
import org.jboss.cache.pojo.test.Link;
import org.jboss.cache.pojo.test.Person;
import org.jboss.cache.Fqn;
+import org.jboss.cache.CacheListener;
+import org.jboss.cache.CacheSPI;
import org.jboss.util.id.UID;
+import org.jgroups.View;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
/**
* Basic PojoCache test case.
@@ -33,6 +37,7 @@
{
Log log = LogFactory.getLog(org.jboss.cache.pojo.passivation.LocalTest.class);
PojoCache cache_;
+ MyCacheListener listener_;
public LocalTest(String name)
{
@@ -43,18 +48,21 @@
{
super.setUp();
log.info("setUp() ....");
- String configFile = "META-INF/local-passivation-service.xml";
+ String configFile = "META-INF/pojocache-passivation-service.xml";
boolean toStart = false;
cache_ = PojoCacheFactory.createCache(configFile, toStart);
cache_.getCache().getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.BatchModeTransactionManagerLookup");
+ listener_ = new MyCacheListener();
+ cache_.getCache().addCacheListener(listener_);
+
cache_.start();
}
protected void tearDown() throws Exception
{
super.tearDown();
- cache_.getCache().getRoot().remove(Fqn.fromString("/"));
+ cache_.getCache().removeNode(Fqn.fromString("/"));
cache_.stop();
}
@@ -72,23 +80,15 @@
return p;
}
- private Person createHugePerson(String name, int age)
+ private void sanityCheck()
{
- Person p = new Person();
- p.setName(name);
- p.setAge(age);
- Address add = new Address();
- add.setZip(95123);
- add.setCity("San Jose");
- p.setAddress(add);
- List list = new ArrayList();
- for(int i=0; i < 10; i++)
+ if(listener_.getActivationCount() == 0 || listener_.getPassivationCount() == 0)
{
- String tmp = RandomString.randomstring(200000, 220000);
- list.add(tmp);
+ fail("Sanity checking for passivation failed. Counters: activation - " +listener_.getActivationCount()
+ + " passivation - " +listener_.getPassivationCount());
}
- p.setLanguages(list);
- return p;
+
+ listener_.reset();
}
public void testSimple() throws Exception
@@ -97,7 +97,7 @@
String id = "person";
Person joe = createPerson("Joe Black", 20);
cache_.attach(id, joe);
- Thread.sleep(11000); // default is 3 seconds so joe should have been passivated.
+ Thread.sleep(9000); // default is 3 seconds so joe should have been passivated.
// assertFalse("Node should be evicted ",
// cache_.getCache().exists(id));
@@ -107,6 +107,28 @@
assertEquals("age ", 20, joe.getAge());
joe.setAge(30);
assertEquals("age ", 30, joe.getAge());
+
+ sanityCheck();
+ }
+
+ public void testSetAddress() throws Exception
+ {
+ log.info("testAddress() ....");
+ String id = "person";
+ Person joe = createPerson("Joe Black", 20);
+ cache_.attach(id, joe);
+ Thread.sleep(9000); // default is 3 seconds so joe should have been passivated.
+
+ assertFalse("Node should be evicted ",
+ cache_.getCache().hasChild(new Fqn(id)));
+
+ Address addr = new Address();
+ addr.setCity("Taipei");
+ addr.setZip(106);
+
+ joe.setAddress(addr);
+
+ sanityCheck();
}
public void testFindAgain() throws Exception
@@ -115,7 +137,7 @@
String id = "person";
Person joe = createPerson("Joe Black", 20);
cache_.attach(id, joe);
- Thread.sleep(11000); // default is 3 seconds so joe should have been passivated.
+ Thread.sleep(9000); // default is 3 seconds so joe should have been passivated.
// assertFalse("Node should be evicted ",
// cache_.getCache().exists(id));
@@ -136,6 +158,8 @@
assertEquals("age ", p.getAge(), joe.getAge());
assertFalse("Instance not equal (this is known side effect) ", joe == p);
+
+ sanityCheck();
}
public void testMultipleReference() throws Exception
@@ -166,7 +190,7 @@
addr.setCity("Santa Clara");
assertEquals(add1.getCity(), add2.getCity());
- Thread.sleep(11000); // default is 3 seconds so joe should have been passivated.
+ Thread.sleep(9000); // default is 3 seconds so joe should have been passivated.
// assertFalse("Node should be evicted ",
// cache_.getCache().exists("/person/joe"));
assertFalse("Node should be evicted ",
@@ -174,7 +198,7 @@
assertEquals("City is ", "Santa Clara", add2.getCity());
- Thread.sleep(11000); // default is 3 seconds so joe should have been passivated.
+ Thread.sleep(9000); // default is 3 seconds so joe should have been passivated.
assertEquals("City is ", "Santa Clara", joe.getAddress().getCity());
cache_.detach(id);
@@ -206,7 +230,7 @@
addr.setCity("Santa Clara");
assertEquals(add1.getCity(), add2.getCity());
- Thread.sleep(11000);
+ Thread.sleep(9000);
// Remove pojo joe will relocate the address field to ben's
cache_.detach("/person/joe");
add2 = (Address) ((Person) cache_.find("/person/ben")).getAddress();
@@ -222,27 +246,11 @@
child.setLink(parent);
cache_.attach("/link/parent", parent);
- Thread.sleep(11000);
+ Thread.sleep(9000);
assertEquals("parent", ((Link) cache_.find("/link/parent")).getName());
assertEquals("child", ((Link) cache_.find("/link/parent")).getLink().getName());
}
- public void XtestGC() throws Exception
- {
- log.info("testGC() ....");
- int i = 0;
- while(i < 500)
- {
- UID uid = new UID();
- String id = "/person/test/" +uid.toString();
- Person p = createHugePerson("Joe Black", 32);
- cache_.attach(id, p);
-// cache_.detach(id);
- i++;
- }
-// Thread.sleep(10000000);
- }
-
public static Test suite() throws Exception
{
@@ -255,4 +263,85 @@
junit.textui.TestRunner.run(org.jboss.cache.pojo.passivation.LocalTest.suite());
}
+ public class MyCacheListener implements CacheListener
+ {
+ int activation = 0;
+ int passivation = 0;
+
+ public int getActivationCount() { return activation;}
+
+ public int getPassivationCount() { return passivation;}
+
+ public void reset()
+ {
+ activation = 0;
+ passivation = 0;
+ }
+
+ public void nodeCreated(Fqn fqn, boolean pre, boolean isLocal)
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void nodeModified(Fqn fqn, boolean pre, boolean isLocal, Map data)
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void nodeRemoved(Fqn fqn, boolean pre, boolean isLocal, Map data)
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void nodeVisited(Fqn fqn, boolean pre)
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void nodeEvicted(Fqn fqn, boolean pre, boolean isLocal)
+ {
+ }
+
+ public void nodeLoaded(Fqn fqn, boolean pre, Map data)
+ {
+ }
+
+ public void nodeMoved(Fqn from, Fqn to, boolean pre)
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void nodeActivated(Fqn fqn, boolean pre)
+ {
+ if(!pre)
+ {
+ System.out.println("nodeActivated: " + fqn);
+ activation++;
+ }
+ }
+
+ public void nodePassivated(Fqn fqn, boolean pre)
+ {
+ if(pre)
+ {
+ System.out.println("nodePassivated: " + fqn);
+ passivation++;
+ }
+ }
+
+ public void cacheStarted(CacheSPI cache)
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void cacheStopped(CacheSPI cache)
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void viewChange(View new_view) // might be MergeView after merging
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+ }
}
More information about the jboss-cvs-commits
mailing list