Fix phase for TaskScheduler instances in tests

Related to: #8856

Many tests create their own `ThreadPoolTaskScheduler` beans.
Therefore, its default phase might affect the memory and performance.

* Use `phase = SmartLifecycle.DEFAULT_PHASE / 2` for manual
 `ThreadPoolTaskScheduler` beans
* Migrate affected tests classes to JUnit 5
* Make some other configuration adjustments for better performance

**Cherry-pick to `6.2.x`**
This commit is contained in:
Artem Bilan
2024-01-16 11:25:54 -05:00
parent ed9616a466
commit 39c99c0719
25 changed files with 249 additions and 205 deletions

View File

@@ -399,7 +399,7 @@
client-mode="true"
retry-interval="123000"
auto-startup="false"
scheduler="sched" />
scheduler="scheduler" />
<ip:tcp-connection-factory id="cfC4"
type="client"
@@ -414,7 +414,7 @@
connection-factory="cfC4"
client-mode="true"
retry-interval="124000"
scheduler="sched"
scheduler="scheduler"
auto-startup="false" />
<ip:tcp-connection-factory id="cfC5"
@@ -432,11 +432,14 @@
reply-timeout="456"
client-mode="true"
retry-interval="125000"
scheduler="sched"
scheduler="scheduler"
auto-startup="false"
/>
<task:scheduler id="sched"/>
<bean id="scheduler"
class="org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler">
<property name="phase" value="1073741823"/>
</bean>
<ip:tcp-inbound-channel-adapter id="tcpAutoChannel" />

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 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.
@@ -236,7 +236,7 @@ public class ParserUnitTests {
TcpInboundGateway inGatewayClientMode;
@Autowired
TaskScheduler sched;
TaskScheduler scheduler;
@Autowired
@Qualifier("tcpOutClientMode.handler")
@@ -624,7 +624,7 @@ public class ParserUnitTests {
assertThat(dfa.getPropertyValue("clientConnectionFactory")).isSameAs(cfC3);
assertThat(dfa.getPropertyValue("serverConnectionFactory")).isNull();
assertThat(dfa.getPropertyValue("isClientMode")).isEqualTo(Boolean.TRUE);
assertThat(dfa.getPropertyValue("taskScheduler")).isSameAs(sched);
assertThat(dfa.getPropertyValue("taskScheduler")).isSameAs(scheduler);
assertThat(dfa.getPropertyValue("retryInterval")).isEqualTo(123000L);
}
@@ -634,7 +634,7 @@ public class ParserUnitTests {
assertThat(dfa.getPropertyValue("clientConnectionFactory")).isSameAs(cfC4);
assertThat(dfa.getPropertyValue("serverConnectionFactory")).isNull();
assertThat(dfa.getPropertyValue("isClientMode")).isEqualTo(Boolean.TRUE);
assertThat(dfa.getPropertyValue("taskScheduler")).isSameAs(sched);
assertThat(dfa.getPropertyValue("taskScheduler")).isSameAs(scheduler);
assertThat(dfa.getPropertyValue("retryInterval")).isEqualTo(124000L);
}
@@ -644,7 +644,7 @@ public class ParserUnitTests {
assertThat(dfa.getPropertyValue("clientConnectionFactory")).isSameAs(cfC5);
assertThat(dfa.getPropertyValue("serverConnectionFactory")).isNull();
assertThat(dfa.getPropertyValue("isClientMode")).isEqualTo(Boolean.TRUE);
assertThat(dfa.getPropertyValue("taskScheduler")).isSameAs(sched);
assertThat(dfa.getPropertyValue("taskScheduler")).isSameAs(scheduler);
assertThat(dfa.getPropertyValue("retryInterval")).isEqualTo(125000L);
}

View File

@@ -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.
@@ -193,6 +193,7 @@ public class TcpInboundGatewayTests {
assertThat(done.get()).isTrue();
gateway.stop();
executorService.shutdown();
taskScheduler.destroy();
}
@Test

View File

@@ -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.
@@ -35,7 +35,7 @@ import java.util.concurrent.atomic.AtomicReference;
import javax.net.ServerSocketFactory;
import javax.net.SocketFactory;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.core.serializer.DefaultDeserializer;
@@ -150,6 +150,7 @@ public class TcpReceivingChannelAdapterTests extends AbstractTcpChannelAdapterTe
latch2.countDown();
ccf.stop();
serverSocket.get().close();
taskScheduler.destroy();
}
@Test

View File

@@ -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.
@@ -39,7 +39,7 @@ import javax.net.SocketFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.beans.factory.BeanFactory;
@@ -217,11 +217,12 @@ public class TcpSendingMessageHandlerTests extends AbstractTcpChannelAdapterTest
adapter.stop();
ccf.stop();
serverSocket.get().close();
taskScheduler.destroy();
}
@Test
public void testNioCrLf() throws Exception {
final AtomicReference<ServerSocket> serverSocket = new AtomicReference<ServerSocket>();
final AtomicReference<ServerSocket> serverSocket = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
final AtomicBoolean done = new AtomicBoolean();
this.executor.execute(() -> {

View File

@@ -21,6 +21,7 @@
<beans:bean id="taskScheduler" class="org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler">
<beans:property name="daemon" value="true" />
<beans:property name="phase" value="1073741823" />
</beans:bean>
</beans:beans>