import junit.framework.TestCase; import org.infinispan.Cache; import org.infinispan.config.Configuration; import org.infinispan.manager.DefaultCacheManager; import org.infinispan.manager.EmbeddedCacheManager; import javax.transaction.TransactionManager; /* * Copyright (C) 2011 eXo Platform SAS. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ /** * @author Nicolas Filotto * @version $Id$ * */ public class TestMultiCacheInstances extends TestCase { private EmbeddedCacheManager manager; /** * @see junit.framework.TestCase#setUp() */ @Override protected void setUp() throws Exception { this.manager = new DefaultCacheManager(getConfiguration()); } /* Uncomment me for ISPN 4 */ private Configuration getConfiguration() { Configuration config = new Configuration(); config.setTransactionManagerLookupClass("org.infinispan.transaction.lookup.JBossStandaloneJTAManagerLookup"); return config; } // */ /* Uncomment me for ISPN 5 * private Configuration getConfiguration() { org.infinispan.config.FluentConfiguration fc = new org.infinispan.config.FluentConfiguration(new Configuration()); fc.transactionManagerLookupClass(org.infinispan.transaction.lookup.JBossStandaloneJTAManagerLookup.class); return fc.build(); } // */ public void testUpdate() throws Exception { Cache cache1 = manager.getCache("cache1"); Cache cache2 = manager.getCache("cache2"); assertFalse(cache1.containsKey("a")); assertFalse(cache2.containsKey("b")); TransactionManager tm = cache1.getAdvancedCache().getTransactionManager(); tm.begin(); cache1.put("a", "value1"); cache2.put("b", "value2"); tm.commit(); assertEquals("value1", cache1.get("a")); assertEquals("value2", cache2.get("b")); tm.begin(); cache1.remove("a"); cache2.remove("b"); tm.commit(); assertFalse(cache1.containsKey("a")); assertFalse(cache2.containsKey("b")); } }