Package org.jboss.cache.interceptors

Source Code of org.jboss.cache.interceptors.InterceptorCacheReferenceTest

/*
* 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);
      }
   }
}
TOP

Related Classes of org.jboss.cache.interceptors.InterceptorCacheReferenceTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.