Skip to content

Commit

Permalink
Close TaskScheduler in tests
Browse files Browse the repository at this point in the history
* Add `@DirtiesContext` to some tests where `TaskScheduler` is used
  • Loading branch information
artembilan committed Jan 30, 2024
1 parent 62fd3e6 commit 0ba60bc
Show file tree
Hide file tree
Showing 15 changed files with 153 additions and 194 deletions.
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 Down Expand Up @@ -363,6 +363,8 @@ public void testTimeoutDefaultExpiry() {
this.resequencer.handleMessage(message1);
Message<?> out3 = discardChannel.receive(0);
assertThat(out3).isNotNull();

taskScheduler.destroy();
}

@Test
Expand Down Expand Up @@ -393,6 +395,8 @@ public void testTimeoutDontExpire() {
assertThat(out3).isNull();
out3 = discardChannel.receive(10_000);
assertThat(out3).isNotNull();

taskScheduler.destroy();
}

private static Message<?> createMessage(String payload, Object correlationId, int sequenceSize, int sequenceNumber,
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 Down Expand Up @@ -51,6 +51,7 @@
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.PollableChannel;
import org.springframework.messaging.SubscribableChannel;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -66,6 +67,7 @@
* @author Gary Russell
*/
@SpringJUnitConfig
@DirtiesContext
public class AggregatorParserTests {

@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 Down Expand Up @@ -263,6 +263,8 @@ public void testZeroForMaxMessagesPerPoll() throws InterruptedException {
assertThat(receive).isNotNull();
assertThat(receive.getPayload()).isEqualTo("test");
pollingChannelAdapter.stop();

taskScheduler.destroy();
}


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,7 +16,7 @@

package org.springframework.integration.config.xml;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.context.support.ClassPathXmlApplicationContext;
Expand All @@ -28,6 +28,7 @@

/**
* @author Mark Fisher
* @author Artem Bilan
*/
public class DefaultConfiguringBeanFactoryPostProcessorHierarchyTests {

Expand All @@ -47,6 +48,9 @@ public void verifySinglePostProcessor() {
.isSameAs(parent.getBean(IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME));
assertThat(child.getBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME))
.isSameAs(parent.getBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME));

child.close();
parent.close();
}

}
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,8 +16,8 @@

package org.springframework.integration.config.xml;

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.context.ApplicationContext;
Expand All @@ -30,8 +30,8 @@
import org.springframework.messaging.MessageChannel;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
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 org.springframework.util.ErrorHandler;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -40,9 +40,10 @@
* @author Mark Fisher
* @author Oleg Zhurakousky
* @author Gary Russell
* @author Artem Bilan
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@SpringJUnitConfig
@DirtiesContext
public class DefaultConfiguringBeanFactoryPostProcessorTests {

@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 Down Expand Up @@ -32,6 +32,7 @@
import org.springframework.integration.test.util.TestUtils;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHandler;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.interceptor.MatchAlwaysTransactionAttributeSource;
Expand All @@ -50,6 +51,7 @@
* @since 1.0.3
*/
@SpringJUnitConfig
@DirtiesContext
public class DelayerParserTests {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2022 the original author or authors.
* Copyright 2013-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 @@ -23,6 +23,7 @@
import org.springframework.integration.endpoint.AbstractEndpoint;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -33,6 +34,7 @@
* @since 3.0
*/
@SpringJUnitConfig
@DirtiesContext
public class IntegrationContextTests {

@Autowired
Expand Down
Loading

0 comments on commit 0ba60bc

Please sign in to comment.