Remove SocketUtils usage

* Remove usage of non-stable `org.springframework.util.SocketUtils`
* Replace it with `0` for those tests where it is possible to select OS port
* Remove the mentioning of the `SocketUtils` from the `testing.adoc`
* Use `TransportConstants.DEFAULT_STOMP_PORT` for `StompServerIntegrationTests`.
We may disable this test in the future for CI if it is not going to be stable
* Introduce `Supplier<String> connectUrl` variants for `ZeroMqMessageHandler`
to let it defer connection evaluation until subscription to the socket `Mono`
in the `ZeroMqMessageHandler`.
* Move connection logic in the `ZeroMqMessageHandler` to `Lifecycle.start()`

Related to https://github.com/spring-projects/spring-framework/issues/28054

**Cherry-pick to `5.5.x`**

# Conflicts:
#	spring-integration-stomp/src/test/java/org/springframework/integration/stomp/client/StompServerIntegrationTests.java
This commit is contained in:
Artem Bilan
2022-02-15 16:11:12 -05:00
parent f8c22dd357
commit 9b27fbee89
12 changed files with 187 additions and 148 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2020 the original author or authors.
* Copyright 2015-2022 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.
@@ -29,7 +29,6 @@ import org.junit.runners.model.Statement;
import org.springframework.integration.ip.util.SocketTestUtils;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.SocketUtils;
/**
* @author Artem Bilan
@@ -76,7 +75,7 @@ public class MulticastRule extends TestWatcher {
}
try {
MulticastSocket socket = new MulticastSocket();
socket.joinGroup(new InetSocketAddress(this.group, SocketUtils.findAvailableUdpPort()), nic);
socket.joinGroup(new InetSocketAddress(this.group, 0), nic);
socket.close();
}
catch (Exception e) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2022 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.
@@ -50,7 +50,6 @@ import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.test.rule.Log4j2LevelAdjuster;
import org.springframework.messaging.Message;
import org.springframework.messaging.SubscribableChannel;
import org.springframework.util.SocketUtils;
/**
*
@@ -284,8 +283,7 @@ public class UdpChannelAdapterTests {
}
}
DatagramSocket datagramSocket =
new DatagramSocket(SocketUtils.findAvailableUdpPort(), inetAddress);
DatagramSocket datagramSocket = new DatagramSocket(0, inetAddress);
datagramSocket.send(packet);
datagramSocket.close();