FileDocCategorySizeDatePackage
OptimisticTreeCacheTest.javaAPI DocHibernate 3.2.53383Tue Dec 12 16:22:26 GMT 2006org.hibernate.test.cache.treecache.optimistic

OptimisticTreeCacheTest

public class OptimisticTreeCacheTest extends org.hibernate.test.cache.BaseCacheProviderTestCase
author
Steve Ebersole

Fields Summary
Constructors Summary
public OptimisticTreeCacheTest(String x)

		super( x );
	
Methods Summary
public java.lang.StringgetCacheConcurrencyStrategy()

		return "transactional";
	
protected java.lang.ClassgetCacheProvider()

		return OptimisticTreeCacheProvider.class;
	
protected java.lang.StringgetConfigResourceKey()

		return Environment.CACHE_PROVIDER_CONFIG;
	
protected java.lang.StringgetConfigResourceLocation()

		return "org/hibernate/test/cache/treecache/optimistic/treecache.xml";
	
public static junit.framework.Testsuite()

		return new FunctionalTestClassTestSuite( OptimisticTreeCacheTest.class );
	
public voidtestCacheLevelStaleWritesFail()

		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 ) {
			}
		}
	
protected booleanuseTransactionManager()

		return true;