Search in sources :

Example 1 with QueryPolicy

use of com.hazelcast.cp.internal.raft.QueryPolicy in project hazelcast by hazelcast.

the class RaftInvocationManagerAnswer method answer.

@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
    String methodName = invocation.getMethod().getName();
    Object[] arguments = invocation.getArguments();
    Class[] argumentClasses = new Class[arguments.length];
    for (int i = 0; i < arguments.length; i++) {
        if (arguments[i] instanceof RaftOp) {
            // transfer the operation to the delegateClassloader via (de)serialization
            Object dataOperation = serializationService.toData(arguments[i]);
            Object delegateDataOperation = proxyObjectForStarter(delegateClassloader, dataOperation);
            Object delegateOperation = delegateToObjectMethod.invoke(delegateSerializationService, delegateDataOperation);
            arguments[i] = delegateOperationClass.cast(delegateOperation);
            argumentClasses[i] = delegateOperationClass;
        } else if (arguments[i] instanceof Integer) {
            argumentClasses[i] = Integer.TYPE;
        } else if (arguments[i] instanceof RaftGroupId) {
            argumentClasses[i] = delegateCPGroupIdClass;
        } else if (arguments[i] instanceof QueryPolicy) {
            argumentClasses[i] = delegateQueryPolicyClass;
        } else {
            argumentClasses[i] = arguments[i].getClass();
        }
    }
    Method delegateMethod = getDelegateMethod(methodName, argumentClasses);
    Object[] proxiedArguments = proxyArgumentsIfNeeded(arguments, delegateClassloader);
    Object result = invoke(false, delegateMethod, proxiedArguments);
    if (invocation.getMethod().getName().equals("invoke")) {
        return mock(invocation.getMethod().getReturnType(), new DelegatingAnswer(result));
    } else {
        return proxyObjectForStarter(targetClassloader, result);
    }
}
Also used : RaftOp(com.hazelcast.cp.internal.RaftOp) RaftGroupId(com.hazelcast.cp.internal.RaftGroupId) Method(java.lang.reflect.Method) QueryPolicy(com.hazelcast.cp.internal.raft.QueryPolicy)

Aggregations

RaftGroupId (com.hazelcast.cp.internal.RaftGroupId)1 RaftOp (com.hazelcast.cp.internal.RaftOp)1 QueryPolicy (com.hazelcast.cp.internal.raft.QueryPolicy)1 Method (java.lang.reflect.Method)1