use of io.aklivity.zilla.runtime.engine.test.annotation.Configure in project zilla by aklivity.
the class EngineRule method apply.
@Override
public Statement apply(Statement base, Description description) {
Class<?> testClass = description.getTestClass();
final String testMethod = description.getMethodName().replaceAll("\\[.*\\]", "");
try {
Configure[] configures = testClass.getDeclaredMethod(testMethod).getAnnotationsByType(Configure.class);
Arrays.stream(configures).forEach(p -> properties.setProperty(p.name(), p.value()));
Configuration config = description.getAnnotation(Configuration.class);
if (config != null) {
if (configurationRoot != null) {
String resourceName = String.format("%s/%s", configurationRoot, config.value());
configURL = testClass.getClassLoader().getResource(resourceName);
} else {
String resourceName = String.format("%s-%s", testClass.getSimpleName(), config.value());
configURL = testClass.getResource(resourceName);
}
}
cleanup();
} catch (Exception e) {
LangUtil.rethrowUnchecked(e);
}
return new Statement() {
@Override
public void evaluate() throws Throwable {
EngineConfiguration config = configuration();
final Thread baseThread = Thread.currentThread();
final List<Throwable> errors = new ArrayList<>();
final ErrorHandler errorHandler = ex -> {
errors.add(ex);
baseThread.interrupt();
};
engine = builder.config(config).configURL(configURL).errorHandler(errorHandler).build();
try {
engine.start().get();
base.evaluate();
} catch (Throwable t) {
errors.add(t);
} finally {
try {
engine.close();
} catch (Throwable t) {
errors.add(t);
} finally {
assertEmpty(errors);
}
}
}
};
}
Aggregations