Rely on MProducerSupport.active for Flux (#3423)

* Rely on `MProducerSupport.active` for `Flux`

* Fix `MessageProducerSupport` to extract an `active` flag and set it before
`isRunning` - the `Flux` subscription relies on the `takeWhile()`
where in case of `autoStartup = false` we will never start consume because
it is set to `true` already after `doStart()`
* Refactor all the `MessageProducerSupport` implementation with similar
`active` state to use already one from the super class

**Cherry-pick to 5.3.x**

* * Remove `MessageProducerSupport.setActive()`
to not let to mutate it from the implementations
* Set `active` to `false` in the `destroy()`
* Clean up and fix typos in the affected `JmsMessageDrivenEndpoint`

* * Pull `active` flag down to the `AbstractEndpoint`
* Set `active = true` in the `start()` before calling `doStart()`
* Do same for `active = false` in the `stop()`
* Clean up `AbstractEndpoint` impls to not call `doStart/doStop` for nothing
* Refactor endpoints to rely on the `active` state from the `AbstractEndpoint`
not their own
This commit is contained in:
Artem Bilan
2020-11-06 13:51:03 -05:00
committed by Gary Russell
parent 27b464ad27
commit 002382e647
23 changed files with 1167 additions and 253 deletions

View File

@@ -16,7 +16,7 @@
package org.springframework.integration.endpoint;
import static org.assertj.core.api.Assertions.assertThat;
import java.time.Duration;
import org.junit.jupiter.api.Test;
@@ -50,17 +50,18 @@ public class ReactiveMessageProducerTests {
@Test
public void test() {
assertThat(this.producer.isRunning()).isTrue();
StepVerifier stepVerifier =
StepVerifier.create(
Flux.from(this.fluxMessageChannel)
.map(Message::getPayload)
.cast(String.class))
.expectNext("test1", "test2")
.thenCancel()
.verifyLater();
StepVerifier.create(
Flux.from(this.fluxMessageChannel)
.map(Message::getPayload)
.cast(String.class))
.expectNext("test1", "test2")
.thenCancel()
.verify();
this.producer.start();
assertThat(this.producer.isRunning()).isFalse();
stepVerifier.verify(Duration.ofSeconds(10));
}
@Configuration
@@ -79,10 +80,12 @@ public class ReactiveMessageProducerTests {
@Override
protected void doStart() {
super.doStart();
subscribeToPublisher(Flux.just("test1", "test2").map(GenericMessage::new));
}
};
producer.setAutoStartup(false);
producer.setOutputChannel(fluxMessageChannel());
return producer;
}