[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/factories ...
Manik Surtani
msurtani at jboss.com
Wed Sep 13 09:11:18 EDT 2006
User: msurtani
Date: 06/09/13 09:11:18
Added: tests/functional/org/jboss/cache/factories
CustomInterceptorChainTest.java
InterceptorChainFactoryTest.java
InterceptorChainTestBase.java
Log:
added code + unit tests for manipulating interceptor chain via CacheSPI
Revision Changes Path
1.1 date: 2006/09/13 13:11:18; author: msurtani; state: Exp;JBossCache/tests/functional/org/jboss/cache/factories/CustomInterceptorChainTest.java
Index: CustomInterceptorChainTest.java
===================================================================
package org.jboss.cache.factories;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.interceptors.Interceptor;
import java.util.List;
/**
* @author <a href="mailto:manik at jboss.org">Manik Surtani</a>
*/
public class CustomInterceptorChainTest extends InterceptorChainTestBase
{
private CacheSPI cache;
protected void setUp() throws Exception
{
Configuration c = new Configuration();
cache = (CacheSPI) new DefaultCacheFactory().createCache(c);
cache.create();
}
protected void tearDown()
{
if (cache != null)
{
cache.stop();
cache = null;
}
}
public void testChainImmutability()
{
try
{
cache.getInterceptorChain().add(new TestInterceptor());
fail("unsupportedException should have been thrown as the chain obtained from the cache should be immutable");
}
catch (UnsupportedOperationException uoe)
{
// this is expected.
}
}
public void testInjectionAtHead()
{
List<Interceptor> interceptors = cache.getInterceptorChain();
assertEquals("Expecting 6 interceptors", 6, interceptors.size());
assertInterceptorLinkage(interceptors);
Interceptor x = new TestInterceptor();
cache.addInterceptor(x, 0);
interceptors = cache.getInterceptorChain();
assertEquals("Expecting 7 interceptors", 7, interceptors.size());
assertInterceptorLinkage(interceptors);
assertEquals(x, interceptors.get(0));
}
public void testInjectionAtTail()
{
List<Interceptor> interceptors = cache.getInterceptorChain();
assertEquals("Expecting 6 interceptors", 6, interceptors.size());
assertInterceptorLinkage(interceptors);
Interceptor x = new TestInterceptor();
cache.addInterceptor(x, 6);
interceptors = cache.getInterceptorChain();
assertEquals("Expecting 7 interceptors", 7, interceptors.size());
assertInterceptorLinkage(interceptors);
assertEquals(x, interceptors.get(6));
}
public void testInjectionInMiddle()
{
List<Interceptor> interceptors = cache.getInterceptorChain();
assertEquals("Expecting 6 interceptors", 6, interceptors.size());
assertInterceptorLinkage(interceptors);
Interceptor x = new TestInterceptor();
cache.addInterceptor(x, 3);
interceptors = cache.getInterceptorChain();
assertEquals("Expecting 7 interceptors", 7, interceptors.size());
assertInterceptorLinkage(interceptors);
assertEquals(x, interceptors.get(3));
}
public void testInjectionBeyondTail()
{
List<Interceptor> interceptors = cache.getInterceptorChain();
assertEquals("Expecting 6 interceptors", 6, interceptors.size());
assertInterceptorLinkage(interceptors);
Interceptor x = new TestInterceptor();
try
{
cache.addInterceptor(x, 8);
fail("Should throw an exception");
}
catch (IndexOutOfBoundsException e)
{
// expected
}
}
public void testRemoveAtHead()
{
List<Interceptor> interceptors = cache.getInterceptorChain();
Interceptor afterHead = interceptors.get(1);
assertEquals("Expecting 6 interceptors", 6, interceptors.size());
assertInterceptorLinkage(interceptors);
cache.removeInterceptor(0);
interceptors = cache.getInterceptorChain();
assertEquals("Expecting 5 interceptors", 5, interceptors.size());
assertInterceptorLinkage(interceptors);
assertEquals(afterHead, interceptors.get(0));
}
public void testRemoveAtTail()
{
List<Interceptor> interceptors = cache.getInterceptorChain();
Interceptor beforeTail = interceptors.get(4);
assertEquals("Expecting 6 interceptors", 6, interceptors.size());
assertInterceptorLinkage(interceptors);
cache.removeInterceptor(5);
interceptors = cache.getInterceptorChain();
System.out.println(interceptors);
assertEquals("Expecting 5 interceptors", 5, interceptors.size());
assertInterceptorLinkage(interceptors);
assertEquals(beforeTail, interceptors.get(4));
}
public void testRemoveAtMiddle()
{
List<Interceptor> interceptors = cache.getInterceptorChain();
assertEquals("Expecting 6 interceptors", 6, interceptors.size());
assertInterceptorLinkage(interceptors);
cache.removeInterceptor(3);
interceptors = cache.getInterceptorChain();
assertEquals("Expecting 5 interceptors", 5, interceptors.size());
assertInterceptorLinkage(interceptors);
}
public void testRemoveBeyondTail()
{
List<Interceptor> interceptors = cache.getInterceptorChain();
assertEquals("Expecting 6 interceptors", 6, interceptors.size());
assertInterceptorLinkage(interceptors);
try
{
cache.removeInterceptor(8);
fail("Should throw an exception");
}
catch (IndexOutOfBoundsException e)
{
// expected
}
}
public static class TestInterceptor extends Interceptor
{
}
}
1.1 date: 2006/09/13 13:11:18; author: msurtani; state: Exp;JBossCache/tests/functional/org/jboss/cache/factories/InterceptorChainFactoryTest.java
Index: InterceptorChainFactoryTest.java
===================================================================
package org.jboss.cache.factories;
import junit.framework.Assert;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.jboss.cache.TreeCache;
import org.jboss.cache.interceptors.*;
import org.jboss.cache.xml.XmlHelper;
import org.w3c.dom.Element;
import java.util.Iterator;
import java.util.List;
public class InterceptorChainFactoryTest extends InterceptorChainTestBase
{
TreeCache cache = null;
protected void setUp() throws Exception
{
super.setUp();
cache = new TreeCache();
cache.getConfiguration().setCacheMode("LOCAL");
}
protected void tearDown() throws Exception
{
super.tearDown();
if (cache != null)
{
cache.stop();
cache.destroy();
}
}
public void testBareConfig() throws Exception
{
cache.getConfiguration().setUseInterceptorMbeans(false);
Interceptor chain = new InterceptorChainFactory().buildInterceptorChain(cache);
List<Interceptor> list = InterceptorChainFactory.asList(chain);
Iterator<Interceptor> interceptors = list.iterator();
System.out.println("testBareConfig interceptors are:\n" + list);
assertNotNull(list);
assertEquals(5, list.size());
assertEquals(InvocationContextInterceptor.class, interceptors.next().getClass());
assertEquals(TxInterceptor.class, interceptors.next().getClass());
assertEquals(UnlockInterceptor.class, interceptors.next().getClass());
assertEquals(PessimisticLockInterceptor.class, interceptors.next().getClass());
assertEquals(CallInterceptor.class, interceptors.next().getClass());
assertInterceptorLinkage(list);
}
public void testTxConfig() throws Exception
{
cache.getConfiguration().setUseInterceptorMbeans(false);
cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
Interceptor chain = new InterceptorChainFactory().buildInterceptorChain(cache);
List<Interceptor> list = InterceptorChainFactory.asList(chain);
Iterator<Interceptor> interceptors = list.iterator();
System.out.println("testTxConfig interceptors are:\n" + list);
assertNotNull(list);
assertEquals(5, list.size());
assertEquals(InvocationContextInterceptor.class, interceptors.next().getClass());
assertEquals(TxInterceptor.class, interceptors.next().getClass());
assertEquals(UnlockInterceptor.class, interceptors.next().getClass());
assertEquals(PessimisticLockInterceptor.class, interceptors.next().getClass());
assertEquals(CallInterceptor.class, interceptors.next().getClass());
assertInterceptorLinkage(list);
}
protected Element getCacheLoaderConfig(boolean pasv, boolean fetchPersistentState) throws Exception
{
String xml = " <config>\n" +
" \n" +
" <passivation>" + pasv + "</passivation>\n" +
" <preload></preload>\n" +
"\n" +
" <cacheloader>\n" +
" <class>org.jboss.cache.loader.FileCacheLoader</class>\n" +
" <properties>\n" +
" location=/tmp\n" +
" </properties>\n" +
" <async>false</async>\n" +
" <fetchPersistentState>" + fetchPersistentState + "</fetchPersistentState>\n" +
" <ignoreModifications>false</ignoreModifications>\n" +
" </cacheloader>\n" +
" \n" +
" </config>";
return XmlHelper.stringToElement(xml);
}
public void testSharedCacheLoaderConfig() throws Exception
{
cache.getConfiguration().setUseInterceptorMbeans(false);
cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
cache.getConfiguration().setCacheLoaderConfiguration(getCacheLoaderConfig(false, false));
cache.getConfiguration().setCacheMode("REPL_ASYNC");
cache.getConfiguration().setFetchInMemoryState(false);
cache.create();
Interceptor chain = new InterceptorChainFactory().buildInterceptorChain(cache);
List<Interceptor> list = InterceptorChainFactory.asList(chain);
Iterator<Interceptor> interceptors = list.iterator();
System.out.println("testSharedCacheLoaderConfig interceptors are:\n" + list);
assertNotNull(list);
assertEquals(8, list.size());
assertEquals(InvocationContextInterceptor.class, interceptors.next().getClass());
assertEquals(TxInterceptor.class, interceptors.next().getClass());
assertEquals(CacheStoreInterceptor.class, interceptors.next().getClass());
assertEquals(ReplicationInterceptor.class, interceptors.next().getClass());
assertEquals(UnlockInterceptor.class, interceptors.next().getClass());
assertEquals(CacheLoaderInterceptor.class, interceptors.next().getClass());
assertEquals(PessimisticLockInterceptor.class, interceptors.next().getClass());
assertEquals(CallInterceptor.class, interceptors.next().getClass());
assertInterceptorLinkage(list);
}
public void testUnsharedCacheLoaderConfig() throws Exception
{
cache.getConfiguration().setUseInterceptorMbeans(false);
cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
cache.getConfiguration().setCacheLoaderConfiguration(getCacheLoaderConfig(false, true));
cache.getConfiguration().setCacheMode("REPL_ASYNC");
cache.getConfiguration().setFetchInMemoryState(false);
cache.create();
Interceptor chain = new InterceptorChainFactory().buildInterceptorChain(cache);
List<Interceptor> list = InterceptorChainFactory.asList(chain);
Iterator<Interceptor> interceptors = list.iterator();
System.out.println("testUnsharedCacheLoaderConfig interceptors are:\n" + list);
assertNotNull(list);
assertEquals(8, list.size());
assertEquals(InvocationContextInterceptor.class, interceptors.next().getClass());
assertEquals(TxInterceptor.class, interceptors.next().getClass());
assertEquals(ReplicationInterceptor.class, interceptors.next().getClass());
assertEquals(UnlockInterceptor.class, interceptors.next().getClass());
assertEquals(CacheLoaderInterceptor.class, interceptors.next().getClass());
assertEquals(CacheStoreInterceptor.class, interceptors.next().getClass());
assertEquals(PessimisticLockInterceptor.class, interceptors.next().getClass());
assertEquals(CallInterceptor.class, interceptors.next().getClass());
assertInterceptorLinkage(list);
}
public void testTxAndRepl() throws Exception
{
cache.getConfiguration().setUseInterceptorMbeans(false);
cache.getConfiguration().setCacheMode("repl_sync");
cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
Interceptor chain = new InterceptorChainFactory().buildInterceptorChain(cache);
List<Interceptor> list = InterceptorChainFactory.asList(chain);
Iterator<Interceptor> interceptors = list.iterator();
System.out.println("testTxAndRepl interceptors are:\n" + list);
assertNotNull(list);
assertEquals(6, list.size());
assertEquals(InvocationContextInterceptor.class, interceptors.next().getClass());
assertEquals(TxInterceptor.class, interceptors.next().getClass());
assertEquals(ReplicationInterceptor.class, interceptors.next().getClass());
assertEquals(UnlockInterceptor.class, interceptors.next().getClass());
assertEquals(PessimisticLockInterceptor.class, interceptors.next().getClass());
assertEquals(CallInterceptor.class, interceptors.next().getClass());
assertInterceptorLinkage(list);
}
public void testOptimisticChain() throws Exception
{
TreeCache cache = new TreeCache();
cache.getConfiguration().setUseInterceptorMbeans(false);
cache.getConfiguration().setNodeLockingOptimistic(true);
Interceptor next = new InterceptorChainFactory().buildInterceptorChain(cache);
// test the chain size.
List<Interceptor> list = InterceptorChainFactory.asList(next);
Iterator<Interceptor> interceptors = list.iterator();
Assert.assertEquals(7, list.size());
assertEquals(InvocationContextInterceptor.class, interceptors.next().getClass());
assertEquals(TxInterceptor.class, interceptors.next().getClass());
assertEquals(OptimisticLockingInterceptor.class, interceptors.next().getClass());
assertEquals(OptimisticValidatorInterceptor.class, interceptors.next().getClass());
assertEquals(OptimisticCreateIfNotExistsInterceptor.class, interceptors.next().getClass());
assertEquals(OptimisticNodeInterceptor.class, interceptors.next().getClass());
assertEquals(CallInterceptor.class, interceptors.next().getClass());
assertInterceptorLinkage(list);
}
public void testOptimisticReplicatedChain() throws Exception
{
TreeCache cache = new TreeCache();
cache.getConfiguration().setUseInterceptorMbeans(false);
cache.getConfiguration().setNodeLockingOptimistic(true);
cache.getConfiguration().setCacheMode("REPL_SYNC");
Interceptor next = new InterceptorChainFactory().buildInterceptorChain(cache);
// test the chain size.
List<Interceptor> list = InterceptorChainFactory.asList(next);
Iterator<Interceptor> interceptors = list.iterator();
Assert.assertEquals(8, list.size());
assertEquals(InvocationContextInterceptor.class, interceptors.next().getClass());
assertEquals(TxInterceptor.class, interceptors.next().getClass());
assertEquals(OptimisticReplicationInterceptor.class, interceptors.next().getClass());
assertEquals(OptimisticLockingInterceptor.class, interceptors.next().getClass());
assertEquals(OptimisticValidatorInterceptor.class, interceptors.next().getClass());
assertEquals(OptimisticCreateIfNotExistsInterceptor.class, interceptors.next().getClass());
assertEquals(OptimisticNodeInterceptor.class, interceptors.next().getClass());
assertEquals(CallInterceptor.class, interceptors.next().getClass());
assertInterceptorLinkage(list);
}
public void testOptimisticCacheLoaderChain() throws Exception
{
TreeCache cache = new TreeCache();
cache.getConfiguration().setUseInterceptorMbeans(false);
cache.getConfiguration().setNodeLockingOptimistic(true);
cache.getConfiguration().setCacheLoaderConfiguration(getCacheLoaderConfig(false, false));
cache.create();
Interceptor next = new InterceptorChainFactory().buildInterceptorChain(cache);
// test the chain size.
List<Interceptor> list = InterceptorChainFactory.asList(next);
Iterator<Interceptor> interceptors = list.iterator();
Assert.assertEquals(9, list.size());
assertEquals(InvocationContextInterceptor.class, interceptors.next().getClass());
assertEquals(TxInterceptor.class, interceptors.next().getClass());
assertEquals(CacheStoreInterceptor.class, interceptors.next().getClass());
assertEquals(CacheLoaderInterceptor.class, interceptors.next().getClass());
assertEquals(OptimisticLockingInterceptor.class, interceptors.next().getClass());
assertEquals(OptimisticValidatorInterceptor.class, interceptors.next().getClass());
assertEquals(OptimisticCreateIfNotExistsInterceptor.class, interceptors.next().getClass());
assertEquals(OptimisticNodeInterceptor.class, interceptors.next().getClass());
assertEquals(CallInterceptor.class, interceptors.next().getClass());
assertInterceptorLinkage(list);
}
public void testOptimisticPassivationCacheLoaderChain() throws Exception
{
TreeCache cache = new TreeCache();
cache.getConfiguration().setUseInterceptorMbeans(false);
cache.getConfiguration().setNodeLockingOptimistic(true);
cache.getConfiguration().setCacheLoaderConfiguration(getCacheLoaderConfig(true, false));
cache.create();
Interceptor next = new InterceptorChainFactory().buildInterceptorChain(cache);
// test the chain size.
List<Interceptor> list = InterceptorChainFactory.asList(next);
Iterator<Interceptor> interceptors = list.iterator();
Assert.assertEquals(9, list.size());
assertEquals(InvocationContextInterceptor.class, interceptors.next().getClass());
assertEquals(TxInterceptor.class, interceptors.next().getClass());
assertEquals(PassivationInterceptor.class, interceptors.next().getClass());
assertEquals(ActivationInterceptor.class, interceptors.next().getClass());
assertEquals(OptimisticLockingInterceptor.class, interceptors.next().getClass());
assertEquals(OptimisticValidatorInterceptor.class, interceptors.next().getClass());
assertEquals(OptimisticCreateIfNotExistsInterceptor.class, interceptors.next().getClass());
assertEquals(OptimisticNodeInterceptor.class, interceptors.next().getClass());
assertEquals(CallInterceptor.class, interceptors.next().getClass());
assertInterceptorLinkage(list);
}
public void testInvalidationInterceptorChain() throws Exception
{
TreeCache cache = new TreeCache();
cache.getConfiguration().setUseInterceptorMbeans(false);
cache.getConfiguration().setCacheMode("REPL_ASYNC");
Interceptor chain = new InterceptorChainFactory().buildInterceptorChain(cache);
// test the chain size.
List<Interceptor> list = InterceptorChainFactory.asList(chain);
Iterator<Interceptor> interceptors = list.iterator();
Assert.assertEquals(6, list.size());
assertEquals(InvocationContextInterceptor.class, interceptors.next().getClass());
assertEquals(TxInterceptor.class, interceptors.next().getClass());
assertEquals(ReplicationInterceptor.class, interceptors.next().getClass());
assertEquals(UnlockInterceptor.class, interceptors.next().getClass());
assertEquals(PessimisticLockInterceptor.class, interceptors.next().getClass());
assertEquals(CallInterceptor.class, interceptors.next().getClass());
// ok, my replication chain looks good.
// now for my invalidation chain.
cache = new TreeCache();
cache.getConfiguration().setUseInterceptorMbeans(false);
cache.getConfiguration().setCacheMode("INVALIDATION_ASYNC");
chain = new InterceptorChainFactory().buildInterceptorChain(cache);
// test the chain size.
list = InterceptorChainFactory.asList(chain);
interceptors = list.iterator();
Assert.assertEquals(6, list.size());
assertEquals(InvocationContextInterceptor.class, interceptors.next().getClass());
assertEquals(TxInterceptor.class, interceptors.next().getClass());
assertEquals(InvalidationInterceptor.class, interceptors.next().getClass());
assertEquals(UnlockInterceptor.class, interceptors.next().getClass());
assertEquals(PessimisticLockInterceptor.class, interceptors.next().getClass());
assertEquals(CallInterceptor.class, interceptors.next().getClass());
assertInterceptorLinkage(list);
}
public void testCacheMgmtConfig() throws Exception
{
cache.getConfiguration().setUseInterceptorMbeans(true);
Interceptor chain = new InterceptorChainFactory().buildInterceptorChain(cache);
List<Interceptor> list = InterceptorChainFactory.asList(chain);
Iterator<Interceptor> interceptors = list.iterator();
System.out.println("testCacheMgmtConfig interceptors are:\n" + list);
assertNotNull(list);
assertEquals(6, list.size());
assertEquals(InvocationContextInterceptor.class, interceptors.next().getClass());
assertEquals(CacheMgmtInterceptor.class, interceptors.next().getClass());
assertEquals(TxInterceptor.class, interceptors.next().getClass());
assertEquals(UnlockInterceptor.class, interceptors.next().getClass());
assertEquals(PessimisticLockInterceptor.class, interceptors.next().getClass());
assertEquals(CallInterceptor.class, interceptors.next().getClass());
assertInterceptorLinkage(list);
}
public void testEvictionInterceptorConfig() throws Exception
{
cache.setIsUsingEviction(true);
Interceptor chain = new InterceptorChainFactory().buildInterceptorChain(cache);
List<Interceptor> list = InterceptorChainFactory.asList(chain);
Iterator<Interceptor> interceptors = list.iterator();
System.out.println("testEvictionInterceptorConfig interceptors are:\n" + list);
assertNotNull(list);
assertEquals(7, list.size());
assertEquals(InvocationContextInterceptor.class, interceptors.next().getClass());
assertEquals(CacheMgmtInterceptor.class, interceptors.next().getClass());
assertEquals(TxInterceptor.class, interceptors.next().getClass());
assertEquals(UnlockInterceptor.class, interceptors.next().getClass());
assertEquals(PessimisticLockInterceptor.class, interceptors.next().getClass());
assertEquals(EvictionInterceptor.class, interceptors.next().getClass());
assertEquals(CallInterceptor.class, interceptors.next().getClass());
assertInterceptorLinkage(list);
}
public void testBuddyReplicationOptLocking() throws Exception
{
String xmlString = "<config><buddyReplicationEnabled>true</buddyReplicationEnabled>\n" +
"<buddyCommunicationTimeout>600000</buddyCommunicationTimeout>\n" +
" <buddyLocatorClass>org.jboss.cache.buddyreplication.NextMemberBuddyLocator</buddyLocatorClass>\n" +
" <buddyLocatorProperties>numBuddies = 1</buddyLocatorProperties>\n";
xmlString += "<buddyPoolName>buddyPoolName</buddyPoolName>";
xmlString += "</config>";
cache.getConfiguration().setCacheMode("REPL_SYNC");
cache.getConfiguration().setBuddyReplicationConfig(XmlHelper.stringToElement(xmlString));
cache.getConfiguration().setNodeLockingScheme("OPTIMISTIC");
cache.create(); // initialise various subsystems such as BRManager
Interceptor chain = new InterceptorChainFactory().buildInterceptorChain(cache);
List<Interceptor> list = InterceptorChainFactory.asList(chain);
Iterator<Interceptor> interceptors = list.iterator();
System.out.println("testEvictionInterceptorConfig interceptors are:\n" + list);
assertNotNull(list);
assertEquals(10, list.size());
assertEquals(InvocationContextInterceptor.class, interceptors.next().getClass());
assertEquals(CacheMgmtInterceptor.class, interceptors.next().getClass());
assertEquals(TxInterceptor.class, interceptors.next().getClass());
assertEquals(OptimisticReplicationInterceptor.class, interceptors.next().getClass());
assertEquals(DataGravitatorInterceptor.class, interceptors.next().getClass());
assertEquals(OptimisticLockingInterceptor.class, interceptors.next().getClass());
assertEquals(OptimisticValidatorInterceptor.class, interceptors.next().getClass());
assertEquals(OptimisticCreateIfNotExistsInterceptor.class, interceptors.next().getClass());
assertEquals(OptimisticNodeInterceptor.class, interceptors.next().getClass());
assertEquals(CallInterceptor.class, interceptors.next().getClass());
assertInterceptorLinkage(list);
}
public void testBuddyReplicationPessLocking() throws Exception
{
String xmlString = "<config><buddyReplicationEnabled>true</buddyReplicationEnabled>\n" +
"<buddyCommunicationTimeout>600000</buddyCommunicationTimeout>\n" +
" <buddyLocatorClass>org.jboss.cache.buddyreplication.NextMemberBuddyLocator</buddyLocatorClass>\n" +
" <buddyLocatorProperties>numBuddies = 1</buddyLocatorProperties>\n";
xmlString += "<buddyPoolName>buddyPoolName</buddyPoolName>";
xmlString += "</config>";
cache.getConfiguration().setCacheMode("REPL_SYNC");
cache.getConfiguration().setBuddyReplicationConfig(XmlHelper.stringToElement(xmlString));
cache.create(); // initialise various subsystems such as BRManager
Interceptor chain = new InterceptorChainFactory().buildInterceptorChain(cache);
List<Interceptor> list = InterceptorChainFactory.asList(chain);
Iterator<Interceptor> interceptors = list.iterator();
System.out.println("testEvictionInterceptorConfig interceptors are:\n" + list);
assertNotNull(list);
assertEquals(8, list.size());
assertEquals(InvocationContextInterceptor.class, interceptors.next().getClass());
assertEquals(CacheMgmtInterceptor.class, interceptors.next().getClass());
assertEquals(TxInterceptor.class, interceptors.next().getClass());
assertEquals(ReplicationInterceptor.class, interceptors.next().getClass());
assertEquals(UnlockInterceptor.class, interceptors.next().getClass());
assertEquals(DataGravitatorInterceptor.class, interceptors.next().getClass());
assertEquals(PessimisticLockInterceptor.class, interceptors.next().getClass());
assertEquals(CallInterceptor.class, interceptors.next().getClass());
assertInterceptorLinkage(list);
}
public static Test suite()
{
return new TestSuite(InterceptorChainFactoryTest.class);
}
public static void main(String[] args)
{
junit.textui.TestRunner.run(suite());
}
}
1.1 date: 2006/09/13 13:11:18; author: msurtani; state: Exp;JBossCache/tests/functional/org/jboss/cache/factories/InterceptorChainTestBase.java
Index: InterceptorChainTestBase.java
===================================================================
package org.jboss.cache.factories;
import junit.framework.TestCase;
import org.jboss.cache.interceptors.Interceptor;
import java.util.List;
/**
* @author <a href="mailto:manik at jboss.org">Manik Surtani</a>
*/
public abstract class InterceptorChainTestBase extends TestCase
{
protected void assertLast(Interceptor first, Interceptor last)
{
assertNotNull("First interceptor in the chain cannot be null", first);
assertNotNull("Last interceptor in the chain cannot be null", last);
Interceptor i = first;
while (i != null)
{
assertEquals("Expected last interceptor (in " + i + ") to be " + last, last, i.getLast());
i = i.getNext();
}
}
protected void assertInterceptorLinkage(List<Interceptor> list)
{
Interceptor previous = null;
for (Interceptor i : list)
{
if (previous == null)
{
previous = i;
continue;
}
assertEquals("Expecting the next interceptor after " + previous + " to be " + i, i, previous.getNext());
previous = i;
}
assertLast(list.get(0), previous);
}
}
More information about the jboss-cvs-commits
mailing list