Add tests of Region.toMap()

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@14124 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Brian Stansberry 2007-10-19 19:32:36 +00:00
parent c0f3881bae
commit 7ec8086743
4 changed files with 61 additions and 2 deletions

View File

@ -21,6 +21,7 @@ import java.util.Set;
import org.hibernate.cache.GeneralDataRegion; import org.hibernate.cache.GeneralDataRegion;
import org.hibernate.cache.QueryResultsRegion; import org.hibernate.cache.QueryResultsRegion;
import org.hibernate.cache.Region;
import org.hibernate.cache.jbc2.JBossCacheRegionFactory; import org.hibernate.cache.jbc2.JBossCacheRegionFactory;
import org.hibernate.cache.jbc2.MultiplexedJBossCacheRegionFactory; import org.hibernate.cache.jbc2.MultiplexedJBossCacheRegionFactory;
import org.hibernate.cache.jbc2.builder.MultiplexingCacheInstanceManager; import org.hibernate.cache.jbc2.builder.MultiplexingCacheInstanceManager;
@ -50,6 +51,16 @@ public abstract class AbstractGeneralDataRegionTestCase extends AbstractRegionIm
super(name); super(name);
} }
@Override
protected void putInRegion(Region region, Object key, Object value) {
((GeneralDataRegion) region).put(key, value);
}
@Override
protected void removeFromRegion(Region region, Object key) {
((GeneralDataRegion) region).evict(key);
}
/** /**
* Test method for {@link QueryResultsRegion#evict(java.lang.Object)}. * Test method for {@link QueryResultsRegion#evict(java.lang.Object)}.
* *

View File

@ -16,6 +16,7 @@
package org.hibernate.test.cache.jbc2; package org.hibernate.test.cache.jbc2;
import java.util.Map;
import java.util.Properties; import java.util.Properties;
import org.hibernate.cache.CacheDataDescription; import org.hibernate.cache.CacheDataDescription;
@ -109,14 +110,40 @@ public abstract class AbstractRegionImplTestCase extends AbstractJBossCacheTestC
assertNull("No region node", localCache.getRoot().getChild( regionFqn )); assertNull("No region node", localCache.getRoot().getChild( regionFqn ));
} }
public void testToMap() throws Exception {
Configuration cfg = CacheTestUtil.buildConfiguration("test", SharedJBossCacheRegionFactory.class, true, true);
JBossCacheRegionFactory regionFactory = CacheTestUtil.startRegionFactory(cfg, getCacheTestSupport());
Region region = createRegion(regionFactory, "test/test", cfg.getProperties(), getCacheDataDescription());
putInRegion(region, "key1", "value1");
putInRegion(region, "key2", "value2");
Map map = region.toMap();
assertNotNull(map);
assertEquals(2, map.size());
assertEquals("value1", map.get("key1"));
assertEquals("value2", map.get("key2"));
removeFromRegion(region, "key1");
map = region.toMap();
assertNotNull(map);
assertEquals(1, map.size());
assertEquals("value2", map.get("key2"));
}
protected abstract Cache getJBossCache(JBossCacheRegionFactory regionFactory); protected abstract Cache getJBossCache(JBossCacheRegionFactory regionFactory);
protected abstract Fqn getRegionFqn(String regionName, String regionPrefix); protected abstract Fqn getRegionFqn(String regionName, String regionPrefix);
protected abstract Region createRegion(JBossCacheRegionFactory regionFactory, String regionName, Properties properties, CacheDataDescription cdd); protected abstract Region createRegion(JBossCacheRegionFactory regionFactory, String regionName, Properties properties, CacheDataDescription cdd);
protected abstract void putInRegion(Region region, Object key, Object value);
protected abstract void removeFromRegion(Region region, Object key);
protected CacheDataDescription getCacheDataDescription() { protected CacheDataDescription getCacheDataDescription() {
return new CacheDataDescriptionImpl(true, true, ComparableComparator.INSTANCE); return new CacheDataDescriptionImpl(true, true, ComparableComparator.INSTANCE);
} }
} }

View File

@ -49,6 +49,7 @@ public class CollectionRegionImplTestCase extends AbstractEntityCollectionRegion
super(name); super(name);
} }
@Override
protected void supportedAccessTypeTest(RegionFactory regionFactory, Properties properties) { protected void supportedAccessTypeTest(RegionFactory regionFactory, Properties properties) {
CollectionRegion region = regionFactory.buildCollectionRegion("test", properties, null); CollectionRegion region = regionFactory.buildCollectionRegion("test", properties, null);
@ -92,6 +93,15 @@ public class CollectionRegionImplTestCase extends AbstractEntityCollectionRegion
protected Fqn getRegionFqn(String regionName, String regionPrefix) { protected Fqn getRegionFqn(String regionName, String regionPrefix) {
return BasicRegionAdapter.getTypeLastRegionFqn(regionName, regionPrefix, CollectionRegionImpl.TYPE); return BasicRegionAdapter.getTypeLastRegionFqn(regionName, regionPrefix, CollectionRegionImpl.TYPE);
} }
@Override
protected void putInRegion(Region region, Object key, Object value) {
((CollectionRegion) region).buildAccessStrategy(AccessType.TRANSACTIONAL).putFromLoad(key, value, System.currentTimeMillis(), new Integer(1));
}
@Override
protected void removeFromRegion(Region region, Object key) {
((CollectionRegion) region).buildAccessStrategy(AccessType.TRANSACTIONAL).remove(key);
}
} }

View File

@ -49,6 +49,7 @@ public class EntityRegionImplTestCase extends AbstractEntityCollectionRegionTest
super(name); super(name);
} }
@Override
protected void supportedAccessTypeTest(RegionFactory regionFactory, Properties properties) { protected void supportedAccessTypeTest(RegionFactory regionFactory, Properties properties) {
EntityRegion region = regionFactory.buildEntityRegion("test", properties, null); EntityRegion region = regionFactory.buildEntityRegion("test", properties, null);
@ -93,6 +94,16 @@ public class EntityRegionImplTestCase extends AbstractEntityCollectionRegionTest
protected Fqn getRegionFqn(String regionName, String regionPrefix) { protected Fqn getRegionFqn(String regionName, String regionPrefix) {
return BasicRegionAdapter.getTypeLastRegionFqn(regionName, regionPrefix, EntityRegionImpl.TYPE); return BasicRegionAdapter.getTypeLastRegionFqn(regionName, regionPrefix, EntityRegionImpl.TYPE);
} }
@Override
protected void putInRegion(Region region, Object key, Object value) {
((EntityRegion) region).buildAccessStrategy(AccessType.TRANSACTIONAL).insert(key, value, new Integer(1));
}
@Override
protected void removeFromRegion(Region region, Object key) {
((EntityRegion) region).buildAccessStrategy(AccessType.TRANSACTIONAL).remove(key);
}
} }