Merge pull request #28237 from artembilan

* pr/28237:
  Polish "Fix Integration `fixedRate` property setting"
  Fix Integration `fixedRate` property setting

Closes gh-28237
pull/28308/head
Stephane Nicoll 3 years ago
commit f00052054e

@ -140,10 +140,10 @@ public class IntegrationAutoConfiguration {
return new CronTrigger(poller.getCron());
}
if (poller.getFixedDelay() != null) {
return createPeriodicTrigger(poller.getFixedDelay(), poller.getInitialDelay(), true);
return createPeriodicTrigger(poller.getFixedDelay(), poller.getInitialDelay(), false);
}
if (poller.getFixedRate() != null) {
return createPeriodicTrigger(poller.getFixedRate(), poller.getInitialDelay(), false);
return createPeriodicTrigger(poller.getFixedRate(), poller.getInitialDelay(), true);
}
return null;
}

@ -18,6 +18,7 @@ package org.springframework.boot.autoconfigure.integration;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import javax.management.MBeanServer;
import javax.sql.DataSource;
@ -70,8 +71,10 @@ import org.springframework.jmx.export.MBeanExporter;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHandler;
import org.springframework.messaging.rsocket.annotation.support.RSocketMessageHandler;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.support.CronTrigger;
import org.springframework.scheduling.support.PeriodicTrigger;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
@ -408,6 +411,10 @@ class IntegrationAutoConfigurationTests {
assertThat(metadata.getMaxMessagesPerPoll()).isEqualTo(PollerMetadata.MAX_MESSAGES_UNBOUNDED);
assertThat(metadata.getReceiveTimeout()).isEqualTo(PollerMetadata.DEFAULT_RECEIVE_TIMEOUT);
assertThat(metadata.getTrigger()).isNull();
GenericMessage<String> testMessage = new GenericMessage<>("test");
context.getBean("testChannel", QueueChannel.class).send(testMessage);
assertThat(context.getBean("sink", BlockingQueue.class).poll(10, TimeUnit.SECONDS)).isSameAs(testMessage);
});
}
@ -447,6 +454,36 @@ class IntegrationAutoConfigurationTests {
}
@Test
void whenFixedDelayPollerPropertyIsSetThenItIsReflectedAsFixedDelayPropertyOfPeriodicTrigger() {
this.contextRunner.withUserConfiguration(PollingConsumerConfiguration.class)
.withPropertyValues("spring.integration.poller.fixed-delay=5000").run((context) -> {
assertThat(context).hasSingleBean(PollerMetadata.class);
PollerMetadata metadata = context.getBean(PollerMetadata.DEFAULT_POLLER, PollerMetadata.class);
assertThat(metadata.getTrigger())
.asInstanceOf(InstanceOfAssertFactories.type(PeriodicTrigger.class))
.satisfies((trigger) -> {
assertThat(trigger.getPeriod()).isEqualTo(5000L);
assertThat(trigger.isFixedRate()).isFalse();
});
});
}
@Test
void whenFixedRatePollerPropertyIsSetThenItIsReflectedAsFixedRatePropertyOfPeriodicTrigger() {
this.contextRunner.withUserConfiguration(PollingConsumerConfiguration.class)
.withPropertyValues("spring.integration.poller.fixed-rate=5000").run((context) -> {
assertThat(context).hasSingleBean(PollerMetadata.class);
PollerMetadata metadata = context.getBean(PollerMetadata.DEFAULT_POLLER, PollerMetadata.class);
assertThat(metadata.getTrigger())
.asInstanceOf(InstanceOfAssertFactories.type(PeriodicTrigger.class))
.satisfies((trigger) -> {
assertThat(trigger.getPeriod()).isEqualTo(5000L);
assertThat(trigger.isFixedRate()).isTrue();
});
});
}
@Configuration(proxyBeanMethods = false)
static class CustomMBeanExporter {

Loading…
Cancel
Save