package org.jboss.cache.optimistic;
import org.jboss.cache.InvocationContext;
import org.jboss.cache.interceptors.Interceptor;
import org.jboss.cache.marshall.MethodCall;
import org.jboss.cache.marshall.MethodDeclarations;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
/**
* Handles putXXX() methods: if the given node doesn't exist, it will be created
* (depending on the create_if_not_exists argument)
*
* @author Bela Ban
* @version $Id: CreateIfNotExistsInterceptor.java,v 1.7 2005/01/26 11:45:14
* belaban Exp $
*/
public class MockFailureInterceptor extends Interceptor
{
private List<Method> allCalled = new ArrayList<Method>();
private List<Method> failurelist = new ArrayList<Method>();
private List<Integer> allCalledIdsList = new ArrayList<Integer>();
@Override
public Object invoke(InvocationContext ctx) throws Throwable
{
MethodCall m = ctx.getMethodCall();
if (!MethodDeclarations.isBlockUnblockMethod(m.getMethodId()))
{
if (failurelist.contains(m.getMethod())) throw new Exception("Failure in method " + m);
allCalled.add(m.getMethod());
allCalledIdsList.add(m.getMethodId());
}
return null;
}
/**
* @return Returns the failurelist.
*/
public List<Method> getFailurelist()
{
return failurelist;
}
/**
* @param failurelist The failurelist to set.
*/
public void setFailurelist(List<Method> failurelist)
{
this.failurelist = failurelist;
}
/**
* @return Returns the called.
*/
public List<Method> getAllCalled()
{
return allCalled;
}
/**
* @param called The called to set.
*/
public void setAllCalled(List<Method> called)
{
this.allCalled = called;
}
public List<Integer> getAllCalledIds()
{
return allCalledIdsList;
}
}