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

@@ -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.
@@ -543,6 +543,7 @@ public class FileWritingMessageHandlerTests {
}
assertThat(flushes.get()).isGreaterThanOrEqualTo(2);
handler.stop();
taskScheduler.destroy();
}
@Test
@@ -586,6 +587,7 @@ public class FileWritingMessageHandlerTests {
verify(out).write(any(byte[].class), anyInt(), anyInt());
assertThat(closeWhileWriting.get()).isFalse();
handler.stop();
taskScheduler.destroy();
}
@Test

View File

@@ -1,14 +1,13 @@
<?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:int-file="http://www.springframework.org/schema/integration/file"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int-file="http://www.springframework.org/schema/integration/file"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/file https://www.springframework.org/schema/integration/file/spring-integration-file.xsd
http://www.springframework.org/schema/task https://www.springframework.org/schema/task/spring-task.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
@@ -16,37 +15,37 @@
<int:channel id="tailErrorChannel"/>
<int-file:tail-inbound-channel-adapter id="default"
channel="input"
task-executor="exec"
file="/tmp/baz"
auto-startup="true"
phase="123"
error-channel="tailErrorChannel"/>
channel="input"
task-executor="exec"
file="/tmp/baz"
auto-startup="true"
phase="123"
error-channel="tailErrorChannel"/>
<int-file:tail-inbound-channel-adapter id="native"
channel="input"
native-options="-F -n 6"
task-executor="exec"
task-scheduler="sched"
enable-status-reader="false"
file-delay="456"
file="/tmp/foo"
auto-startup="true"
delay="${empty}"
end="${empty}"
reopen="${empty}"
phase="123" />
channel="input"
native-options="-F -n 6"
task-executor="exec"
task-scheduler="scheduler"
enable-status-reader="false"
file-delay="456"
file="/tmp/foo"
auto-startup="true"
delay="${empty}"
end="${empty}"
reopen="${empty}"
phase="123"/>
<int-file:tail-inbound-channel-adapter id="apacheDefault"
channel="input"
native-options="${empty}"
task-executor="exec"
file="/tmp/bar"
delay="${foo}"
file-delay="10000"
idle-event-interval="10000"
auto-startup="false"
phase="123" />
channel="input"
native-options="${empty}"
task-executor="exec"
file="/tmp/bar"
delay="${foo}"
file-delay="10000"
idle-event-interval="10000"
auto-startup="false"
phase="123"/>
<context:property-placeholder properties-ref="props"/>
@@ -56,20 +55,23 @@
</util:properties>
<int-file:tail-inbound-channel-adapter id="apacheEndReopen"
channel="input"
task-executor="exec"
file="/tmp/qux"
delay="2000"
file-delay="10000"
end="false"
reopen="true"
auto-startup="false"
phase="123" />
channel="input"
task-executor="exec"
file="/tmp/qux"
delay="2000"
file-delay="10000"
end="false"
reopen="true"
auto-startup="false"
phase="123"/>
<int:channel id="input" />
<int:channel id="input"/>
<task:scheduler id="sched" />
<bean id="scheduler"
class="org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler">
<property name="phase" value="1073741823"/>
</bean>
<bean class="org.springframework.integration.file.config.FileTailInboundChannelAdapterParserTests$Config" />
<bean class="org.springframework.integration.file.config.FileTailInboundChannelAdapterParserTests$Config"/>
</beans>

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.
@@ -66,7 +66,7 @@ public class FileTailInboundChannelAdapterParserTests {
private TaskExecutor exec;
@Autowired
private TaskScheduler sched;
private TaskScheduler scheduler;
@Autowired
private MessageChannel tailErrorChannel;
@@ -95,7 +95,7 @@ public class FileTailInboundChannelAdapterParserTests {
assertThat(normalizedName).isEqualTo("/tmp/foo");
assertThat(TestUtils.getPropertyValue(nativeAdapter, "command")).isEqualTo("tail -F -n 6 " + fileName);
assertThat(TestUtils.getPropertyValue(nativeAdapter, "taskExecutor")).isSameAs(exec);
assertThat(TestUtils.getPropertyValue(nativeAdapter, "taskScheduler")).isSameAs(sched);
assertThat(TestUtils.getPropertyValue(nativeAdapter, "taskScheduler")).isSameAs(scheduler);
assertThat(TestUtils.getPropertyValue(nativeAdapter, "autoStartup", Boolean.class)).isTrue();
assertThat(TestUtils.getPropertyValue(nativeAdapter, "enableStatusReader", Boolean.class)).isFalse();
assertThat(TestUtils.getPropertyValue(nativeAdapter, "phase")).isEqualTo(123);

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.
@@ -144,8 +144,7 @@ public class FileTailingMessageProducerTests {
if (event instanceof FileTailingIdleEvent) {
idleCountDownLatch.countDown();
}
if (event instanceof FileTailingEvent) {
FileTailingEvent fileTailingEvent = (FileTailingEvent) event;
if (event instanceof FileTailingEvent fileTailingEvent) {
if (fileTailingEvent.getMessage().contains("File not found")) {
fileExistCountDownLatch.countDown();
}
@@ -184,6 +183,7 @@ public class FileTailingMessageProducerTests {
assertThat(eventRaised).as("idle event did not emit").isTrue();
adapter.stop();
file.delete();
taskScheduler.destroy();
}
private void testGuts(FileTailingMessageProducerSupport adapter, String field) throws Exception {