[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/optimistic ...
Manik Surtani
msurtani at jboss.com
Wed Jan 3 13:12:23 EST 2007
User: msurtani
Date: 07/01/03 13:12:23
Modified: tests/functional/org/jboss/cache/optimistic
NodeInterceptorRemoveNodeTest.java
Log:
fixed broken ut
Revision Changes Path
1.16 +38 -142 JBossCache/tests/functional/org/jboss/cache/optimistic/NodeInterceptorRemoveNodeTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: NodeInterceptorRemoveNodeTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/optimistic/NodeInterceptorRemoveNodeTest.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- NodeInterceptorRemoveNodeTest.java 31 Dec 2006 02:08:41 -0000 1.15
+++ NodeInterceptorRemoveNodeTest.java 3 Jan 2007 18:12:23 -0000 1.16
@@ -12,13 +12,13 @@
import org.jboss.cache.Node;
import org.jboss.cache.OptimisticTransactionEntry;
import org.jboss.cache.TransactionTable;
+import org.jboss.cache.factories.InterceptorChainFactory;
+import org.jboss.cache.interceptors.CallInterceptor;
import org.jboss.cache.interceptors.Interceptor;
-import org.jboss.cache.interceptors.OptimisticCreateIfNotExistsInterceptor;
-import org.jboss.cache.interceptors.OptimisticNodeInterceptor;
import org.jboss.cache.loader.SamplePojo;
-import org.jboss.cache.transaction.DummyTransactionManager;
import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
import java.util.HashMap;
import java.util.Map;
@@ -27,7 +27,10 @@
*/
public class NodeInterceptorRemoveNodeTest extends AbstractOptimisticTestCase
{
-
+ private CacheImpl cache;
+ private TestListener listener;
+ private MockInterceptor dummy;
+ private TransactionManager mgr;
/**
* @param name
@@ -35,29 +38,42 @@
public NodeInterceptorRemoveNodeTest(String name)
{
super(name);
-
}
- public void testTransactionRemoveNotExistsNodeMethod() throws Exception
+ protected void setUp() throws Exception
{
+ super.setUp();
+ listener = new TestListener();
+ cache = createCacheWithListener(listener);
- TestListener listener = new TestListener();
- final CacheImpl cache = createCacheWithListener(listener);
-
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- interceptor.setCache(cache);
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- nodeInterceptor.setCache(cache);
- MockInterceptor dummy = new MockInterceptor();
+ dummy = new MockInterceptor();
dummy.setCache(cache);
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
+ Interceptor interceptor = cache.getInterceptorChain().get(0); // get the first interceptor
+ // replace the last (call) interceptor with the mock interceptor.
+ Interceptor next = interceptor, prev = interceptor;
+ while (!(next instanceof CallInterceptor))
+ {
+ prev = next;
+ next = next.getNext();
+ }
+
+ prev.setNext(dummy);
+
+ InterceptorChainFactory.setLastInterceptorPointer(interceptor, dummy);
cache.setInterceptorChain(interceptor);
+ mgr = cache.getTransactionManager();
+ }
+
+ protected void tearDown()
+ {
+ super.tearDown();
+ cache.stop();
+ }
-// first set up a node with a pojo
- DummyTransactionManager mgr = DummyTransactionManager.getInstance();
+ public void testTransactionRemoveNotExistsNodeMethod() throws Exception
+ {
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -67,16 +83,15 @@
cache.remove("/one/two");
- mgr.commit();
- assertEquals(null, dummy.getCalled());
- TransactionTable table = cache.getTransactionTable();
+ TransactionTable table = cache.getTransactionTable();
GlobalTransaction gtx = table.get(tx);
-
OptimisticTransactionEntry entry = (OptimisticTransactionEntry) table.get(gtx);
-
TransactionWorkspace workspace = entry.getTransactionWorkSpace();
+ mgr.commit();
+ assertEquals(null, dummy.getCalled());
+
//assert what should be the results of our call
assertEquals(0, workspace.getNodes().size());
@@ -86,29 +101,10 @@
assertEquals(null, dummy.getCalled());
assertEquals(0, listener.getNodesAdded());
- cache.stop();
}
public void testTransactionRemoveNodeMethod() throws Exception
{
-
- TestListener listener = new TestListener();
- final CacheImpl cache = createCacheWithListener(listener);
-
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- interceptor.setCache(cache);
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- nodeInterceptor.setCache(cache);
- MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
-
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- cache.setInterceptorChain(interceptor);
-
-// first set up a node with a pojo
- DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -142,34 +138,13 @@
assertEquals(false, workspace.getNode(Fqn.fromString("/one")).isDeleted());
assertEquals(0, workspace.getNode(Fqn.fromString("/one")).getMergedChildren().size());
assertEquals(null, workspace.getNode(Fqn.fromString("/one")).getChild(Fqn.fromString("/two")));
- assertTrue(entry.getLocks().isEmpty());
assertEquals(2, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
- cache.stop();
-
}
public void testTransactionRemoveIntermediateNodeMethod() throws Exception
{
-
- TestListener listener = new TestListener();
- final CacheImpl cache = createCacheWithListener(listener);
-
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- interceptor.setCache(cache);
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- nodeInterceptor.setCache(cache);
- MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
-
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- cache.setInterceptorChain(interceptor);
-
-// first set up a node with a pojo
- DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -204,33 +179,13 @@
assertEquals(1, workspace.getNode(Fqn.fromString("/one")).getMergedChildren().size());
assertNotNull(workspace.getNode(Fqn.fromString("/one")).getChild(Fqn.fromString("two")));
assertEquals(null, workspace.getNode(Fqn.fromString("/")).getChild(Fqn.fromString("/one")));
- assertTrue(entry.getLocks().isEmpty());
assertEquals(2, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
- cache.stop();
}
public void testTransactionRemoveTwiceMethod() throws Exception
{
-
- TestListener listener = new TestListener();
- final CacheImpl cache = createCacheWithListener(listener);
-
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- interceptor.setCache(cache);
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- nodeInterceptor.setCache(cache);
- MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
-
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- cache.setInterceptorChain(interceptor);
-
-// first set up a node with a pojo
- DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -291,30 +246,11 @@
assertEquals(3, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
- cache.stop();
}
public void testTransactionRemovePutNodeMethod() throws Exception
{
-
- TestListener listener = new TestListener();
- final CacheImpl cache = createCacheWithListener(listener);
-
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- interceptor.setCache(cache);
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- nodeInterceptor.setCache(cache);
- MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
-
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- cache.setInterceptorChain(interceptor);
-
-// first set up a node with a pojo
- DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -374,33 +310,13 @@
assertEquals(3, entry.getModifications().size());
- assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
assertEquals(4, listener.getNodesAdded());
- cache.stop();
}
public void testTransactionRemovePutkeyValMethod() throws Exception
{
-
- TestListener listener = new TestListener();
- final CacheImpl cache = createCacheWithListener(listener);
-
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- interceptor.setCache(cache);
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- nodeInterceptor.setCache(cache);
- MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
-
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- cache.setInterceptorChain(interceptor);
-
-// first set up a node with a pojo
- DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -465,29 +381,10 @@
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
assertEquals(3, listener.getNodesAdded());
- cache.stop();
}
public void testTransactionRemoveSubNodeMethod() throws Exception
{
-
- TestListener listener = new TestListener();
- final CacheImpl cache = createCacheWithListener(listener);
-
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- interceptor.setCache(cache);
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- nodeInterceptor.setCache(cache);
- MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
-
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- cache.setInterceptorChain(interceptor);
-
-// first set up a node with a pojo
- DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -537,6 +434,5 @@
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
assertEquals(2, listener.getNodesAdded());
- cache.stop();
}
}
More information about the jboss-cvs-commits
mailing list