AtomicHashMap can't be restored from storage
ilucker May 1, 2010 5:47 AMHello. I have probles using AtomicHashMap as cache value in caches with enapled storage. There is testcase that reproduce problem
package org.infinispan.atomic; import org.infinispan.Cache; import org.infinispan.config.Configuration; import org.infinispan.loaders.file.FileCacheStoreConfig; import org.infinispan.manager.CacheManager; import org.infinispan.test.AbstractInfinispanTest; import org.infinispan.test.TestingUtil; import org.infinispan.test.fwk.TestCacheManagerFactory; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import javax.transaction.TransactionManager; import java.io.File; import java.io.IOException; @Test(groups = "functional", testName = "atomic.AtomicMapFunctionalTest") public class AtomicMapStorageTest extends AbstractInfinispanTest { private int id; private Cache<String, Object> cache; private TransactionManager tm; private CacheManager cm; @BeforeMethod public void setUp() throws IOException { final FileCacheStoreConfig storeConfig = new FileCacheStoreConfig(); storeConfig.setLocation(getTmpDirName()); final Configuration cfg = new Configuration(); cfg.getCacheLoaderManagerConfig().addCacheLoaderConfig(storeConfig); // these 2 need to be set to use the AtomicMapCache cfg.setInvocationBatchingEnabled(true); cm = TestCacheManagerFactory.createCacheManager(cfg, true); cache = cm.getCache(); tm = TestingUtil.getTransactionManager(cache); } @AfterMethod public void tearDown() { TestingUtil.killCacheManagers(cm); cache = null; tm = null; } public void testRestoreAtomicMap() { final AtomicMap<String, String> map = AtomicMapLookup.getAtomicMap(cache, "key"); map.put("a", "b"); //evict from memory cache.evict("key"); // now re-retrieve the map assert AtomicMapLookup.getAtomicMap(cache, "key").get("a").equals("b"); } public void testRestoreTransactionalAtomicMap() throws Exception{ tm.begin(); final AtomicMap<String, String> map = AtomicMapLookup.getAtomicMap(cache, "key"); map.put("a", "b"); tm.commit(); //evict from memory cache.evict("key"); // now re-retrieve the map and make sure we see the diffs assert AtomicMapLookup.getAtomicMap(cache, "key").get("a").equals("b"); } private String getTmpDirName() throws IOException { final File location = File.createTempFile(getClass().getSimpleName(), "" + id++); location.delete(); location.mkdir(); location.deleteOnExit(); return location.getAbsolutePath(); } }
and there is errors
java.lang.ClassCastException: org.infinispan.atomic.AtomicHashMapDelta cannot be cast to org.infinispan.atomic.AtomicHashMap at org.infinispan.atomic.AtomicMapLookup.getAtomicMap(AtomicMapLookup.java:25) at org.infinispan.atomic.AtomicMapStorageTest.testRestoreAtomicMap(AtomicMapStorageTest.java:57) =============================================== java.lang.ClassCastException: org.infinispan.atomic.NullDelta cannot be cast to org.infinispan.atomic.AtomicHashMap at org.infinispan.atomic.AtomicMapLookup.getAtomicMap(AtomicMapLookup.java:25) at org.infinispan.atomic.AtomicMapStorageTest.testRestoreTransactionalAtomicMap(AtomicMapStorageTest.java:70)