Optimize BPPs as AopInfrastructureBean
There is no need to post-process the framework internal BPPs.
Therefore, mark `GatewayProxyInstantiationPostProcessor`, `GlobalChannelInterceptorProcessor`, `IntegrationFlowBeanPostProcessor`
and `BaseIntegrationFlowDefinition.ReplyProducerCleaner` as an `AopInfrastructureBean`.
This way they are not post-processed via AOP `BeanPostProcessor`
* Migrate `org.springframework.integration.aop` tests to JUnit 5
* Fix race condition in the `FluxMessageChannelTests.noMemoryLeakInFluxMessageChannelForVolatilePublishers()`
where `FluxMessageChannel.upstreamSubscriptions` is updated from a different thread
(cherry picked from commit a8ed1dd9aa)
This commit is contained in:
committed by
Spring Builds
parent
de291d81d1
commit
9ae23dc0b8
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2022 the original author or authors.
|
||||
* Copyright 2022-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.integration.config;
|
||||
|
||||
import org.springframework.aop.framework.AopInfrastructureBean;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition;
|
||||
import org.springframework.beans.factory.aot.BeanRegistrationAotContribution;
|
||||
@@ -44,7 +45,7 @@ import org.springframework.integration.gateway.AnnotationGatewayProxyFactoryBean
|
||||
* @see AnnotationGatewayProxyFactoryBean
|
||||
*/
|
||||
class GatewayProxyInstantiationPostProcessor implements
|
||||
InstantiationAwareBeanPostProcessor, BeanRegistrationAotProcessor, ApplicationContextAware {
|
||||
InstantiationAwareBeanPostProcessor, BeanRegistrationAotProcessor, ApplicationContextAware, AopInfrastructureBean {
|
||||
|
||||
private final BeanDefinitionRegistry registry;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,6 +25,7 @@ import java.util.Set;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.aop.framework.AopInfrastructureBean;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanFactoryAware;
|
||||
@@ -54,7 +55,7 @@ import org.springframework.util.StringUtils;
|
||||
* @since 2.0
|
||||
*/
|
||||
public final class GlobalChannelInterceptorProcessor
|
||||
implements BeanFactoryAware, SmartInitializingSingleton, BeanPostProcessor {
|
||||
implements BeanFactoryAware, SmartInitializingSingleton, BeanPostProcessor, AopInfrastructureBean {
|
||||
|
||||
private static final Log LOGGER = LogFactory.getLog(GlobalChannelInterceptorProcessor.class);
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ import reactor.core.publisher.Flux;
|
||||
import reactor.util.function.Tuple2;
|
||||
|
||||
import org.springframework.aop.framework.Advised;
|
||||
import org.springframework.aop.framework.AopInfrastructureBean;
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
@@ -3047,7 +3048,7 @@ public abstract class BaseIntegrationFlowDefinition<B extends BaseIntegrationFlo
|
||||
}
|
||||
}
|
||||
|
||||
public static final class ReplyProducerCleaner implements DestructionAwareBeanPostProcessor {
|
||||
public static final class ReplyProducerCleaner implements DestructionAwareBeanPostProcessor, AopInfrastructureBean {
|
||||
|
||||
@Override
|
||||
public boolean requiresDestruction(Object bean) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-2023 the original author or authors.
|
||||
* Copyright 2016-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,6 +19,7 @@ package org.springframework.integration.dsl.context;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.aop.framework.AopInfrastructureBean;
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.aop.support.NameMatchMethodPointcutAdvisor;
|
||||
import org.springframework.beans.BeansException;
|
||||
@@ -90,7 +91,7 @@ import org.springframework.util.StringValueResolver;
|
||||
* @since 5.0
|
||||
*/
|
||||
public class IntegrationFlowBeanPostProcessor
|
||||
implements BeanPostProcessor, ApplicationContextAware, SmartInitializingSingleton {
|
||||
implements BeanPostProcessor, ApplicationContextAware, SmartInitializingSingleton, AopInfrastructureBean {
|
||||
|
||||
private ConfigurableApplicationContext applicationContext;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,8 +16,7 @@
|
||||
|
||||
package org.springframework.integration.aop;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.integration.annotation.Publisher;
|
||||
@@ -25,8 +24,8 @@ import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.handler.annotation.Header;
|
||||
import org.springframework.messaging.handler.annotation.Payload;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -37,8 +36,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringJUnitConfig
|
||||
@DirtiesContext
|
||||
public class AnnotationConfigRegistrationTests {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/aop https://www.springframework.org/schema/aop/spring-aop.xsd
|
||||
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd"
|
||||
xmlns:si="http://www.springframework.org/schema/integration">
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
package org.springframework.integration.aop;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.integration.annotation.Publisher;
|
||||
@@ -25,8 +25,8 @@ import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.handler.annotation.Header;
|
||||
import org.springframework.messaging.handler.annotation.Payload;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -37,8 +37,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringJUnitConfig
|
||||
@DirtiesContext
|
||||
public class MessagePublishingAnnotationUsageTests {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,8 +20,8 @@ import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
@@ -49,7 +49,7 @@ public class MessagePublishingInterceptorTests {
|
||||
|
||||
private DefaultListableBeanFactory beanFactory;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
beanFactory = new DefaultListableBeanFactory();
|
||||
channelResolver = new BeanFactoryChannelResolver(beanFactory);
|
||||
|
||||
@@ -31,7 +31,9 @@
|
||||
<property name="headerExpressionMap">
|
||||
<map>
|
||||
<entry key="setName">
|
||||
<map><entry key="foo" value="'bar'"/></map>
|
||||
<map>
|
||||
<entry key="foo" value="'bar'"/>
|
||||
</map>
|
||||
</entry>
|
||||
</map>
|
||||
</property>
|
||||
@@ -42,16 +44,6 @@
|
||||
</property>
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
<property name="channelResolver">
|
||||
<bean
|
||||
class="org.springframework.messaging.core.BeanFactoryMessageChannelDestinationResolver">
|
||||
<!-- <property name="channelMap">-->
|
||||
<!-- <map>-->
|
||||
<!-- <entry key="channel" value-ref="messagePublishingInterceptorUsageTestChannel" />-->
|
||||
<!-- </map>-->
|
||||
<!-- </property>-->
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,14 +16,14 @@
|
||||
|
||||
package org.springframework.integration.aop;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -34,8 +34,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringJUnitConfig
|
||||
@DirtiesContext
|
||||
public class MessagePublishingInterceptorUsageTests {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,7 +22,7 @@ import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
import org.springframework.expression.Expression;
|
||||
@@ -32,6 +32,8 @@ import org.springframework.messaging.handler.annotation.Payload;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
@@ -104,10 +106,11 @@ public class MethodAnnotationPublisherMetadataSourceTests {
|
||||
assertThat(payloadExpression).isEqualTo("#method");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void voidReturnWithInvalidPayloadExpression() {
|
||||
Method method = getMethod("methodWithVoidReturnAndReturnValueAsPayload");
|
||||
source.getExpressionForPayload(method);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> source.getExpressionForPayload(method));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -117,22 +120,25 @@ public class MethodAnnotationPublisherMetadataSourceTests {
|
||||
assertThat(payloadExpression).isEqualTo("#args[0]");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test
|
||||
public void voidReturnAndParameterPayloadAnnotationWithExpression() {
|
||||
Method method = getMethod("methodWithVoidReturnAndParameterPayloadAnnotationWithExpression", String.class);
|
||||
source.getExpressionForPayload(method).getExpressionString();
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> source.getExpressionForPayload(method).getExpressionString());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test
|
||||
public void voidReturnAndParameterPayloadAnnotationWithValue() {
|
||||
Method method = getMethod("methodWithVoidReturnAndParameterPayloadAnnotationWithValue", String.class);
|
||||
source.getExpressionForPayload(method).getExpressionString();
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> source.getExpressionForPayload(method).getExpressionString());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void voidReturnAndNoPayloadAnnotation() {
|
||||
Method method = getMethod("methodWithVoidReturnAndNoPayloadAnnotation", String.class);
|
||||
source.getExpressionForPayload(method);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> source.getExpressionForPayload(method));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,9 +16,9 @@
|
||||
|
||||
package org.springframework.integration.aop;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.context.support.StaticApplicationContext;
|
||||
@@ -36,7 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Gary Russell
|
||||
* @author Artme Bilan
|
||||
* @author Artem Bilan
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
@@ -45,7 +45,7 @@ public class PublisherExpressionTests {
|
||||
private final StaticApplicationContext context = new StaticApplicationContext();
|
||||
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() throws Exception {
|
||||
this.context.registerSingleton("testChannel", QueueChannel.class);
|
||||
IntegrationEvaluationContextFactoryBean factory = new IntegrationEvaluationContextFactoryBean();
|
||||
@@ -57,7 +57,7 @@ public class PublisherExpressionTests {
|
||||
this.context.getBeanFactory().registerSingleton("foo", "foo");
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
this.context.close();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-2023 the original author or authors.
|
||||
* Copyright 2016-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -164,7 +164,7 @@ public class FluxMessageChannelTests {
|
||||
|
||||
Disposable.Composite upstreamSubscriptions =
|
||||
TestUtils.getPropertyValue(messageChannel, "upstreamSubscriptions", Disposable.Composite.class);
|
||||
assertThat(upstreamSubscriptions.size()).isEqualTo(0);
|
||||
await().untilAsserted(() -> assertThat(upstreamSubscriptions.size()).isEqualTo(0));
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
Reference in New Issue
Block a user