HHH-6827 correct testing 2L cache impl, mostly are copied from ehcache impl

This commit is contained in:
Strong Liu 2011-11-21 20:09:34 +08:00
parent 15a46a9661
commit ba764816b9
8 changed files with 84 additions and 28 deletions

View File

@ -40,7 +40,9 @@ abstract class BaseRegionAccessStrategy implements RegionAccessStrategy {
);
protected abstract BaseGeneralDataRegion getInternalRegion();
protected abstract boolean isDefaultMinimalPutOverride();
@Override
public Object get(Object key, long txTimestamp) throws CacheException {
return getInternalRegion().get( key );
@ -68,13 +70,32 @@ abstract class BaseRegionAccessStrategy implements RegionAccessStrategy {
}
/**
* Region locks are not supported.
*
* @return <code>null</code>
*
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#lockRegion()
* @see org.hibernate.cache.spi.access.CollectionRegionAccessStrategy#lockRegion()
*/
@Override
public SoftLock lockItem(Object key, Object version) throws CacheException {
public SoftLock lockRegion() throws CacheException {
return null;
}
/**
* Region locks are not supported - perform a cache clear as a precaution.
*
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#unlockRegion(org.hibernate.cache.spi.access.SoftLock)
* @see org.hibernate.cache.spi.access.CollectionRegionAccessStrategy#unlockRegion(org.hibernate.cache.spi.access.SoftLock)
*/
@Override
public SoftLock lockRegion() throws CacheException {
public void unlockRegion(SoftLock lock) throws CacheException {
evictAll();
}
@Override
public SoftLock lockItem(Object key, Object version) throws CacheException {
return null;
}
@ -82,16 +103,23 @@ abstract class BaseRegionAccessStrategy implements RegionAccessStrategy {
public void unlockItem(Object key, SoftLock lock) throws CacheException {
}
@Override
public void unlockRegion(SoftLock lock) throws CacheException {
evictAll();
}
/**
* A no-op since this is an asynchronous cache access strategy.
*
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#remove(java.lang.Object)
* @see org.hibernate.cache.spi.access.CollectionRegionAccessStrategy#remove(java.lang.Object)
*/
@Override
public void remove(Object key) throws CacheException {
evict( key );
}
/**
* Called to evict data from the entire region
*
* @throws CacheException Propogated from underlying {@link org.hibernate.cache.spi.Region}
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#removeAll()
* @see org.hibernate.cache.spi.access.CollectionRegionAccessStrategy#removeAll()
*/
@Override
public void removeAll() throws CacheException {
evictAll();

View File

@ -63,8 +63,8 @@ class CollectionRegionImpl extends BaseTransactionalDataRegion implements Collec
case NONSTRICT_READ_WRITE:
return new NonstrictReadWriteCollectionRegionAccessStrategy( this );
case TRANSACTIONAL:
throw new UnsupportedOperationException( "doesn't support this access strategy" );
return new TransactionalCollectionRegionAccessStrategy( this );
// throw new UnsupportedOperationException( "doesn't support this access strategy" );
default:
throw new IllegalArgumentException( "unrecognized access strategy type [" + accessType + "]" );
}

View File

@ -67,7 +67,7 @@ class EntityRegionImpl extends BaseTransactionalDataRegion implements EntityRegi
return new NonstrictReadWriteEntityRegionAccessStrategy( this );
case TRANSACTIONAL:
// throw new UnsupportedOperationException( "doesn't support this access strategy" );
return new NonstrictReadWriteEntityRegionAccessStrategy( this );
return new TransactionalEntityRegionAccessStrategy( this );
default:
throw new IllegalArgumentException( "unrecognized access strategy type [" + accessType + "]" );

View File

@ -33,10 +33,6 @@ import org.hibernate.internal.CoreMessageLogger;
* @author Strong Liu
*/
class NonstrictReadWriteCollectionRegionAccessStrategy extends BaseCollectionRegionAccessStrategy {
private static final CoreMessageLogger LOG = Logger.getMessageLogger(
CoreMessageLogger.class, NonstrictReadWriteCollectionRegionAccessStrategy.class.getName()
);
NonstrictReadWriteCollectionRegionAccessStrategy(CollectionRegionImpl region) {
super( region );
}
@ -45,4 +41,8 @@ class NonstrictReadWriteCollectionRegionAccessStrategy extends BaseCollectionReg
evict( key );
}
@Override
public void remove(Object key) throws CacheException {
evict( key );
}
}

View File

@ -37,25 +37,49 @@ class NonstrictReadWriteEntityRegionAccessStrategy extends BaseEntityRegionAcces
super( region );
}
/**
* Since this is a non-strict read/write strategy item locking is not used.
*/
@Override
public void unlockItem(Object key, SoftLock lock) throws CacheException {
evict( key );
}
/**
* Returns <code>false</code> since this is an asynchronous cache access strategy.
*/
@Override
public boolean insert(Object key, Object value, Object version) throws CacheException {
return false;
}
/**
* Returns <code>false</code> since this is a non-strict read/write cache access strategy
*/
@Override
public boolean afterInsert(Object key, Object value, Object version) throws CacheException {
return false;
}
/**
* Removes the entry since this is a non-strict read/write cache strategy.
*/
@Override
public boolean update(Object key, Object value, Object currentVersion, Object previousVersion)
throws CacheException {
evict( key );
return false;
}
@Override
public boolean afterUpdate(Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock)
throws CacheException {
unlockItem( key, lock );
return false;
}
@Override
public void remove(Object key) throws CacheException {
evict( key );
}
}

View File

@ -52,8 +52,6 @@ class ReadOnlyCollectionRegionAccessStrategy extends BaseCollectionRegionAccessS
throw new UnsupportedOperationException( "Can't write to a readonly object" );
}
@Override
public void remove(Object key) throws CacheException {
}
}

View File

@ -40,11 +40,9 @@ class ReadOnlyEntityRegionAccessStrategy extends BaseEntityRegionAccessStrategy
ReadOnlyEntityRegionAccessStrategy(EntityRegionImpl region) {
super( region );
}
@Override
public void remove(Object key) throws CacheException {
}
/**
* This cache is asynchronous hence a no-op
*/
@Override
public boolean insert(Object key, Object value, Object version) throws CacheException {
return false; //wait until tx complete, see afterInsert().
@ -56,7 +54,9 @@ class ReadOnlyEntityRegionAccessStrategy extends BaseEntityRegionAccessStrategy
return true;
}
/**
* This cache is asynchronous hence a no-op
*/
@Override
public void unlockItem(Object key, SoftLock lock) throws CacheException {
LOG.invalidEditOfReadOnlyItem( key );
@ -68,6 +68,11 @@ class ReadOnlyEntityRegionAccessStrategy extends BaseEntityRegionAccessStrategy
throw new UnsupportedOperationException( "Can't write to a readonly object" );
}
/**
* Throws UnsupportedOperationException since this cache is read-only
*
* @throws UnsupportedOperationException always
*/
@Override
public boolean update(Object key, Object value, Object currentVersion, Object previousVersion)
throws CacheException {
@ -75,6 +80,11 @@ class ReadOnlyEntityRegionAccessStrategy extends BaseEntityRegionAccessStrategy
throw new UnsupportedOperationException( "Can't write to a readonly object" );
}
/**
* Throws UnsupportedOperationException since this cache is read-only
*
* @throws UnsupportedOperationException always
*/
@Override
public boolean afterUpdate(Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock)
throws CacheException {

View File

@ -52,10 +52,6 @@ class ReadWriteEntityRegionAccessStrategy extends AbstractReadWriteAccessStrateg
return false;
}
@Override
public void evict(Object key) throws CacheException {
}
@Override
public boolean afterInsert(Object key, Object value, Object version) throws CacheException {