I had a small bug in the UT; I fixed it and the UT still reproduces the problems.
| import junit.framework.TestCase; | import org.jboss.cache.TreeCache; | import org.jboss.cache.TreeCacheListener; | import org.jboss.cache.Fqn; | import org.jboss.cache.CacheException; | import org.jgroups.View; | | import java.util.List; | import java.util.ArrayList; | | /** | * Responsible to test the [EMAIL PROTECTED] TreeCache} outside AS. | * | * @author Claudiu Anghel | * @version 1.0 | */ | public class TreeCacheListenerTest extends TestCase { | private TreeCache treeCache; | | protected void setUp() throws Exception { | super.setUp(); | treeCache = new UnitTestableTreeCache(); | } | | public void testNodeCreated() throws Exception { | SimpleTreeCacheListener listener = new SimpleTreeCacheListener(treeCache); | treeCache.addTreeCacheListener(listener); | String key = String.valueOf(System.currentTimeMillis()); | treeCache.put("/UT/TestObjects/String:" + key, key, "TestValue"); | assertNotNull("The added object could not be retrieved by cache listener upon nodeCreated event.", | listener.getObjRetrievedByNodeCreated()); | } | | public void testNodeRemoved() throws Exception { | SimpleTreeCacheListener listener = new SimpleTreeCacheListener(treeCache); | treeCache.addTreeCacheListener(listener); | String key = String.valueOf(System.currentTimeMillis()); | String fqn = "/UT/TestObjects/String:" + key; | treeCache.put(fqn, key, "TestValue"); | treeCache.remove(fqn, key); | List removedNodeFqns = listener.getRemovedNodeFqns(); | assertEquals("Wrong number of nodes are reported as removed.", 1, removedNodeFqns.size()); | } | | private static class UnitTestableTreeCache extends TreeCache { | public UnitTestableTreeCache() throws Exception { | createInterceptorChain(); | } | } | | private static class SimpleTreeCacheListener implements TreeCacheListener { | private TreeCache treeCache; | private Object objRetrievedByNodeCreated; | private List removedNodeFqns = new ArrayList(); | | public SimpleTreeCacheListener(TreeCache treeCache) { | this.treeCache = treeCache; | } | | public void nodeCreated(Fqn fqn) { | try { | if (fqn.size() < 3) { | return; | } | objRetrievedByNodeCreated = treeCache.get(fqn, getKey(fqn)); | } | catch (CacheException e) { | e.printStackTrace(); | } | } | | public void nodeRemoved(Fqn fqn) { | if (fqn.size() < 3) { | return; | } | removedNodeFqns.add(fqn); | } | | public void nodeLoaded(Fqn fqn) { | /* do nothing */ | } | | public void nodeEvicted(Fqn fqn) { | /* do nothing */ | } | | public void nodeModified(Fqn fqn) { | /* do nothing */ | } | | public void nodeVisited(Fqn fqn) { | /* do nothing */ | } | | public void cacheStarted(TreeCache cache) { | /* do nothing */ | } | | public void cacheStopped(TreeCache cache) { | /* do nothing */ | } | | public void viewChange(View new_view) // might be MergeView after merging | { | /* do nothing */ | } | | public Object getObjRetrievedByNodeCreated() { | return objRetrievedByNodeCreated; | } | | public List getRemovedNodeFqns() { | return removedNodeFqns; | } | | private String getKey(Fqn fqn) { | String lastPart = (String) fqn.get(2); | return lastPart.substring(lastPart.indexOf(":") + 1); | } | } | } | Claudiu View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3891815#3891815 Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3891815 ------------------------------------------------------- SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf _______________________________________________ JBoss-user mailing list JBoss-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jboss-user