Skip to content

Commit 0ba60bc

Browse files
committed
Close TaskScheduler in tests
* Add `@DirtiesContext` to some tests where `TaskScheduler` is used
1 parent 62fd3e6 commit 0ba60bc

File tree

15 files changed

+153
-194
lines changed

15 files changed

+153
-194
lines changed

spring-integration-core/src/test/java/org/springframework/integration/aggregator/ResequencerTests.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -363,6 +363,8 @@ public void testTimeoutDefaultExpiry() {
363363
this.resequencer.handleMessage(message1);
364364
Message<?> out3 = discardChannel.receive(0);
365365
assertThat(out3).isNotNull();
366+
367+
taskScheduler.destroy();
366368
}
367369

368370
@Test
@@ -393,6 +395,8 @@ public void testTimeoutDontExpire() {
393395
assertThat(out3).isNull();
394396
out3 = discardChannel.receive(10_000);
395397
assertThat(out3).isNotNull();
398+
399+
taskScheduler.destroy();
396400
}
397401

398402
private static Message<?> createMessage(String payload, Object correlationId, int sequenceSize, int sequenceNumber,

spring-integration-core/src/test/java/org/springframework/integration/config/AggregatorParserTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -51,6 +51,7 @@
5151
import org.springframework.messaging.MessageChannel;
5252
import org.springframework.messaging.PollableChannel;
5353
import org.springframework.messaging.SubscribableChannel;
54+
import org.springframework.test.annotation.DirtiesContext;
5455
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
5556

5657
import static org.assertj.core.api.Assertions.assertThat;
@@ -66,6 +67,7 @@
6667
* @author Gary Russell
6768
*/
6869
@SpringJUnitConfig
70+
@DirtiesContext
6971
public class AggregatorParserTests {
7072

7173
@Autowired

spring-integration-core/src/test/java/org/springframework/integration/config/SourcePollingChannelAdapterFactoryBeanTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -263,6 +263,8 @@ public void testZeroForMaxMessagesPerPoll() throws InterruptedException {
263263
assertThat(receive).isNotNull();
264264
assertThat(receive.getPayload()).isEqualTo("test");
265265
pollingChannelAdapter.stop();
266+
267+
taskScheduler.destroy();
266268
}
267269

268270

spring-integration-core/src/test/java/org/springframework/integration/config/xml/DefaultConfiguringBeanFactoryPostProcessorHierarchyTests.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@
1616

1717
package org.springframework.integration.config.xml;
1818

19-
import org.junit.Test;
19+
import org.junit.jupiter.api.Test;
2020

2121
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
2222
import org.springframework.context.support.ClassPathXmlApplicationContext;
@@ -28,6 +28,7 @@
2828

2929
/**
3030
* @author Mark Fisher
31+
* @author Artem Bilan
3132
*/
3233
public class DefaultConfiguringBeanFactoryPostProcessorHierarchyTests {
3334

@@ -47,6 +48,9 @@ public void verifySinglePostProcessor() {
4748
.isSameAs(parent.getBean(IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME));
4849
assertThat(child.getBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME))
4950
.isSameAs(parent.getBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME));
51+
52+
child.close();
53+
parent.close();
5054
}
5155

5256
}

spring-integration-core/src/test/java/org/springframework/integration/config/xml/DefaultConfiguringBeanFactoryPostProcessorTests.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,8 +16,8 @@
1616

1717
package org.springframework.integration.config.xml;
1818

19-
import org.junit.Test;
20-
import org.junit.runner.RunWith;
19+
20+
import org.junit.jupiter.api.Test;
2121

2222
import org.springframework.beans.factory.annotation.Autowired;
2323
import org.springframework.context.ApplicationContext;
@@ -30,8 +30,8 @@
3030
import org.springframework.messaging.MessageChannel;
3131
import org.springframework.scheduling.TaskScheduler;
3232
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
33-
import org.springframework.test.context.ContextConfiguration;
34-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
33+
import org.springframework.test.annotation.DirtiesContext;
34+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
3535
import org.springframework.util.ErrorHandler;
3636

3737
import static org.assertj.core.api.Assertions.assertThat;
@@ -40,9 +40,10 @@
4040
* @author Mark Fisher
4141
* @author Oleg Zhurakousky
4242
* @author Gary Russell
43+
* @author Artem Bilan
4344
*/
44-
@RunWith(SpringJUnit4ClassRunner.class)
45-
@ContextConfiguration
45+
@SpringJUnitConfig
46+
@DirtiesContext
4647
public class DefaultConfiguringBeanFactoryPostProcessorTests {
4748

4849
@Autowired

spring-integration-core/src/test/java/org/springframework/integration/config/xml/DelayerParserTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -32,6 +32,7 @@
3232
import org.springframework.integration.test.util.TestUtils;
3333
import org.springframework.messaging.Message;
3434
import org.springframework.messaging.MessageHandler;
35+
import org.springframework.test.annotation.DirtiesContext;
3536
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
3637
import org.springframework.transaction.TransactionDefinition;
3738
import org.springframework.transaction.interceptor.MatchAlwaysTransactionAttributeSource;
@@ -50,6 +51,7 @@
5051
* @since 1.0.3
5152
*/
5253
@SpringJUnitConfig
54+
@DirtiesContext
5355
public class DelayerParserTests {
5456

5557
@Autowired

spring-integration-core/src/test/java/org/springframework/integration/context/IntegrationContextTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2022 the original author or authors.
2+
* Copyright 2013-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@
2323
import org.springframework.integration.endpoint.AbstractEndpoint;
2424
import org.springframework.integration.test.util.TestUtils;
2525
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
26+
import org.springframework.test.annotation.DirtiesContext;
2627
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
2728

2829
import static org.assertj.core.api.Assertions.assertThat;
@@ -33,6 +34,7 @@
3334
* @since 3.0
3435
*/
3536
@SpringJUnitConfig
37+
@DirtiesContext
3638
public class IntegrationContextTests {
3739

3840
@Autowired

0 commit comments

Comments
 (0)