KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > interceptors > InterceptorCacheReferenceTest


1 /*
2  * JBoss, Home of Professional Open Source
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.cache.interceptors;
8
9 import junit.framework.TestCase;
10 import org.jboss.cache.Cache;
11 import org.jboss.cache.CacheSPI;
12 import org.jboss.cache.config.Configuration;
13 import org.jboss.cache.factories.DefaultCacheFactory;
14
15 /**
16  * Tests that all interceptors in a given interceptor chain have the same cache instance.
17  *
18  * @author <a HREF="mailto:manik@jboss.org">Manik Surtani (manik@jboss.org)</a>
19  */

20 public class InterceptorCacheReferenceTest extends TestCase
21 {
22    public void testPessLocking() throws Exception JavaDoc
23    {
24       Configuration c = new Configuration();
25       c.setNodeLockingScheme(Configuration.NodeLockingScheme.PESSIMISTIC);
26       Cache cache = DefaultCacheFactory.getInstance().createCache(c);
27
28       assertInterceptorsHaveSameCache((CacheSPI) cache);
29
30       cache.stop();
31    }
32
33    public void testOptLocking() throws Exception JavaDoc
34    {
35       Configuration c = new Configuration();
36       c.setNodeLockingScheme(Configuration.NodeLockingScheme.OPTIMISTIC);
37       Cache cache = DefaultCacheFactory.getInstance().createCache(c);
38
39       assertInterceptorsHaveSameCache((CacheSPI) cache);
40
41       cache.stop();
42    }
43
44    private void assertInterceptorsHaveSameCache(CacheSPI c) throws Exception JavaDoc
45    {
46       for (Interceptor i : c.getInterceptorChain())
47       {
48          System.out.println("Testing " + i);
49          assertSame(c, i.cache);
50       }
51    }
52 }
53
Popular Tags