@Override public Optional<ProcessorDefinition> handle(Throttle step, ProcessorDefinition route, SyndesisRouteBuilder routeBuilder) { ThrottleDefinition throttle = route.throttle(step.getMaximumRequests()); Long period = step.getPeriodMillis(); if (period != null) { throttle.timePeriodMillis(period); } return routeBuilder.addSteps(throttle, step.getSteps()); }
@Override public ProcessorDefinition handle(Throttle step, ProcessorDefinition route, SyndesisRouteBuilder routeBuilder) { ThrottleDefinition throttle = route.throttle(step.getMaximumRequests()); Long period = step.getPeriodMillis(); if (period != null) { throttle.timePeriodMillis(period); } return routeBuilder.addSteps(throttle, step.getSteps()); }
@Test public void shouldConfigureRouteWithoutThrottling() throws Exception { route.throttleMaxPerPeriod = -1; route.periodInMs = 100; route.configure(); RouteDefinition routeDefinition = route.getRouteCollection().getRoutes().get(0); assertThat(routeDefinition.getOutputs().stream().filter(processorDefinition -> processorDefinition instanceof ThrottleDefinition).findFirst()).isEmpty(); }
@Test public void shouldConfigureRouteWithThrottling() throws Exception { route.throttleMaxPerPeriod = 10; route.periodInMs = 100; route.configure(); RouteDefinition routeDefinition = route.getRouteCollection().getRoutes().get(0); ThrottleDefinition throttleDefinition = (ThrottleDefinition) routeDefinition.getOutputs().stream().filter(processorDefinition -> processorDefinition instanceof ThrottleDefinition).findFirst().get(); assertThat(throttleDefinition.getExpression().getExpressionValue().toString()).isEqualTo("10"); assertThat(throttleDefinition.getTimePeriodMillis()).isEqualTo(100); }
public static ThrottleDefinition throttle(ProcessorDefinition<?> self, Closure<?> expression) { return self.throttle(toExpression(expression)); }