Search in sources :

Example 1 with AnnotatedMethodRetriever

use of com.hazelcast.simulator.utils.AnnotatedMethodRetriever in project hazelcast-simulator by hazelcast.

the class TimeStepModel method loadAfterRunMethods.

private void loadAfterRunMethods() {
    List<Method> methods = new AnnotatedMethodRetriever(testClass, AfterRun.class).findAll();
    validateModifiers(methods);
    validateBeforeAndAfterRunArguments(AfterRun.class.getSimpleName(), methods);
    for (Method method : methods) {
        AfterRun afterRun = method.getAnnotation(AfterRun.class);
        String executionGroupName = afterRun.executionGroup();
        ensureExecutionGroupIsIdentifier(method, executionGroupName);
        ExecutionGroup executionGroup = executionGroups.get(executionGroupName);
        if (executionGroup == null) {
            if (executionGroupName.equals("")) {
                throw new IllegalTestException("@AfterRun " + method + " is part of default executionGroup," + " but no timeStep methods for that executionGroup exist ");
            } else {
                throw new IllegalTestException("@AfterRun " + method + " is part of executionGroup [" + executionGroupName + "], but no timeStep methods for that executionGroup exist ");
            }
        }
        executionGroup.afterRunMethods.add(method);
    }
}
Also used : AfterRun(com.hazelcast.simulator.test.annotations.AfterRun) Method(java.lang.reflect.Method) AnnotatedMethodRetriever(com.hazelcast.simulator.utils.AnnotatedMethodRetriever)

Example 2 with AnnotatedMethodRetriever

use of com.hazelcast.simulator.utils.AnnotatedMethodRetriever in project hazelcast-simulator by hazelcast.

the class TimeStepModel method loadTimeStepMethods.

private void loadTimeStepMethods() {
    List<Method> methods = new AnnotatedMethodRetriever(testClass, TimeStep.class).findAll();
    // we can easily increase the number to 256 in the future
    if (methods.size() > Byte.MAX_VALUE) {
        throw new IllegalTestException(testClass.getName() + " has more than 127 TimeStep methods, found: " + methods.size());
    }
    validateUniqueMethodNames(methods);
    validateModifiers(methods);
    validateTimeStepParameters(methods);
    for (Method method : methods) {
        TimeStep timeStep = method.getAnnotation(TimeStep.class);
        String group = timeStep.executionGroup();
        ensureExecutionGroupIsIdentifier(method, group);
        ExecutionGroup executionGroup = executionGroups.get(group);
        if (executionGroup == null) {
            executionGroup = new ExecutionGroup(group);
            executionGroups.put(group, executionGroup);
        }
        executionGroup.timeStepMethods.add(method);
    }
}
Also used : TimeStep(com.hazelcast.simulator.test.annotations.TimeStep) Method(java.lang.reflect.Method) AnnotatedMethodRetriever(com.hazelcast.simulator.utils.AnnotatedMethodRetriever)

Example 3 with AnnotatedMethodRetriever

use of com.hazelcast.simulator.utils.AnnotatedMethodRetriever in project hazelcast-simulator by hazelcast.

the class TestContainer method registerSetupTask.

private void registerSetupTask() {
    List<Method> setupMethods = new AnnotatedMethodRetriever(testClass, Setup.class).withVoidReturnType().withPublicNonStaticModifier().findAll();
    List<Callable> callableList = new ArrayList<Callable>(setupMethods.size());
    for (Method setupMethod : setupMethods) {
        Class[] parameterTypes = setupMethod.getParameterTypes();
        Object[] args;
        switch(parameterTypes.length) {
            case 0:
                args = new Object[0];
                break;
            case 1:
                Class<?> parameterType = setupMethod.getParameterTypes()[0];
                if (!parameterType.isAssignableFrom(TestContext.class) || parameterType.isAssignableFrom(Object.class)) {
                    throw new IllegalTestException(format("Method %s.%s() supports arguments of type %s, but found %s", testClass.getSimpleName(), setupMethod, TestContext.class.getName(), parameterType.getName()));
                }
                args = new Object[] { testContext };
                break;
            default:
                throw new IllegalTestException(format("Setup method '%s' can have at most a single argument", setupMethod));
        }
        callableList.add(new MethodInvokingCallable(testInstance, setupMethod, args));
    }
    taskPerPhaseMap.put(SETUP, new CompositeCallable(callableList));
}
Also used : ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) AnnotatedMethodRetriever(com.hazelcast.simulator.utils.AnnotatedMethodRetriever) Callable(java.util.concurrent.Callable) Setup(com.hazelcast.simulator.test.annotations.Setup)

Example 4 with AnnotatedMethodRetriever

use of com.hazelcast.simulator.utils.AnnotatedMethodRetriever in project hazelcast-simulator by hazelcast.

the class TestContainer method loadRunStrategy.

private RunStrategy loadRunStrategy() {
    try {
        List<String> runAnnotations = new LinkedList<String>();
        RunStrategy runStrategy = null;
        Method runMethod = new AnnotatedMethodRetriever(testClass, Run.class).withoutArgs().withVoidReturnType().withPublicNonStaticModifier().find();
        if (runMethod != null) {
            runAnnotations.add(Run.class.getName());
            runStrategy = new PrimordialRunStrategy(testInstance, runMethod);
        }
        List<Method> timeStepMethods = new AnnotatedMethodRetriever(testClass, TimeStep.class).findAll();
        if (!timeStepMethods.isEmpty()) {
            runAnnotations.add(TimeStep.class.getName());
            runStrategy = new TimeStepRunStrategy(this);
        }
        if (runAnnotations.size() == 0) {
            throw new IllegalTestException("Test is missing a run strategy, it must contain one of the following annotations: " + asList(Run.class.getName(), TimeStep.class.getName()));
        } else if (runAnnotations.size() > 1) {
            throw new IllegalTestException("Test has more than one run strategy, found the following annotations: " + runAnnotations);
        } else {
            return runStrategy;
        }
    } catch (IllegalTestException e) {
        throw rethrow(e);
    } catch (Exception e) {
        throw new IllegalTestException(format("Error loading run strategy in %s: [%s] %s", testClass.getName(), e.getClass().getSimpleName(), e.getMessage()), e);
    }
}
Also used : Run(com.hazelcast.simulator.test.annotations.Run) Method(java.lang.reflect.Method) LinkedList(java.util.LinkedList) AnnotatedMethodRetriever(com.hazelcast.simulator.utils.AnnotatedMethodRetriever) InvocationTargetException(java.lang.reflect.InvocationTargetException) TimeStep(com.hazelcast.simulator.test.annotations.TimeStep)

Example 5 with AnnotatedMethodRetriever

use of com.hazelcast.simulator.utils.AnnotatedMethodRetriever in project hazelcast-simulator by hazelcast.

the class TimeStepModel method loadBeforeRunMethods.

private void loadBeforeRunMethods() {
    List<Method> methods = new AnnotatedMethodRetriever(testClass, BeforeRun.class).findAll();
    validateModifiers(methods);
    validateBeforeAndAfterRunArguments(BeforeRun.class.getSimpleName(), methods);
    for (Method method : methods) {
        BeforeRun beforeRun = method.getAnnotation(BeforeRun.class);
        String executionGroupName = beforeRun.executionGroup();
        ensureExecutionGroupIsIdentifier(method, executionGroupName);
        ExecutionGroup executionGroup = executionGroups.get(executionGroupName);
        if (executionGroup == null) {
            if (executionGroupName.equals("")) {
                throw new IllegalTestException("@BeforeRun " + method + " is part of default executionGroup," + " but no timeStep methods for that executionGroup exist ");
            } else {
                throw new IllegalTestException("@BeforeRun " + method + " is part of executionGroup [" + executionGroupName + "], but no timeStep methods for that executionGroup exist ");
            }
        }
        executionGroup.beforeRunMethods.add(method);
    }
}
Also used : BeforeRun(com.hazelcast.simulator.test.annotations.BeforeRun) Method(java.lang.reflect.Method) AnnotatedMethodRetriever(com.hazelcast.simulator.utils.AnnotatedMethodRetriever)

Aggregations

AnnotatedMethodRetriever (com.hazelcast.simulator.utils.AnnotatedMethodRetriever)5 Method (java.lang.reflect.Method)5 TimeStep (com.hazelcast.simulator.test.annotations.TimeStep)2 AfterRun (com.hazelcast.simulator.test.annotations.AfterRun)1 BeforeRun (com.hazelcast.simulator.test.annotations.BeforeRun)1 Run (com.hazelcast.simulator.test.annotations.Run)1 Setup (com.hazelcast.simulator.test.annotations.Setup)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 Callable (java.util.concurrent.Callable)1