1 7 package org.jboss.cache.optimistic; 8 9 import org.jboss.cache.CacheImpl; 10 import org.jboss.cache.interceptors.Interceptor; 11 import org.jboss.cache.interceptors.OptimisticCreateIfNotExistsInterceptor; 12 import org.jboss.cache.interceptors.OptimisticNodeInterceptor; 13 14 17 public class NodeInterceptorTransactionTest extends AbstractOptimisticTestCase 18 { 19 20 23 public NodeInterceptorTransactionTest(String name) 24 { 25 super(name); 26 27 } 28 29 public void testNoTransactionCRUDMethod() throws Exception 30 { 31 32 TestListener listener = new TestListener(); 33 final CacheImpl cache = createCacheWithListener(listener); 34 35 Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor(); 36 interceptor.setCache(cache); 37 Interceptor nodeInterceptor = new OptimisticNodeInterceptor(); 38 nodeInterceptor.setCache(cache); 39 MockInterceptor dummy = new MockInterceptor(); 40 dummy.setCache(cache); 41 42 interceptor.setNext(nodeInterceptor); 43 nodeInterceptor.setNext(dummy); 44 45 cache.setInterceptorChain(interceptor); 46 47 try 48 { 49 cache.put("/one/two", "key1", new Object ()); 50 fail(); 51 } 52 catch (Throwable t) 53 { 54 55 assertTrue(true); 56 } 57 assertEquals(null, dummy.getCalled()); 58 cache.stop(); 59 } 60 61 public void testNoTransactionGetMethod() throws Exception 62 { 63 64 TestListener listener = new TestListener(); 65 final CacheImpl cache = createCacheWithListener(listener); 66 67 Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor(); 68 interceptor.setCache(cache); 69 Interceptor nodeInterceptor = new OptimisticNodeInterceptor(); 70 nodeInterceptor.setCache(cache); 71 MockInterceptor dummy = new MockInterceptor(); 72 dummy.setCache(cache); 73 74 interceptor.setNext(nodeInterceptor); 75 nodeInterceptor.setNext(dummy); 76 77 cache.setInterceptorChain(interceptor); 78 79 boolean fail = false; 80 try 81 { 82 assertEquals(null, cache.get("/one/two", "key1")); 83 } 84 catch (Exception e) 85 { 86 fail = true; 87 } 88 assertTrue(fail); 89 assertEquals(null, dummy.getCalled()); 90 cache.stop(); 91 } 92 93 94 } 95 | Popular Tags |