Skip to content

Commit 63f8907

Browse files
committed
Change RMI tests to use fixed port
Our CI plans fail from time to time in the test which is based on the OS-selected port * Change the port to use a `SocketUtils.findAvailableTcpPort()` since all other with the fixed port don't fail * Rework all the RMI tests to JUnit 5
1 parent 83f2185 commit 63f8907

File tree

5 files changed

+27
-34
lines changed

5 files changed

+27
-34
lines changed

spring-integration-rmi/src/test/java/org/springframework/integration/rmi/BackToBackTests.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2019 the original author or authors.
2+
* Copyright 2013-2020 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.
@@ -21,8 +21,7 @@
2121
import static org.mockito.ArgumentMatchers.any;
2222
import static org.mockito.Mockito.verify;
2323

24-
import org.junit.Test;
25-
import org.junit.runner.RunWith;
24+
import org.junit.jupiter.api.Test;
2625

2726
import org.springframework.beans.factory.annotation.Autowired;
2827
import org.springframework.context.support.AbstractApplicationContext;
@@ -34,7 +33,7 @@
3433
import org.springframework.messaging.SubscribableChannel;
3534
import org.springframework.messaging.support.GenericMessage;
3635
import org.springframework.test.annotation.DirtiesContext;
37-
import org.springframework.test.context.junit4.SpringRunner;
36+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
3837
import org.springframework.transaction.PlatformTransactionManager;
3938
import org.springframework.transaction.TransactionDefinition;
4039

@@ -45,7 +44,7 @@
4544
* @since 3.0
4645
*
4746
*/
48-
@RunWith(SpringRunner.class)
47+
@SpringJUnitConfig
4948
@DirtiesContext
5049
public class BackToBackTests {
5150

spring-integration-rmi/src/test/java/org/springframework/integration/rmi/RmiOutboundGatewayTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 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,13 +29,13 @@
2929
import org.springframework.integration.gateway.RequestReplyExchanger;
3030
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
3131
import org.springframework.integration.support.MessageBuilder;
32-
import org.springframework.integration.test.util.TestUtils;
3332
import org.springframework.messaging.Message;
3433
import org.springframework.messaging.MessageHandlingException;
3534
import org.springframework.messaging.MessagingException;
3635
import org.springframework.messaging.support.GenericMessage;
3736
import org.springframework.remoting.RemoteLookupFailureException;
3837
import org.springframework.remoting.rmi.RmiServiceExporter;
38+
import org.springframework.util.SocketUtils;
3939

4040
/**
4141
* @author Mark Fisher
@@ -52,16 +52,16 @@ public class RmiOutboundGatewayTests {
5252

5353
@BeforeAll
5454
static void setup() throws RemoteException {
55+
int rmiPort = SocketUtils.findAvailableTcpPort();
56+
5557
EXPORTER = new RmiServiceExporter();
5658
EXPORTER.setService(new TestExchanger());
5759
EXPORTER.setServiceInterface(RequestReplyExchanger.class);
5860
EXPORTER.setServiceName("testRemoteHandler");
59-
EXPORTER.setRegistryPort(0);
61+
EXPORTER.setRegistryPort(rmiPort);
6062
EXPORTER.afterPropertiesSet();
6163

62-
Integer localPort = TestUtils.getPropertyValue(EXPORTER, "registry.ref.ref.ep.port", Integer.class);
63-
64-
GATEWAY = new RmiOutboundGateway("rmi://localhost:" + localPort + "/testRemoteHandler");
64+
GATEWAY = new RmiOutboundGateway("rmi://localhost:" + rmiPort + "/testRemoteHandler");
6565
GATEWAY.setOutputChannel(OUTPUT);
6666
}
6767

spring-integration-rmi/src/test/java/org/springframework/integration/rmi/config/DefaultConfigurationTests.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 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.
@@ -18,8 +18,7 @@
1818

1919
import static org.assertj.core.api.Assertions.assertThat;
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.context.ApplicationContext;
@@ -30,18 +29,17 @@
3029
import org.springframework.integration.test.util.TestUtils;
3130
import org.springframework.messaging.MessageChannel;
3231
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
33-
import org.springframework.test.context.ContextConfiguration;
34-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
32+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
3533
import org.springframework.util.ErrorHandler;
3634

3735
/**
3836
* @author Mark Fisher
3937
* @author Artem Bilan
4038
* @author Gary Russell
39+
*
4140
* @since 1.0.3
4241
*/
43-
@RunWith(SpringJUnit4ClassRunner.class)
44-
@ContextConfiguration
42+
@SpringJUnitConfig
4543
public class DefaultConfigurationTests {
4644

4745
@Autowired

spring-integration-rmi/src/test/java/org/springframework/integration/rmi/config/RmiInboundGatewayParserTests.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 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.
@@ -18,8 +18,7 @@
1818

1919
import static org.assertj.core.api.Assertions.assertThat;
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.beans.factory.annotation.Qualifier;
@@ -28,15 +27,15 @@
2827
import org.springframework.integration.test.util.TestUtils;
2928
import org.springframework.messaging.MessageChannel;
3029
import org.springframework.test.annotation.DirtiesContext;
31-
import org.springframework.test.context.junit4.SpringRunner;
30+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
3231
import org.springframework.util.SocketUtils;
3332

3433
/**
3534
* @author Mark Fisher
3635
* @author Gary Russell
3736
* @author Artem Bilan
3837
*/
39-
@RunWith(SpringRunner.class)
38+
@SpringJUnitConfig
4039
@DirtiesContext
4140
public class RmiInboundGatewayParserTests {
4241

spring-integration-rmi/src/test/java/org/springframework/integration/rmi/config/RmiOutboundGatewayParserTests.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 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.
@@ -21,10 +21,9 @@
2121
import static org.mockito.Mockito.mock;
2222
import static org.mockito.Mockito.verify;
2323

24-
import org.junit.AfterClass;
25-
import org.junit.BeforeClass;
26-
import org.junit.Test;
27-
import org.junit.runner.RunWith;
24+
import org.junit.jupiter.api.AfterAll;
25+
import org.junit.jupiter.api.BeforeAll;
26+
import org.junit.jupiter.api.Test;
2827

2928
import org.springframework.beans.factory.BeanFactory;
3029
import org.springframework.beans.factory.annotation.Autowired;
@@ -41,17 +40,15 @@
4140
import org.springframework.messaging.support.GenericMessage;
4241
import org.springframework.remoting.rmi.RmiProxyFactoryBean;
4342
import org.springframework.test.annotation.DirtiesContext;
44-
import org.springframework.test.context.ContextConfiguration;
45-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
43+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
4644
import org.springframework.util.SocketUtils;
4745

4846
/**
4947
* @author Mark Fisher
5048
* @author Gary Russell
5149
* @author Artem Bilan
5250
*/
53-
@ContextConfiguration
54-
@RunWith(SpringJUnit4ClassRunner.class)
51+
@SpringJUnitConfig
5552
@DirtiesContext
5653
public class RmiOutboundGatewayParserTests {
5754

@@ -87,7 +84,7 @@ public class RmiOutboundGatewayParserTests {
8784
@Qualifier("advised.handler")
8885
RmiOutboundGateway advised;
8986

90-
@BeforeClass
87+
@BeforeAll
9188
public static void setupTestInboundGateway() {
9289
testChannel.setBeanName("testChannel");
9390
rmiInboundGateway.setRequestChannel(testChannel);
@@ -97,7 +94,7 @@ public static void setupTestInboundGateway() {
9794
rmiInboundGateway.afterPropertiesSet();
9895
}
9996

100-
@AfterClass
97+
@AfterAll
10198
public static void destroyInboundGateway() {
10299
rmiInboundGateway.destroy();
103100
}

0 commit comments

Comments
 (0)