[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/passivation ...
Manik Surtani
msurtani at jboss.com
Wed Sep 6 11:31:00 EDT 2006
User: msurtani
Date: 06/09/06 11:31:00
Modified: tests/functional/org/jboss/cache/passivation
BasicPassivationTest.java
LocalPassivationIntegrationTest.java
PassivationTestsBase.java
PassivationToLocalDelegatingCacheLoaderTest.java
Log:
Removed TreeCache dependency on ServiceMBeanSupport
Revision Changes Path
1.8 +3 -3 JBossCache/tests/functional/org/jboss/cache/passivation/BasicPassivationTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: BasicPassivationTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/passivation/BasicPassivationTest.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- BasicPassivationTest.java 30 Aug 2006 15:18:09 -0000 1.7
+++ BasicPassivationTest.java 6 Sep 2006 15:31:00 -0000 1.8
@@ -19,7 +19,7 @@
/**
* @author Ben Wang
- * @version $Revision: 1.7 $
+ * @version $Revision: 1.8 $
*/
public class BasicPassivationTest extends TestCase
{
@@ -57,14 +57,14 @@
cache_.setConfiguration(new XmlConfigurationParser().parseFile("META-INF/local-passivation-service.xml")); // read in generic local xml
cache_.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
CacheListener listener = new TestCacheListener();
- cache_.startService();
+ cache_.start();
cache_.getNotifier().addCacheListener(listener);
}
public void tearDown() throws Exception
{
super.tearDown();
- cache_.stopService();
+ cache_.stop();
}
public void testBasic()
1.8 +2 -2 JBossCache/tests/functional/org/jboss/cache/passivation/LocalPassivationIntegrationTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: LocalPassivationIntegrationTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/passivation/LocalPassivationIntegrationTest.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- LocalPassivationIntegrationTest.java 4 Sep 2006 21:06:18 -0000 1.7
+++ LocalPassivationIntegrationTest.java 6 Sep 2006 15:31:00 -0000 1.8
@@ -41,7 +41,7 @@
initCaches(cache_);
cache_.getConfiguration().setUseRegionBasedMarshalling(true);
- cache_.startService();
+ cache_.start();
cache_.getNotifier().addCacheListener(listener_);
listener_.resetCounter();
@@ -63,7 +63,7 @@
public void tearDown() throws Exception
{
super.tearDown();
- cache_.stopService();
+ cache_.stop();
}
/**
1.16 +487 -368 JBossCache/tests/functional/org/jboss/cache/passivation/PassivationTestsBase.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: PassivationTestsBase.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/passivation/PassivationTestsBase.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- PassivationTestsBase.java 31 Aug 2006 14:56:46 -0000 1.15
+++ PassivationTestsBase.java 6 Sep 2006 15:31:00 -0000 1.16
@@ -3,42 +3,50 @@
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
-import org.jboss.cache.*;
-import org.jboss.cache.xml.XmlHelper;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.CacheException;
+import org.jboss.cache.DataNode;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.Modification;
+import org.jboss.cache.TreeCache;
import org.jboss.cache.loader.CacheLoader;
import org.jboss.cache.loader.SamplePojo;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.statetransfer.StateTransferManager;
import org.jboss.cache.transaction.DummyTransactionManager;
+import org.jboss.cache.xml.XmlHelper;
import org.jboss.invocation.MarshalledValueInputStream;
import org.jboss.invocation.MarshalledValueOutputStream;
import org.w3c.dom.Element;
import javax.transaction.NotSupportedException;
import javax.transaction.Transaction;
-
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.Serializable;
-import java.util.*;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
/**
* Base tests for passivation using any of the cache loaders
*
* @author <a href="mailto:{hmesha at novell.com}">{Hany Mesha}</a>
- * @version $Id: PassivationTestsBase.java,v 1.15 2006/08/31 14:56:46 vblagojevic Exp $
+ * @version $Id: PassivationTestsBase.java,v 1.16 2006/09/06 15:31:00 msurtani Exp $
*/
-abstract public class PassivationTestsBase extends TestCase {
+abstract public class PassivationTestsBase extends TestCase
+{
Log log = LogFactory.getLog(getClass());
//Cache Loader fields
TreeCache cache;
- CacheLoader loader=null;
- Transaction tx=null;
+ CacheLoader loader = null;
+ Transaction tx = null;
static final Fqn FQN = new Fqn("key");
@@ -57,38 +65,43 @@
return XmlHelper.stringToElement(xml);
}
- protected void setUp() throws Exception {
+ protected void setUp() throws Exception
+ {
super.setUp();
log.debug("Testing " + getName());
log.debug("");
- cache=new TreeCache();
+ cache = new TreeCache();
cache.getConfiguration().setCacheMode("local");
configureCache();
// cache.setCacheLoaderPreload("/1/2/3/4/5/d");
cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
cache.getConfiguration().setIsolationLevel(IsolationLevel.SERIALIZABLE);
- cache.createService();
- cache.startService();
- loader=cache.getCacheLoader();
+ cache.create();
+ cache.start();
+ loader = cache.getCacheLoader();
}
abstract protected void configureCache() throws Exception;
- protected void tearDown() throws Exception {
+ protected void tearDown() throws Exception
+ {
super.tearDown();
- if(tx != null) {
- try {
+ if (tx != null)
+ {
+ try
+ {
tx.commit();
}
- catch(Throwable e) {
+ catch (Throwable e)
+ {
e.printStackTrace();
}
}
cache.remove("/");
loader.remove(Fqn.fromString("/"));
- cache.stopService();
- cache.destroyService();
+ cache.stop();
+ cache.destroy();
}
@@ -97,16 +110,17 @@
; // returns immediately in this case. Subclasses may override where a delay is needed.
}
- public void testPrintPassivation() throws Exception {
- final Fqn NODE=Fqn.fromString("/test");
- final String KEY="key";
+ public void testPrintPassivation() throws Exception
+ {
+ final Fqn NODE = Fqn.fromString("/test");
+ final String KEY = "key";
loader.remove(NODE);
cache.put(NODE, KEY, new Integer(10));
cache.evict(NODE);
assertTrue(loader.exists(NODE));
addDelay();
log.info("print node " + NODE);
- String ret=cache.print(NODE);
+ String ret = cache.print(NODE);
assertNotNull(ret);
log.info("loader exists " + NODE);
assertTrue(!loader.exists(NODE));
@@ -114,59 +128,66 @@
assertFalse(loader.exists(NODE));
}
- public void testPutPassivation() throws Exception {
- final String NODE="/test";
- final String KEY="key";
- Object retval=null;
+ public void testPutPassivation() throws Exception
+ {
+ final String NODE = "/test";
+ final String KEY = "key";
+ Object retval = null;
cache.remove(NODE); // nothing to remove
addDelay();
- retval=cache.put(NODE, KEY, new Integer(10)); // put in memory
+ retval = cache.put(NODE, KEY, new Integer(10)); // put in memory
assertNull(retval);
- retval=cache.put(NODE, KEY, new Integer(20)); // put in memory
+ retval = cache.put(NODE, KEY, new Integer(20)); // put in memory
addDelay();
assertEquals(new Integer(10), retval); // get from memory
cache.evict(Fqn.fromString(NODE)); // passivate node
addDelay();
log.debug("______________");
- retval=cache.put(NODE, KEY, new Integer(30)); // activate node then does put in memory
+ retval = cache.put(NODE, KEY, new Integer(30)); // activate node then does put in memory
assertFalse(loader.exists(Fqn.fromString(NODE)));
assertEquals(new Integer(20), retval);
}
- public void testPut2Passivation() throws CacheException {
- final String NODE="/a/b/c";
- final String KEY="key";
- Object retval=null;
+ public void testPut2Passivation() throws CacheException
+ {
+ final String NODE = "/a/b/c";
+ final String KEY = "key";
+ Object retval = null;
cache.remove(NODE); // nothing to remove
addDelay();
- retval=cache.put(NODE, KEY, new Integer(10)); // put in memory
+ retval = cache.put(NODE, KEY, new Integer(10)); // put in memory
assertNull(retval);
addDelay();
- retval=cache.put(NODE, KEY, new Integer(20)); // put in memory
+ retval = cache.put(NODE, KEY, new Integer(20)); // put in memory
assertEquals(new Integer(10), retval);
cache.evict(Fqn.fromString(NODE)); // passivate node
cache.evict(Fqn.fromString("/a/b")); // passivate parent node
cache.evict(Fqn.fromString("/a")); // passivate parent node
addDelay();
- try{
+ try
+ {
assertTrue(loader.exists(Fqn.fromString("/a/b/c")));
}
- catch(Exception e){
+ catch (Exception e)
+ {
fail(e.toString());
}
- retval=cache.put(NODE, KEY, new Integer(30)); // activate node, put in memory new value
- try{
+ retval = cache.put(NODE, KEY, new Integer(30)); // activate node, put in memory new value
+ try
+ {
assertFalse(loader.exists(Fqn.fromString(NODE)));
}
- catch(Exception e){
+ catch (Exception e)
+ {
fail(e.toString());
}
assertEquals(new Integer(20), retval);
}
- public void testSerializationPassivation() throws CacheException {
- SamplePojo pojo=new SamplePojo(39, "Hany");
+ public void testSerializationPassivation() throws CacheException
+ {
+ SamplePojo pojo = new SamplePojo(39, "Hany");
pojo.getHobbies().add("Running");
pojo.getHobbies().add("Beerathlon");
pojo.getHobbies().add("Triathlon");
@@ -174,17 +195,21 @@
addDelay();
assertNotNull(cache.get("/mypojo", new Integer(322649))); // get from memory
cache.evict(Fqn.fromString("/mypojo")); // passivate node
- try{
+ try
+ {
assertTrue(loader.exists(Fqn.fromString("/mypojo")));
}
- catch(Exception e) {
+ catch (Exception e)
+ {
fail(e.toString());
}
- SamplePojo pojo2=(SamplePojo)cache.get("/mypojo", new Integer(322649)); // activate node
- try{
+ SamplePojo pojo2 = (SamplePojo) cache.get("/mypojo", new Integer(322649)); // activate node
+ try
+ {
assertFalse(loader.exists(Fqn.fromString("/mypojo")));
}
- catch(Exception e) {
+ catch (Exception e)
+ {
fail(e.toString());
}
assertNotNull(pojo2);
@@ -193,11 +218,15 @@
assertEquals(3, pojo2.getHobbies().size());
}
- /** Just adds some data that wil be later retrieved. This test has to be run first */
- public void testPopulate() {
- try {
- Map m=new HashMap();
- for(int i=0; i < 10; i++)
+ /**
+ * Just adds some data that wil be later retrieved. This test has to be run first
+ */
+ public void testPopulate()
+ {
+ try
+ {
+ Map m = new HashMap();
+ for (int i = 0; i < 10; i++)
m.put("key" + i, "val" + i);
cache.put("/a/b/c", m);
cache.load("/1/2/3/4/5");
@@ -217,22 +246,26 @@
assertTrue(cache.exists("/a/b/c"));
assertFalse(cache.exists("/a/b/c/d"));
}
- catch(Exception e) {
+ catch (Exception e)
+ {
fail(e.toString());
}
}
- public void testPreloadingPassivation() throws Exception {
+ public void testPreloadingPassivation() throws Exception
+ {
cache.remove("/"); // remove nothing
cache.put("1/2/3/4/5/d", "key", "val"); // put in memory
cache.evict(Fqn.fromString("1/2/3/4/5/d")); // passivate node
System.out.println("-- checking for 1/2/3/4/5/d");
addDelay();
- try{
+ try
+ {
assertTrue(loader.exists(Fqn.fromString("1/2/3/4/5/d")));
}
- catch(Exception e) {
+ catch (Exception e)
+ {
fail(e.toString());
}
cache.get("1/2/3/4/5/d"); // get from loader but doesn't load attributes
@@ -244,29 +277,34 @@
}
-
- public void testCacheLoading2() throws CacheException {
- Set keys=null;
+ public void testCacheLoading2() throws CacheException
+ {
+ Set keys = null;
cache.put("/a/b/c", "key", "val");
- try {
- keys=cache.getKeys("/a/b/c");
+ try
+ {
+ keys = cache.getKeys("/a/b/c");
assertNotNull(keys);
assertEquals(1, keys.size());
}
- catch(Exception e) {
+ catch (Exception e)
+ {
fail(e.toString());
}
- try {
+ try
+ {
keys.add("myKey");
}
- catch(UnsupportedOperationException ex) {
+ catch (UnsupportedOperationException ex)
+ {
fail("unsupported operation: " + ex);
}
}
- public void testExists() throws Exception {
+ public void testExists() throws Exception
+ {
cache.put("/eins/zwei/drei", "key1", "val1");
assertTrue(cache.exists("/eins/zwei/drei"));
assertTrue(cache.exists("/eins/zwei/drei", "key1"));
@@ -275,12 +313,13 @@
assertFalse(cache.exists("/une/due/tre", "key1"));
}
- public void testGetChildren() throws Exception {
- cache.put("/d/one", (Map)null);
- cache.put("/d/two", (Map)null);
- cache.put("/d/three", (Map)null);
+ public void testGetChildren() throws Exception
+ {
+ cache.put("/d/one", (Map) null);
+ cache.put("/d/two", (Map) null);
+ cache.put("/d/three", (Map) null);
cache.get("/d");
- Set children=cache.getChildrenNames("/d");
+ Set children = cache.getChildrenNames("/d");
assertNotNull(children);
assertEquals(3, children.size());
assertTrue(children.contains("one"));
@@ -289,7 +328,8 @@
}
- public void testGetChildrenWithEvictionPassivation() throws CacheException {
+ public void testGetChildrenWithEvictionPassivation() throws CacheException
+ {
cache.put("/a/b/c/1", null);
cache.put("/a/b/c/2", null);
cache.put("/a/b/c/3", null);
@@ -301,98 +341,116 @@
cache.evict(Fqn.fromString("/a")); // passivate node
cache.evict(Fqn.fromString("/")); // passivate node
addDelay();
- Set children=cache.getChildrenNames("/a/b/c"); // load node children names
+ Set children = cache.getChildrenNames("/a/b/c"); // load node children names
assertNotNull(children);
assertEquals(3, children.size());
assertTrue(children.contains("1"));
assertTrue(children.contains("2"));
assertTrue(children.contains("3"));
- try{
+ try
+ {
assertTrue(loader.exists(Fqn.fromString("/a/b/c")));
}
- catch(Exception e) {
+ catch (Exception e)
+ {
fail(e.toString());
}
cache.get("/a/b/c/1", "test"); // load child
cache.get("/a/b/c/2", "test"); // load child
cache.get("/a/b/c/3", "test"); // load child
cache.get("/a/b/c", "test"); // load attributes
- try{
+ try
+ {
assertFalse(loader.exists(Fqn.fromString("/a/b/c/1")));
assertFalse(loader.exists(Fqn.fromString("/a/b/c/2")));
assertFalse(loader.exists(Fqn.fromString("/a/b/c/3")));
assertFalse(loader.exists(Fqn.fromString("/a/b/c")));
}
- catch(Exception e) {
+ catch (Exception e)
+ {
fail(e.toString());
}
}
- public void testGetChildren2() {
- try {
+ public void testGetChildren2()
+ {
+ try
+ {
cache.put("/1", null);
cache.put("a", null);
- Set children=cache.getChildrenNames("/"); // get root node children names
+ Set children = cache.getChildrenNames("/"); // get root node children names
assertNotNull(children);
assertEquals(2, children.size());
assertTrue(children.contains("1"));
assertTrue(children.contains("a"));
}
- catch(Exception e) {
+ catch (Exception e)
+ {
fail(e.toString());
}
}
- public void testGetChildren3() {
- try {
+ public void testGetChildren3()
+ {
+ try
+ {
cache.put("/1", null);
cache.put("a", null);
- Set children=cache.getChildrenNames(""); // get children from root node
+ Set children = cache.getChildrenNames(""); // get children from root node
assertNotNull(children);
assertEquals(2, children.size());
assertTrue(children.contains("1"));
assertTrue(children.contains("a"));
}
- catch(Exception e) {
+ catch (Exception e)
+ {
fail(e.toString());
}
}
- public void testGetChildren4() {
- try {
- if(!cache.exists("/a/b/c"))
+ public void testGetChildren4()
+ {
+ try
+ {
+ if (!cache.exists("/a/b/c"))
cache.put("/a/b/c", null);
- Set children=cache.getChildrenNames((Fqn)null); // get "null* node children names
+ Set children = cache.getChildrenNames((Fqn) null); // get "null* node children names
assertNull(children);
}
- catch(Exception e) {
+ catch (Exception e)
+ {
fail(e.toString());
}
}
- public void testGetChildren5() {
- try {
+ public void testGetChildren5()
+ {
+ try
+ {
cache.put("/a/1", null);
cache.put("/a/2", null);
cache.put("/a/3", null);
System.out.println("cache is " + cache.printLockInfo());
- DataNode n=cache.get("/a");
+ DataNode n = cache.get("/a");
assertNotNull(n);
- Set children=cache.getChildrenNames("/a");
+ Set children = cache.getChildrenNames("/a");
assertNotNull(children);
assertEquals(3, children.size());
}
- catch(Exception e) {
+ catch (Exception e)
+ {
fail(e.toString());
}
}
- public void testGetChildren6Passivation() {
- try {
+ public void testGetChildren6Passivation()
+ {
+ try
+ {
cache.put("/a/1", null); // put node in memory
cache.put("/a/2", null); // put node in memory
cache.put("/a/3", null); // put node in memory
@@ -406,7 +464,7 @@
addDelay();
assertNotNull(cache.get("/a")); // load node
assertTrue(loader.exists(Fqn.fromString("/a"))); // children haven't been loaded
- Set children=cache.getChildrenNames("/a");
+ Set children = cache.getChildrenNames("/a");
assertNotNull("No children were loaded", children);
System.out.println("children: " + children);
assertEquals("3 children weren't loaded", 3, children.size());
@@ -419,13 +477,16 @@
cache.get("/a", "test"); // activate node
assertFalse(loader.exists(Fqn.fromString("/a")));
}
- catch(Exception e) {
+ catch (Exception e)
+ {
fail(e.toString());
}
}
- public void testGetChildren7Passivation() {
- try {
+ public void testGetChildren7Passivation()
+ {
+ try
+ {
cache.put("/a/1", null);
cache.put("/a/2", null);
cache.put("/a/3", null);
@@ -438,10 +499,10 @@
assertTrue(loader.exists(Fqn.fromString("/a")));
System.out.println("cache is " + cache.printLockInfo());
addDelay();
- Object val=cache.get("/a", "test"); // load node's attributes but not children
+ Object val = cache.get("/a", "test"); // load node's attributes but not children
assertEquals("attributes weren't loaded", "test", val);
- Set children=cache.getChildrenNames("/a"); // get node's children names
+ Set children = cache.getChildrenNames("/a"); // get node's children names
assertNotNull("No children were loaded", children);
System.out.println("children: " + children);
assertEquals("3 children weren't loaded", 3, children.size());
@@ -453,13 +514,16 @@
assertFalse(loader.exists(Fqn.fromString("/a/3")));
assertTrue(loader.exists(Fqn.fromString("/a")));
}
- catch(Exception e) {
+ catch (Exception e)
+ {
fail(e.toString());
}
}
- public void testGetChildren8Passivation() {
- try {
+ public void testGetChildren8Passivation()
+ {
+ try
+ {
cache.put("/a/1", null);
cache.put("/a/2", null);
cache.put("/a/3", null);
@@ -476,19 +540,22 @@
assertNull(cache.get("/a/1", "test")); // activate node
assertFalse(loader.exists(Fqn.fromString("/a/1"))); // loaded attributes and has no children
- Set children=cache.getChildrenNames("/a"); // load children names
+ Set children = cache.getChildrenNames("/a"); // load children names
assertNotNull("No children were loaded", children);
System.out.println("children: " + children);
assertEquals("3 children weren't loaded", 3, children.size());
assertTrue(loader.exists(Fqn.fromString("/a"))); //loaded children but didn't initalizae them
}
- catch(Exception e) {
+ catch (Exception e)
+ {
fail(e.toString());
}
}
- public void testGetChildren9Passivation() {
- try {
+ public void testGetChildren9Passivation()
+ {
+ try
+ {
cache.put("/a/1", null);
cache.put("/a/2", null);
cache.put("/a/3", null);
@@ -507,7 +574,7 @@
assertFalse(loader.exists(Fqn.fromString("/a/2")));
cache.get("/a/3", "test"); // activate node
assertFalse(loader.exists(Fqn.fromString("/a/3")));
- Set children=cache.getChildrenNames("/a"); // get node's children names
+ Set children = cache.getChildrenNames("/a"); // get node's children names
assertNotNull("No children were loaded", children);
System.out.println("children: " + children);
assertEquals("3 children weren't loaded", 3, children.size());
@@ -527,21 +594,24 @@
assertFalse(loader.exists(Fqn.fromString("/a/2")));
cache.get("/a/3", "test"); // activate node
assertFalse(loader.exists(Fqn.fromString("/a/3")));
- children=cache.getChildrenNames("/a"); // get children names
+ children = cache.getChildrenNames("/a"); // get children names
assertNotNull("No children were loaded", children);
System.out.println("children: " + children);
assertEquals("3 children weren't loaded", 3, children.size());
assertNull(cache.get("/a", "test")); // load attributes and has no children by now, activation
assertFalse(loader.exists(Fqn.fromString("/a")));
}
- catch(Exception e) {
+ catch (Exception e)
+ {
fail(e.toString());
}
}
- public void testGetChildren10Passivation() {
- try {
+ public void testGetChildren10Passivation()
+ {
+ try
+ {
cache.put("/a/1", null);
cache.put("/a/2", null);
cache.put("/a/3", null);
@@ -561,7 +631,7 @@
assertFalse(loader.exists(Fqn.fromString("/a/2")));
cache.get("/a/3", "test"); // passivate node
assertFalse(loader.exists(Fqn.fromString("/a/3")));
- Set children=cache.getChildrenNames("/a");
+ Set children = cache.getChildrenNames("/a");
assertNotNull("No children were loaded", children);
System.out.println("children: " + children);
assertEquals("3 children weren't loaded", 3, children.size());
@@ -569,67 +639,74 @@
assertNull(cache.get("/a", "test")); // activate node
assertFalse(loader.exists(Fqn.fromString("/a")));
}
- catch(Exception e) {
+ catch (Exception e)
+ {
fail(e.toString());
}
}
- public void testRemoveData() throws Exception {
- String key="/x/y/z/";
+ public void testRemoveData() throws Exception
+ {
+ String key = "/x/y/z/";
cache.put(key, "keyA", "valA");
cache.put(key, "keyB", "valB");
cache.put(key, "keyC", "valC");
assertEquals(3, cache.getKeys(key).size());
cache.removeData(key);
- Set keys=cache.getKeys(key);
+ Set keys = cache.getKeys(key);
assertEquals(0, keys.size());
cache.remove("/x");
- Object val=cache.get(key, "keyA");
+ Object val = cache.get(key, "keyA");
assertNull(val);
}
- public void testRemoveData2Passivation() throws Exception {
+ public void testRemoveData2Passivation() throws Exception
+ {
Set keys;
- Fqn key=Fqn.fromString("/x/y/z/");
+ Fqn key = Fqn.fromString("/x/y/z/");
cache.put(key, "keyA", "valA");
cache.put(key, "keyB", "valB");
cache.put(key, "keyC", "valC");
addDelay();
- keys=cache.getKeys(key);
+ keys = cache.getKeys(key);
assertEquals(3, keys.size());
cache.removeData(key);
cache.evict(key); // passivate node
addDelay();
- keys=cache.getKeys(key); // activate node
- try{
+ keys = cache.getKeys(key); // activate node
+ try
+ {
assertFalse(loader.exists(key));
}
- catch(Exception e) {
+ catch (Exception e)
+ {
fail(e.toString());
}
assertEquals(0, keys.size());
}
- public void testRemoveData3Passivation() throws Exception {
+ public void testRemoveData3Passivation() throws Exception
+ {
Set keys;
- Fqn key=Fqn.fromString("/x/y/z/");
+ Fqn key = Fqn.fromString("/x/y/z/");
cache.put(key, "keyA", "valA");
cache.put(key, "keyB", "valB");
cache.put(key, "keyC", "valC");
- keys=cache.getKeys(key);
+ keys = cache.getKeys(key);
assertEquals(3, keys.size());
cache.evict(key); // passivate node
assertTrue(loader.exists(key));
cache.removeData(key);
- keys=cache.getKeys(key); // activate node
+ keys = cache.getKeys(key); // activate node
assertFalse(loader.exists(key));
assertEquals(0, keys.size());
}
- public void testRemoveKey() throws Exception {
- String key="/x/y/z/";
+ public void testRemoveKey() throws Exception
+ {
+ String key = "/x/y/z/";
cache.put(key, "keyA", "valA");
cache.put(key, "keyB", "valB");
cache.put(key, "keyC", "valC");
@@ -639,75 +716,85 @@
}
- public void testRemoveKey2() throws CacheException {
- final String NODE="/test";
- final String KEY="key";
- Object retval=null;
+ public void testRemoveKey2() throws CacheException
+ {
+ final String NODE = "/test";
+ final String KEY = "key";
+ Object retval = null;
cache.remove(NODE);
- retval=cache.put(NODE, KEY, new Integer(10));
+ retval = cache.put(NODE, KEY, new Integer(10));
assertNull(retval);
addDelay();
- retval=cache.remove(NODE, KEY);
+ retval = cache.remove(NODE, KEY);
assertEquals(new Integer(10), retval);
addDelay();
- retval=cache.remove(NODE, KEY);
+ retval = cache.remove(NODE, KEY);
assertNull(retval);
}
- public void testRemoveKey3Passivation() throws CacheException {
- final String NODE="/test";
- final String KEY="key";
- Object retval=null;
+ public void testRemoveKey3Passivation() throws CacheException
+ {
+ final String NODE = "/test";
+ final String KEY = "key";
+ Object retval = null;
cache.remove(NODE);
- retval=cache.put(NODE, KEY, new Integer(10));
+ retval = cache.put(NODE, KEY, new Integer(10));
assertNull(retval);
cache.evict(Fqn.fromString(NODE)); // passivate node
addDelay();
- try{
+ try
+ {
assertTrue(loader.exists(Fqn.fromString(NODE)));
assertEquals(new Integer(10), loader.get(Fqn.fromString(NODE)).get(KEY));
}
- catch(Exception e) {
+ catch (Exception e)
+ {
fail(e.toString());
}
- retval=cache.remove(NODE, KEY); // activate node
+ retval = cache.remove(NODE, KEY); // activate node
assertEquals(new Integer(10), retval);
- try{
+ try
+ {
assertFalse(loader.exists(Fqn.fromString(NODE)));
}
- catch(Exception e) {
+ catch (Exception e)
+ {
fail(e.toString());
}
cache.evict(Fqn.fromString(NODE)); // passiave node
addDelay();
- retval=cache.remove(NODE, KEY); // activate node
- try{
+ retval = cache.remove(NODE, KEY); // activate node
+ try
+ {
assertFalse(loader.exists(Fqn.fromString(NODE)));
}
- catch(Exception e) {
+ catch (Exception e)
+ {
fail(e.toString());
}
assertNull(retval);
}
- public void testRemove() throws Exception {
- String key="/x/y/z/";
+ public void testRemove() throws Exception
+ {
+ String key = "/x/y/z/";
cache.put(key, "keyA", "valA");
cache.put(key, "keyB", "valB");
cache.put(key, "keyC", "valC");
cache.remove("/x");
assertNull(cache.get(key, "keyA"));
addDelay();
- Set keys=cache.getKeys(key);
+ Set keys = cache.getKeys(key);
assertNull(keys);
cache.remove("/x");
}
- public void testRemoveRoot() throws Exception {
+ public void testRemoveRoot() throws Exception
+ {
assertEquals(0, cache.getKeys("/").size());
cache.put("/1/2/3/4/5", null);
cache.put("uno/due/tre", null);
@@ -719,17 +806,18 @@
}
- public void testEvictionWithCacheLoaderPassivation() throws Exception {
+ public void testEvictionWithCacheLoaderPassivation() throws Exception
+ {
cache.put("/first/second", "key1", "val1");
cache.put("/first/second/third", "key2", "val2");
cache.evict(Fqn.fromString("/first/second")); // pasivate node to cache loader
addDelay();
assertTrue(loader.exists(Fqn.fromString("/first/second")));
assertTrue(cache.exists("/first"));
- String val=(String)cache.get("/first/second", "key1"); // loads attributes only
+ String val = (String) cache.get("/first/second", "key1"); // loads attributes only
assertTrue(loader.exists(Fqn.fromString("/first/second")));
assertEquals("val1", val);
- String val2=(String)cache.get("/first/second/third", "key2"); // activate node
+ String val2 = (String) cache.get("/first/second/third", "key2"); // activate node
assertFalse(loader.exists(Fqn.fromString("/first/second/third")));
assertEquals("val2", val2);
assertTrue(cache.exists("/first/second/third"));
@@ -738,23 +826,28 @@
}
- public void testEvictionWithCacheLoaderPassivation2() throws Exception {
+ public void testEvictionWithCacheLoaderPassivation2() throws Exception
+ {
cache.put("/first/second/third", "key1", "val1"); // stored in cache loader
cache.evict(Fqn.fromString("/first/second/third")); // passivate node, note: it has no children
addDelay();
- try{
+ try
+ {
assertTrue(loader.exists(Fqn.fromString("/first/second/third")));
}
- catch(Exception e){
+ catch (Exception e)
+ {
fail(e.toString());
}
assertTrue(cache.exists("/first/second"));
assertTrue(cache.exists("/first"));
- String val=(String)cache.get("/first/second/third", "key1"); // activate node
- try{
+ String val = (String) cache.get("/first/second/third", "key1"); // activate node
+ try
+ {
assertFalse(loader.exists(Fqn.fromString("/first/second/third")));
}
- catch(Exception e){
+ catch (Exception e)
+ {
fail(e.toString());
}
assertEquals("val1", val);
@@ -764,8 +857,8 @@
}
-
- public void testEvictionWithGetChildrenNamesPassivation() throws Exception {
+ public void testEvictionWithGetChildrenNamesPassivation() throws Exception
+ {
cache.put("/a/1", null);
cache.put("/a/2", null);
cache.put("/a/3", null);
@@ -778,10 +871,10 @@
cache.evict(Fqn.fromString("/a")); // passivate node
assertTrue(loader.exists(Fqn.fromString("/a")));
addDelay();
- DummyTransactionManager mgr=DummyTransactionManager.getInstance();
+ DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
- tx=mgr.getTransaction();
- Set children=cache.getChildrenNames("/a");
+ tx = mgr.getTransaction();
+ Set children = cache.getChildrenNames("/a");
assertEquals(3, children.size());
assertTrue(children.contains("1"));
assertTrue(children.contains("2"));
@@ -791,12 +884,12 @@
}
+ public void testTxPutCommit() throws Exception, NotSupportedException
+ {
- public void testTxPutCommit() throws Exception, NotSupportedException {
-
- DummyTransactionManager mgr=DummyTransactionManager.getInstance();
+ DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
- tx=mgr.getTransaction();
+ tx = mgr.getTransaction();
cache.put("/one/two/three", "key1", "val1");
cache.put("/one/two/three/four", "key2", "val2");
@@ -806,7 +899,7 @@
assertNotNull(cache.getKeys("/one/two/three"));
assertEquals("val1", cache.get(Fqn.fromString("/one/two/three"), "key1"));
mgr.begin();
- tx=mgr.getTransaction();
+ tx = mgr.getTransaction();
cache.evict(Fqn.fromString("/one/two/three"));
cache.evict(Fqn.fromString("/one/two/three/four"));
@@ -815,36 +908,37 @@
assertTrue(loader.exists(Fqn.fromString("/one/two/three")));
assertTrue(loader.exists(Fqn.fromString("/one/two/three/four")));
assertNotNull(cache.getKeys("/one/two/three"));
- Set children=cache.getChildrenNames("/one");
+ Set children = cache.getChildrenNames("/one");
assertEquals(1, children.size());
cache.remove("/");
}
- public void testTxPutRollback() throws Exception, NotSupportedException {
- DummyTransactionManager mgr=DummyTransactionManager.getInstance();
+ public void testTxPutRollback() throws Exception, NotSupportedException
+ {
+ DummyTransactionManager mgr = DummyTransactionManager.getInstance();
cache.remove("/one");
addDelay();
mgr.begin();
- tx=mgr.getTransaction();
+ tx = mgr.getTransaction();
cache.put("/one/two/three", "key1", "val1");
cache.put("/one/two/three/four", "key2", "val2");
tx.rollback();
addDelay();
assertNull(cache.getKeys("/one/two/three"));
- Set children=cache.getChildrenNames("/one");
+ Set children = cache.getChildrenNames("/one");
assertNull(children);
assertFalse(loader.exists(Fqn.fromString("/one/two/three")));
assertFalse(loader.exists(Fqn.fromString("/one/two/three/four")));
}
-
- public void testPassivationAndActivation() throws Exception {
+ public void testPassivationAndActivation() throws Exception
+ {
Object val, val2;
- Fqn NODE=Fqn.fromString("/test");
+ Fqn NODE = Fqn.fromString("/test");
loader.remove(Fqn.fromString("/"));
cache.put(NODE, "key", "val");
//val=loader.get(NODE).get("key");
@@ -852,10 +946,10 @@
cache.evict(NODE);
assertEquals(0, cache.getNumberOfNodes());
assertEquals(0, cache.getNumberOfAttributes());
- val=loader.get(NODE).get("key");
+ val = loader.get(NODE).get("key");
assertNotNull("value must have been passivated on evict()", val);
assertEquals(val, "val");
- val2=cache.get(NODE, "key");
+ val2 = cache.get(NODE, "key");
assertNotNull(val2);
assertEquals(val, val2);
// val=loader.get(NODE).get("key");
@@ -863,13 +957,12 @@
}
-
-
/**
* Tests basic operations without a transaction.
*/
public void testBasicOperations()
- throws Exception {
+ throws Exception
+ {
doTestBasicOperations();
}
@@ -878,11 +971,12 @@
* Tests basic operations with a transaction.
*/
public void testBasicOperationsTransactional()
- throws Exception {
+ throws Exception
+ {
- DummyTransactionManager mgr=DummyTransactionManager.getInstance();
+ DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
- tx=mgr.getTransaction();
+ tx = mgr.getTransaction();
doTestBasicOperations();
tx.commit();
}
@@ -890,7 +984,8 @@
/**
* Tests basic operations.
*/
- private void doTestBasicOperations() throws Exception {
+ private void doTestBasicOperations() throws Exception
+ {
/* One FQN only. */
doPutTests(new Fqn("key"));
@@ -919,7 +1014,8 @@
* Do basic put tests for a given FQN.
*/
private void doPutTests(Fqn fqn)
- throws Exception {
+ throws Exception
+ {
assertTrue(!loader.exists(fqn));
@@ -964,7 +1060,8 @@
* Do basic remove tests for a given FQN.
*/
private void doRemoveTests(Fqn fqn)
- throws Exception {
+ throws Exception
+ {
/* remove(Fqn,Object) */
Object oldVal;
@@ -996,7 +1093,8 @@
* and tests removing subtrees.
*/
public void testMultiLevelTree()
- throws Exception {
+ throws Exception
+ {
/* Create top level node implicitly. */
assertTrue(!loader.exists(new Fqn("key0")));
@@ -1159,23 +1257,24 @@
* Tests the getChildrenNames() method.
*/
public void testGetChildrenNames()
- throws Exception {
+ throws Exception
+ {
checkChildren(new Fqn(), null);
checkChildren(Fqn.fromString("/key0"), null);
loader.put(Fqn.fromString("/key0"), null);
addDelay();
- checkChildren(new Fqn(), new String[] { "key0" });
+ checkChildren(new Fqn(), new String[]{"key0"});
loader.put(Fqn.fromString("/key1/x"), null);
addDelay();
- checkChildren(new Fqn(), new String[] { "key0", "key1" });
- checkChildren(Fqn.fromString("/key1"), new String[] { "x" });
+ checkChildren(new Fqn(), new String[]{"key0", "key1"});
+ checkChildren(Fqn.fromString("/key1"), new String[]{"x"});
loader.remove(Fqn.fromString("/key1/x"));
addDelay();
- checkChildren(new Fqn(), new String[] { "key0", "key1" });
+ checkChildren(new Fqn(), new String[]{"key0", "key1"});
checkChildren(Fqn.fromString("/key0"), null);
checkChildren(Fqn.fromString("/key1"), null);
@@ -1184,23 +1283,23 @@
loader.put(Fqn.fromString("/key0/abc"), null);
addDelay();
checkChildren(Fqn.fromString("/key0"),
- new String[] { "a", "ab", "abc" });
+ new String[]{"a", "ab", "abc"});
loader.put(Fqn.fromString("/key0/xxx"), null);
loader.put(Fqn.fromString("/key0/xx"), null);
loader.put(Fqn.fromString("/key0/x"), null);
addDelay();
checkChildren(Fqn.fromString("/key0"),
- new String[] { "a", "ab", "abc", "x", "xx", "xxx" });
+ new String[]{"a", "ab", "abc", "x", "xx", "xxx"});
loader.put(Fqn.fromString("/key0/a/1"), null);
loader.put(Fqn.fromString("/key0/a/2"), null);
loader.put(Fqn.fromString("/key0/a/2/1"), null);
addDelay();
- checkChildren(Fqn.fromString("/key0/a/2"), new String[] { "1" });
- checkChildren(Fqn.fromString("/key0/a"), new String[] { "1", "2" });
+ checkChildren(Fqn.fromString("/key0/a/2"), new String[]{"1"});
+ checkChildren(Fqn.fromString("/key0/a"), new String[]{"1", "2"});
checkChildren(Fqn.fromString("/key0"),
- new String[] { "a", "ab", "abc", "x", "xx", "xxx" });
+ new String[]{"a", "ab", "abc", "x", "xx", "xxx"});
//
// loader.put(Fqn.fromString("/key0/\u0000"), null);
// loader.put(Fqn.fromString("/key0/\u0001"), null);
@@ -1227,15 +1326,20 @@
* Checks that the given list of children part names is returned.
*/
private void checkChildren(Fqn fqn, String[] names)
- throws Exception {
+ throws Exception
+ {
Set set = loader.getChildrenNames(fqn);
- if (names != null) {
+ if (names != null)
+ {
assertEquals(names.length, set.size());
- for (int i = 0; i < names.length; i += 1) {
+ for (int i = 0; i < names.length; i += 1)
+ {
assertTrue(set.contains(names[i]));
}
- } else {
+ }
+ else
+ {
assertNull(set);
}
}
@@ -1244,7 +1348,8 @@
* Tests basic operations without a transaction.
*/
public void testModifications()
- throws Exception {
+ throws Exception
+ {
doTestModifications();
}
@@ -1253,10 +1358,11 @@
* Tests basic operations with a transaction.
*/
public void testModificationsTransactional()
- throws Exception {
- DummyTransactionManager mgr=DummyTransactionManager.getInstance();
+ throws Exception
+ {
+ DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
- tx=mgr.getTransaction();
+ tx = mgr.getTransaction();
doTestModifications();
tx.commit();
}
@@ -1265,7 +1371,8 @@
* Tests modifications.
*/
private void doTestModifications()
- throws Exception {
+ throws Exception
+ {
/* PUT_KEY_VALUE, PUT_DATA */
List list = createUpdates();
@@ -1311,7 +1418,8 @@
* Tests a one-phase transaction.
*/
public void testOnePhaseTransaction()
- throws Exception {
+ throws Exception
+ {
List mods = createUpdates();
loader.prepare(null, mods, true);
checkModifications(mods);
@@ -1321,7 +1429,8 @@
* Tests a two-phase transaction.
*/
public void testTwoPhaseTransactionPassivation()
- throws Exception {
+ throws Exception
+ {
Object txnKey = new Object();
List mods = createUpdates();
@@ -1339,7 +1448,8 @@
* Tests rollback of a two-phase transaction.
*/
public void testTransactionRollbackPassivation()
- throws Exception {
+ throws Exception
+ {
loader.remove(Fqn.fromString("/"));
@@ -1359,13 +1469,14 @@
loader.loadEntireState(os);
os.close();
- assertEquals(num,baos.size());
+ assertEquals(num, baos.size());
}
/**
* Creates a set of update (PUT_KEY_VALUE, PUT_DATA) modifications.
*/
- private List createUpdates() {
+ private List createUpdates()
+ {
List list = new ArrayList();
@@ -1399,18 +1510,22 @@
* Checks that a list of modifications was applied.
*/
private void checkModifications(List list)
- throws Exception {
+ throws Exception
+ {
- for (int i = 0; i < list.size(); i += 1) {
+ for (int i = 0; i < list.size(); i += 1)
+ {
Modification mod = (Modification) list.get(i);
Fqn fqn = mod.getFqn();
- switch (mod.getType()) {
+ switch (mod.getType())
+ {
case Modification.PUT_KEY_VALUE:
assertEquals(mod.getValue(), loader.get(fqn).get(mod.getKey()));
break;
case Modification.PUT_DATA:
Map map = mod.getData();
- for (Iterator iter = map.keySet().iterator(); iter.hasNext();) {
+ for (Iterator iter = map.keySet().iterator(); iter.hasNext();)
+ {
Object key = iter.next();
assertEquals(map.get(key), loader.get(fqn).get(key));
}
@@ -1434,16 +1549,12 @@
}
-
-
-
-
-
/**
* Tests that null keys and values work as for a standard Java Map.
*/
public void testNullKeysAndValues()
- throws Exception {
+ throws Exception
+ {
loader.put(FQN, null, "x");
addDelay();
@@ -1497,7 +1608,8 @@
* Test non-default database name.
*/
public void testDatabaseNamePassivation()
- throws Exception {
+ throws Exception
+ {
loader.put(FQN, "one", "two");
addDelay();
@@ -1508,7 +1620,8 @@
* Test load/store state.
*/
public void testLoadAndStore()
- throws Exception {
+ throws Exception
+ {
/* Empty state. */
loader.remove(Fqn.fromString("/"));
@@ -1537,11 +1650,10 @@
loader.loadEntireState(os);
os.writeObject(StateTransferManager.STREAMING_DELIMETER_NODE);
os.close();
- assertTrue(baos.size()>0);
+ assertTrue(baos.size() > 0);
byte [] savedState = baos.toByteArray();
-
/* Restore state. */
ByteArrayInputStream bais = new ByteArrayInputStream(savedState);
MarshalledValueInputStream is = new MarshalledValueInputStream(bais);
@@ -1555,36 +1667,41 @@
}
-
-
-
/**
* Complex object whose class description is stored in the class catalog.
*/
- private static class Complex implements Serializable {
+ private static class Complex implements Serializable
+ {
Complex nested;
- Complex() {
+ Complex()
+ {
this(null);
}
- Complex(Complex nested) {
+ Complex(Complex nested)
+ {
this.nested = nested;
}
- public boolean equals(Object o) {
- try {
+ public boolean equals(Object o)
+ {
+ try
+ {
Complex x = (Complex) o;
return (nested != null) ? nested.equals(x.nested)
: (x.nested == null);
- } catch (ClassCastException e) {
+ }
+ catch (ClassCastException e)
+ {
return false;
}
}
- public int hashCode() {
- if(nested == null)
+ public int hashCode()
+ {
+ if (nested == null)
return super.hashCode();
else
return 13 + nested.hashCode();
@@ -1592,11 +1709,13 @@
}
- public static Test suite() {
+ public static Test suite()
+ {
return new TestSuite(PassivationTestsBase.class);
}
- public static void main(String[] args) {
+ public static void main(String[] args)
+ {
junit.textui.TestRunner.run(suite());
}
1.5 +21 -16 JBossCache/tests/functional/org/jboss/cache/passivation/PassivationToLocalDelegatingCacheLoaderTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: PassivationToLocalDelegatingCacheLoaderTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/passivation/PassivationToLocalDelegatingCacheLoaderTest.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- PassivationToLocalDelegatingCacheLoaderTest.java 20 Jul 2006 10:59:14 -0000 1.4
+++ PassivationToLocalDelegatingCacheLoaderTest.java 6 Sep 2006 15:31:00 -0000 1.5
@@ -11,38 +11,43 @@
* Runs a test against using delegated cache loader
*
* @author <a href="mailto:{hmesha at novell.com}">{Hany Mesha}</a>
- * @version $Id: PassivationToLocalDelegatingCacheLoaderTest.java,v 1.4 2006/07/20 10:59:14 msurtani Exp $
+ * @version $Id: PassivationToLocalDelegatingCacheLoaderTest.java,v 1.5 2006/09/06 15:31:00 msurtani Exp $
*/
-public class PassivationToLocalDelegatingCacheLoaderTest extends PassivationTestsBase {
+public class PassivationToLocalDelegatingCacheLoaderTest extends PassivationTestsBase
+{
TreeCache delegating_cache;
DelegatingCacheLoader cache_loader;
- protected void configureCache() throws Exception {
- delegating_cache=new TreeCache();
+ protected void configureCache() throws Exception
+ {
+ delegating_cache = new TreeCache();
delegating_cache.getConfiguration().setCacheMode(Configuration.CacheMode.LOCAL);
- delegating_cache.createService();
- delegating_cache.startService();
- cache_loader=new LocalDelegatingCacheLoader(delegating_cache);
+ delegating_cache.create();
+ delegating_cache.start();
+ cache_loader = new LocalDelegatingCacheLoader(delegating_cache);
// configure first ...
cache.getConfiguration().setCacheLoaderConfiguration(getCacheLoaderConfig("", "org.jboss.cache.loader.LocalDelegatingCacheLoader", "", false, false));
cache.setCacheLoader(cache_loader);
}
- protected void tearDown() throws Exception {
+ protected void tearDown() throws Exception
+ {
super.tearDown();
- delegating_cache.stopService();
- delegating_cache.destroyService();
+ delegating_cache.stop();
+ delegating_cache.destroy();
}
- public static Test suite() {
+ public static Test suite()
+ {
return new TestSuite(PassivationToLocalDelegatingCacheLoaderTest.class);
}
- public static void main(String[] args) {
+ public static void main(String[] args)
+ {
junit.textui.TestRunner.run(suite());
}
More information about the jboss-cvs-commits
mailing list