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);
}
}
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);
}
}
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));
}
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);
}
}
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);
}
}
Aggregations