Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8269657: Test java/nio/channels/DatagramChannel/Loopback.java failed: Unexpected message #2720

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
@@ -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
@@ -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);
@@ -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);
}
}
}