|
18 | 18 |
|
19 | 19 | import java.util.concurrent.BlockingQueue;
|
20 | 20 | import java.util.concurrent.LinkedBlockingQueue;
|
21 |
| -import java.util.concurrent.TimeUnit; |
22 | 21 |
|
23 | 22 | import javax.management.MBeanServer;
|
24 | 23 | import javax.sql.DataSource;
|
25 | 24 |
|
26 | 25 | import io.rsocket.transport.ClientTransport;
|
27 | 26 | import io.rsocket.transport.netty.client.TcpClientTransport;
|
| 27 | +import org.assertj.core.api.InstanceOfAssertFactories; |
28 | 28 | import org.junit.jupiter.api.Test;
|
29 |
| -import reactor.core.publisher.Mono; |
30 | 29 |
|
31 | 30 | import org.springframework.beans.DirectFieldAccessor;
|
32 | 31 | import org.springframework.boot.autoconfigure.AutoConfigurations;
|
|
42 | 41 | import org.springframework.boot.autoconfigure.rsocket.RSocketServerAutoConfiguration;
|
43 | 42 | import org.springframework.boot.autoconfigure.rsocket.RSocketStrategiesAutoConfiguration;
|
44 | 43 | import org.springframework.boot.autoconfigure.task.TaskSchedulingAutoConfiguration;
|
| 44 | +import org.springframework.boot.context.properties.source.MutuallyExclusiveConfigurationPropertiesException; |
45 | 45 | import org.springframework.boot.jdbc.init.DataSourceScriptDatabaseInitializer;
|
46 | 46 | import org.springframework.boot.sql.init.DatabaseInitializationMode;
|
47 | 47 | import org.springframework.boot.sql.init.DatabaseInitializationSettings;
|
|
70 | 70 | import org.springframework.messaging.Message;
|
71 | 71 | import org.springframework.messaging.MessageHandler;
|
72 | 72 | import org.springframework.messaging.rsocket.annotation.support.RSocketMessageHandler;
|
73 |
| -import org.springframework.messaging.support.GenericMessage; |
74 | 73 | import org.springframework.scheduling.TaskScheduler;
|
75 | 74 | import org.springframework.scheduling.support.CronTrigger;
|
76 | 75 |
|
@@ -404,49 +403,48 @@ void whenTheUserDefinesTheirOwnDatabaseInitializerThenTheAutoConfiguredIntegrati
|
404 | 403 | @Test
|
405 | 404 | void defaultPoller() {
|
406 | 405 | this.contextRunner.withUserConfiguration(PollingConsumerConfiguration.class).run((context) -> {
|
407 |
| - assertThat(context).hasSingleBean(PollerMetadata.class).getBean(PollerMetadata.DEFAULT_POLLER) |
408 |
| - .hasFieldOrPropertyWithValue("maxMessagesPerPoll", (long) PollerMetadata.MAX_MESSAGES_UNBOUNDED) |
409 |
| - .hasFieldOrPropertyWithValue("receiveTimeout", PollerMetadata.DEFAULT_RECEIVE_TIMEOUT) |
410 |
| - .hasFieldOrPropertyWithValue("trigger", null); |
411 |
| - |
412 |
| - GenericMessage<String> testMessage = new GenericMessage<>("test"); |
413 |
| - context.getBean("testChannel", QueueChannel.class).send(testMessage); |
414 |
| - @SuppressWarnings("unchecked") |
415 |
| - BlockingQueue<Message<?>> sink = context.getBean("sink", BlockingQueue.class); |
416 |
| - assertThat(sink.poll(10, TimeUnit.SECONDS)).isSameAs(testMessage); |
| 406 | + assertThat(context).hasSingleBean(PollerMetadata.class); |
| 407 | + PollerMetadata metadata = context.getBean(PollerMetadata.DEFAULT_POLLER, PollerMetadata.class); |
| 408 | + assertThat(metadata.getMaxMessagesPerPoll()).isEqualTo(PollerMetadata.MAX_MESSAGES_UNBOUNDED); |
| 409 | + assertThat(metadata.getReceiveTimeout()).isEqualTo(PollerMetadata.DEFAULT_RECEIVE_TIMEOUT); |
| 410 | + assertThat(metadata.getTrigger()).isNull(); |
417 | 411 | });
|
418 | 412 | }
|
419 | 413 |
|
420 | 414 | @Test
|
421 |
| - void customPollerProperties() { |
| 415 | + void whenCustomPollerPropertiesAreSetThenTheyAreReflectedInPollerMetadata() { |
422 | 416 | this.contextRunner.withUserConfiguration(PollingConsumerConfiguration.class)
|
423 | 417 | .withPropertyValues("spring.integration.poller.cron=* * * ? * *",
|
424 | 418 | "spring.integration.poller.max-messages-per-poll=1",
|
425 | 419 | "spring.integration.poller.receive-timeout=10s")
|
426 | 420 | .run((context) -> {
|
427 |
| - assertThat(context).hasSingleBean(PollerMetadata.class) |
428 |
| - .getBean(PollerMetadata.DEFAULT_POLLER, PollerMetadata.class) |
429 |
| - .hasFieldOrPropertyWithValue("maxMessagesPerPoll", 1L) |
430 |
| - .hasFieldOrPropertyWithValue("receiveTimeout", 10000L) |
431 |
| - .extracting(PollerMetadata::getTrigger).isInstanceOf(CronTrigger.class) |
432 |
| - .hasFieldOrPropertyWithValue("expression", "* * * ? * *"); |
433 |
| - |
434 |
| - GenericMessage<String> testMessage = new GenericMessage<>("test"); |
435 |
| - context.getBean("testChannel", QueueChannel.class).send(testMessage); |
436 |
| - @SuppressWarnings("unchecked") |
437 |
| - BlockingQueue<Message<?>> sink = context.getBean("sink", BlockingQueue.class); |
438 |
| - assertThat(sink.poll(10, TimeUnit.SECONDS)).isSameAs(testMessage); |
| 421 | + assertThat(context).hasSingleBean(PollerMetadata.class); |
| 422 | + PollerMetadata metadata = context.getBean(PollerMetadata.DEFAULT_POLLER, PollerMetadata.class); |
| 423 | + assertThat(metadata.getMaxMessagesPerPoll()).isEqualTo(1L); |
| 424 | + assertThat(metadata.getReceiveTimeout()).isEqualTo(10000L); |
| 425 | + assertThat(metadata.getTrigger()).asInstanceOf(InstanceOfAssertFactories.type(CronTrigger.class)) |
| 426 | + .satisfies((trigger) -> assertThat(trigger.getExpression()).isEqualTo("* * * ? * *")); |
439 | 427 | });
|
440 | 428 | }
|
441 | 429 |
|
442 | 430 | @Test
|
443 |
| - void triggerPropertiesAreMutuallyExclusive() { |
| 431 | + void whenPollerPropertiesForMultipleTriggerTypesAreSetThenRefreshFails() { |
444 | 432 | this.contextRunner
|
445 | 433 | .withPropertyValues("spring.integration.poller.cron=* * * ? * *",
|
446 | 434 | "spring.integration.poller.fixed-delay=1s")
|
447 | 435 | .run((context) -> assertThat(context).hasFailed().getFailure()
|
448 |
| - .hasRootCauseExactlyInstanceOf(IllegalArgumentException.class).hasMessageContaining( |
449 |
| - "The 'cron', 'fixedDelay' and 'fixedRate' are mutually exclusive 'spring.integration.poller' properties.")); |
| 436 | + .hasRootCauseExactlyInstanceOf(MutuallyExclusiveConfigurationPropertiesException.class) |
| 437 | + .getRootCause() |
| 438 | + .asInstanceOf( |
| 439 | + InstanceOfAssertFactories.type(MutuallyExclusiveConfigurationPropertiesException.class)) |
| 440 | + .satisfies((ex) -> { |
| 441 | + assertThat(ex.getConfiguredNames()).containsExactlyInAnyOrder( |
| 442 | + "spring.integration.poller.cron", "spring.integration.poller.fixed-delay"); |
| 443 | + assertThat(ex.getMutuallyExclusiveNames()).containsExactlyInAnyOrder( |
| 444 | + "spring.integration.poller.cron", "spring.integration.poller.fixed-delay", |
| 445 | + "spring.integration.poller.fixed-rate"); |
| 446 | + })); |
| 447 | + |
450 | 448 | }
|
451 | 449 |
|
452 | 450 | @Configuration(proxyBeanMethods = false)
|
|
0 commit comments