Author: galder.zamarreno(a)jboss.com
Date: 2009-08-14 09:10:49 -0400 (Fri, 14 Aug 2009)
New Revision: 17302
Added:
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/classloader/
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/classloader/Account.hbm.xml
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/classloader/Account.java
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/classloader/AccountHolder.java
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/classloader/ClassLoaderTestDAO.java
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/SessionRefreshTestCase.java
Removed:
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/InfinispanTest.java
core/branches/INFINISPAN/cache-infinispan/src/test/resources/invalid-infinispan-configs.xml
Modified:
core/branches/INFINISPAN/cache-infinispan/pom.xml
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanRegionFactory.java
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/InfinispanCollectionRegion.java
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/ReadOnlyAccess.java
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/TransactionalAccess.java
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/entity/ReadOnlyAccess.java
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/entity/TransactionalAccess.java
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/impl/BaseGeneralDataRegion.java
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/query/InfinispanQueryResultsRegion.java
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/timestamp/InfinispanTimestampsRegion.java
core/branches/INFINISPAN/cache-infinispan/src/main/resources/org/hibernate/cache/infinispan/builder/infinispan-configs.xml
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/InfinispanRegionFactoryTestCase.java
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/BasicReadOnlyTestCase.java
Log:
[ISPN-6] Keep adding more unit tests. Added test dependency on Infinispan test to be able
to print cache contents in test.
Modified: core/branches/INFINISPAN/cache-infinispan/pom.xml
===================================================================
--- core/branches/INFINISPAN/cache-infinispan/pom.xml 2009-08-13 20:15:08 UTC (rev 17301)
+++ core/branches/INFINISPAN/cache-infinispan/pom.xml 2009-08-14 13:10:49 UTC (rev 17302)
@@ -51,6 +51,13 @@
<!-- <scope>test</scope> TODO fix this -->
</dependency>
<dependency>
+ <groupId>org.infinispan</groupId>
+ <artifactId>infinispan-core</artifactId>
+ <version>${version.infinispan}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>${version.hsqldb}</version>
Modified:
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanRegionFactory.java
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanRegionFactory.java 2009-08-13
20:15:08 UTC (rev 17301)
+++
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanRegionFactory.java 2009-08-14
13:10:49 UTC (rev 17302)
@@ -1,5 +1,6 @@
package org.hibernate.cache.infinispan;
+import java.io.IOException;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
@@ -82,14 +83,14 @@
*/
public static final String COLLECTION_CACHE_RESOURCE_PROP = PREFIX + COLLECTION_KEY +
CONFIG_SUFFIX;
- private static final String TIMESTAMP_KEY = "timestamp";
+ private static final String TIMESTAMPS_KEY = "timestamps";
/**
* Name of the configuration that should be used for timestamp caches.
*
* @see #DEF_TS_RESOURCE
*/
- public static final String TIMESTAMP_CACHE_RESOURCE_PROP = PREFIX + TIMESTAMP_KEY +
CONFIG_SUFFIX;
+ public static final String TIMESTAMPS_CACHE_RESOURCE_PROP = PREFIX + TIMESTAMPS_KEY +
CONFIG_SUFFIX;
private static final String QUERY_KEY = "query";
@@ -111,9 +112,9 @@
public static final String DEF_ENTITY_RESOURCE = "entity";
/**
- * Default value for {@link #TIMESTAMP_CACHE_RESOURCE_PROP}.
+ * Default value for {@link #TIMESTAMPS_CACHE_RESOURCE_PROP}.
*/
- public static final String DEF_TIMESTAMP_RESOURCE = "timestamp";
+ public static final String DEF_TIMESTAMPS_RESOURCE = "timestamps";
/**
* Default value for {@link #QUERY_CACHE_RESOURCE_PROP}.
@@ -190,7 +191,8 @@
public QueryResultsRegion buildQueryResultsRegion(String regionName, Properties
properties)
throws CacheException {
log.debug("Building query results cache region [" + regionName +
"]");
- return new InfinispanQueryResultsRegion(manager.getCache(regionName), regionName);
+ String cacheName = typeOverrides.get(QUERY_KEY).getCacheName();
+ return new InfinispanQueryResultsRegion(manager.getCache(cacheName), regionName);
}
/**
@@ -199,7 +201,8 @@
public TimestampsRegion buildTimestampsRegion(String regionName, Properties
properties)
throws CacheException {
log.debug("Building timestamps cache region [" + regionName +
"]");
- return new InfinispanTimestampsRegion(manager.getCache(regionName), regionName);
+ String cacheName = typeOverrides.get(TIMESTAMPS_KEY).getCacheName();
+ return new InfinispanTimestampsRegion(manager.getCache(cacheName), regionName);
}
/**
@@ -231,7 +234,7 @@
log.debug("Starting Infinispan CacheManager");
try {
String configLoc = PropertiesHelper.getString(INFINISPAN_CONFIG_RESOURCE_PROP,
properties, DEF_INFINISPAN_CONFIG_RESOURCE);
- manager = new DefaultCacheManager(configLoc);
+ manager = createCacheManager(configLoc);
initGenericDataTypeOverrides();
Enumeration keys = properties.propertyNames();
while (keys.hasMoreElements()) {
@@ -309,7 +312,15 @@
public Set<String> getDefinedConfigurations() {
return Collections.unmodifiableSet(definedConfigurations);
}
-
+
+ protected CacheManager createCacheManager(String configLoc) throws CacheException {
+ try {
+ return new DefaultCacheManager(configLoc);
+ } catch (IOException e) {
+ throw new CacheException("Unable to create default cache manager",
e);
+ }
+ }
+
// private Configuration createCacheConfig(TypeOverrides config) {
// Configuration cacheCfg = new Configuration();
// return overrideCacheConfig(config, cacheCfg);
@@ -323,8 +334,8 @@
collectionOverrides.setCacheName(DEF_ENTITY_RESOURCE);
typeOverrides.put(COLLECTION_KEY, collectionOverrides);
TypeOverrides timestampOverrides = new TimestampTypeOverrides();
- timestampOverrides.setCacheName(DEF_TIMESTAMP_RESOURCE);
- typeOverrides.put(TIMESTAMP_KEY, timestampOverrides);
+ timestampOverrides.setCacheName(DEF_TIMESTAMPS_RESOURCE);
+ typeOverrides.put(TIMESTAMPS_KEY, timestampOverrides);
TypeOverrides queryOverrides = new TypeOverrides();
queryOverrides.setCacheName(DEF_QUERY_RESOURCE);
typeOverrides.put(QUERY_KEY, queryOverrides);
@@ -389,7 +400,7 @@
}
private void defineGenericDataTypeCacheConfigurations() throws CacheException {
- String[] defaultGenericDataTypes = new String[]{ENTITY_KEY, COLLECTION_KEY,
TIMESTAMP_KEY, QUERY_KEY};
+ String[] defaultGenericDataTypes = new String[]{ENTITY_KEY, COLLECTION_KEY,
TIMESTAMPS_KEY, QUERY_KEY};
for (String type : defaultGenericDataTypes) {
TypeOverrides override = typeOverrides.get(type);
String cacheName = override.getCacheName();
Modified:
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/InfinispanCollectionRegion.java
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/InfinispanCollectionRegion.java 2009-08-13
20:15:08 UTC (rev 17301)
+++
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/InfinispanCollectionRegion.java 2009-08-14
13:10:49 UTC (rev 17302)
@@ -8,6 +8,9 @@
import org.hibernate.cache.infinispan.impl.BaseTransactionalDataRegion;
import org.infinispan.Cache;
+/**
+ * @author Chris Bredesen
+ */
public class InfinispanCollectionRegion extends BaseTransactionalDataRegion implements
CollectionRegion {
public InfinispanCollectionRegion(Cache<Object, Object> cache, String name,
CacheDataDescription metadata) {
Modified:
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/ReadOnlyAccess.java
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/ReadOnlyAccess.java 2009-08-13
20:15:08 UTC (rev 17301)
+++
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/ReadOnlyAccess.java 2009-08-14
13:10:49 UTC (rev 17302)
@@ -5,72 +5,73 @@
import org.hibernate.cache.access.CollectionRegionAccessStrategy;
import org.hibernate.cache.access.SoftLock;
+/**
+ * @author Chris Bredesen
+ */
public class ReadOnlyAccess implements CollectionRegionAccessStrategy {
- private final InfinispanCollectionRegion region;
-
- public ReadOnlyAccess( InfinispanCollectionRegion region ) {
- this.region = region;
- }
+ private final InfinispanCollectionRegion region;
- public void evict( Object key ) throws CacheException {
- region.getCache().evict( key );
- }
+ public ReadOnlyAccess(InfinispanCollectionRegion region) {
+ this.region = region;
+ }
- public void evictAll() throws CacheException {
- // TODO ensure proper clustering semantics here
- region.getCache().clear();
- }
+ public void evict(Object key) throws CacheException {
+ region.getCache().evict(key);
+ }
- public Object get( Object key, long txTimestamp ) throws CacheException {
- // TODO Auto-generated method stub
- return null;
- }
+ public void evictAll() throws CacheException {
+ // TODO ensure proper clustering semantics here
+ region.getCache().clear();
+ }
- public CollectionRegion getRegion() {
- return region;
- }
+ public Object get(Object key, long txTimestamp) throws CacheException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- public SoftLock lockItem( Object key, Object version ) throws CacheException {
- // TODO Auto-generated method stub
- return null;
- }
+ public CollectionRegion getRegion() {
+ return region;
+ }
- public SoftLock lockRegion() throws CacheException {
- // TODO Auto-generated method stub
- return null;
- }
+ public SoftLock lockItem(Object key, Object version) throws CacheException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- public boolean putFromLoad( Object key, Object value, long txTimestamp, Object version
)
- throws CacheException {
- // TODO Auto-generated method stub
- return false;
- }
+ public SoftLock lockRegion() throws CacheException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- public boolean putFromLoad( Object key, Object value, long txTimestamp, Object version,
- boolean minimalPutOverride ) throws CacheException {
- // TODO Auto-generated method stub
- return false;
- }
+ public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version)
throws CacheException {
+ // TODO Auto-generated method stub
+ return false;
+ }
- public void remove( Object key ) throws CacheException {
- // TODO Auto-generated method stub
-
- }
+ public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version,
boolean minimalPutOverride)
+ throws CacheException {
+ // TODO Auto-generated method stub
+ return false;
+ }
- public void removeAll() throws CacheException {
- // TODO Auto-generated method stub
-
- }
+ public void remove(Object key) throws CacheException {
+ // TODO Auto-generated method stub
- public void unlockItem( Object key, SoftLock lock ) throws CacheException {
- // TODO Auto-generated method stub
-
- }
+ }
- public void unlockRegion( SoftLock lock ) throws CacheException {
- // TODO Auto-generated method stub
-
- }
+ public void removeAll() throws CacheException {
+ // TODO Auto-generated method stub
-
+ }
+
+ public void unlockItem(Object key, SoftLock lock) throws CacheException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void unlockRegion(SoftLock lock) throws CacheException {
+ // TODO Auto-generated method stub
+
+ }
+
}
Modified:
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/TransactionalAccess.java
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/TransactionalAccess.java 2009-08-13
20:15:08 UTC (rev 17301)
+++
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/TransactionalAccess.java 2009-08-14
13:10:49 UTC (rev 17302)
@@ -11,63 +11,62 @@
* @author Chris Bredesen
*/
public class TransactionalAccess implements CollectionRegionAccessStrategy {
- private final InfinispanCollectionRegion region;
+ private final InfinispanCollectionRegion region;
- public TransactionalAccess( InfinispanCollectionRegion region ) {
- this.region = region;
- }
+ public TransactionalAccess(InfinispanCollectionRegion region) {
+ this.region = region;
+ }
- public void evict( Object key ) throws CacheException {
- region.getCache().evict( key );
- }
+ public void evict(Object key) throws CacheException {
+ region.getCache().evict(key);
+ }
- public void evictAll() throws CacheException {
- // TODO ensure proper clustering semantics
- region.getCache().clear();
- }
+ public void evictAll() throws CacheException {
+ // TODO ensure proper clustering semantics
+ region.getCache().clear();
+ }
- public Object get( Object key, long txTimestamp ) throws CacheException {
- return region.getCache().get( key );
- }
+ public Object get(Object key, long txTimestamp) throws CacheException {
+ return region.getCache().get(key);
+ }
- public boolean putFromLoad( Object key, Object value, long txTimestamp, Object version
)
- throws CacheException {
- region.getCache().putForExternalRead( key, value );
- return true;
- }
+ public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version)
throws CacheException {
+ region.getCache().putForExternalRead(key, value);
+ return true;
+ }
- public boolean putFromLoad( Object key, Object value, long txTimestamp, Object version,
- boolean minimalPutOverride ) throws CacheException {
- region.getCache().putForExternalRead( key, value );
- return true;
- }
+ public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version,
boolean minimalPutOverride)
+ throws CacheException {
+ region.getCache().putForExternalRead(key, value);
+ return true;
+ }
- public void remove( Object key ) throws CacheException {
- region.getCache().remove( key );
- }
+ public void remove(Object key) throws CacheException {
+ region.getCache().remove(key);
+ }
- public void removeAll() throws CacheException {
- region.getCache().clear();
- }
+ public void removeAll() throws CacheException {
+ region.getCache().clear();
+ }
- public CollectionRegion getRegion() {
- return region;
- }
+ public CollectionRegion getRegion() {
+ return region;
+ }
- // following methods copied from o.h.c.jbc2.collection.TransactionalAccess
+ // following methods copied from o.h.c.jbc2.collection.TransactionalAccess
- public SoftLock lockItem(Object key, Object version) throws CacheException {
- return null;
- }
+ public SoftLock lockItem(Object key, Object version) throws CacheException {
+ return null;
+ }
- public SoftLock lockRegion() throws CacheException {
- return null;
- }
+ public SoftLock lockRegion() throws CacheException {
+ return null;
+ }
- public void unlockItem(Object key, SoftLock lock) throws CacheException {
- }
+ public void unlockItem(Object key, SoftLock lock) throws CacheException {
+ }
- public void unlockRegion(SoftLock lock) throws CacheException {
- }
+ public void unlockRegion(SoftLock lock) throws CacheException {
+ }
}
\ No newline at end of file
Modified:
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/entity/ReadOnlyAccess.java
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/entity/ReadOnlyAccess.java 2009-08-13
20:15:08 UTC (rev 17301)
+++
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/entity/ReadOnlyAccess.java 2009-08-14
13:10:49 UTC (rev 17302)
@@ -6,43 +6,42 @@
import org.slf4j.LoggerFactory;
/**
- * A specialization of {@link TransactionalAccess} that ensures we never update
- * data. Infinispan access is always transactional.
+ * A specialization of {@link TransactionalAccess} that ensures we never update data.
Infinispan
+ * access is always transactional.
*
* @author Chris Bredesen
*/
class ReadOnlyAccess extends TransactionalAccess {
- private static final Logger log = LoggerFactory.getLogger( ReadOnlyAccess.class );
+ private static final Logger log = LoggerFactory.getLogger(ReadOnlyAccess.class);
- ReadOnlyAccess( InfinispanEntityRegion region ) {
- super( region );
- }
+ ReadOnlyAccess(InfinispanEntityRegion region) {
+ super(region);
+ }
- public SoftLock lockItem( Object key, Object version ) throws CacheException {
- throw new UnsupportedOperationException( "Illegal attempt to edit read only
item" );
- }
+ public SoftLock lockItem(Object key, Object version) throws CacheException {
+ throw new UnsupportedOperationException("Illegal attempt to edit read only
item");
+ }
- public SoftLock lockRegion() throws CacheException {
- throw new UnsupportedOperationException( "Illegal attempt to edit read only
item" );
- }
+ public SoftLock lockRegion() throws CacheException {
+ throw new UnsupportedOperationException("Illegal attempt to edit read only
item");
+ }
- public void unlockItem( Object key, SoftLock lock ) throws CacheException {
- log.error( "Illegal attempt to edit read only item" );
- }
+ public void unlockItem(Object key, SoftLock lock) throws CacheException {
+ log.error("Illegal attempt to edit read only item");
+ }
- public void unlockRegion( SoftLock lock ) throws CacheException {
- log.error( "Illegal attempt to edit read only item" );
- }
+ public void unlockRegion(SoftLock lock) throws CacheException {
+ log.error("Illegal attempt to edit read only item");
+ }
- @Override
- public boolean update(Object key, Object value, Object currentVersion, Object
previousVersion)
- throws CacheException {
- throw new UnsupportedOperationException("Illegal attempt to edit read only
item");
- }
+ @Override
+ public boolean update(Object key, Object value, Object currentVersion, Object
previousVersion) throws CacheException {
+ throw new UnsupportedOperationException("Illegal attempt to edit read only
item");
+ }
- @Override
- public boolean afterUpdate(Object key, Object value, Object currentVersion, Object
previousVersion, SoftLock lock)
+ @Override
+ public boolean afterUpdate(Object key, Object value, Object currentVersion, Object
previousVersion, SoftLock lock)
throws CacheException {
- throw new UnsupportedOperationException("Illegal attempt to edit read only
item");
- }
+ throw new UnsupportedOperationException("Illegal attempt to edit read only
item");
+ }
}
\ No newline at end of file
Modified:
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/entity/TransactionalAccess.java
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/entity/TransactionalAccess.java 2009-08-13
20:15:08 UTC (rev 17301)
+++
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/entity/TransactionalAccess.java 2009-08-14
13:10:49 UTC (rev 17302)
@@ -13,82 +13,80 @@
* @author Chris Bredesen
*/
class TransactionalAccess implements EntityRegionAccessStrategy {
- private static final Logger log = LoggerFactory.getLogger( TransactionalAccess.class );
- private final InfinispanEntityRegion region;
+ private static final Logger log = LoggerFactory.getLogger(TransactionalAccess.class);
+ private final InfinispanEntityRegion region;
- TransactionalAccess( InfinispanEntityRegion region ) {
- this.region = region;
- }
+ TransactionalAccess(InfinispanEntityRegion region) {
+ this.region = region;
+ }
- public void evict( Object key ) throws CacheException {
- region.getCache().evict( key );
- }
+ public void evict(Object key) throws CacheException {
+ region.getCache().evict(key);
+ }
- public void evictAll() throws CacheException {
- region.getCache().clear();
- }
+ public void evictAll() throws CacheException {
+ region.getCache().clear();
+ }
- public Object get( Object key, long txTimestamp ) throws CacheException {
- return region.getCache().get( key );
- }
+ public Object get(Object key, long txTimestamp) throws CacheException {
+ return region.getCache().get(key);
+ }
- public EntityRegion getRegion() {
- return this.region;
- }
+ public EntityRegion getRegion() {
+ return this.region;
+ }
- public boolean insert( Object key, Object value, Object version ) throws CacheException
{
- region.getCache().put( key, value );
- return true; // TODO this is suspect
- }
+ public boolean insert(Object key, Object value, Object version) throws CacheException
{
+ region.getCache().put(key, value);
+ return true; // TODO this is suspect
+ }
- public boolean putFromLoad( Object key, Object value, long txTimestamp, Object version
)
- throws CacheException {
- region.getCache().putForExternalRead( key, value );
- return true;
- }
+ public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version)
throws CacheException {
+ region.getCache().putForExternalRead(key, value);
+ return true;
+ }
- public boolean putFromLoad( Object key, Object value, long txTimestamp, Object version,
- boolean minimalPutOverride ) throws CacheException {
- region.getCache().putForExternalRead( key, value );
- return true;
- }
+ public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version,
boolean minimalPutOverride)
+ throws CacheException {
+ region.getCache().putForExternalRead(key, value);
+ return true;
+ }
- public void remove( Object key ) throws CacheException {
- region.getCache().remove( key );
- }
+ public void remove(Object key) throws CacheException {
+ region.getCache().remove(key);
+ }
- public void removeAll() throws CacheException {
- region.getCache().clear(); // TODO is this right?
- }
+ public void removeAll() throws CacheException {
+ region.getCache().clear(); // TODO is this right?
+ }
- public boolean update( Object key, Object value, Object currentVersion, Object
previousVersion )
- throws CacheException {
- region.getCache().put( key, value );
- return true; // JBC2 provider does this...
- }
-
- // all remaining methods copied from the o.h.c.jbc2.entity.TransactionalAccess
+ public boolean update(Object key, Object value, Object currentVersion, Object
previousVersion) throws CacheException {
+ region.getCache().put(key, value);
+ return true; // JBC2 provider does this...
+ }
- public SoftLock lockItem(Object key, Object version) throws CacheException {
- return null;
- }
+ // all remaining methods copied from the o.h.c.jbc2.entity.TransactionalAccess
- public SoftLock lockRegion() throws CacheException {
- return null;
- }
+ public SoftLock lockItem(Object key, Object version) throws CacheException {
+ return null;
+ }
- public void unlockItem(Object key, SoftLock lock) throws CacheException {
- }
+ public SoftLock lockRegion() throws CacheException {
+ return null;
+ }
- public void unlockRegion(SoftLock lock) throws CacheException {
- }
+ public void unlockItem(Object key, SoftLock lock) throws CacheException {
+ }
- public boolean afterInsert(Object key, Object value, Object version) throws
CacheException {
- return false;
- }
+ public void unlockRegion(SoftLock lock) throws CacheException {
+ }
- public boolean afterUpdate(Object key, Object value, Object currentVersion, Object
previousVersion, SoftLock lock)
+ public boolean afterInsert(Object key, Object value, Object version) throws
CacheException {
+ return false;
+ }
+
+ public boolean afterUpdate(Object key, Object value, Object currentVersion, Object
previousVersion, SoftLock lock)
throws CacheException {
- return false;
- }
+ return false;
+ }
}
\ No newline at end of file
Modified:
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/impl/BaseGeneralDataRegion.java
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/impl/BaseGeneralDataRegion.java 2009-08-13
20:15:08 UTC (rev 17301)
+++
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/impl/BaseGeneralDataRegion.java 2009-08-14
13:10:49 UTC (rev 17302)
@@ -11,24 +11,24 @@
*/
public abstract class BaseGeneralDataRegion extends BaseRegion implements
GeneralDataRegion {
- public BaseGeneralDataRegion( Cache<Object, Object> cache, String name ) {
- super( cache, name );
- }
+ public BaseGeneralDataRegion(Cache<Object, Object> cache, String name) {
+ super(cache, name);
+ }
- public void evict( Object key ) throws CacheException {
- getCache().evict( key );
- }
+ public void evict(Object key) throws CacheException {
+ getCache().evict(key);
+ }
- public void evictAll() throws CacheException {
- getCache().clear();
- }
+ public void evictAll() throws CacheException {
+ getCache().clear();
+ }
- public Object get( Object key ) throws CacheException {
- return getCache().get( key );
- }
+ public Object get(Object key) throws CacheException {
+ return getCache().get(key);
+ }
- public void put( Object key, Object value ) throws CacheException {
- getCache().put( key, value );
- }
+ public void put(Object key, Object value) throws CacheException {
+ getCache().put(key, value);
+ }
}
\ No newline at end of file
Modified:
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/query/InfinispanQueryResultsRegion.java
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/query/InfinispanQueryResultsRegion.java 2009-08-13
20:15:08 UTC (rev 17301)
+++
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/query/InfinispanQueryResultsRegion.java 2009-08-14
13:10:49 UTC (rev 17302)
@@ -4,10 +4,13 @@
import org.hibernate.cache.infinispan.impl.BaseGeneralDataRegion;
import org.infinispan.Cache;
+/**
+ * @author Chris Bredesen
+ */
public class InfinispanQueryResultsRegion extends BaseGeneralDataRegion implements
QueryResultsRegion {
- public InfinispanQueryResultsRegion( Cache<Object, Object> cache, String name ) {
- super( cache, name );
- }
+ public InfinispanQueryResultsRegion(Cache<Object, Object> cache, String name) {
+ super(cache, name);
+ }
}
\ No newline at end of file
Modified:
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/timestamp/InfinispanTimestampsRegion.java
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/timestamp/InfinispanTimestampsRegion.java 2009-08-13
20:15:08 UTC (rev 17301)
+++
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/timestamp/InfinispanTimestampsRegion.java 2009-08-14
13:10:49 UTC (rev 17302)
@@ -4,10 +4,13 @@
import org.hibernate.cache.infinispan.impl.BaseGeneralDataRegion;
import org.infinispan.Cache;
+/**
+ * @author Chris Bredesen
+ */
public class InfinispanTimestampsRegion extends BaseGeneralDataRegion implements
TimestampsRegion {
- public InfinispanTimestampsRegion( Cache<Object, Object> cache, String name ) {
- super( cache, name );
- }
-
+ public InfinispanTimestampsRegion(Cache<Object, Object> cache, String name) {
+ super(cache, name);
+ }
+
}
\ No newline at end of file
Modified:
core/branches/INFINISPAN/cache-infinispan/src/main/resources/org/hibernate/cache/infinispan/builder/infinispan-configs.xml
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/main/resources/org/hibernate/cache/infinispan/builder/infinispan-configs.xml 2009-08-13
20:15:08 UTC (rev 17301)
+++
core/branches/INFINISPAN/cache-infinispan/src/main/resources/org/hibernate/cache/infinispan/builder/infinispan-configs.xml 2009-08-14
13:10:49 UTC (rev 17302)
@@ -20,7 +20,7 @@
<!-- Default configuration is appropriate for entity/collection caching. -->
<namedCache name="entity">
- <clustering mode="INVALIDATION_SYNC">
+ <clustering mode="invalidation">
<stateRetrieval fetchInMemoryState="false"
timeout="20000"/>
<sync replTimeout="20000"/>
</clustering>
@@ -30,39 +30,32 @@
repeatable-read semantic. Before choosing this config, carefully read the docs
and make sure you really need REPEATABLE_READ.
-->
- <locking isolationLevel="READ_COMMITTED"
concurrencyLevel="1000" lockAcquisitionTimeout="15000"/>
- <!--
- Eviction configuration. WakeupInterval defines how often the eviction thread
runs, in milliseconds. 0 means
- the eviction thread will never run. A separate executor is used for eviction in
each cache.
- -->
+ <locking isolationLevel="READ_COMMITTED"
concurrencyLevel="1000" lockAcquisitionTimeout="15000"/>
+ <!-- Eviction configuration. WakeupInterval defines how often the eviction
thread runs, in milliseconds.
+ 0 means the eviction thread will never run. A separate executor is used for
eviction in each cache. -->
<eviction wakeUpInterval="5000" maxEntries="10000"
strategy="FIFO"/>
<expiration maxIdle="100000"/>
<lazyDeserialization enabled="true"/>
</namedCache>
- <!-- A config appropriate for query caching. Does not replicate
- queries. DO NOT STORE TIMESTAMPS IN THIS CACHE.
- -->
+ <!-- A config appropriate for query caching. Does not replicate queries. -->
<namedCache name="local-query">
- <locking isolationLevel="READ_COMMITTED"
concurrencyLevel="1000" lockAcquisitionTimeout="15000"/>
- <!--
- Eviction configuration. WakeupInterval defines how often the eviction thread
runs, in milliseconds. 0 means
- the eviction thread will never run. A separate executor is used for eviction in
each cache.
- -->
+ <locking isolationLevel="READ_COMMITTED"
concurrencyLevel="1000" lockAcquisitionTimeout="15000"/>
+ <!--Eviction configuration. WakeupInterval defines how often the eviction
thread runs, in milliseconds. 0 means
+ the eviction thread will never run. A separate executor is used for eviction in
each cache. -->
<eviction wakeUpInterval="5000" maxEntries="10000"
strategy="FIFO"/>
<expiration maxIdle="100000"/>
</namedCache>
<!-- Optimized for timestamp caching. A clustered timestamp cache
is required if query caching is used, even if the query cache
- itself is configured with CacheMode=LOCAL.
- -->
- <namedCache name="timestamp">
- <clustering mode="REPL_ASYNC">
+ itself is configured with CacheMode=LOCAL. -->
+ <namedCache name="timestamps">
+ <clustering mode="replication">
<stateRetrieval fetchInMemoryState="true"
timeout="20000"/>
<async/>
</clustering>
- <locking isolationLevel="READ_COMMITTED"
concurrencyLevel="1000" lockAcquisitionTimeout="15000"/>
+ <locking isolationLevel="READ_COMMITTED"
concurrencyLevel="1000" lockAcquisitionTimeout="15000"/>
<lazyDeserialization enabled="true"/>
<!-- Don't ever evict modification timestamps -->
<eviction wakeUpInterval="0" strategy="NONE"/>
Modified:
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/InfinispanRegionFactoryTestCase.java
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/InfinispanRegionFactoryTestCase.java 2009-08-13
20:15:08 UTC (rev 17301)
+++
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/InfinispanRegionFactoryTestCase.java 2009-08-14
13:10:49 UTC (rev 17302)
@@ -27,9 +27,14 @@
import org.hibernate.cache.infinispan.InfinispanRegionFactory;
import org.hibernate.cache.infinispan.collection.InfinispanCollectionRegion;
import org.hibernate.cache.infinispan.entity.InfinispanEntityRegion;
+import org.hibernate.cache.infinispan.query.InfinispanQueryResultsRegion;
+import org.hibernate.cache.infinispan.timestamp.InfinispanTimestampsRegion;
import org.infinispan.Cache;
import org.infinispan.config.Configuration;
+import org.infinispan.config.Configuration.CacheMode;
import org.infinispan.eviction.EvictionStrategy;
+import org.infinispan.manager.CacheManager;
+import org.infinispan.manager.DefaultCacheManager;
import junit.framework.TestCase;
@@ -63,7 +68,7 @@
assertEquals("entity",
factory.getTypeOverrides().get("entity").getCacheName());
assertEquals("entity",
factory.getTypeOverrides().get("collection").getCacheName());
- assertEquals("timestamp",
factory.getTypeOverrides().get("timestamp").getCacheName());
+ assertEquals("timestamps",
factory.getTypeOverrides().get("timestamps").getCacheName());
assertEquals("person-cache",
factory.getTypeOverrides().get(person).getCacheName());
assertEquals(EvictionStrategy.LRU,
factory.getTypeOverrides().get(person).getEvictionStrategy());
@@ -112,12 +117,22 @@
p.setProperty("hibernate.cache.infinispan.collection.eviction.max_entries",
"25000");
InfinispanRegionFactory factory = new InfinispanRegionFactory();
factory.start(null, p);
- assertNotNull(factory.getTypeOverrides().get(person));
- assertFalse(factory.getDefinedConfigurations().contains(person));
- assertNotNull(factory.getTypeOverrides().get(addresses));
- assertFalse(factory.getDefinedConfigurations().contains(addresses));
- Cache cache = null;
+ CacheManager manager = factory.getCacheManager();
+ manager.getGlobalConfiguration().setTransportClass(null);
+// Configuration config = new Configuration();
+// // Set to local to avoid creating a JGroups channel
+// config.setCacheMode(CacheMode.LOCAL);
+// manager.defineConfiguration("entity", config);
+// manager.defineConfiguration("timestamps", config);
+// manager.defineConfiguration("myentity-cache", config);
+// manager.defineConfiguration("mycollection-cache", config);
try {
+ assertNotNull(factory.getTypeOverrides().get(person));
+ assertFalse(factory.getDefinedConfigurations().contains(person));
+ assertNotNull(factory.getTypeOverrides().get(addresses));
+ assertFalse(factory.getDefinedConfigurations().contains(addresses));
+ Cache cache = null;
+
InfinispanEntityRegion region = (InfinispanEntityRegion)
factory.buildEntityRegion(person, p, null);
assertNotNull(factory.getTypeOverrides().get(person));
assertTrue(factory.getDefinedConfigurations().contains(person));
@@ -129,80 +144,60 @@
assertEquals(5000, cacheCfg.getEvictionMaxEntries());
assertEquals(60000, cacheCfg.getExpirationLifespan());
assertEquals(30000, cacheCfg.getExpirationMaxIdle());
- } finally {
- if (cache != null) cache.stop();
- }
- try {
- InfinispanEntityRegion region = (InfinispanEntityRegion)
factory.buildEntityRegion(address, p, null);
+ region = (InfinispanEntityRegion) factory.buildEntityRegion(address, p, null);
assertNotNull(factory.getTypeOverrides().get(person));
assertTrue(factory.getDefinedConfigurations().contains(person));
assertNull(factory.getTypeOverrides().get(address));
cache = region.getCache();
- Configuration cacheCfg = cache.getConfiguration();
+ cacheCfg = cache.getConfiguration();
assertEquals(EvictionStrategy.FIFO, cacheCfg.getEvictionStrategy());
assertEquals(3000, cacheCfg.getEvictionWakeUpInterval());
assertEquals(20000, cacheCfg.getEvictionMaxEntries());
- } finally {
- if (cache != null) cache.stop();
- }
- try {
- InfinispanEntityRegion region = (InfinispanEntityRegion)
factory.buildEntityRegion(car, p, null);
+ region = (InfinispanEntityRegion) factory.buildEntityRegion(car, p, null);
assertNotNull(factory.getTypeOverrides().get(person));
assertTrue(factory.getDefinedConfigurations().contains(person));
assertNull(factory.getTypeOverrides().get(address));
cache = region.getCache();
- Configuration cacheCfg = cache.getConfiguration();
+ cacheCfg = cache.getConfiguration();
assertEquals(EvictionStrategy.FIFO, cacheCfg.getEvictionStrategy());
assertEquals(3000, cacheCfg.getEvictionWakeUpInterval());
assertEquals(20000, cacheCfg.getEvictionMaxEntries());
- } finally {
- if (cache != null) cache.stop();
- }
- try {
- InfinispanCollectionRegion region = (InfinispanCollectionRegion)
factory.buildCollectionRegion(addresses, p, null);
+ InfinispanCollectionRegion collectionRegion = (InfinispanCollectionRegion)
factory.buildCollectionRegion(addresses, p, null);
assertNotNull(factory.getTypeOverrides().get(addresses));
assertTrue(factory.getDefinedConfigurations().contains(person));
assertNull(factory.getTypeOverrides().get(parts));
- cache = region.getCache();
- Configuration cacheCfg = cache.getConfiguration();
+ cache = collectionRegion .getCache();
+ cacheCfg = cache.getConfiguration();
assertEquals(EvictionStrategy.FIFO, cacheCfg.getEvictionStrategy());
assertEquals(2500, cacheCfg.getEvictionWakeUpInterval());
assertEquals(5500, cacheCfg.getEvictionMaxEntries());
assertEquals(65000, cacheCfg.getExpirationLifespan());
assertEquals(35000, cacheCfg.getExpirationMaxIdle());
- } finally {
- if (cache != null) cache.stop();
- }
- try {
- InfinispanCollectionRegion region = (InfinispanCollectionRegion)
factory.buildCollectionRegion(parts, p, null);
+ collectionRegion = (InfinispanCollectionRegion)
factory.buildCollectionRegion(parts, p, null);
assertNotNull(factory.getTypeOverrides().get(addresses));
assertTrue(factory.getDefinedConfigurations().contains(addresses));
assertNull(factory.getTypeOverrides().get(parts));
- cache = region.getCache();
- Configuration cacheCfg = cache.getConfiguration();
+ cache = collectionRegion.getCache();
+ cacheCfg = cache.getConfiguration();
assertEquals(EvictionStrategy.LRU, cacheCfg.getEvictionStrategy());
assertEquals(3500, cacheCfg.getEvictionWakeUpInterval());
assertEquals(25000, cacheCfg.getEvictionMaxEntries());
- } finally {
- if (cache != null) cache.stop();
- }
- try {
- InfinispanCollectionRegion region = (InfinispanCollectionRegion)
factory.buildCollectionRegion(parts, p, null);
+ collectionRegion = (InfinispanCollectionRegion)
factory.buildCollectionRegion(parts, p, null);
assertNotNull(factory.getTypeOverrides().get(addresses));
assertTrue(factory.getDefinedConfigurations().contains(addresses));
assertNull(factory.getTypeOverrides().get(parts));
- cache = region.getCache();
- Configuration cacheCfg = cache.getConfiguration();
+ cache = collectionRegion.getCache();
+ cacheCfg = cache.getConfiguration();
assertEquals(EvictionStrategy.LRU, cacheCfg.getEvictionStrategy());
assertEquals(3500, cacheCfg.getEvictionWakeUpInterval());
assertEquals(25000, cacheCfg.getEvictionMaxEntries());
} finally {
- if (cache != null) cache.stop();
+ factory.stop();
}
}
@@ -217,6 +212,8 @@
p.setProperty("hibernate.cache.infinispan.collection.eviction.max_entries",
"35000");
InfinispanRegionFactory factory = new InfinispanRegionFactory();
factory.start(null, p);
+ CacheManager manager = factory.getCacheManager();
+ manager.getGlobalConfiguration().setTransportClass(null);
try {
InfinispanEntityRegion region = (InfinispanEntityRegion)
factory.buildEntityRegion("com.acme.Address", p, null);
assertNull(factory.getTypeOverrides().get("com.acme.Address"));
@@ -226,20 +223,17 @@
assertEquals(3000, cacheCfg.getEvictionWakeUpInterval());
assertEquals(30000, cacheCfg.getEvictionMaxEntries());
assertEquals(100000, cacheCfg.getExpirationMaxIdle());
- } finally {
- if (cache != null) cache.stop();
- }
- try {
- InfinispanCollectionRegion region = (InfinispanCollectionRegion)
factory.buildCollectionRegion("com.acme.Person.addresses", p, null);
+
+ InfinispanCollectionRegion collectionRegion = (InfinispanCollectionRegion)
factory.buildCollectionRegion("com.acme.Person.addresses", p, null);
assertNull(factory.getTypeOverrides().get("com.acme.Person.addresses"));
- cache = region.getCache();
- Configuration cacheCfg = cache.getConfiguration();
+ cache = collectionRegion.getCache();
+ cacheCfg = cache.getConfiguration();
assertEquals(EvictionStrategy.LRU, cacheCfg.getEvictionStrategy());
assertEquals(3500, cacheCfg.getEvictionWakeUpInterval());
assertEquals(35000, cacheCfg.getEvictionMaxEntries());
assertEquals(100000, cacheCfg.getExpirationMaxIdle());
} finally {
- if (cache != null) cache.stop();
+ factory.stop();
}
}
@@ -256,14 +250,15 @@
p.setProperty("hibernate.cache.infinispan.entity.eviction.max_entries",
"10000");
InfinispanRegionFactory factory = new InfinispanRegionFactory();
factory.start(null, p);
- assertNotNull(factory.getTypeOverrides().get(person));
- assertFalse(factory.getDefinedConfigurations().contains(person));
- Cache cache = null;
+ CacheManager manager = factory.getCacheManager();
+ manager.getGlobalConfiguration().setTransportClass(null);
try {
+ assertNotNull(factory.getTypeOverrides().get(person));
+ assertFalse(factory.getDefinedConfigurations().contains(person));
InfinispanEntityRegion region = (InfinispanEntityRegion)
factory.buildEntityRegion(person, p, null);
assertNotNull(factory.getTypeOverrides().get(person));
assertTrue(factory.getDefinedConfigurations().contains(person));
- cache = region.getCache();
+ Cache cache = region.getCache();
Configuration cacheCfg = cache.getConfiguration();
assertEquals(EvictionStrategy.LRU, cacheCfg.getEvictionStrategy());
assertEquals(3000, cacheCfg.getEvictionWakeUpInterval());
@@ -271,18 +266,118 @@
assertEquals(60000, cacheCfg.getExpirationLifespan());
assertEquals(30000, cacheCfg.getExpirationMaxIdle());
} finally {
- if (cache != null) cache.stop();
+ factory.stop();
}
}
- public void testTimestampNoEvictionValidation() {
+ public void testTimestampValidation() {
Properties p = new Properties();
- p.setProperty("hibernate.cache.infinispan.cfg",
"invalid-infinispan-configs.xml");
- InfinispanRegionFactory factory = new InfinispanRegionFactory();
+ final DefaultCacheManager manager = new DefaultCacheManager();
+ InfinispanRegionFactory factory = new InfinispanRegionFactory() {
+ @Override
+ protected CacheManager createCacheManager(String configLoc) throws
CacheException {
+ return manager;
+ }
+ };
+ Configuration config = new Configuration();
+ config.setCacheMode(CacheMode.INVALIDATION_SYNC);
+ manager.defineConfiguration("timestamps", config);
try {
factory.start(null, p);
fail("Should have failed saying that invalidation is not allowed for
timestamp caches.");
} catch(CacheException ce) {
}
+
+ fail("Add more validations!");
}
+
+ public void testBuildDefaultTimestampsRegion() {
+ final String timestamps = "org.hibernate.cache.UpdateTimestampsCache";
+ Properties p = new Properties();
+ InfinispanRegionFactory factory = new InfinispanRegionFactory();
+ factory.start(null, p);
+ CacheManager manager = factory.getCacheManager();
+ manager.getGlobalConfiguration().setTransportClass(null);
+ try {
+
assertTrue(factory.getDefinedConfigurations().contains("timestamps"));
+
assertTrue(factory.getTypeOverrides().get("timestamps").getCacheName().equals("timestamps"));
+ Configuration config = new Configuration();
+ config.setFetchInMemoryState(false);
+ manager.defineConfiguration("timestamps", config);
+ InfinispanTimestampsRegion region = (InfinispanTimestampsRegion)
factory.buildTimestampsRegion(timestamps, p);
+ Cache cache = region.getCache();
+ Configuration cacheCfg = cache.getConfiguration();
+ assertEquals(EvictionStrategy.NONE, cacheCfg.getEvictionStrategy());
+ assertEquals(CacheMode.REPL_ASYNC, cacheCfg.getCacheMode());
+ assertTrue(cacheCfg.isUseLazyDeserialization());
+ } finally {
+ factory.stop();
+ }
+ }
+
+ public void testBuildDiffCacheNameTimestampsRegion() {
+ final String timestamps = "org.hibernate.cache.UpdateTimestampsCache";
+ Properties p = new Properties();
+ p.setProperty("hibernate.cache.infinispan.timestamps.cfg",
"unrecommended-timestamps");
+ InfinispanRegionFactory factory = new InfinispanRegionFactory();
+ factory.start(null, p);
+ CacheManager manager = factory.getCacheManager();
+ manager.getGlobalConfiguration().setTransportClass(null);
+ try {
+
assertFalse(factory.getDefinedConfigurations().contains("timestamp"));
+
assertTrue(factory.getDefinedConfigurations().contains("unrecommended-timestamps"));
+
assertTrue(factory.getTypeOverrides().get("timestamps").getCacheName().equals("unrecommended-timestamps"));
+ Configuration config = new Configuration();
+ config.setFetchInMemoryState(false);
+ config.setCacheMode(CacheMode.REPL_SYNC);
+ manager.defineConfiguration("unrecommended-timestamps", config);
+ InfinispanTimestampsRegion region = (InfinispanTimestampsRegion)
factory.buildTimestampsRegion(timestamps, p);
+ Cache cache = region.getCache();
+ Configuration cacheCfg = cache.getConfiguration();
+ assertEquals(EvictionStrategy.NONE, cacheCfg.getEvictionStrategy());
+ assertEquals(CacheMode.REPL_SYNC, cacheCfg.getCacheMode());
+ assertFalse(cacheCfg.isUseLazyDeserialization());
+ } finally {
+ factory.stop();
+ }
+ }
+
+ public void testBuildTimestamRegionWithOverrides() {
+ final String timestamps = "org.hibernate.cache.UpdateTimestampsCache";
+ Properties p = new Properties();
+ InfinispanRegionFactory factory = new InfinispanRegionFactory();
+ p.setProperty("hibernate.cache.infinispan.timestamps.cfg",
"mytimestamps-cache");
+ p.setProperty("hibernate.cache.infinispan.entity.eviction.strategy",
"FIFO");
+
p.setProperty("hibernate.cache.infinispan.entity.eviction.wake_up_interval",
"3000");
+ p.setProperty("hibernate.cache.infinispan.entity.eviction.max_entries",
"10000");
+ factory.start(null, p);
+ CacheManager manager = factory.getCacheManager();
+ manager.getGlobalConfiguration().setTransportClass(null);
+ try {
+ InfinispanTimestampsRegion region = (InfinispanTimestampsRegion)
factory.buildTimestampsRegion(timestamps, p);
+ assertTrue(factory.getDefinedConfigurations().contains(timestamps));
+ fail("Should fail cos no eviction configurations are allowed for timestamp
caches");
+ } finally {
+ factory.stop();
+ }
+ }
+
+ public void testBuildQueryRegion() {
+ final String query = "org.hibernate.cache.StandardQueryCache";
+ Properties p = new Properties();
+ InfinispanRegionFactory factory = new InfinispanRegionFactory();
+ factory.start(null, p);
+ CacheManager manager = factory.getCacheManager();
+ manager.getGlobalConfiguration().setTransportClass(null);
+ try {
+
assertTrue(factory.getDefinedConfigurations().contains("local-query"));
+ InfinispanQueryResultsRegion region = (InfinispanQueryResultsRegion)
factory.buildQueryResultsRegion(query, p);
+ Cache cache = region.getCache();
+ Configuration cacheCfg = cache.getConfiguration();
+ assertEquals(CacheMode.LOCAL, cacheCfg.getCacheMode());
+ } finally {
+ factory.stop();
+ }
+ }
+
}
Deleted:
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/InfinispanTest.java
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/InfinispanTest.java 2009-08-13
20:15:08 UTC (rev 17301)
+++
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/InfinispanTest.java 2009-08-14
13:10:49 UTC (rev 17302)
@@ -1,41 +0,0 @@
-package org.hibernate.test.cache.infinispan;
-
-import org.hibernate.cache.infinispan.InfinispanRegionFactory;
-import org.hibernate.test.cache.BaseRegionFactoryTestCase;
-
-/**
- * TODO: what is this exactly testing???
- */
-public class InfinispanTest extends BaseRegionFactoryTestCase {
-
- public InfinispanTest( String x ) {
- super( x );
- }
-
- @SuppressWarnings("unchecked")
- @Override
- protected Class getRegionFactory() {
- return InfinispanRegionFactory.class;
- }
-
- @Override
- protected String getConfigResourceKey() {
- return null;
- }
-
- @Override
- protected String getConfigResourceLocation() {
- return null;
- }
-
- @Override
- protected boolean useTransactionManager() {
- return false;
- }
-
- @Override
- public String getCacheConcurrencyStrategy() {
- return "read-only";
- }
-
-}
\ No newline at end of file
Modified:
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/BasicReadOnlyTestCase.java
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/BasicReadOnlyTestCase.java 2009-08-13
20:15:08 UTC (rev 17301)
+++
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/BasicReadOnlyTestCase.java 2009-08-14
13:10:49 UTC (rev 17302)
@@ -2,8 +2,8 @@
public class BasicReadOnlyTestCase extends AbstractInfinispanTestCase {
- public BasicReadOnlyTestCase( String string ) {
- super( string, "read-only" );
- }
-
+ public BasicReadOnlyTestCase(String string) {
+ super(string, "read-only");
+ }
+
}
\ No newline at end of file
Added:
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/classloader/Account.hbm.xml
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/classloader/Account.hbm.xml
(rev 0)
+++
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/classloader/Account.hbm.xml 2009-08-14
13:10:49 UTC (rev 17302)
@@ -0,0 +1,46 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<!--
+ ~ Hibernate, Relational Persistence for Idiomatic Java
+ ~
+ ~ Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ ~ indicated by the @author tags or express copyright attribution
+ ~ statements applied by the authors. All third-party contributions are
+ ~ distributed under license by Red Hat Middleware LLC.
+ ~
+ ~ This copyrighted material is made available to anyone wishing to use, modify,
+ ~ copy, or redistribute it subject to the terms and conditions of the GNU
+ ~ Lesser General Public License, as published by the Free Software Foundation.
+ ~
+ ~ This program is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ ~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ ~ for more details.
+ ~
+ ~ You should have received a copy of the GNU Lesser General Public License
+ ~ along with this distribution; if not, write to:
+ ~ Free Software Foundation, Inc.
+ ~ 51 Franklin Street, Fifth Floor
+ ~ Boston, MA 02110-1301 USA
+ -->
+<hibernate-mapping
+ package="org.hibernate.test.cache.infinispan.functional.classloader">
+
+ <class name="Account" table="Accounts">
+
+ <cache usage="transactional"/>
+
+ <id name="id">
+ <generator class="assigned"/>
+ </id>
+
+ <property name="branch" not-null="true"/>
+ <property name="balance" not-null="true"/>
+ <property name="accountHolder" type="serializable"
not-null="true"/>
+
+ </class>
+
+</hibernate-mapping>
Property changes on:
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/classloader/Account.hbm.xml
___________________________________________________________________
Name: svn:executable
+ *
Added:
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/classloader/Account.java
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/classloader/Account.java
(rev 0)
+++
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/classloader/Account.java 2009-08-14
13:10:49 UTC (rev 17302)
@@ -0,0 +1,123 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.cache.infinispan.functional.classloader;
+
+import java.io.Serializable;
+
+/**
+ * Comment
+ *
+ * @author Brian Stansberry
+ * @version $Revision: 60233 $
+ */
+public class Account implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ private Integer id;
+ private AccountHolder accountHolder;
+ private Integer balance;
+ private String branch;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public AccountHolder getAccountHolder() {
+ return accountHolder;
+ }
+
+ public void setAccountHolder(AccountHolder accountHolder) {
+ this.accountHolder = accountHolder;
+ }
+
+ public Integer getBalance() {
+ return balance;
+ }
+
+ public void setBalance(Integer balance) {
+ this.balance = balance;
+ }
+
+ public String getBranch() {
+ return branch;
+ }
+
+ public void setBranch(String branch) {
+ this.branch = branch;
+ }
+
+ public boolean equals(Object obj) {
+ if (obj == this)
+ return true;
+ if (!(obj instanceof Account))
+ return false;
+ Account acct = (Account) obj;
+ if (!safeEquals(id, acct.id))
+ return false;
+ if (!safeEquals(branch, acct.branch))
+ return false;
+ if (!safeEquals(balance, acct.balance))
+ return false;
+ if (!safeEquals(accountHolder, acct.accountHolder))
+ return false;
+ return true;
+ }
+
+ public int hashCode() {
+ int result = 17;
+ result = result * 31 + safeHashCode(id);
+ result = result * 31 + safeHashCode(branch);
+ result = result * 31 + safeHashCode(balance);
+ result = result * 31 + safeHashCode(accountHolder);
+ return result;
+ }
+
+ public String toString() {
+ StringBuffer sb = new StringBuffer(getClass().getName());
+ sb.append("[id=");
+ sb.append(id);
+ sb.append(",branch=");
+ sb.append(branch);
+ sb.append(",balance=");
+ sb.append(balance);
+ sb.append(",accountHolder=");
+ sb.append(accountHolder);
+ sb.append("]");
+ return sb.toString();
+ }
+
+ private static int safeHashCode(Object obj) {
+ return obj == null ? 0 : obj.hashCode();
+ }
+
+ private static boolean safeEquals(Object a, Object b) {
+ return (a == b || (a != null && a.equals(b)));
+ }
+
+}
Added:
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/classloader/AccountHolder.java
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/classloader/AccountHolder.java
(rev 0)
+++
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/classloader/AccountHolder.java 2009-08-14
13:10:49 UTC (rev 17302)
@@ -0,0 +1,97 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.cache.infinispan.functional.classloader;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.Serializable;
+
+/**
+ * Comment
+ *
+ * @author Brian Stansberry
+ * @version $Revision: 60233 $
+ */
+public class AccountHolder implements Serializable
+{
+ private static final long serialVersionUID = 1L;
+
+ private String lastName;
+ private String ssn;
+ private transient boolean deserialized;
+
+ public AccountHolder( ) {
+ this("Stansberry", "123-456-7890");
+ }
+
+ public AccountHolder(String lastName, String ssn)
+ {
+ this.lastName = lastName;
+ this.ssn = ssn;
+ }
+
+ public String getLastName( ) { return this.lastName; }
+ public void setLastName(String lastName) { this.lastName = lastName; }
+
+ public String getSsn( ) { return ssn; }
+ public void setSsn(String ssn) { this.ssn = ssn; }
+
+ public boolean equals(Object obj)
+ {
+ if (obj == this) return true;
+ if (!(obj instanceof AccountHolder)) return false;
+ AccountHolder pk = (AccountHolder)obj;
+ if (!lastName.equals(pk.lastName)) return false;
+ if (!ssn.equals(pk.ssn)) return false;
+ return true;
+ }
+
+ public int hashCode( )
+ {
+ int result = 17;
+ result = result * 31 + lastName.hashCode();
+ result = result * 31 + ssn.hashCode();
+ return result;
+ }
+
+ public String toString()
+ {
+ StringBuffer sb = new StringBuffer(getClass().getName());
+ sb.append("[lastName=");
+ sb.append(lastName);
+ sb.append(",ssn=");
+ sb.append(ssn);
+ sb.append(",deserialized=");
+ sb.append(deserialized);
+ sb.append("]");
+ return sb.toString();
+ }
+
+ private void readObject(ObjectInputStream ois) throws IOException,
ClassNotFoundException
+ {
+ ois.defaultReadObject();
+ deserialized = true;
+ }
+
+}
Added:
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/classloader/ClassLoaderTestDAO.java
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/classloader/ClassLoaderTestDAO.java
(rev 0)
+++
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/classloader/ClassLoaderTestDAO.java 2009-08-14
13:10:49 UTC (rev 17302)
@@ -0,0 +1,295 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.hibernate.test.cache.infinispan.functional.classloader;
+
+import java.lang.reflect.Method;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.transaction.TransactionManager;
+
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Comment
+ *
+ * @author Brian Stansberry
+ */
+public class ClassLoaderTestDAO {
+ private static final Logger log = LoggerFactory.getLogger(ClassLoaderTestDAO.class);
+
+ private SessionFactory sessionFactory;
+ private TransactionManager tm;
+
+ private Class acctClass;
+ private Class holderClass;
+ private Method setId;
+ private Method setBalance;
+ private Method setBranch;
+ private Method setHolder;
+ private Object smith;
+ private Object jones;
+ private Object barney;
+ private Method setName;
+ private Method setSsn;
+
+ public ClassLoaderTestDAO(SessionFactory factory, TransactionManager tm) throws
Exception {
+ this.sessionFactory = factory;
+ this.tm = tm;
+
+ acctClass = Thread.currentThread().getContextClassLoader().loadClass(
+ getClass().getPackage().getName() + ".Account");
+ holderClass = Thread.currentThread().getContextClassLoader().loadClass(
+ getClass().getPackage().getName() + ".AccountHolder");
+ setId = acctClass.getMethod("setId", Integer.class);
+ setBalance = acctClass.getMethod("setBalance", Integer.class);
+ setBranch = acctClass.getMethod("setBranch", String.class);
+ setHolder = acctClass.getMethod("setAccountHolder", holderClass);
+
+ setName = holderClass.getMethod("setLastName", String.class);
+ setSsn = holderClass.getMethod("setSsn", String.class);
+
+ smith = holderClass.newInstance();
+ setName.invoke(smith, "Smith");
+ setSsn.invoke(smith, "1000");
+
+ jones = holderClass.newInstance();
+ setName.invoke(jones, "Jones");
+ setSsn.invoke(jones, "2000");
+
+ barney = holderClass.newInstance();
+ setName.invoke(barney, "Barney");
+ setSsn.invoke(barney, "3000");
+ }
+
+ public Object getSmith() {
+ return smith;
+ }
+
+ public Object getJones() {
+ return jones;
+ }
+
+ public Object getBarney() {
+ return barney;
+ }
+
+ public void updateAccountBranch(Integer id, String branch) throws Exception {
+ log.debug("Updating account " + id + " to branch " + branch);
+ tm.begin();
+ try {
+ Session session = sessionFactory.getCurrentSession();
+ Object account = session.get(acctClass, id);
+ log.debug("Set branch " + branch);
+ setBranch.invoke(account, branch);
+ session.update(account);
+ tm.commit();
+ } catch (Exception e) {
+ log.error("rolling back", e);
+ tm.rollback();
+ throw e;
+ }
+ log.debug("Updated account " + id + " to branch " + branch);
+ }
+
+ public int getCountForBranch(String branch, boolean useRegion) throws Exception {
+ tm.begin();
+ try {
+ Query query = sessionFactory.getCurrentSession().createQuery(
+ "select account from Account as account where account.branch =
:branch");
+ query.setString("branch", branch);
+ if (useRegion) {
+ query.setCacheRegion("AccountRegion");
+ }
+ query.setCacheable(true);
+ int result = query.list().size();
+ tm.commit();
+ return result;
+ } catch (Exception e) {
+ log.error("rolling back", e);
+ tm.rollback();
+ throw e;
+ }
+
+ }
+
+ public void createAccount(Object holder, Integer id, Integer openingBalance, String
branch) throws Exception {
+ log.debug("Creating account " + id);
+ tm.begin();
+ try {
+ Object account = acctClass.newInstance();
+ setId.invoke(account, id);
+ setHolder.invoke(account, holder);
+ setBalance.invoke(account, openingBalance);
+ log.debug("Set branch " + branch);
+ setBranch.invoke(account, branch);
+ sessionFactory.getCurrentSession().persist(account);
+ tm.commit();
+ } catch (Exception e) {
+ log.error("rolling back", e);
+ tm.rollback();
+ throw e;
+ }
+
+ log.debug("Created account " + id);
+ }
+
+ public Account getAccount(Integer id) throws Exception {
+ log.debug("Getting account " + id);
+ tm.begin();
+ try {
+ Session session = sessionFactory.getCurrentSession();
+ Account acct = (Account) session.get(acctClass, id);
+ tm.commit();
+ return acct;
+ } catch (Exception e) {
+ log.error("rolling back", e);
+ tm.rollback();
+ throw e;
+ }
+ }
+
+ public Account getAccountWithRefresh(Integer id) throws Exception {
+ log.debug("Getting account " + id + " with refresh");
+ tm.begin();
+ try {
+ Session session = sessionFactory.getCurrentSession();
+ Account acct = (Account) session.get(acctClass, id);
+ session.refresh(acct);
+ acct = (Account) session.get(acctClass, id);
+ tm.commit();
+ return acct;
+ } catch (Exception e) {
+ log.error("rolling back", e);
+ tm.rollback();
+ throw e;
+ }
+ }
+
+ public void updateAccountBalance(Integer id, Integer newBalance) throws Exception {
+ log.debug("Updating account " + id + " to balance " +
newBalance);
+ tm.begin();
+ try {
+ Session session = sessionFactory.getCurrentSession();
+ Object account = session.get(acctClass, id);
+ setBalance.invoke(account, newBalance);
+ session.update(account);
+ tm.commit();
+ } catch (Exception e) {
+ log.error("rolling back", e);
+ tm.rollback();
+ throw e;
+ }
+ log.debug("Updated account " + id + " to balance " +
newBalance);
+ }
+
+ public String getBranch(Object holder, boolean useRegion) throws Exception {
+ tm.begin();
+ try {
+ Query query = sessionFactory.getCurrentSession().createQuery(
+ "select account.branch from Account as account where
account.accountHolder = ?");
+ query.setParameter(0, holder);
+ if (useRegion) {
+ query.setCacheRegion("AccountRegion");
+ }
+ query.setCacheable(true);
+ String result = (String) query.list().get(0);
+ tm.commit();
+ return result;
+ } catch (Exception e) {
+ log.error("rolling back", e);
+ tm.rollback();
+ throw e;
+ }
+ }
+
+ public int getTotalBalance(Object holder, boolean useRegion) throws Exception {
+ List results = null;
+ tm.begin();
+ try {
+ Query query = sessionFactory.getCurrentSession().createQuery(
+ "select account.balance from Account as account where
account.accountHolder = ?");
+ query.setParameter(0, holder);
+ if (useRegion) {
+ query.setCacheRegion("AccountRegion");
+ }
+ query.setCacheable(true);
+ results = query.list();
+ tm.commit();
+ } catch (Exception e) {
+ log.error("rolling back", e);
+ tm.rollback();
+ throw e;
+ }
+
+ int total = 0;
+ if (results != null) {
+ for (Iterator it = results.iterator(); it.hasNext();) {
+ total += ((Integer) it.next()).intValue();
+ System.out.println("Total = " + total);
+ }
+ }
+ return total;
+ }
+
+ public void cleanup() throws Exception {
+ internalCleanup();
+ }
+
+ private void internalCleanup() throws Exception {
+ if (sessionFactory != null) {
+ tm.begin();
+ try {
+
+ Session session = sessionFactory.getCurrentSession();
+ Query query = session.createQuery("select account from Account as
account");
+ List accts = query.list();
+ if (accts != null) {
+ for (Iterator it = accts.iterator(); it.hasNext();) {
+ try {
+ Object acct = it.next();
+ log.info("Removing " + acct);
+ session.delete(acct);
+ } catch (Exception ignored) {
+ }
+ }
+ }
+ tm.commit();
+ } catch (Exception e) {
+ tm.rollback();
+ throw e;
+ }
+ }
+ }
+
+ public void remove() {
+ try {
+ internalCleanup();
+ } catch (Exception e) {
+ log.error("Caught exception in remove", e);
+ }
+ }
+}
Added:
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/SessionRefreshTestCase.java
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/SessionRefreshTestCase.java
(rev 0)
+++
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/SessionRefreshTestCase.java 2009-08-14
13:10:49 UTC (rev 17302)
@@ -0,0 +1,131 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.hibernate.test.cache.infinispan.functional.cluster;
+
+import javax.transaction.TransactionManager;
+
+import org.hibernate.SessionFactory;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+import org.hibernate.test.cache.infinispan.functional.classloader.Account;
+import org.hibernate.test.cache.infinispan.functional.classloader.ClassLoaderTestDAO;
+import org.infinispan.Cache;
+import org.infinispan.manager.CacheManager;
+import org.infinispan.test.TestingUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * SessionRefreshTestCase.
+ *
+ * @author Galder Zamarreño
+ * @since 4.0
+ */
+public class SessionRefreshTestCase extends AbstractDualNodeTestCase {
+
+ public static final String OUR_PACKAGE =
SessionRefreshTestCase.class.getPackage().getName();
+
+ protected final Logger log = LoggerFactory.getLogger(getClass());
+
+ static int test = 0;
+
+ private Cache localCache;
+
+ public SessionRefreshTestCase(String string) {
+ super(string);
+ }
+
+ protected String getEntityCacheConfigName() {
+ return "entity";
+ }
+
+ /**
+ * Disables use of the second level cache for this session factory.
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ protected void configureSecondNode(Configuration cfg) {
+ super.configureSecondNode(cfg);
+ cfg.setProperty(Environment.USE_SECOND_LEVEL_CACHE, "false");
+ }
+
+ @Override
+ public String[] getMappings() {
+ return new String[] {
"cache/infinispan/functional/classloader/Account.hbm.xml" };
+ }
+
+ @Override
+ protected void cleanupTransactionManagement() {
+ // Don't clean up the managers, just the transactions
+ // Managers are still needed by the long-lived caches
+ DualNodeJtaTransactionManagerImpl.cleanupTransactions();
+ }
+
+ public void testRefreshAfterExternalChange() throws Exception {
+ // First session factory uses a cache
+ CacheManager localManager =
ClusterAwareRegionFactory.getCacheManager(AbstractDualNodeTestCase.LOCAL);
+ localCache = localManager.getCache(Account.class.getName());
+ TransactionManager localTM =
DualNodeJtaTransactionManagerImpl.getInstance(AbstractDualNodeTestCase.LOCAL);
+ SessionFactory localFactory = getEnvironment().getSessionFactory();
+
+ // Second session factory doesn't; just needs a transaction manager
+ TransactionManager remoteTM =
DualNodeJtaTransactionManagerImpl.getInstance(AbstractDualNodeTestCase.REMOTE);
+ SessionFactory remoteFactory = getSecondNodeEnvironment().getSessionFactory();
+
+ ClassLoaderTestDAO dao0 = new ClassLoaderTestDAO(localFactory, localTM);
+ ClassLoaderTestDAO dao1 = new ClassLoaderTestDAO(remoteFactory, remoteTM);
+
+ Integer id = new Integer(1);
+ dao0.createAccount(dao0.getSmith(), id, new Integer(5),
AbstractDualNodeTestCase.LOCAL);
+
+ // Basic sanity check
+ Account acct1 = dao1.getAccount(id);
+ assertNotNull(acct1);
+ assertEquals(AbstractDualNodeTestCase.LOCAL, acct1.getBranch());
+
+ // This dao's session factory isn't caching, so cache won't see this
change
+ dao1.updateAccountBranch(id, AbstractDualNodeTestCase.REMOTE);
+
+ // dao1's session doesn't touch the cache,
+ // so reading from dao0 should show a stale value from the cache
+ // (we check to confirm the cache is used)
+ Account acct0 = dao0.getAccount(id);
+ assertNotNull(acct0);
+ assertEquals(AbstractDualNodeTestCase.LOCAL, acct0.getBranch());
+ log.debug("Contents when re-reading from local: " +
TestingUtil.printCache(localCache));
+
+ // Now call session.refresh and confirm we get the correct value
+ acct0 = dao0.getAccountWithRefresh(id);
+ assertNotNull(acct0);
+ assertEquals(AbstractDualNodeTestCase.REMOTE, acct0.getBranch());
+ log.debug("Contents after refreshing in remote: " +
TestingUtil.printCache(localCache));
+
+ // Double check with a brand new session, in case the other session
+ // for some reason bypassed the 2nd level cache
+ ClassLoaderTestDAO dao0A = new ClassLoaderTestDAO(localFactory, localTM);
+ Account acct0A = dao0A.getAccount(id);
+ assertNotNull(acct0A);
+ assertEquals(AbstractDualNodeTestCase.REMOTE, acct0A.getBranch());
+ log.debug("Contents after creating a new session: " +
TestingUtil.printCache(localCache));
+ }
+}
Deleted:
core/branches/INFINISPAN/cache-infinispan/src/test/resources/invalid-infinispan-configs.xml
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/test/resources/invalid-infinispan-configs.xml 2009-08-13
20:15:08 UTC (rev 17301)
+++
core/branches/INFINISPAN/cache-infinispan/src/test/resources/invalid-infinispan-configs.xml 2009-08-14
13:10:49 UTC (rev 17302)
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<infinispan
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:infinispan:config:4.0">
- <global>
- <transport transportClass =
"org.infinispan.remoting.transport.jgroups.JGroupsTransport"
- clusterName="infinispan-hibernate-cluster"
distributedSyncTimeout="50000">
- <!-- Note that the JGroups transport uses sensible defaults if no
configuration property is defined. -->
- <properties>
- <!-- TODO: Change to udp.xml once streaming transfer requirement has been
removed. -->
- <property name="configurationFile"
value="flush-udp.xml"/>
- </properties>
- <!-- See the JGroupsTransport javadocs for more flags -->
- </transport>
- <serialization
marshallerClass="org.infinispan.marshall.VersionAwareMarshaller"
version="4.0"/>
- </global>
-
- <default>
- <!-- Used to register JMX statistics in any available MBean server -->
- <jmxStatistics enabled="false"/>
- </default>
-
- <!-- Invalid timestamp configuration, cannot be used
- Optimized for timestamp caching. A clustered timestamp cache
- is required if query caching is used, even if the query cache
- itself is configured with CacheMode=LOCAL.
- -->
- <namedCache name="timestamp">
- <clustering mode="INVALIDATION_ASYNC">
- <stateRetrieval fetchInMemoryState="true"
timeout="20000"/>
- <async/>
- </clustering>
- <locking isolationLevel="READ_COMMITTED"
concurrencyLevel="1000" lockAcquisitionTimeout="15000"/>
- <lazyDeserialization enabled="true"/>
- <!-- Don't ever evict modification timestamps -->
- <eviction wakeUpInterval="0" strategy="NONE"/>
- </namedCache>
-
-</infinispan>
\ No newline at end of file