From 1a3c25b01988ab17f73800ed043f59af05a14fd9 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Tue, 16 Jan 2024 11:25:54 -0500 Subject: [PATCH] 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`** (cherry picked from commit 39c99c07197c0d6ec767944b1f0a346d1b91d92d) --- .../config/AggregatorParserTests-context.xml | 127 +++++++++--------- .../config/xml/DelayerParserTests-context.xml | 1 + .../config/xml/DelayerUsageTests-context.xml | 1 + .../config/xml/GatewayParserTests-context.xml | 8 +- .../config/xml/GatewayParserTests.java | 6 +- .../xml/superParentApplicationContext.xml | 4 +- .../dsl/flows/IntegrationFlowTests.java | 8 +- ...aluatingMessageSourceIntegrationTests.java | 3 +- .../store/MessageStoreReaperTests-context.xml | 25 ++-- .../file/FileWritingMessageHandlerTests.java | 4 +- ...boundChannelAdapterParserTests-context.xml | 96 ++++++------- ...eTailInboundChannelAdapterParserTests.java | 6 +- .../tail/FileTailingMessageProducerTests.java | 6 +- ...oovyControlBusIntegrationTests-context.xml | 5 +- .../ip/config/ParserTests-context.xml | 11 +- .../ip/config/ParserUnitTests.java | 10 +- .../ip/tcp/TcpInboundGatewayTests.java | 3 +- .../tcp/TcpReceivingChannelAdapterTests.java | 5 +- .../ip/tcp/TcpSendingMessageHandlerTests.java | 7 +- .../ip/udp/testIp-common-context.xml | 1 + .../jms/JmsOutboundGatewayTests.java | 3 +- .../integration/monitor/lifecycle-source.xml | 50 +++---- .../monitor/self-destruction-context.xml | 5 +- .../client/StompServerIntegrationTests.java | 6 +- .../integration/test/util/TestUtils.java | 47 ++++--- 25 files changed, 246 insertions(+), 202 deletions(-) diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/AggregatorParserTests-context.xml b/spring-integration-core/src/test/java/org/springframework/integration/config/AggregatorParserTests-context.xml index 6ed6b5c754c..15a048a1275 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/AggregatorParserTests-context.xml +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/AggregatorParserTests-context.xml @@ -1,19 +1,17 @@ - + @@ -40,96 +38,99 @@ - + input-channel="completelyDefinedAggregatorInput" + output-channel="outputChannel" + discard-channel="discardChannel" + ref="aggregatorBean" + release-strategy="releaseStrategy" + correlation-strategy="correlationStrategy" + send-timeout="86420000" + send-partial-result-on-expiry="true" + expire-groups-upon-completion="true" + expire-groups-upon-timeout="false" + empty-group-min-timeout="123" + group-timeout="456" + lock-registry="lockRegistry" + scheduler="scheduler" + message-store="store" + pop-sequence="false" + order="5" + expire-duration="10000" + expire-timeout="250"> + - + + + + input-channel="aggregatorWithExpressionsInput" + output-channel="aggregatorWithExpressionsOutput" + expression="?[payload.startsWith('1')].![payload]" + release-strategy-expression="#root.size()>2" + correlation-strategy-expression="headers['foo']"/> + ref="adderBean" + method="add" + input-channel="aggregatorWithReferenceAndMethodInput" + output-channel="outputChannel"/> + input-channel="aggregatorWithPojoReleaseStrategyInput" + output-channel="outputChannel" + ref="adderBean" + method="add" + release-strategy="pojoReleaseStrategy" + release-strategy-method="checkCompletenessAsList"/> + input-channel="aggregatorWithPojoReleaseStrategyInputAsCollection" + output-channel="outputChannel" + ref="adderBean" + method="add" + release-strategy="pojoReleaseStrategy" + release-strategy-method="checkCompletenessAsCollection"/> + input-channel="aggregatorWithExpressionsAndPojoAggregatorInput" + ref="aggregatorBean" + release-strategy-expression="size() == 2" + correlation-strategy-expression="headers['foo']" + empty-group-min-timeout="60000"/> + class="org.springframework.integration.config.TestAggregatorBean"/> + class="org.springframework.integration.aggregator.SimpleMessageGroupProcessor"/> + class="org.springframework.integration.config.AggregatorParserTests$MyMGP"/> - + + class="org.springframework.integration.config.TestReleaseStrategy"/> - + class="org.springframework.integration.config.MaxValueReleaseStrategy"> + diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/DelayerParserTests-context.xml b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/DelayerParserTests-context.xml index a6cf20ac4af..3bad3c9e88b 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/DelayerParserTests-context.xml +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/DelayerParserTests-context.xml @@ -75,6 +75,7 @@ diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/DelayerUsageTests-context.xml b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/DelayerUsageTests-context.xml index f91966bafdb..6702c4d75a4 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/DelayerUsageTests-context.xml +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/DelayerUsageTests-context.xml @@ -49,6 +49,7 @@ diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/GatewayParserTests-context.xml b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/GatewayParserTests-context.xml index 946938031e7..636ed22f952 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/GatewayParserTests-context.xml +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/GatewayParserTests-context.xml @@ -24,10 +24,14 @@ default-request-channel="requestChannel" proxy-default-methods="true"/> + + + + + default-reply-channel="receiveChannel" + default-reply-timeout="5000"/> ("foo")); TestService service = (TestService) context.getBean("solicitResponse"); String result = service.solicitResponse(); diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/superParentApplicationContext.xml b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/superParentApplicationContext.xml index 9bbe4122381..8126b804c47 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/superParentApplicationContext.xml +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/superParentApplicationContext.xml @@ -7,6 +7,8 @@ https://www.springframework.org/schema/integration/spring-integration.xsd"> + class="org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler"> + + diff --git a/spring-integration-core/src/test/java/org/springframework/integration/dsl/flows/IntegrationFlowTests.java b/spring-integration-core/src/test/java/org/springframework/integration/dsl/flows/IntegrationFlowTests.java index 384c82ce5c0..a86b1011508 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/dsl/flows/IntegrationFlowTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/dsl/flows/IntegrationFlowTests.java @@ -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. @@ -41,6 +41,7 @@ import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.Lifecycle; +import org.springframework.context.SmartLifecycle; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; @@ -586,6 +587,7 @@ public PollerSpec poller() { @Bean(name = IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME) public TaskScheduler taskScheduler() { ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler(); + threadPoolTaskScheduler.setPhase(SmartLifecycle.DEFAULT_PHASE / 2); threadPoolTaskScheduler.setPoolSize(100); return threadPoolTaskScheduler; } @@ -925,7 +927,9 @@ public IntegrationFlow dedicatedPollingThreadFlow() { @Bean public TaskScheduler dedicatedTaskScheduler() { - return new ThreadPoolTaskScheduler(); + ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler(); + threadPoolTaskScheduler.setPhase(SmartLifecycle.DEFAULT_PHASE / 2); + return threadPoolTaskScheduler; } @Bean diff --git a/spring-integration-core/src/test/java/org/springframework/integration/endpoint/ExpressionEvaluatingMessageSourceIntegrationTests.java b/spring-integration-core/src/test/java/org/springframework/integration/endpoint/ExpressionEvaluatingMessageSourceIntegrationTests.java index 35f5d4c5fc7..d6806fd1c4a 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/endpoint/ExpressionEvaluatingMessageSourceIntegrationTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/endpoint/ExpressionEvaluatingMessageSourceIntegrationTests.java @@ -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. @@ -80,6 +80,7 @@ public void test() throws Exception { for (int i = 0; i < 3; i++) { messages.add(channel.receive(1000)); } + adapter.stop(); scheduler.destroy(); Message message1 = messages.get(0); assertThat(message1.getPayload()).isEqualTo("test-1"); diff --git a/spring-integration-core/src/test/java/org/springframework/integration/store/MessageStoreReaperTests-context.xml b/spring-integration-core/src/test/java/org/springframework/integration/store/MessageStoreReaperTests-context.xml index 4ca53e86c02..593993de63e 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/store/MessageStoreReaperTests-context.xml +++ b/spring-integration-core/src/test/java/org/springframework/integration/store/MessageStoreReaperTests-context.xml @@ -1,9 +1,9 @@ @@ -23,7 +23,10 @@ - + + + @@ -35,21 +38,21 @@ - + - + + discard-channel="discards" + message-store="messageStore3"/> - + - + diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/FileWritingMessageHandlerTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/FileWritingMessageHandlerTests.java index 3e7d3762252..db825fb94a2 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/FileWritingMessageHandlerTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/FileWritingMessageHandlerTests.java @@ -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 void noFlushAppend() throws Exception { } assertThat(flushes.get()).isGreaterThanOrEqualTo(2); handler.stop(); + taskScheduler.destroy(); } @Test @@ -586,6 +587,7 @@ protected BufferedOutputStream createOutputStream(File fileToWriteTo, boolean ap verify(out).write(any(byte[].class), anyInt(), anyInt()); assertThat(closeWhileWriting.get()).isFalse(); handler.stop(); + taskScheduler.destroy(); } @Test diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileTailInboundChannelAdapterParserTests-context.xml b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileTailInboundChannelAdapterParserTests-context.xml index 631a000eccf..6eb052a52da 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileTailInboundChannelAdapterParserTests-context.xml +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileTailInboundChannelAdapterParserTests-context.xml @@ -1,14 +1,13 @@ @@ -16,37 +15,37 @@ + channel="input" + task-executor="exec" + file="/tmp/baz" + auto-startup="true" + phase="123" + error-channel="tailErrorChannel"/> + 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"/> + 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"/> @@ -56,20 +55,23 @@ + channel="input" + task-executor="exec" + file="/tmp/qux" + delay="2000" + file-delay="10000" + end="false" + reopen="true" + auto-startup="false" + phase="123"/> - + - + + + - + diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileTailInboundChannelAdapterParserTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileTailInboundChannelAdapterParserTests.java index b2da04b9406..e942de017a8 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileTailInboundChannelAdapterParserTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileTailInboundChannelAdapterParserTests.java @@ -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 void testNative() { 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); diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/tail/FileTailingMessageProducerTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/tail/FileTailingMessageProducerTests.java index d33ce7e928c..fd031a8bd21 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/tail/FileTailingMessageProducerTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/tail/FileTailingMessageProducerTests.java @@ -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 void testIdleEvent() throws Exception { 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 boolean exists() { assertThat(eventRaised).as("idle event did not emit").isTrue(); adapter.stop(); file.delete(); + taskScheduler.destroy(); } private void testGuts(FileTailingMessageProducerSupport adapter, String field) throws Exception { diff --git a/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/GroovyControlBusIntegrationTests-context.xml b/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/GroovyControlBusIntegrationTests-context.xml index 66ff2b4cc40..e920798e7f8 100644 --- a/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/GroovyControlBusIntegrationTests-context.xml +++ b/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/GroovyControlBusIntegrationTests-context.xml @@ -19,7 +19,10 @@ - + + + + scheduler="scheduler" /> - + + + diff --git a/spring-integration-ip/src/test/java/org/springframework/integration/ip/config/ParserUnitTests.java b/spring-integration-ip/src/test/java/org/springframework/integration/ip/config/ParserUnitTests.java index 8f106d27bc6..b4ec8243012 100644 --- a/spring-integration-ip/src/test/java/org/springframework/integration/ip/config/ParserUnitTests.java +++ b/spring-integration-ip/src/test/java/org/springframework/integration/ip/config/ParserUnitTests.java @@ -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 void testInClientMode() { 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 void testOutClientMode() { 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 void testInGatewayClientMode() { 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); } diff --git a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/TcpInboundGatewayTests.java b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/TcpInboundGatewayTests.java index 0b25cc4cdd7..d242830720e 100644 --- a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/TcpInboundGatewayTests.java +++ b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/TcpInboundGatewayTests.java @@ -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 void testNetClientMode() throws Exception { assertThat(done.get()).isTrue(); gateway.stop(); executorService.shutdown(); + taskScheduler.destroy(); } @Test diff --git a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/TcpReceivingChannelAdapterTests.java b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/TcpReceivingChannelAdapterTests.java index 106fe3774a4..6dd33f0f876 100644 --- a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/TcpReceivingChannelAdapterTests.java +++ b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/TcpReceivingChannelAdapterTests.java @@ -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 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 void testNetClientMode() throws Exception { latch2.countDown(); ccf.stop(); serverSocket.get().close(); + taskScheduler.destroy(); } @Test diff --git a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/TcpSendingMessageHandlerTests.java b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/TcpSendingMessageHandlerTests.java index c553b7204c6..92f18072f37 100644 --- a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/TcpSendingMessageHandlerTests.java +++ b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/TcpSendingMessageHandlerTests.java @@ -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 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 void testNetCrLfClientMode() throws Exception { adapter.stop(); ccf.stop(); serverSocket.get().close(); + taskScheduler.destroy(); } @Test public void testNioCrLf() throws Exception { - final AtomicReference serverSocket = new AtomicReference(); + final AtomicReference serverSocket = new AtomicReference<>(); final CountDownLatch latch = new CountDownLatch(1); final AtomicBoolean done = new AtomicBoolean(); this.executor.execute(() -> { diff --git a/spring-integration-ip/src/test/java/org/springframework/integration/ip/udp/testIp-common-context.xml b/spring-integration-ip/src/test/java/org/springframework/integration/ip/udp/testIp-common-context.xml index 1fd1828d31a..e7d3740517c 100644 --- a/spring-integration-ip/src/test/java/org/springframework/integration/ip/udp/testIp-common-context.xml +++ b/spring-integration-ip/src/test/java/org/springframework/integration/ip/udp/testIp-common-context.xml @@ -21,6 +21,7 @@ + diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/JmsOutboundGatewayTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/JmsOutboundGatewayTests.java index 2760f471058..b5c01190007 100644 --- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/JmsOutboundGatewayTests.java +++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/JmsOutboundGatewayTests.java @@ -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. @@ -149,6 +149,7 @@ public void testReplyContainerRecovery() throws Exception { finally { gateway.stop(); exec.shutdownNow(); + taskScheduler.destroy(); } } diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/lifecycle-source.xml b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/lifecycle-source.xml index f3e5f614445..5883f8564e3 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/lifecycle-source.xml +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/lifecycle-source.xml @@ -1,52 +1,56 @@ + http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd"> - + - + - + - + - + - + - + - + - + + + - + - + - - + + - - + + - + diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/self-destruction-context.xml b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/self-destruction-context.xml index e2fd9b34693..cbbfcef7999 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/self-destruction-context.xml +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/self-destruction-context.xml @@ -25,7 +25,10 @@ - + + + diff --git a/spring-integration-stomp/src/test/java/org/springframework/integration/stomp/client/StompServerIntegrationTests.java b/spring-integration-stomp/src/test/java/org/springframework/integration/stomp/client/StompServerIntegrationTests.java index 7e09afec50c..adc3ad0d607 100644 --- a/spring-integration-stomp/src/test/java/org/springframework/integration/stomp/client/StompServerIntegrationTests.java +++ b/spring-integration-stomp/src/test/java/org/springframework/integration/stomp/client/StompServerIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-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. @@ -69,6 +69,8 @@ public class StompServerIntegrationTests { private static final EmbeddedActiveMQ broker = new EmbeddedActiveMQ(); + private static final ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler(); + private static ReactorNettyTcpStompClient stompClient; @BeforeAll @@ -89,7 +91,6 @@ public static void setup() throws Exception { stompClient = new ReactorNettyTcpStompClient("127.0.0.1", TransportConstants.DEFAULT_STOMP_PORT); stompClient.setMessageConverter(new PassThruMessageConverter()); - ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler(); taskScheduler.afterPropertiesSet(); stompClient.setTaskScheduler(taskScheduler); stompClient.setReceiptTimeLimit(5000); @@ -99,6 +100,7 @@ public static void setup() throws Exception { public static void teardown() throws Exception { stompClient.shutdown(); broker.stop(); + taskScheduler.destroy(); } @Test diff --git a/spring-integration-test-support/src/main/java/org/springframework/integration/test/util/TestUtils.java b/spring-integration-test-support/src/main/java/org/springframework/integration/test/util/TestUtils.java index 5e86082e3a0..9a2a09b3c4e 100644 --- a/spring-integration-test-support/src/main/java/org/springframework/integration/test/util/TestUtils.java +++ b/spring-integration-test-support/src/main/java/org/springframework/integration/test/util/TestUtils.java @@ -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. @@ -36,6 +36,7 @@ import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.BeanFactory; +import org.springframework.context.SmartLifecycle; import org.springframework.context.support.GenericApplicationContext; import org.springframework.format.support.DefaultFormattingConversionService; import org.springframework.lang.Nullable; @@ -61,6 +62,27 @@ public abstract class TestUtils { private static final Log LOGGER = LogFactory.getLog(TestUtils.class); + /** + * Obtain a value for the property from the provide object + * and try to cast it to the provided type. + * Supports nested properties via period delimiter. + * @param root the object to obtain the property value + * @param propertyPath the property name to obtain a value. + * @param type the expected value type. + * @param the expected value type. + * Can be nested path defined by the period. + * @return the value of the property or null + * @see DirectFieldAccessor + */ + @SuppressWarnings("unchecked") + public static T getPropertyValue(Object root, String propertyPath, Class type) { + Object value = getPropertyValue(root, propertyPath); + if (value != null) { + Assert.isAssignable(type, value.getClass()); + } + return (T) value; + } + /** * Obtain a value for the property from the provide object. * Supports nested properties via period delimiter. @@ -90,27 +112,6 @@ else if (i == tokens.length - 1) { return value; } - /** - * Obtain a value for the property from the provide object - * and try to cast it to the provided type. - * Supports nested properties via period delimiter. - * @param root the object to obtain the property value - * @param propertyPath the property name to obtain a value. - * @param type the expected value type. - * @param the expected value type. - * Can be nested path defined by the period. - * @return the value of the property or null - * @see DirectFieldAccessor - */ - @SuppressWarnings("unchecked") - public static T getPropertyValue(Object root, String propertyPath, Class type) { - Object value = getPropertyValue(root, propertyPath); - if (value != null) { - Assert.isAssignable(type, value.getClass()); - } - return (T) value; - } - /** * Create a {@link TestApplicationContext} instance * supplied with the basic Spring Integration infrastructure. @@ -140,6 +141,7 @@ public static ThreadPoolTaskScheduler createTaskScheduler(int poolSize) { ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler(); scheduler.setPoolSize(poolSize); scheduler.setRejectedExecutionHandler(new CallerRunsPolicy()); + scheduler.setPhase(SmartLifecycle.DEFAULT_PHASE / 2); scheduler.afterPropertiesSet(); return scheduler; } @@ -216,6 +218,7 @@ private String getComponentNameIfNamed(final MessageChannel channel) { */ public static Properties locateComponentInHistory(List history, String componentName, int startingIndex) { + Assert.notNull(history, "'history' must not be null"); Assert.isTrue(StringUtils.hasText(componentName), "'componentName' must be provided"); Assert.isTrue(startingIndex < history.size(), "'startingIndex' can not be greater then size of history");