Skip to content

Commit a190aa3

Browse files
committed
Prefer IPv4 for UDP tests
* Enable UDP tests back **Auto-cherry-pick to `7.0.x` & `6.5.x`**
1 parent 79302dd commit a190aa3

3 files changed

Lines changed: 15 additions & 31 deletions

File tree

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,8 @@ project('spring-integration-ip') {
625625

626626
tasks.withType(JavaForkOptions) {
627627
jvmArgs '--add-opens', 'java.base/java.nio.channels.spi=ALL-UNNAMED',
628-
'--add-opens', 'java.base/java.util=ALL-UNNAMED'
628+
'--add-opens', 'java.base/java.util=ALL-UNNAMED',
629+
'-Djava.net.preferIPv4Stack=true'
629630
}
630631
}
631632

spring-integration-ip/src/test/java/org/springframework/integration/ip/udp/DatagramPacketMulticastSendingHandlerTests.java

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
import java.util.concurrent.atomic.AtomicInteger;
3030

3131
import org.junit.jupiter.api.Test;
32-
import org.junit.jupiter.api.condition.DisabledOnOs;
33-
import org.junit.jupiter.api.condition.OS;
3432

3533
import org.springframework.core.task.SimpleAsyncTaskExecutor;
3634
import org.springframework.integration.ip.IpHeaders;
@@ -50,7 +48,6 @@
5048
* @since 2.0
5149
*/
5250
@Multicast
53-
@DisabledOnOs(value = OS.MAC, disabledReason = "Multicast tests don't work on MacOS")
5451
public class DatagramPacketMulticastSendingHandlerTests implements TestApplicationContextAware {
5552

5653
@Test
@@ -64,7 +61,7 @@ public void verifySendMulticast(MulticastCondition multicastCondition) throws Ex
6461
}
6562
final int testPort = socket.getLocalPort();
6663
final String multicastAddress = multicastCondition.getGroup();
67-
final String payload = "foo";
64+
final String payload = "test";
6865
final CountDownLatch listening = new CountDownLatch(2);
6966
final CountDownLatch received = new CountDownLatch(2);
7067
Runnable catcher = () -> {
@@ -94,7 +91,7 @@ public void verifySendMulticast(MulticastCondition multicastCondition) throws Ex
9491
Executor executor = new SimpleAsyncTaskExecutor("verifySendMulticast-");
9592
executor.execute(catcher);
9693
executor.execute(catcher);
97-
assertThat(listening.await(10000, TimeUnit.MILLISECONDS)).isTrue();
94+
assertThat(listening.await(20, TimeUnit.SECONDS)).isTrue();
9895
MulticastSendingMessageHandler handler = new MulticastSendingMessageHandler(multicastAddress, testPort);
9996
handler.setBeanFactory(TEST_INTEGRATION_CONTEXT);
10097
NetworkInterface nic = multicastCondition.getNic();
@@ -117,26 +114,19 @@ public void verifySendMulticast(MulticastCondition multicastCondition) throws Ex
117114
}
118115
handler.afterPropertiesSet();
119116
handler.handleMessage(MessageBuilder.withPayload(payload).build());
120-
assertThat(received.await(10000, TimeUnit.MILLISECONDS)).isTrue();
117+
assertThat(received.await(20000, TimeUnit.MILLISECONDS)).isTrue();
121118
handler.stop();
122119
socket.close();
123120
}
124121

125122
@Test
126123
public void verifySendMulticastWithAcks(MulticastCondition multicastCondition) throws Exception {
127-
128-
MulticastSocket socket;
129-
try {
130-
socket = new MulticastSocket();
131-
}
132-
catch (Exception e) {
133-
return;
134-
}
124+
MulticastSocket socket = new MulticastSocket();
135125
final int testPort = socket.getLocalPort();
136126
final AtomicInteger ackPort = new AtomicInteger();
137127

138128
final String multicastAddress = multicastCondition.getGroup();
139-
final String payload = "foobar";
129+
final String payload = "test_test";
140130
final CountDownLatch listening = new CountDownLatch(2);
141131
final CountDownLatch ackListening = new CountDownLatch(1);
142132
final CountDownLatch ackSent = new CountDownLatch(2);
@@ -151,14 +141,14 @@ public void verifySendMulticastWithAcks(MulticastCondition multicastCondition) t
151141
InetAddress group = InetAddress.getByName(multicastAddress);
152142
socket1.joinGroup(new InetSocketAddress(group, 0), null);
153143
listening.countDown();
154-
assertThat(ackListening.await(10, TimeUnit.SECONDS)).isTrue();
144+
assertThat(ackListening.await(20, TimeUnit.SECONDS)).isTrue();
155145
socket1.receive(receivedPacket);
156146
socket1.close();
157147
byte[] src = receivedPacket.getData();
158148
int length = receivedPacket.getLength();
159149
int offset = receivedPacket.getOffset();
160-
byte[] dest = new byte[6];
161-
System.arraycopy(src, offset + length - 6, dest, 0, 6);
150+
byte[] dest = new byte[9];
151+
System.arraycopy(src, offset + length - 9, dest, 0, 9);
162152
assertThat(new String(dest)).isEqualTo(payload);
163153
DatagramPacketMessageMapper mapper = new DatagramPacketMessageMapper();
164154
mapper.setAcknowledge(true);
@@ -196,9 +186,9 @@ public void verifySendMulticastWithAcks(MulticastCondition multicastCondition) t
196186
Executor executor = new SimpleAsyncTaskExecutor("verifySendMulticastWithAcks-");
197187
executor.execute(catcher);
198188
executor.execute(catcher);
199-
assertThat(listening.await(10000, TimeUnit.MILLISECONDS)).isTrue();
189+
assertThat(listening.await(20000, TimeUnit.MILLISECONDS)).isTrue();
200190
MulticastSendingMessageHandler handler =
201-
new MulticastSendingMessageHandler(multicastAddress, testPort, true, true, "localhost", 0, 10000);
191+
new MulticastSendingMessageHandler(multicastAddress, testPort, true, true, "localhost", 0, 20000);
202192

203193
if (nic != null) {
204194
String hostName = null;
@@ -225,7 +215,7 @@ public void verifySendMulticastWithAcks(MulticastCondition multicastCondition) t
225215
ackPort.set(handler.getAckPort());
226216
ackListening.countDown();
227217
handler.handleMessage(MessageBuilder.withPayload(payload).build());
228-
assertThat(ackSent.await(10000, TimeUnit.MILLISECONDS)).isTrue();
218+
assertThat(ackSent.await(20000, TimeUnit.MILLISECONDS)).isTrue();
229219
handler.stop();
230220
socket.close();
231221
}

spring-integration-ip/src/test/java/org/springframework/integration/ip/udp/UdpChannelAdapterTests.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@
3030
import java.util.concurrent.atomic.AtomicBoolean;
3131
import java.util.concurrent.atomic.AtomicReference;
3232

33-
import org.junit.jupiter.api.Disabled;
3433
import org.junit.jupiter.api.Test;
35-
import org.junit.jupiter.api.condition.DisabledOnOs;
36-
import org.junit.jupiter.api.condition.OS;
3734

3835
import org.springframework.context.ConfigurableApplicationContext;
3936
import org.springframework.context.support.ClassPathXmlApplicationContext;
@@ -48,7 +45,6 @@
4845
import org.springframework.integration.ip.udp.outbound.UnicastSendingMessageHandler;
4946
import org.springframework.integration.ip.util.SocketTestUtils;
5047
import org.springframework.integration.support.MessageBuilder;
51-
import org.springframework.integration.test.condition.LogLevels;
5248
import org.springframework.integration.test.support.TestApplicationContextAware;
5349
import org.springframework.messaging.Message;
5450
import org.springframework.messaging.SubscribableChannel;
@@ -66,7 +62,6 @@
6662
*
6763
*/
6864
@Multicast
69-
@LogLevels(categories = "org.springframework.integration.ip.udp", level = "TRACE")
7065
public class UdpChannelAdapterTests implements TestApplicationContextAware {
7166

7267
@Test
@@ -260,7 +255,6 @@ public void testUnicastSender() {
260255

261256
@SuppressWarnings("unchecked")
262257
@Test
263-
@Disabled("Fails on Java > 17")
264258
public void testMulticastReceiver(MulticastCondition multicastCondition) throws Exception {
265259
QueueChannel channel = new QueueChannel(2);
266260
MulticastReceivingChannelAdapter adapter =
@@ -309,7 +303,6 @@ public void testMulticastReceiver(MulticastCondition multicastCondition) throws
309303

310304
@SuppressWarnings("unchecked")
311305
@Test
312-
@DisabledOnOs(value = OS.MAC, disabledReason = "Multicast tests don't work on MacOS")
313306
public void testMulticastSender(MulticastCondition multicastCondition) {
314307
QueueChannel channel = new QueueChannel(2);
315308
UnicastReceivingChannelAdapter adapter =
@@ -378,12 +371,12 @@ public void testSocketExpression() throws Exception {
378371
UnicastReceivingChannelAdapter adapter = context.getBean(UnicastReceivingChannelAdapter.class);
379372
SocketTestUtils.waitListening(adapter);
380373
int receiverServerPort = adapter.getPort();
381-
DatagramPacket packet = new DatagramPacket("foo".getBytes(), 3);
374+
DatagramPacket packet = new DatagramPacket("test".getBytes(), 4);
382375
packet.setSocketAddress(new InetSocketAddress("localhost", receiverServerPort));
383376
DatagramSocket socket = new DatagramSocket();
384377
socket.send(packet);
385378
socket.receive(packet);
386-
assertThat(new String(packet.getData())).isEqualTo("FOO");
379+
assertThat(new String(packet.getData())).isEqualTo("TEST");
387380
assertThat(packet.getPort()).isEqualTo(receiverServerPort);
388381
socket.close();
389382
context.close();

0 commit comments

Comments
 (0)