Skip to content

Commit 2145f1e

Browse files
committed
Fix RMI tests to rely on the random local port
1 parent aeada86 commit 2145f1e

File tree

6 files changed

+34
-37
lines changed

6 files changed

+34
-37
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
</int:channel>
3030

3131
<bean id="port" class="java.lang.Integer">
32-
<constructor-arg value="#{T(org.springframework.integration.test.util.SocketUtils).findAvailableServerSocket()}" />
32+
<constructor-arg value="#{T(org.springframework.util.SocketUtils).findAvailableTcpPort()}" />
3333
</bean>
3434

3535
<!-- Bad -->

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: 10 additions & 8 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
@@ -46,22 +46,24 @@ public class RmiOutboundGatewayTests {
4646

4747
private static final QueueChannel OUTPUT = new QueueChannel(1);
4848

49+
private static int RMI_PORT;
50+
4951
private static RmiServiceExporter EXPORTER;
5052

5153
private static RmiOutboundGateway GATEWAY;
5254

5355
@BeforeAll
5456
static void setup() throws RemoteException {
57+
RMI_PORT = SocketUtils.findAvailableTcpPort();
58+
5559
EXPORTER = new RmiServiceExporter();
5660
EXPORTER.setService(new TestExchanger());
5761
EXPORTER.setServiceInterface(RequestReplyExchanger.class);
5862
EXPORTER.setServiceName("testRemoteHandler");
59-
EXPORTER.setRegistryPort(0);
63+
EXPORTER.setRegistryPort(RMI_PORT);
6064
EXPORTER.afterPropertiesSet();
6165

62-
Integer localPort = TestUtils.getPropertyValue(EXPORTER, "registry.ref.ref.ep.port", Integer.class);
63-
64-
GATEWAY = new RmiOutboundGateway("rmi://localhost:" + localPort + "/testRemoteHandler");
66+
GATEWAY = new RmiOutboundGateway("rmi://localhost:" + RMI_PORT + "/testRemoteHandler");
6567
GATEWAY.setOutputChannel(OUTPUT);
6668
}
6769

@@ -120,7 +122,7 @@ void nonSerializableAttribute() {
120122

121123
@Test
122124
void invalidServiceName() {
123-
RmiOutboundGateway gateway = new RmiOutboundGateway("rmi://localhost:1099/noSuchService");
125+
RmiOutboundGateway gateway = new RmiOutboundGateway("rmi://localhost:" + RMI_PORT + "/noSuchService");
124126
assertThatExceptionOfType(MessageHandlingException.class)
125127
.isThrownBy(() -> gateway.handleMessage(new GenericMessage<>("test")))
126128
.withCauseInstanceOf(RemoteLookupFailureException.class);
@@ -136,7 +138,7 @@ void invalidHost() {
136138

137139
@Test
138140
void invalidUrl() {
139-
RmiOutboundGateway gateway = new RmiOutboundGateway("invalid");
141+
RmiOutboundGateway gateway = new RmiOutboundGateway("https://sample.com/");
140142
assertThatExceptionOfType(MessageHandlingException.class)
141143
.isThrownBy(() -> gateway.handleMessage(new GenericMessage<>("test")))
142144
.withCauseInstanceOf(RemoteLookupFailureException.class);

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

Lines changed: 7 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,19 @@
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.annotation.DirtiesContext;
33+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
3534
import org.springframework.util.ErrorHandler;
3635

3736
/**
3837
* @author Mark Fisher
3938
* @author Artem Bilan
4039
* @author Gary Russell
40+
*
4141
* @since 1.0.3
4242
*/
43-
@RunWith(SpringJUnit4ClassRunner.class)
44-
@ContextConfiguration
43+
@SpringJUnitConfig
44+
@DirtiesContext
4545
public class DefaultConfigurationTests {
4646

4747
@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)