package com.db.fdr.test.cache; import java.util.Properties; import java.util.concurrent.CyclicBarrier; import org.infinispan.Cache; import org.infinispan.config.Configuration; import org.infinispan.config.GlobalConfiguration; import org.infinispan.context.Flag; import org.infinispan.manager.DefaultCacheManager; import org.infinispan.manager.EmbeddedCacheManager; import org.infinispan.tree.Fqn; import org.infinispan.tree.TreeCache; import org.infinispan.tree.TreeCacheFactory; import org.infinispan.util.concurrent.IsolationLevel; import com.db.fdr.test.TestCase; /** * *

* * Copyright 2010 Deutsche Bank * * * * @author Konstantin Kuzmin * * @version $Revision$ * * @since Dec 17, 2010 * */ public class TestInfinispan extends TestCase { private Cache cache1; private Cache cache2; private TreeCache treeCache1; private TreeCache treeCache2; private static final String KEY = "key"; public static Cache createCache() throws Exception { final GlobalConfiguration gc = GlobalConfiguration.getClusteredDefault(); final Properties p = new Properties(); p.setProperty("configurationFile", "jgroups-config.xml"); gc.setTransportProperties(p); final Configuration configuration = new Configuration(); configuration.setCacheMode(Configuration.CacheMode.INVALIDATION_SYNC); configuration.setTransactionManagerLookupClass("org.infinispan.transaction.lookup.DummyTransactionManagerLookup"); configuration.setIsolationLevel(IsolationLevel.READ_COMMITTED); configuration.setLockAcquisitionTimeout(1000L); configuration.setSyncCommitPhase(true); configuration.setSyncRollbackPhase(true); configuration.setUseLockStriping(true); configuration.setConcurrencyLevel(500); configuration.setInvocationBatchingEnabled(true); final EmbeddedCacheManager manager = new DefaultCacheManager(gc, configuration, true); return manager.getCache(); } public static TreeCache createTreeCache(final Cache cache) throws Exception { final TreeCacheFactory tcf = new TreeCacheFactory(); return tcf.createTreeCache(cache); } @Override protected void setUp() throws Exception { super.setUp(); cache1 = createCache(); cache2 = createCache(); } public void testCacheLocalPut() throws Exception { cache1.getAdvancedCache().withFlags(Flag.CACHE_MODE_LOCAL).put(KEY, "1"); cache2.getAdvancedCache().withFlags(Flag.CACHE_MODE_LOCAL).put(KEY, "2"); assertEquals("cache2 was updated locally", "2", cache2.get(KEY)); assertEquals("cache1 should not be invalidated in case of LOCAL put in cache2", "1", cache1.get(KEY)); } public void testTreeCacheLocalPut() throws Exception { treeCache1 = createTreeCache(cache1); treeCache2 = createTreeCache(cache2); final Fqn fqn = Fqn.fromElements("TEST"); treeCache1.put(fqn, KEY, "1", Flag.CACHE_MODE_LOCAL); treeCache2.put(fqn, KEY, "2", Flag.CACHE_MODE_LOCAL); assertEquals("treeCache2 was updated locally", "2", treeCache2.get(fqn, KEY)); assertEquals("treeCache1 should not be invalidated in case of LOCAL put in treeCache2", "1", treeCache1.get(fqn, KEY)); } }