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:
parent
c0f3881bae
commit
7ec8086743
|
@ -21,6 +21,7 @@ import java.util.Set;
|
|||
|
||||
import org.hibernate.cache.GeneralDataRegion;
|
||||
import org.hibernate.cache.QueryResultsRegion;
|
||||
import org.hibernate.cache.Region;
|
||||
import org.hibernate.cache.jbc2.JBossCacheRegionFactory;
|
||||
import org.hibernate.cache.jbc2.MultiplexedJBossCacheRegionFactory;
|
||||
import org.hibernate.cache.jbc2.builder.MultiplexingCacheInstanceManager;
|
||||
|
@ -50,6 +51,16 @@ public abstract class AbstractGeneralDataRegionTestCase extends AbstractRegionIm
|
|||
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)}.
|
||||
*
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package org.hibernate.test.cache.jbc2;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.hibernate.cache.CacheDataDescription;
|
||||
|
@ -109,12 +110,38 @@ public abstract class AbstractRegionImplTestCase extends AbstractJBossCacheTestC
|
|||
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 Fqn getRegionFqn(String regionName, String regionPrefix);
|
||||
|
||||
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() {
|
||||
return new CacheDataDescriptionImpl(true, true, ComparableComparator.INSTANCE);
|
||||
}
|
||||
|
|
|
@ -49,6 +49,7 @@ public class CollectionRegionImplTestCase extends AbstractEntityCollectionRegion
|
|||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void supportedAccessTypeTest(RegionFactory regionFactory, Properties properties) {
|
||||
|
||||
CollectionRegion region = regionFactory.buildCollectionRegion("test", properties, null);
|
||||
|
@ -93,5 +94,14 @@ public class CollectionRegionImplTestCase extends AbstractEntityCollectionRegion
|
|||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -49,6 +49,7 @@ public class EntityRegionImplTestCase extends AbstractEntityCollectionRegionTest
|
|||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void supportedAccessTypeTest(RegionFactory regionFactory, Properties properties) {
|
||||
|
||||
EntityRegion region = regionFactory.buildEntityRegion("test", properties, null);
|
||||
|
@ -94,5 +95,15 @@ public class EntityRegionImplTestCase extends AbstractEntityCollectionRegionTest
|
|||
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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue