Skip to content

Commit e2aa904

Browse files
committed
More @DirtiesContext for tests in attempt to mitigate OOM error on CI/CD
1 parent 567fb9b commit e2aa904

File tree

36 files changed

+255
-191
lines changed

36 files changed

+255
-191
lines changed

spring-integration-amqp/src/test/java/org/springframework/integration/amqp/support/BoundRabbitChannelAdviceIntegrationTests.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018-2023 the original author or authors.
2+
* Copyright 2018-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.
@@ -36,6 +36,7 @@
3636
import org.springframework.integration.config.EnableIntegration;
3737
import org.springframework.integration.dsl.IntegrationFlow;
3838
import org.springframework.integration.test.util.TestUtils;
39+
import org.springframework.test.annotation.DirtiesContext;
3940
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
4041

4142
import static org.assertj.core.api.Assertions.assertThat;
@@ -52,6 +53,7 @@
5253
*
5354
*/
5455
@SpringJUnitConfig
56+
@DirtiesContext
5557
@RabbitAvailable(queues = BoundRabbitChannelAdviceIntegrationTests.QUEUE)
5658
public class BoundRabbitChannelAdviceIntegrationTests {
5759

spring-integration-event/src/test/java/org/springframework/integration/event/config/EventInboundChannelAdapterParserTests.java

+24-32
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.
@@ -22,7 +22,6 @@
2222

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

25-
import org.springframework.beans.DirectFieldAccessor;
2625
import org.springframework.beans.factory.annotation.Autowired;
2726
import org.springframework.beans.factory.annotation.Qualifier;
2827
import org.springframework.context.ApplicationContext;
@@ -36,7 +35,7 @@
3635
import org.springframework.messaging.Message;
3736
import org.springframework.messaging.MessageChannel;
3837
import org.springframework.messaging.PollableChannel;
39-
import org.springframework.test.context.ContextConfiguration;
38+
import org.springframework.test.annotation.DirtiesContext;
4039
import org.springframework.test.context.TestExecutionListeners;
4140
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
4241
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
@@ -53,7 +52,7 @@
5352
* @since 2.0
5453
*/
5554
@SpringJUnitConfig
56-
@ContextConfiguration
55+
@DirtiesContext
5756
@TestExecutionListeners(DependencyInjectionTestExecutionListener.class)
5857
public class EventInboundChannelAdapterParserTests {
5958

@@ -73,44 +72,38 @@ public class EventInboundChannelAdapterParserTests {
7372
@Test
7473
public void validateEventParser() {
7574
Object adapter = context.getBean("eventAdapterSimple");
76-
assertThat(adapter).isNotNull();
77-
assertThat(adapter instanceof ApplicationEventListeningMessageProducer).isTrue();
78-
DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
79-
assertThat(adapterAccessor.getPropertyValue("outputChannel")).isEqualTo(context.getBean("input"));
80-
assertThat(adapterAccessor.getPropertyValue("errorChannel")).isSameAs(errorChannel);
75+
assertThat(adapter).isInstanceOf(ApplicationEventListeningMessageProducer.class);
76+
assertThat(TestUtils.getPropertyValue(adapter, "outputChannel")).isEqualTo(context.getBean("input"));
77+
assertThat(TestUtils.getPropertyValue(adapter, "errorChannel")).isSameAs(errorChannel);
8178
}
8279

8380
@Test
8481
@SuppressWarnings("unchecked")
8582
public void validateEventParserWithEventTypes() {
8683
Object adapter = context.getBean("eventAdapterFiltered");
87-
assertThat(adapter).isNotNull();
88-
assertThat(adapter instanceof ApplicationEventListeningMessageProducer).isTrue();
89-
DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
90-
assertThat(adapterAccessor.getPropertyValue("outputChannel")).isEqualTo(context.getBean("inputFiltered"));
91-
Set<ResolvableType> eventTypes = (Set<ResolvableType>) adapterAccessor.getPropertyValue("eventTypes");
92-
assertThat(eventTypes).isNotNull();
93-
assertThat(eventTypes.size() == 3).isTrue();
94-
assertThat(eventTypes.contains(ResolvableType.forClass(SampleEvent.class))).isTrue();
95-
assertThat(eventTypes.contains(ResolvableType.forClass(AnotherSampleEvent.class))).isTrue();
96-
assertThat(eventTypes.contains(ResolvableType.forClass(Date.class))).isTrue();
97-
assertThat(adapterAccessor.getPropertyValue("errorChannel")).isNull();
84+
assertThat(adapter).isInstanceOf(ApplicationEventListeningMessageProducer.class);
85+
assertThat(TestUtils.getPropertyValue(adapter, "outputChannel")).isEqualTo(context.getBean("inputFiltered"));
86+
Set<ResolvableType> eventTypes = TestUtils.getPropertyValue(adapter, "eventTypes", Set.class);
87+
assertThat(eventTypes)
88+
.hasSize(3)
89+
.contains(ResolvableType.forClass(SampleEvent.class),
90+
ResolvableType.forClass(AnotherSampleEvent.class),
91+
ResolvableType.forClass(Date.class));
92+
assertThat(TestUtils.getPropertyValue(adapter, "errorChannel")).isNull();
9893
}
9994

10095
@Test
10196
@SuppressWarnings("unchecked")
10297
public void validateEventParserWithEventTypesAndPlaceholder() {
10398
Object adapter = context.getBean("eventAdapterFilteredPlaceHolder");
104-
assertThat(adapter).isNotNull();
105-
assertThat(adapter instanceof ApplicationEventListeningMessageProducer).isTrue();
106-
DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
107-
assertThat(adapterAccessor.getPropertyValue("outputChannel"))
99+
assertThat(adapter).isInstanceOf(ApplicationEventListeningMessageProducer.class);
100+
assertThat(TestUtils.getPropertyValue(adapter, "outputChannel"))
108101
.isEqualTo(context.getBean("inputFilteredPlaceHolder"));
109-
Set<ResolvableType> eventTypes = (Set<ResolvableType>) adapterAccessor.getPropertyValue("eventTypes");
110-
assertThat(eventTypes).isNotNull();
111-
assertThat(eventTypes.size() == 2).isTrue();
112-
assertThat(eventTypes.contains(ResolvableType.forClass(SampleEvent.class))).isTrue();
113-
assertThat(eventTypes.contains(ResolvableType.forClass(AnotherSampleEvent.class))).isTrue();
102+
Set<ResolvableType> eventTypes = TestUtils.getPropertyValue(adapter, "eventTypes", Set.class);
103+
assertThat(eventTypes)
104+
.hasSize(2)
105+
.contains(ResolvableType.forClass(SampleEvent.class), ResolvableType.forClass(AnotherSampleEvent.class));
106+
114107
}
115108

116109
@Test
@@ -132,9 +125,8 @@ public void validateUsageWithHistory() {
132125
public void validatePayloadExpression() {
133126
Object adapter = context.getBean("eventAdapterSpel");
134127
assertThat(adapter).isNotNull();
135-
assertThat(adapter instanceof ApplicationEventListeningMessageProducer).isTrue();
136-
DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
137-
Expression expression = (Expression) adapterAccessor.getPropertyValue("payloadExpression");
128+
assertThat(adapter).isInstanceOf(ApplicationEventListeningMessageProducer.class);
129+
Expression expression = TestUtils.getPropertyValue(adapter, "payloadExpression", Expression.class);
138130
assertThat(expression.getExpressionString()).isEqualTo("source + '-test'");
139131
}
140132

spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyFilterTests.java

+3-1
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.
@@ -38,6 +38,7 @@
3838
import org.springframework.messaging.MessageHandlingException;
3939
import org.springframework.messaging.support.GenericMessage;
4040
import org.springframework.stereotype.Component;
41+
import org.springframework.test.annotation.DirtiesContext;
4142
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
4243

4344
import static org.assertj.core.api.Assertions.assertThat;
@@ -50,6 +51,7 @@
5051
* @since 2.0
5152
*/
5253
@SpringJUnitConfig
54+
@DirtiesContext
5355
public class GroovyFilterTests {
5456

5557
@Autowired

spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyHeaderEnricherTests.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818

1919
import java.util.Map;
2020

21-
import org.junit.Test;
22-
import org.junit.runner.RunWith;
21+
import org.junit.jupiter.api.Test;
2322

2423
import org.springframework.beans.factory.annotation.Autowired;
2524
import org.springframework.integration.channel.QueueChannel;
@@ -29,8 +28,8 @@
2928
import org.springframework.integration.transformer.support.HeaderValueMessageProcessor;
3029
import org.springframework.messaging.MessageChannel;
3130
import org.springframework.messaging.support.GenericMessage;
32-
import org.springframework.test.context.ContextConfiguration;
33-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
31+
import org.springframework.test.annotation.DirtiesContext;
32+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
3433

3534
import static org.assertj.core.api.Assertions.assertThat;
3635

@@ -41,8 +40,8 @@
4140
*
4241
* @since 2.0
4342
*/
44-
@ContextConfiguration
45-
@RunWith(SpringJUnit4ClassRunner.class)
43+
@SpringJUnitConfig
44+
@DirtiesContext
4645
public class GroovyHeaderEnricherTests {
4746

4847
@Autowired

spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyRefreshTests.java

+7-8
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.
@@ -20,16 +20,15 @@
2020
import java.io.ByteArrayInputStream;
2121
import java.io.InputStream;
2222

23-
import org.junit.Test;
24-
import org.junit.runner.RunWith;
23+
import org.junit.jupiter.api.Test;
2524

2625
import org.springframework.beans.factory.annotation.Autowired;
2726
import org.springframework.core.io.AbstractResource;
2827
import org.springframework.integration.channel.QueueChannel;
2928
import org.springframework.integration.support.MessageBuilder;
3029
import org.springframework.messaging.MessageChannel;
31-
import org.springframework.test.context.ContextConfiguration;
32-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
30+
import org.springframework.test.annotation.DirtiesContext;
31+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
3332

3433
import static org.assertj.core.api.Assertions.assertThat;
3534

@@ -39,8 +38,8 @@
3938
*
4039
* @since 2.0
4140
*/
42-
@ContextConfiguration
43-
@RunWith(SpringJUnit4ClassRunner.class)
41+
@SpringJUnitConfig
42+
@DirtiesContext
4443
public class GroovyRefreshTests {
4544

4645
@Autowired
@@ -70,7 +69,7 @@ private static class CycleResource extends AbstractResource {
7069

7170
private int count = -1;
7271

73-
private String[] scripts =
72+
private final String[] scripts =
7473
{"\"groovy-${binding.variables['payload']}-0\"",
7574
"\"groovy-${binding.variables['payload']}-1\""};
7675

spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyRouterTests.java

+8-9
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,7 @@
1616

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

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

2221
import org.springframework.beans.factory.annotation.Autowired;
2322
import org.springframework.beans.factory.annotation.Qualifier;
@@ -30,8 +29,8 @@
3029
import org.springframework.messaging.MessageHandler;
3130
import org.springframework.messaging.PollableChannel;
3231
import org.springframework.messaging.support.GenericMessage;
33-
import org.springframework.test.context.ContextConfiguration;
34-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
32+
import org.springframework.test.annotation.DirtiesContext;
33+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
3534

3635
import static org.assertj.core.api.Assertions.assertThat;
3736

@@ -41,8 +40,8 @@
4140
*
4241
* @since 2.0
4342
*/
44-
@ContextConfiguration
45-
@RunWith(SpringJUnit4ClassRunner.class)
43+
@SpringJUnitConfig
44+
@DirtiesContext
4645
public class GroovyRouterTests {
4746

4847
@Autowired
@@ -105,12 +104,12 @@ public void inlineScript() { // long is > 5
105104

106105
@Test
107106
public void testInt2433VerifyRiddingOfMessageProcessorsWrapping() {
108-
assertThat(this.groovyRouterMessageHandler instanceof MethodInvokingRouter).isTrue();
107+
assertThat(this.groovyRouterMessageHandler).isInstanceOf(MethodInvokingRouter.class);
109108
@SuppressWarnings("rawtypes")
110109
MessageProcessor messageProcessor = TestUtils.getPropertyValue(this.groovyRouterMessageHandler,
111110
"messageProcessor", MessageProcessor.class);
112111
//before it was MethodInvokingMessageProcessor
113-
assertThat(messageProcessor instanceof GroovyScriptExecutingMessageProcessor).isTrue();
112+
assertThat(messageProcessor).isInstanceOf(GroovyScriptExecutingMessageProcessor.class);
114113
}
115114

116115
}

spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyServiceActivatorTests.java

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.springframework.messaging.support.ErrorMessage;
4242
import org.springframework.messaging.support.GenericMessage;
4343
import org.springframework.scripting.groovy.GroovyObjectCustomizer;
44+
import org.springframework.test.annotation.DirtiesContext;
4445
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
4546

4647
import static org.assertj.core.api.Assertions.assertThat;
@@ -55,6 +56,7 @@
5556
* @since 2.0
5657
*/
5758
@SpringJUnitConfig
59+
@DirtiesContext
5860
public class GroovyServiceActivatorTests {
5961

6062
@Autowired

spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovySplitterTests.java

+3-1
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.
@@ -29,6 +29,7 @@
2929
import org.springframework.messaging.Message;
3030
import org.springframework.messaging.MessageChannel;
3131
import org.springframework.messaging.MessageHandler;
32+
import org.springframework.test.annotation.DirtiesContext;
3233
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
3334

3435
import static org.assertj.core.api.Assertions.assertThat;
@@ -39,6 +40,7 @@
3940
* @since 2.0
4041
*/
4142
@SpringJUnitConfig
43+
@DirtiesContext
4244
public class GroovySplitterTests {
4345

4446
@Autowired

spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyTransformerTests.java

+11-12
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@
1616

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

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

2221
import org.springframework.beans.factory.annotation.Autowired;
2322
import org.springframework.beans.factory.annotation.Qualifier;
2423
import org.springframework.integration.channel.QueueChannel;
2524
import org.springframework.integration.groovy.GroovyScriptExecutingMessageProcessor;
26-
import org.springframework.integration.handler.MessageProcessor;
2725
import org.springframework.integration.support.MessageBuilder;
2826
import org.springframework.integration.test.util.TestUtils;
2927
import org.springframework.integration.transformer.AbstractMessageProcessingTransformer;
@@ -32,18 +30,19 @@
3230
import org.springframework.messaging.Message;
3331
import org.springframework.messaging.MessageChannel;
3432
import org.springframework.messaging.MessageHandler;
35-
import org.springframework.test.context.ContextConfiguration;
36-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
33+
import org.springframework.test.annotation.DirtiesContext;
34+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
3735

3836
import static org.assertj.core.api.Assertions.assertThat;
3937

4038
/**
4139
* @author Mark Fisher
4240
* @author Artem Bilan
41+
*
4342
* @since 2.0
4443
*/
45-
@ContextConfiguration
46-
@RunWith(SpringJUnit4ClassRunner.class)
44+
@SpringJUnitConfig
45+
@DirtiesContext
4746
public class GroovyTransformerTests {
4847

4948
@Autowired
@@ -87,12 +86,12 @@ public void inlineScript() {
8786
@Test
8887
public void testInt2433VerifyRiddingOfMessageProcessorsWrapping() {
8988
assertThat(this.groovyTransformerMessageHandler instanceof MessageTransformingHandler).isTrue();
90-
Transformer transformer = TestUtils.getPropertyValue(this.groovyTransformerMessageHandler, "transformer", Transformer.class);
91-
assertThat(transformer instanceof AbstractMessageProcessingTransformer).isTrue();
92-
@SuppressWarnings("rawtypes")
93-
MessageProcessor messageProcessor = TestUtils.getPropertyValue(transformer, "messageProcessor", MessageProcessor.class);
89+
Transformer transformer =
90+
TestUtils.getPropertyValue(this.groovyTransformerMessageHandler, "transformer", Transformer.class);
91+
assertThat(transformer).isInstanceOf(AbstractMessageProcessingTransformer.class);
9492
//before it was MethodInvokingMessageProcessor
95-
assertThat(messageProcessor instanceof GroovyScriptExecutingMessageProcessor).isTrue();
93+
assertThat(TestUtils.getPropertyValue(transformer, "messageProcessor"))
94+
.isInstanceOf(GroovyScriptExecutingMessageProcessor.class);
9695
}
9796

9897
}

0 commit comments

Comments
 (0)