8264975: java/net/DatagramSocket/DatagramSocketMulticasting.java fails infrequently
Reviewed-by: alanb, chegar
This commit is contained in:
parent
a52a08d20b
commit
178343750f
@ -38,14 +38,12 @@ import java.net.DatagramPacket;
|
|||||||
import java.net.DatagramSocket;
|
import java.net.DatagramSocket;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.MulticastSocket;
|
|
||||||
import java.net.NetworkInterface;
|
import java.net.NetworkInterface;
|
||||||
import java.net.ProtocolFamily;
|
import java.net.ProtocolFamily;
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
import java.net.SocketOption;
|
import java.net.SocketOption;
|
||||||
import java.net.SocketTimeoutException;
|
import java.net.SocketTimeoutException;
|
||||||
import java.nio.channels.DatagramChannel;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -59,6 +57,7 @@ import static java.net.StandardSocketOptions.IP_MULTICAST_IF;
|
|||||||
import static java.net.StandardSocketOptions.IP_MULTICAST_LOOP;
|
import static java.net.StandardSocketOptions.IP_MULTICAST_LOOP;
|
||||||
import static java.net.StandardSocketOptions.IP_MULTICAST_TTL;
|
import static java.net.StandardSocketOptions.IP_MULTICAST_TTL;
|
||||||
import static java.net.StandardSocketOptions.SO_REUSEADDR;
|
import static java.net.StandardSocketOptions.SO_REUSEADDR;
|
||||||
|
import static jdk.test.lib.NetworkConfiguration.isSameInterface;
|
||||||
|
|
||||||
public class DatagramSocketMulticasting {
|
public class DatagramSocketMulticasting {
|
||||||
static final ProtocolFamily UNSPEC = () -> "UNSPEC";
|
static final ProtocolFamily UNSPEC = () -> "UNSPEC";
|
||||||
@ -239,7 +238,7 @@ public class DatagramSocketMulticasting {
|
|||||||
|
|
||||||
// setOption(IP_MULTICAST_IF)
|
// setOption(IP_MULTICAST_IF)
|
||||||
s.setOption(IP_MULTICAST_IF, ni);
|
s.setOption(IP_MULTICAST_IF, ni);
|
||||||
assertTrue(s.getOption(IP_MULTICAST_IF).equals(ni));
|
assertTrue(isSameInterface(s.getOption(IP_MULTICAST_IF), ni));
|
||||||
|
|
||||||
// bad values for IP_MULTICAST_IF
|
// bad values for IP_MULTICAST_IF
|
||||||
assertThrows(IllegalArgumentException.class,
|
assertThrows(IllegalArgumentException.class,
|
||||||
|
@ -79,6 +79,7 @@ public class SendReceiveMaxSize {
|
|||||||
IPSupport.throwSkippedExceptionIfNonOperational();
|
IPSupport.throwSkippedExceptionIfNonOperational();
|
||||||
HOST_ADDR = InetAddress.getLocalHost();
|
HOST_ADDR = InetAddress.getLocalHost();
|
||||||
BUF_LIMIT = (HOST_ADDR instanceof Inet6Address) ? IPV6_SNDBUF : IPV4_SNDBUF;
|
BUF_LIMIT = (HOST_ADDR instanceof Inet6Address) ? IPV6_SNDBUF : IPV4_SNDBUF;
|
||||||
|
System.out.printf("Host address: %s, Buffer limit: %d%n", HOST_ADDR, BUF_LIMIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@DataProvider
|
@DataProvider
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -35,6 +35,7 @@ import java.util.LinkedHashMap;
|
|||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
@ -92,6 +93,38 @@ public class NetworkConfiguration {
|
|||||||
return Inet6Address.class.isInstance(a) && a.isLinkLocalAddress();
|
return Inet6Address.class.isInstance(a) && a.isLinkLocalAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the two interfaces point to the same network interface.
|
||||||
|
*
|
||||||
|
* @implNote
|
||||||
|
* This method first looks at whether the two interfaces are
|
||||||
|
* {@linkplain NetworkInterface#equals(Object) equals}, and if so it returns
|
||||||
|
* true. Otherwise, it looks at whether the two interfaces have the same
|
||||||
|
* {@linkplain NetworkInterface#getName() name} and
|
||||||
|
* {@linkplain NetworkInterface#getIndex() index}, and if so returns true.
|
||||||
|
* Otherwise, it returns false.
|
||||||
|
*
|
||||||
|
* @apiNote
|
||||||
|
* This method ignores differences in the addresses to which the network
|
||||||
|
* interfaces are bound, to cater for possible reconfiguration that might
|
||||||
|
* have happened between the time at which each interface configuration
|
||||||
|
* was looked up.
|
||||||
|
*
|
||||||
|
* @param ni1 A network interface, may be {@code null}
|
||||||
|
* @param ni2 An other network interface, may be {@code null}
|
||||||
|
* @return {@code true} if the two network interfaces have the same name
|
||||||
|
* and index, {@code false} otherwise.
|
||||||
|
*/
|
||||||
|
public static boolean isSameInterface(NetworkInterface ni1, NetworkInterface ni2) {
|
||||||
|
if (Objects.equals(ni1, ni2)) return true;
|
||||||
|
// Objects equals has taken care of the case where
|
||||||
|
// ni1 == ni2 so either they are both non-null or only
|
||||||
|
// one of them is null - in which case they can't be equal.
|
||||||
|
if (ni1 == null || ni2 == null) return false;
|
||||||
|
if (ni1.getIndex() != ni2.getIndex()) return false;
|
||||||
|
return Objects.equals(ni1.getName(), ni2.getName());
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isTestable(NetworkInterface nif) {
|
public static boolean isTestable(NetworkInterface nif) {
|
||||||
if (Platform.isOSX()) {
|
if (Platform.isOSX()) {
|
||||||
if (nif.getName().contains("awdl")) {
|
if (nif.getName().contains("awdl")) {
|
||||||
|
Loading…
Reference in New Issue
Block a user