Description
taking a example from unit test (which is disabled due to Time sensitive issue)
test method reference org.springframework.integration.aggregator.AggregatorTests#testAggPerfDefaultPartial
@Test
@Disabled("Time sensitive")
public void testAggPerfDefaultPartial() throws InterruptedException, ExecutionException,TimeoutException {
AggregatingMessageHandler handler = new AggregatingMessageHandler(new DefaultAggregatingMessageGroupProcessor());
handler.setCorrelationStrategy(message -> "foo");
handler.setReleasePartialSequences(true);
....
}
in above test, we set releasePartialSequences to true, which will set releaseStrategy to SequenceSizeReleaseStrategy
.
// class AbstractCorrelatingMessageHandler
public void setReleasePartialSequences(boolean releasePartialSequences) {
if (!this.releaseStrategySet && releasePartialSequences) {
setReleaseStrategy(new SequenceSizeReleaseStrategy());
}
this.releasePartialSequences = releasePartialSequences;
}
however, the releasePartialSequences value is never propagated to SequenceSizeReleaseStrategy.
actually it is propagated in onInit() method, inside afterPropertiesSet()
, which means only we call afterPropertiesSet()
, it will be propagated.
// class AbstractCorrelatingMessageHandler
@Override
protected void onInit() {
super.onInit();
// ...
if (this.releasePartialSequences) {
Assert.isInstanceOf(SequenceSizeReleaseStrategy.class, this.releaseStrategy, () ->
"Release strategy of type [" + this.releaseStrategy.getClass().getSimpleName() +
"] cannot release partial sequences. Use a SequenceSizeReleaseStrategy instead.");
((SequenceSizeReleaseStrategy) this.releaseStrategy)
.setReleasePartialSequences(this.releasePartialSequences);
}
// ...
}
I think it is our unit test issue, also the assertion is not correct. even it passes when we enabled the test.
for fix, I prefer remove the value propagation in method onInit()
, and add this logic in setReleasePartialSequences()
// class AbstractCorrelatingMessageHandler
public void setReleasePartialSequences(boolean releasePartialSequences) {
if (!this.releaseStrategySet && releasePartialSequences) {
SequenceSizeReleaseStrategy sequenceSizeReleaseStrategy = new SequenceSizeReleaseStrategy();
sequenceSizeReleaseStrategy.setReleasePartialSequences(releasePartialSequences);
setReleaseStrategy(sequenceSizeReleaseStrategy);
}
this.releasePartialSequences = releasePartialSequences;
}
kindly confirm.