Skip to content

Commit

Permalink
8269657: Test java/nio/channels/DatagramChannel/Loopback.java failed:…
Browse files Browse the repository at this point in the history
… Unexpected message

Reviewed-by: dfuchs
  • Loading branch information
SendaoYan authored and dfuch committed Jun 28, 2024
1 parent 99d2bbf commit c798316
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions test/jdk/java/nio/channels/DatagramChannel/Loopback.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -118,7 +118,8 @@ static void test(ProtocolFamily family, InetAddress group, NetworkInterface ni)

// send datagram to multicast group
System.out.format("send %s -> %s%n", dc.getLocalAddress(), target);
ByteBuffer src = ByteBuffer.wrap("hello".getBytes("UTF-8"));
String str = "hello " + System.nanoTime();
ByteBuffer src = ByteBuffer.wrap(str.getBytes("UTF-8"));
dc.send(src, target);

// receive datagram sent to multicast group
Expand All @@ -142,6 +143,7 @@ static void test(ProtocolFamily family, InetAddress group, NetworkInterface ni)
System.out.format("send %s -> %s%n", dc.getLocalAddress(), target);
src.clear();
dc.send(src, target);
src.flip();

// test that we don't receive the datagram sent to multicast group
dc.configureBlocking(false);
Expand All @@ -157,10 +159,16 @@ static void test(ProtocolFamily family, InetAddress group, NetworkInterface ni)
} else {
sel.selectedKeys().clear();
SocketAddress sender = dc.receive(dst);
if (src.mismatch(dst) != -1) {
System.out.println("src: " + src + "not equal to dst: " + dst);
dst.clear();
continue;
}
if (sender != null) {
System.out.format("received %s from %s%n", dst, sender);
senderPort = ((InetSocketAddress) sender).getPort();
assertTrue(senderPort != localPort, "Unexpected message");
assertTrue(senderPort != localPort,
"Unexpected message: localPort=" + localPort);
}
}
}
Expand Down

0 comments on commit c798316

Please sign in to comment.