1 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 ; 20 import java.util.ArrayList ; 21 import java.util.Arrays ; 22 import java.util.HashMap ; 23 import java.util.List ; 24 25 29 public class TreeCacheListenerTest extends TestCase 30 { 31 32 public TreeCacheListenerTest(String s) 33 { 34 super(s); 35 } 36 37 private TreeCache cache; 38 39 protected void setUp() throws Exception 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 51 { 52 super.tearDown(); 53 cache.stop(); 54 cache.destroy(); 55 } 56 57 public void testRemovePropertyWithCommit() throws Exception 58 { 59 cache.put("/", "name", "value"); 60 61 EventLog el = new EventLog(); 62 cache.addTreeCacheListener(el); 63 64 TransactionManager tm = cache.getTransactionManager(); 65 tm.begin(); 66 cache.remove("/", "name"); 67 tm.commit(); 68 69 assertEquals(Arrays.asList(new Object []{"modified /"}), el.events); 70 } 71 72 public void testRemoveNodeWithRollback() throws Exception 73 { 74 cache.put("/child", new HashMap ()); 75 76 EventLog el = new EventLog(); 77 cache.addTreeCacheListener(el); 78 79 TransactionManager tm = cache.getTransactionManager(); 80 tm.begin(); 81 cache.remove("/child"); 82 tm.rollback(); 83 84 assertEquals(Arrays.asList(new Object []{"removed /child","created /child"}), el.events); 85 } 86 87 public static class EventLog implements TreeCacheListener 88 { 89 public final List events = new ArrayList (); 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 (); 101 } 102 public void nodeEvicted(Fqn fqn) 103 { 104 throw new UnsupportedOperationException (); 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 (); 113 } 114 public void cacheStarted(TreeCache treeCache) 115 { 116 throw new UnsupportedOperationException (); 117 } 118 public void cacheStopped(TreeCache treeCache) 119 { 120 throw new UnsupportedOperationException (); 121 } 122 public void viewChange(View view) 123 { 124 throw new UnsupportedOperationException (); 125 } 126 } 127 128 129 } 130 | Popular Tags |