use of org.apache.camel.dsl.yaml.YamlRoutesBuilderLoader in project camel-k-runtime by apache.
the class CronTest method testCronTimerActivation.
@ParameterizedTest
@MethodSource("parameters")
public void testCronTimerActivation(String code, String cronOverride) throws Exception {
final Runtime runtime = Runtime.on(new DefaultCamelContext());
runtime.getRegistry().bind("__camel_k_resolver", new CustomResolver());
final YamlRoutesBuilderLoader loader = new YamlRoutesBuilderLoader();
loader.setCamelContext(runtime.getCamelContext());
loader.start();
final CronSourceLoaderInterceptor interceptor = new CronSourceLoaderInterceptor();
interceptor.setRuntime(runtime);
interceptor.setOverridableComponents(cronOverride);
final RouteBuilder builder = (RouteBuilder) loader.loadRoutesBuilder(ResourceHelper.fromBytes("my-cron.yaml", code.getBytes(StandardCharsets.UTF_8)));
builder.addLifecycleInterceptor(interceptor);
runtime.getCamelContext().addRoutes(builder);
CountDownLatch termination = new CountDownLatch(1);
runtime.getCamelContext().addLifecycleStrategy(new LifecycleStrategySupport() {
@Override
public void onContextStopped(CamelContext context) {
termination.countDown();
}
});
MockEndpoint mock = runtime.getCamelContext().getEndpoint("mock:result", MockEndpoint.class);
mock.expectedMessageCount(1);
mock.setResultWaitTime(10000);
runtime.getCamelContext().start();
mock.assertIsSatisfied();
termination.await(10, TimeUnit.SECONDS);
assertThat(termination.getCount()).isZero();
}
use of org.apache.camel.dsl.yaml.YamlRoutesBuilderLoader in project camel-k-runtime by apache.
the class Application method load.
@GET
@Path("/load")
@Produces(MediaType.TEXT_PLAIN)
public String load() throws Exception {
final String code = "" + "\n- from:" + "\n uri: \"timer:tick?period=1&delay=60000\"" + "\n steps:" + "\n - log: \"${body}\"";
final YamlRoutesBuilderLoader loader = new YamlRoutesBuilderLoader();
loader.setCamelContext(context);
loader.build();
final Runtime rt = new DelegatingRuntime(runtime) {
@Override
public void stop() throws Exception {
stopped.set(true);
}
};
final CronSourceLoaderInterceptor interceptor = new CronSourceLoaderInterceptor();
interceptor.setRuntime(rt);
interceptor.setOverridableComponents("timer");
final RouteBuilder builder = (RouteBuilder) loader.loadRoutesBuilder(ResourceHelper.fromBytes("my-cron.yaml", code.getBytes(StandardCharsets.UTF_8)));
builder.addLifecycleInterceptor(interceptor);
try {
context.addRoutes(builder);
} catch (Exception e) {
throw new RuntimeException(e);
}
return "" + context.getRoutesSize();
}
Aggregations