INT-4513: Clean IntManageConf from removed beans

JIRA: https://jira.spring.io/browse/INT-4513

The `IntegrationManagementConfigurer` keeps metrics beans in its local
stores.
When we add beans at runtime, they are not removed from those caches
after their removal

* Implement `DestructionAwareBeanPostProcessor` in the `IntegrationManagementConfigurer`
and clean up caches according provided bean type and its name
* Improve `ManualFlowTests` and `FtpTests` to be sure that
`IntegrationManagementConfigurer` caches are cleared after destroying
 `IntegrationFlowRegistration`

**Cherry-pick to 5.0.x**
This commit is contained in:
Artem Bilan
2018-07-27 12:36:39 -04:00
committed by Gary Russell
parent bd0fd50313
commit adbbca13fb
3 changed files with 57 additions and 5 deletions

View File

@@ -46,6 +46,8 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.integration.IntegrationMessageHeaderAccessor;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.config.EnableIntegration;
import org.springframework.integration.config.EnableIntegrationManagement;
import org.springframework.integration.config.IntegrationManagementConfigurer;
import org.springframework.integration.core.MessageSource;
import org.springframework.integration.dsl.IntegrationFlow;
import org.springframework.integration.dsl.IntegrationFlows;
@@ -85,6 +87,9 @@ public class FtpTests extends FtpTestSupport {
@Autowired
private ApplicationContext context;
@Autowired
private IntegrationManagementConfigurer integrationManagementConfigurer;
@Test
public void testFtpInboundFlow() throws IOException {
QueueChannel out = new QueueChannel();
@@ -132,7 +137,12 @@ public class FtpTests extends FtpTestSupport {
MessageSource<?> source = context.getBean(FtpInboundFileSynchronizingMessageSource.class);
assertThat(TestUtils.getPropertyValue(source, "maxFetchSize"), equalTo(10));
assertNotNull(this.integrationManagementConfigurer.getSourceMetrics("ftpInboundAdapter.source"));
registration.destroy();
assertNull(this.integrationManagementConfigurer.getSourceMetrics("ftpInboundAdapter.source"));
}
@Test
@@ -221,6 +231,7 @@ public class FtpTests extends FtpTestSupport {
@Configuration
@EnableIntegration
@EnableIntegrationManagement
public static class ContextConfiguration {
}