1 7 package org.jboss.cache.loader; 8 9 import org.jboss.cache.CacheImpl; 10 import org.jboss.cache.interceptors.CacheStoreInterceptor; 11 import org.jboss.cache.interceptors.Interceptor; 12 13 import java.util.Iterator ; 14 15 20 public class SharedCacheLoaderTest extends AbstractCacheLoaderTestBase 21 { 22 private CacheImpl cache1, cache2; 23 private DummyCacheLoader dummyCacheLoader; 24 25 protected void setUp() throws Exception 26 { 27 if (cache1 != null || cache2 != null) tearDown(); 28 29 cache1 = new CacheImpl(); 31 cache2 = new CacheImpl(); 32 33 cache1.getConfiguration().setCacheMode("REPL_SYNC"); 34 cache2.getConfiguration().setCacheMode("REPL_SYNC"); 35 36 cache1.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig("", DummyCacheLoader.class.getName(), "", false, false, true)); 37 cache2.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig("", DummyCacheLoader.class.getName(), "", false, false, true)); 38 39 cache1.start(); 40 cache2.start(); 41 42 dummyCacheLoader = new DummyCacheLoader(); 44 45 cache1.setCacheLoader(dummyCacheLoader); 46 cache2.setCacheLoader(dummyCacheLoader); 47 findCacheStoreInterceptor(cache1).setCache(cache1); 48 findCacheStoreInterceptor(cache2).setCache(cache2); 49 } 50 51 protected CacheStoreInterceptor findCacheStoreInterceptor(CacheImpl cache) 52 { 53 Iterator ints = cache.getInterceptors().iterator(); 54 CacheStoreInterceptor csi = null; 55 while (ints.hasNext()) 56 { 57 Interceptor i = (Interceptor) ints.next(); 58 if (i instanceof CacheStoreInterceptor) 59 { 60 csi = (CacheStoreInterceptor) i; 61 break; 62 } 63 } 64 return csi; 65 } 66 67 protected void tearDown() 68 { 69 if (cache1 != null) cache1.stop(); 70 if (cache2 != null) cache2.stop(); 71 cache1 = null; 72 cache2 = null; 73 } 74 75 public void testReplicationWithSharedCL() throws Exception 76 { 77 cache1.put("/test", "one", "two"); 78 79 assertEquals("two", cache1.get("/test", "one")); 81 assertEquals("two", cache2.get("/test", "one")); 82 83 assertEquals(1, dummyCacheLoader.getPutCount()); 85 } 86 } 87 | Popular Tags |