From: <ste...@us...> - 2006-02-09 20:51:22
|
Update of /cvsroot/hibernate/Hibernate3/test/org/hibernate/test/cache/treecache/optimistic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8585/test/org/hibernate/test/cache/treecache/optimistic Added Files: OptimisticTreeCacheTest.java treecache.xml Log Message: started an actual CacheProvider unit test suite --- NEW FILE: OptimisticTreeCacheTest.java --- package org.hibernate.test.cache.treecache.optimistic; import org.hibernate.test.cache.BaseCacheProviderTestCase; import org.hibernate.test.tm.DummyTransactionManager; import org.hibernate.cache.OptimisticTreeCacheProvider; import org.hibernate.engine.SessionFactoryImplementor; import org.jboss.cache.TreeCache; import org.jboss.cache.Fqn; import org.jboss.cache.optimistic.DataVersion; import org.jboss.cache.config.Option; import junit.framework.Test; import junit.framework.TestSuite; /** * @author Steve Ebersole */ public class OptimisticTreeCacheTest extends BaseCacheProviderTestCase { // note that a lot of the fucntionality here is intended to be used // in creating specific tests for each CacheProvider that would extend // from a base test case (this) for common requirement testing... public OptimisticTreeCacheTest(String x) { super( x ); } public static Test suite() { return new TestSuite( OptimisticTreeCacheTest.class ); } public String getCacheConcurrencyStrategy() { return "transactional"; } protected Class getCacheProvider() { return OptimisticTreeCacheProvider.class; } protected String getConfigResourceKey() { return OptimisticTreeCacheProvider.CONFIG_RESOURCE; } protected String getConfigResourceLocation() { return "org/hibernate/test/cache/treecache/optimistic/treecache.xml"; } protected boolean useTransactionManager() { return true; } public void testCacheLevelStaleWritesFail() throws Throwable { Fqn fqn = new Fqn( "whatever" ); TreeCache treeCache = ( ( OptimisticTreeCacheProvider ) sfi().getSettings().getCacheProvider() ).getUnderlyingCache(); Long long1 = new Long(1); Long long2 = new Long(2); try { System.out.println( "****************************************************************" ); DummyTransactionManager.INSTANCE.begin(); treeCache.put( fqn, "ITEM", long1, ManualDataVersion.gen( 1 ) ); DummyTransactionManager.INSTANCE.commit(); System.out.println( "****************************************************************" ); DummyTransactionManager.INSTANCE.begin(); treeCache.put( fqn, "ITEM", long2, ManualDataVersion.gen( 2 ) ); DummyTransactionManager.INSTANCE.commit(); try { System.out.println( "****************************************************************" ); DummyTransactionManager.INSTANCE.begin(); treeCache.put( fqn, "ITEM", long1, ManualDataVersion.gen( 1 ) ); DummyTransactionManager.INSTANCE.commit(); fail( "stale write allowed" ); } catch( Throwable ignore ) { // expected behavior DummyTransactionManager.INSTANCE.rollback(); } Long current = ( Long ) treeCache.get( fqn, "ITEM" ); assertEquals( "unexpected current value", 2, current.longValue() ); } finally { try { treeCache.remove( fqn, "ITEM" ); } catch( Throwable ignore ) { } } } private static class ManualDataVersion implements DataVersion { private final int version; public ManualDataVersion(int version) { this.version = version; } public boolean newerThan(DataVersion dataVersion) { return this.version > ( ( ManualDataVersion ) dataVersion ).version; } public static Option gen(int version) { ManualDataVersion mdv = new ManualDataVersion( version ); Option option = new Option(); option.setDataVersion( mdv ); return option; } } public SessionFactoryImplementor sfi() { return ( SessionFactoryImplementor ) getSessions(); } } --- NEW FILE: treecache.xml --- <?xml version="1.0" encoding="UTF-8"?> <!-- ===================================================================== --> <!-- --> <!-- Sample TreeCache Service Configuration --> <!-- Recommended for use as Hibernate's 2nd Level Cache --> <!-- For use with JBossCache >= 1.3.0 ONLY!!! --> <!-- --> <!-- ===================================================================== --> <server> <classpath codebase="./lib" archives="jboss-cache.jar, jgroups.jar"/> <!-- ==================================================================== --> <!-- Defines TreeCache configuration --> <!-- ==================================================================== --> <mbean code="org.jboss.cache.TreeCache" name="jboss.cache:service=TreeCache"> <depends>jboss:service=Naming</depends> <depends>jboss:service=TransactionManager</depends> <!-- Configure the TransactionManager : no matter since Hibernate will plug in an "adapter" to its own TransactionManagerLookup strategy here --> <attribute name="TransactionManagerLookupClass">org.jboss.cache.GenericTransactionManagerLookup</attribute> <!-- Node locking scheme: OPTIMISTIC PESSIMISTIC (default) --> <attribute name="NodeLockingScheme">OPTIMISTIC</attribute> <!-- Note that this attribute is IGNORED if your NodeLockingScheme above is OPTIMISTIC. Isolation level : SERIALIZABLE REPEATABLE_READ (default) READ_COMMITTED READ_UNCOMMITTED NONE --> <attribute name="IsolationLevel">REPEATABLE_READ</attribute> <!-- Valid modes are LOCAL REPL_ASYNC REPL_SYNC INVALIDATION_ASYNC INVALIDATION_SYNC INVALIDATION_ASYNC is highly recommended as the mode for use with clustered second-level caches. --> <attribute name="CacheMode">LOCAL</attribute> <!-- Just used for async repl: use a replication queue --> <attribute name="UseReplQueue">false</attribute> <!-- Replication interval for replication queue (in ms) --> <attribute name="ReplQueueInterval">0</attribute> <!-- Max number of elements which trigger replication --> <attribute name="ReplQueueMaxElements">0</attribute> <!-- Name of cluster. Needs to be the same for all clusters, in order to find each other --> <attribute name="ClusterName">TreeCache-Cluster</attribute> <!-- JGroups protocol stack properties. Can also be a URL, e.g. file:/home/bela/default.xml <attribute name="ClusterProperties"></attribute> --> <attribute name="ClusterConfig"> <config> <!-- UDP: if you have a multihomed machine, set the bind_addr attribute to the appropriate NIC IP address --> <!-- UDP: On Windows machines, because of the media sense feature being broken with multicast (even after disabling media sense) set the loopback attribute to true --> <UDP mcast_addr="228.1.2.3" mcast_port="48866" ip_ttl="64" ip_mcast="true" mcast_send_buf_size="150000" mcast_recv_buf_size="80000" ucast_send_buf_size="150000" ucast_recv_buf_size="80000" loopback="false"/> <PING timeout="2000" num_initial_members="3" up_thread="false" down_thread="false"/> <MERGE2 min_interval="10000" max_interval="20000"/> <!-- <FD shun="true" up_thread="true" down_thread="true" />--> <FD_SOCK/> <VERIFY_SUSPECT timeout="1500" up_thread="false" down_thread="false"/> <pbcast.NAKACK gc_lag="50" retransmit_timeout="600,1200,2400,4800" max_xmit_size="8192" up_thread="false" down_thread="false"/> <UNICAST timeout="600,1200,2400" window_size="100" min_threshold="10" down_thread="false"/> <pbcast.STABLE desired_avg_gossip="20000" up_thread="false" down_thread="false"/> <FRAG frag_size="8192" down_thread="false" up_thread="false"/> <pbcast.GMS join_timeout="5000" join_retry_timeout="2000" shun="true" print_local_addr="true"/> <pbcast.STATE_TRANSFER up_thread="true" down_thread="true"/> </config> </attribute> <!-- Whether or not to fetch state on joining a cluster NOTE this used to be called FetchStateOnStartup and has been renamed to be more descriptive. --> <attribute name="FetchInMemoryState">false</attribute> <!-- Number of milliseconds to wait until all responses for a synchronous call have been received. --> <attribute name="SyncReplTimeout">20000</attribute> <!-- Max number of milliseconds to wait for a lock acquisition --> <attribute name="LockAcquisitionTimeout">15000</attribute> <!-- Name of the eviction policy class. --> <attribute name="EvictionPolicyClass"></attribute> <!-- Indicate whether to use marshalling or not. Set this to true if you are running under a scoped class loader, e.g., inside an application server. Default is "false". --> <attribute name="UseMarshalling">false</attribute> </mbean> </server> |