[infinispan-commits] Infinispan SVN: r1391 - in trunk/core/src/test/java/org/infinispan/loaders: dummy and 1 other directory.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Tue Jan 19 05:49:05 EST 2010
Author: manik.surtani at jboss.com
Date: 2010-01-19 05:49:05 -0500 (Tue, 19 Jan 2010)
New Revision: 1391
Added:
trunk/core/src/test/java/org/infinispan/loaders/dummy/DummyInMemoryCacheStoreFunctionalTest.java
Modified:
trunk/core/src/test/java/org/infinispan/loaders/BaseCacheStoreFunctionalTest.java
Log:
More tests
Modified: trunk/core/src/test/java/org/infinispan/loaders/BaseCacheStoreFunctionalTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/loaders/BaseCacheStoreFunctionalTest.java 2010-01-19 10:48:37 UTC (rev 1390)
+++ trunk/core/src/test/java/org/infinispan/loaders/BaseCacheStoreFunctionalTest.java 2010-01-19 10:49:05 UTC (rev 1391)
@@ -21,32 +21,36 @@
*/
package org.infinispan.loaders;
-import java.util.Arrays;
-import java.util.Collections;
-
import org.infinispan.Cache;
import org.infinispan.config.CacheLoaderManagerConfig;
import org.infinispan.config.Configuration;
import org.infinispan.config.GlobalConfiguration;
+import org.infinispan.container.DataContainer;
+import org.infinispan.container.entries.InternalCacheEntry;
import org.infinispan.manager.CacheManager;
import org.infinispan.test.AbstractInfinispanTest;
import org.infinispan.test.TestingUtil;
import org.infinispan.test.fwk.TestCacheManagerFactory;
+import org.infinispan.util.Util;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.concurrent.TimeUnit;
+
/**
- * This is a base functional test class containing tests that should be executed for each cache store/loader
- * implementation. As these are functional tests, they should interact against Cache/CacheManager only and
- * any access to the underlying cache store/loader should be done to verify contents.
+ * This is a base functional test class containing tests that should be executed for each cache store/loader
+ * implementation. As these are functional tests, they should interact against Cache/CacheManager only and any access to
+ * the underlying cache store/loader should be done to verify contents.
*/
@Test(groups = "unit", testName = "loaders.BaseCacheStoreFunctionalTest")
public abstract class BaseCacheStoreFunctionalTest extends AbstractInfinispanTest {
-
+
protected abstract CacheStoreConfig createCacheStoreConfig() throws Exception;
-
+
protected CacheStoreConfig csConfig;
-
+
@BeforeMethod
public void setUp() throws Exception {
try {
@@ -63,7 +67,7 @@
try {
GlobalConfiguration configuration = localCacheManager.getGlobalConfiguration();
CacheLoaderManagerConfig clmConfig = new CacheLoaderManagerConfig();
- clmConfig.setCacheLoaderConfigs(Collections.singletonList((CacheLoaderConfig)csConfig));
+ clmConfig.setCacheLoaderConfigs(Collections.singletonList((CacheLoaderConfig) csConfig));
configuration.getDefaultConfiguration().setCacheLoaderManagerConfig(clmConfig);
localCacheManager.defineConfiguration("first", new Configuration());
localCacheManager.defineConfiguration("second", new Configuration());
@@ -80,38 +84,54 @@
assert first.get("key").equals("val");
assert second.get("key") == null;
- second.put("key2","val2");
+ second.put("key2", "val2");
assert second.get("key2").equals("val2");
- assert first.get("key2") == null;
+ assert first.get("key2") == null;
} finally {
TestingUtil.killCacheManagers(localCacheManager);
}
}
-
- public void testPreloading() {
- doRunPreloadingTest(60000);
- doRunPreloadingTest(60000);
- doRunPreloadingTest(70000);
- doRunPreloadingTest(70000);
- }
-
- private void doRunPreloadingTest(int count) {
- CacheManager local = TestCacheManagerFactory.createLocalCacheManager();
+
+ public void testPreloadAndExpiry() {
+ CacheLoaderManagerConfig cacheLoaders = new CacheLoaderManagerConfig();
+ cacheLoaders.setPreload(true);
+ cacheLoaders.addCacheLoaderConfig(csConfig);
+ Configuration cfg = TestCacheManagerFactory.getDefaultConfiguration(false);
+ cfg.setCacheLoaderManagerConfig(cacheLoaders);
+ CacheManager local = TestCacheManagerFactory.createCacheManager(cfg);
try {
- CacheLoaderManagerConfig cacheLoaders = new CacheLoaderManagerConfig();
- cacheLoaders.setPreload(true);
- CacheLoaderManagerConfig clmConfig = new CacheLoaderManagerConfig();
- clmConfig.setCacheLoaderConfigs(Collections.singletonList((CacheLoaderConfig)csConfig));
- local.getGlobalConfiguration().getDefaultConfiguration().setCacheLoaderManagerConfig(clmConfig);
- Cache cache = local.getCache("testPreloading");
+ Cache<String, String> cache = local.getCache();
cache.start();
- byte[] bytes = new byte[count];
- Arrays.fill(bytes, (byte) 1);
- cache.put("test_object", bytes);
- int cacheSize = cache.size();
- assert 1 == cacheSize;
+
+ assert cache.getConfiguration().getCacheLoaderManagerConfig().isPreload();
+
+ cache.put("k1", "v");
+ cache.put("k2", "v", 111111, TimeUnit.MILLISECONDS);
+ cache.put("k3", "v", -1, TimeUnit.MILLISECONDS, 222222, TimeUnit.MILLISECONDS);
+ cache.put("k4", "v", 333333, TimeUnit.MILLISECONDS, 444444, TimeUnit.MILLISECONDS);
+
+ cache.stop();
+
+ cache.start();
+
+ assertCacheEntry(cache, "k1", "v", -1, -1);
+ assertCacheEntry(cache, "k2", "v", 111111, -1);
+ assertCacheEntry(cache, "k3", "v", -1, 222222);
+ assertCacheEntry(cache, "k4", "v", 333333, 444444);
} finally {
TestingUtil.killCacheManagers(local);
}
}
+
+ private void assertCacheEntry(Cache cache, String key, String value, long lifespanMillis, long maxIdleMillis) {
+ DataContainer dc = cache.getAdvancedCache().getDataContainer();
+ InternalCacheEntry ice = dc.get(key);
+ assert ice != null : "No such entry for key " + key;
+ assert Util.safeEquals(ice.getValue(), value) : ice.getValue() + " is not the same as " + value;
+ assert ice.getLifespan() == lifespanMillis : "Lifespan " + ice.getLifespan() + " not the same as " + lifespanMillis;
+ assert ice.getMaxIdle() == maxIdleMillis : "MaxIdle " + ice.getMaxIdle() + " not the same as " + maxIdleMillis;
+ if (lifespanMillis > -1) assert ice.getCreated() > -1 : "Lifespan is set but created time is not";
+ if (maxIdleMillis > -1) assert ice.getLastUsed() > -1 : "Max idle is set but last used is not";
+
+ }
}
Added: trunk/core/src/test/java/org/infinispan/loaders/dummy/DummyInMemoryCacheStoreFunctionalTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/loaders/dummy/DummyInMemoryCacheStoreFunctionalTest.java (rev 0)
+++ trunk/core/src/test/java/org/infinispan/loaders/dummy/DummyInMemoryCacheStoreFunctionalTest.java 2010-01-19 10:49:05 UTC (rev 1391)
@@ -0,0 +1,29 @@
+package org.infinispan.loaders.dummy;
+
+import org.infinispan.loaders.BaseCacheStoreFunctionalTest;
+import org.infinispan.loaders.CacheStoreConfig;
+import org.infinispan.loaders.file.FileCacheStoreConfig;
+import org.infinispan.test.TestingUtil;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Parameters;
+import org.testng.annotations.Test;
+
+import java.io.File;
+
+ at Test(groups = "unit", testName = "loaders.dummy.DummyInMemoryCacheStoreFunctionalTest")
+public class DummyInMemoryCacheStoreFunctionalTest extends BaseCacheStoreFunctionalTest {
+
+ @AfterClass
+ protected void clearTempDir() {
+ DummyInMemoryCacheStore.stores.remove(getClass().getName());
+ }
+
+ @Override
+ protected CacheStoreConfig createCacheStoreConfig() throws Exception {
+ DummyInMemoryCacheStore.Cfg cfg = new DummyInMemoryCacheStore.Cfg(getClass().getName(), false);
+ cfg.setPurgeSynchronously(true); // for more accurate unit testing
+ return cfg;
+ }
+
+}
Property changes on: trunk/core/src/test/java/org/infinispan/loaders/dummy/DummyInMemoryCacheStoreFunctionalTest.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
More information about the infinispan-commits
mailing list