KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > tests > basic > TreeCacheListenerTest


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  *****************************************/

9 package org.jboss.cache.tests.basic;
10
11 import junit.framework.TestCase;
12 import org.jboss.cache.DummyTransactionManagerLookup;
13 import org.jboss.cache.Fqn;
14 import org.jboss.cache.TreeCache;
15 import org.jboss.cache.TreeCacheListener;
16 import org.jboss.cache.lock.IsolationLevel;
17 import org.jgroups.View;
18
19 import javax.transaction.TransactionManager JavaDoc;
20 import java.util.ArrayList JavaDoc;
21 import java.util.Arrays JavaDoc;
22 import java.util.HashMap JavaDoc;
23 import java.util.List JavaDoc;
24
25 /**
26  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
27  * @version $Id: TreeCacheListenerTest.java,v 1.1.1.1 2005/03/31 10:15:08 belaban Exp $
28  */

29 public class TreeCacheListenerTest extends TestCase
30 {
31
32    public TreeCacheListenerTest(String JavaDoc s)
33    {
34       super(s);
35    }
36
37    private TreeCache cache;
38
39    protected void setUp() throws Exception JavaDoc
40    {
41       super.setUp();
42       cache = new TreeCache();
43       cache.setCacheMode(TreeCache.LOCAL);
44       cache.setIsolationLevel(IsolationLevel.REPEATABLE_READ);
45       cache.setTransactionManagerLookup(new DummyTransactionManagerLookup());
46       cache.create();
47       cache.start();
48    }
49
50    protected void tearDown() throws Exception JavaDoc
51    {
52       super.tearDown();
53       cache.stop();
54       cache.destroy();
55    }
56
57    public void testRemovePropertyWithCommit() throws Exception JavaDoc
58    {
59       cache.put("/", "name", "value");
60
61       EventLog el = new EventLog();
62       cache.addTreeCacheListener(el);
63
64       TransactionManager JavaDoc tm = cache.getTransactionManager();
65       tm.begin();
66       cache.remove("/", "name");
67       tm.commit();
68
69       assertEquals(Arrays.asList(new Object JavaDoc[]{"modified /"}), el.events);
70    }
71
72    public void testRemoveNodeWithRollback() throws Exception JavaDoc
73    {
74       cache.put("/child", new HashMap JavaDoc());
75
76       EventLog el = new EventLog();
77       cache.addTreeCacheListener(el);
78
79       TransactionManager JavaDoc tm = cache.getTransactionManager();
80       tm.begin();
81       cache.remove("/child");
82       tm.rollback();
83
84       assertEquals(Arrays.asList(new Object JavaDoc[]{"removed /child","created /child"}), el.events);
85    }
86
87    public static class EventLog implements TreeCacheListener
88    {
89       public final List JavaDoc events = new ArrayList JavaDoc();
90       public void nodeCreated(Fqn fqn)
91       {
92          events.add("created " + fqn);
93       }
94       public void nodeRemoved(Fqn fqn)
95       {
96          events.add("removed " + fqn);
97       }
98       public void nodeLoaded(Fqn fqn)
99       {
100          throw new UnsupportedOperationException JavaDoc();
101       }
102       public void nodeEvicted(Fqn fqn)
103       {
104          throw new UnsupportedOperationException JavaDoc();
105       }
106       public void nodeModified(Fqn fqn)
107       {
108          events.add("modified " + fqn);
109       }
110       public void nodeVisited(Fqn fqn)
111       {
112          throw new UnsupportedOperationException JavaDoc();
113       }
114       public void cacheStarted(TreeCache treeCache)
115       {
116          throw new UnsupportedOperationException JavaDoc();
117       }
118       public void cacheStopped(TreeCache treeCache)
119       {
120          throw new UnsupportedOperationException JavaDoc();
121       }
122       public void viewChange(View view)
123       {
124          throw new UnsupportedOperationException JavaDoc();
125       }
126    }
127
128
129 }
130
Popular Tags