Skip to content

Commit

Permalink
Optimize BPPs as AopInfrastructureBean
Browse files Browse the repository at this point in the history
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 a8ed1dd)
  • Loading branch information
artembilan authored and spring-builds committed Feb 9, 2024
1 parent de291d8 commit 9ae23dc
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 65 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -44,7 +45,7 @@
* @see AnnotationGatewayProxyFactoryBean
*/
class GatewayProxyInstantiationPostProcessor implements
InstantiationAwareBeanPostProcessor, BeanRegistrationAotProcessor, ApplicationContextAware {
InstantiationAwareBeanPostProcessor, BeanRegistrationAotProcessor, ApplicationContextAware, AopInfrastructureBean {

private final BeanDefinitionRegistry registry;

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -25,6 +25,7 @@
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;
Expand Down Expand Up @@ -54,7 +55,7 @@
* @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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
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;
Expand Down Expand Up @@ -3047,7 +3048,7 @@ protected static Object extractProxyTarget(@Nullable Object target) {
}
}

public static final class ReplyProducerCleaner implements DestructionAwareBeanPostProcessor {
public static final class ReplyProducerCleaner implements DestructionAwareBeanPostProcessor, AopInfrastructureBean {

@Override
public boolean requiresDestruction(Object bean) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -19,6 +19,7 @@
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;
Expand Down Expand Up @@ -90,7 +91,7 @@
* @since 5.0
*/
public class IntegrationFlowBeanPostProcessor
implements BeanPostProcessor, ApplicationContextAware, SmartInitializingSingleton {
implements BeanPostProcessor, ApplicationContextAware, SmartInitializingSingleton, AopInfrastructureBean {

private ConfigurableApplicationContext applicationContext;

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -16,17 +16,16 @@

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;
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;

Expand All @@ -37,8 +36,8 @@
*
* @since 2.0
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@SpringJUnitConfig
@DirtiesContext
public class AnnotationConfigRegistrationTests {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
@@ -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">

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -16,17 +16,17 @@

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;
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;

Expand All @@ -37,8 +37,8 @@
*
* @since 2.0
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@SpringJUnitConfig
@DirtiesContext
public class MessagePublishingAnnotationUsageTests {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -20,8 +20,8 @@
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;
Expand Down Expand Up @@ -49,7 +49,7 @@ public class MessagePublishingInterceptorTests {

private DefaultListableBeanFactory beanFactory;

@Before
@BeforeEach
public void setup() {
beanFactory = new DefaultListableBeanFactory();
channelResolver = new BeanFactoryChannelResolver(beanFactory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;

Expand All @@ -34,8 +34,8 @@
*
* @since 2.0
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@SpringJUnitConfig
@DirtiesContext
public class MessagePublishingInterceptorUsageTests {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -22,7 +22,7 @@
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;
Expand All @@ -32,6 +32,8 @@
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
Expand Down Expand Up @@ -104,10 +106,11 @@ public void voidReturnWithValidPayloadExpression() {
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
Expand All @@ -117,22 +120,25 @@ public void voidReturnAndParameterPayloadAnnotation() {
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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand All @@ -36,7 +36,7 @@
/**
* @author Mark Fisher
* @author Gary Russell
* @author Artme Bilan
* @author Artem Bilan
*
* @since 2.0
*/
Expand All @@ -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();
Expand All @@ -57,7 +57,7 @@ public void setup() throws Exception {
this.context.getBeanFactory().registerSingleton("foo", "foo");
}

@After
@AfterEach
public void tearDown() {
this.context.close();
}
Expand Down
Loading

0 comments on commit 9ae23dc

Please sign in to comment.