/*
* JBoss, Home of Professional Open Source
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.cache.interceptors;
import org.jboss.cache.Cache;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.config.Configuration;
import static org.testng.AssertJUnit.assertSame;
import org.testng.annotations.Test;
/**
* Tests that all interceptors in a given interceptor chain have the same cache instance.
*
* @author <a href="mailto:manik@jboss.org">Manik Surtani (manik@jboss.org)</a>
*/
@Test(groups = {"functional"})
public class InterceptorCacheReferenceTest
{
public void testPessLocking() throws Exception
{
Configuration c = new Configuration();
c.setNodeLockingScheme(Configuration.NodeLockingScheme.PESSIMISTIC);
Cache cache = new DefaultCacheFactory().createCache(c);
assertInterceptorsHaveSameCache((CacheSPI) cache);
cache.stop();
}
public void testOptLocking() throws Exception
{
Configuration c = new Configuration();
c.setNodeLockingScheme(Configuration.NodeLockingScheme.OPTIMISTIC);
Cache cache = new DefaultCacheFactory().createCache(c);
assertInterceptorsHaveSameCache((CacheSPI) cache);
cache.stop();
}
private void assertInterceptorsHaveSameCache(CacheSPI<?, ?> c)
{
for (Interceptor i : c.getInterceptorChain())
{
System.out.println("Testing " + i);
assertSame(c, i.cache);
}
}
}