11/*
2- * Copyright (c) 2019, 2020 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2019, 2024 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * 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)
118118
119119 // send datagram to multicast group
120120 System .out .format ("send %s -> %s%n" , dc .getLocalAddress (), target );
121- ByteBuffer src = ByteBuffer .wrap ("hello" .getBytes ("UTF-8" ));
121+ String str = "hello " + System .nanoTime ();
122+ ByteBuffer src = ByteBuffer .wrap (str .getBytes ("UTF-8" ));
122123 dc .send (src , target );
123124
124125 // receive datagram sent to multicast group
@@ -142,6 +143,7 @@ static void test(ProtocolFamily family, InetAddress group, NetworkInterface ni)
142143 System .out .format ("send %s -> %s%n" , dc .getLocalAddress (), target );
143144 src .clear ();
144145 dc .send (src , target );
146+ src .flip ();
145147
146148 // test that we don't receive the datagram sent to multicast group
147149 dc .configureBlocking (false );
@@ -157,10 +159,16 @@ static void test(ProtocolFamily family, InetAddress group, NetworkInterface ni)
157159 } else {
158160 sel .selectedKeys ().clear ();
159161 SocketAddress sender = dc .receive (dst );
162+ if (src .mismatch (dst ) != -1 ) {
163+ System .out .println ("src: " + src + "not equal to dst: " + dst );
164+ dst .clear ();
165+ continue ;
166+ }
160167 if (sender != null ) {
161168 System .out .format ("received %s from %s%n" , dst , sender );
162169 senderPort = ((InetSocketAddress ) sender ).getPort ();
163- assertTrue (senderPort != localPort , "Unexpected message" );
170+ assertTrue (senderPort != localPort ,
171+ "Unexpected message: localPort=" + localPort );
164172 }
165173 }
166174 }
0 commit comments