test/jdk/java/net/MulticastSocket/SetGetNetworkInterfaceTest.java
author aeubanks
Tue, 16 Apr 2019 13:06:23 -0700
changeset 54770 62b6e7587b1f
parent 53426 1b665a4f343a
child 54811 9db7c0f561a6
permissions -rw-r--r--
8220673: Add test library support for determining platform IP support Reviewed-by: dfuchs, chegar Contributed-by: aeubanks@google.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
19866
f5e8a8275078 6458027: Disabling IPv6 on a specific network interface causes problems
msheppar
parents:
diff changeset
     1
/*
53426
1b665a4f343a 8207404: MulticastSocket tests failing on AIX
clanger
parents: 47216
diff changeset
     2
 * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
19866
f5e8a8275078 6458027: Disabling IPv6 on a specific network interface causes problems
msheppar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f5e8a8275078 6458027: Disabling IPv6 on a specific network interface causes problems
msheppar
parents:
diff changeset
     4
 *
f5e8a8275078 6458027: Disabling IPv6 on a specific network interface causes problems
msheppar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f5e8a8275078 6458027: Disabling IPv6 on a specific network interface causes problems
msheppar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f5e8a8275078 6458027: Disabling IPv6 on a specific network interface causes problems
msheppar
parents:
diff changeset
     7
 * published by the Free Software Foundation.
f5e8a8275078 6458027: Disabling IPv6 on a specific network interface causes problems
msheppar
parents:
diff changeset
     8
 *
f5e8a8275078 6458027: Disabling IPv6 on a specific network interface causes problems
msheppar
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
f5e8a8275078 6458027: Disabling IPv6 on a specific network interface causes problems
msheppar
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f5e8a8275078 6458027: Disabling IPv6 on a specific network interface causes problems
msheppar
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f5e8a8275078 6458027: Disabling IPv6 on a specific network interface causes problems
msheppar
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
f5e8a8275078 6458027: Disabling IPv6 on a specific network interface causes problems
msheppar
parents:
diff changeset
    13
 * accompanied this code).
f5e8a8275078 6458027: Disabling IPv6 on a specific network interface causes problems
msheppar
parents:
diff changeset
    14
 *
f5e8a8275078 6458027: Disabling IPv6 on a specific network interface causes problems
msheppar
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
f5e8a8275078 6458027: Disabling IPv6 on a specific network interface causes problems
msheppar
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
f5e8a8275078 6458027: Disabling IPv6 on a specific network interface causes problems
msheppar
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f5e8a8275078 6458027: Disabling IPv6 on a specific network interface causes problems
msheppar
parents:
diff changeset
    18
 *
f5e8a8275078 6458027: Disabling IPv6 on a specific network interface causes problems
msheppar
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f5e8a8275078 6458027: Disabling IPv6 on a specific network interface causes problems
msheppar
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f5e8a8275078 6458027: Disabling IPv6 on a specific network interface causes problems
msheppar
parents:
diff changeset
    21
 * questions.
f5e8a8275078 6458027: Disabling IPv6 on a specific network interface causes problems
msheppar
parents:
diff changeset
    22
 */
f5e8a8275078 6458027: Disabling IPv6 on a specific network interface causes problems
msheppar
parents:
diff changeset
    23
53426
1b665a4f343a 8207404: MulticastSocket tests failing on AIX
clanger
parents: 47216
diff changeset
    24
import java.io.IOException;
1b665a4f343a 8207404: MulticastSocket tests failing on AIX
clanger
parents: 47216
diff changeset
    25
import java.io.UncheckedIOException;
1b665a4f343a 8207404: MulticastSocket tests failing on AIX
clanger
parents: 47216
diff changeset
    26
import java.net.MulticastSocket;
1b665a4f343a 8207404: MulticastSocket tests failing on AIX
clanger
parents: 47216
diff changeset
    27
import java.net.NetworkInterface;
19866
f5e8a8275078 6458027: Disabling IPv6 on a specific network interface causes problems
msheppar
parents:
diff changeset
    28
53426
1b665a4f343a 8207404: MulticastSocket tests failing on AIX
clanger
parents: 47216
diff changeset
    29
import jdk.test.lib.NetworkConfiguration;
54770
62b6e7587b1f 8220673: Add test library support for determining platform IP support
aeubanks
parents: 53426
diff changeset
    30
import jdk.test.lib.net.IPSupport;
53426
1b665a4f343a 8207404: MulticastSocket tests failing on AIX
clanger
parents: 47216
diff changeset
    31
1b665a4f343a 8207404: MulticastSocket tests failing on AIX
clanger
parents: 47216
diff changeset
    32
/**
19866
f5e8a8275078 6458027: Disabling IPv6 on a specific network interface causes problems
msheppar
parents:
diff changeset
    33
 * @test
f5e8a8275078 6458027: Disabling IPv6 on a specific network interface causes problems
msheppar
parents:
diff changeset
    34
 * @bug 6458027
f5e8a8275078 6458027: Disabling IPv6 on a specific network interface causes problems
msheppar
parents:
diff changeset
    35
 * @summary Disabling IPv6 on a specific network interface causes problems.
53426
1b665a4f343a 8207404: MulticastSocket tests failing on AIX
clanger
parents: 47216
diff changeset
    36
 * @library /test/lib
1b665a4f343a 8207404: MulticastSocket tests failing on AIX
clanger
parents: 47216
diff changeset
    37
 * @build jdk.test.lib.NetworkConfiguration
1b665a4f343a 8207404: MulticastSocket tests failing on AIX
clanger
parents: 47216
diff changeset
    38
 *        jdk.test.lib.Platform
1b665a4f343a 8207404: MulticastSocket tests failing on AIX
clanger
parents: 47216
diff changeset
    39
 * @run main SetGetNetworkInterfaceTest
1b665a4f343a 8207404: MulticastSocket tests failing on AIX
clanger
parents: 47216
diff changeset
    40
 * @run main/othervm -Djava.net.preferIPv4Stack=true SetGetNetworkInterfaceTest
1b665a4f343a 8207404: MulticastSocket tests failing on AIX
clanger
parents: 47216
diff changeset
    41
*/
1b665a4f343a 8207404: MulticastSocket tests failing on AIX
clanger
parents: 47216
diff changeset
    42
public class SetGetNetworkInterfaceTest {
19866
f5e8a8275078 6458027: Disabling IPv6 on a specific network interface causes problems
msheppar
parents:
diff changeset
    43
f5e8a8275078 6458027: Disabling IPv6 on a specific network interface causes problems
msheppar
parents:
diff changeset
    44
    public static void main(String[] args) throws Exception {
54770
62b6e7587b1f 8220673: Add test library support for determining platform IP support
aeubanks
parents: 53426
diff changeset
    45
        IPSupport.skipIfCurrentConfigurationIsInvalid();
53426
1b665a4f343a 8207404: MulticastSocket tests failing on AIX
clanger
parents: 47216
diff changeset
    46
        NetworkConfiguration nc = NetworkConfiguration.probe();
1b665a4f343a 8207404: MulticastSocket tests failing on AIX
clanger
parents: 47216
diff changeset
    47
        try (MulticastSocket ms = new MulticastSocket()) {
1b665a4f343a 8207404: MulticastSocket tests failing on AIX
clanger
parents: 47216
diff changeset
    48
            nc.multicastInterfaces(true).forEach(nif -> setGetNetworkInterface(ms, nif));
19866
f5e8a8275078 6458027: Disabling IPv6 on a specific network interface causes problems
msheppar
parents:
diff changeset
    49
        } catch (IOException e) {
f5e8a8275078 6458027: Disabling IPv6 on a specific network interface causes problems
msheppar
parents:
diff changeset
    50
            e.printStackTrace();
f5e8a8275078 6458027: Disabling IPv6 on a specific network interface causes problems
msheppar
parents:
diff changeset
    51
        }
53426
1b665a4f343a 8207404: MulticastSocket tests failing on AIX
clanger
parents: 47216
diff changeset
    52
        System.out.println("Test passed.");
19866
f5e8a8275078 6458027: Disabling IPv6 on a specific network interface causes problems
msheppar
parents:
diff changeset
    53
    }
f5e8a8275078 6458027: Disabling IPv6 on a specific network interface causes problems
msheppar
parents:
diff changeset
    54
53426
1b665a4f343a 8207404: MulticastSocket tests failing on AIX
clanger
parents: 47216
diff changeset
    55
    static void setGetNetworkInterface(MulticastSocket ms, NetworkInterface nif) {
1b665a4f343a 8207404: MulticastSocket tests failing on AIX
clanger
parents: 47216
diff changeset
    56
        try {
1b665a4f343a 8207404: MulticastSocket tests failing on AIX
clanger
parents: 47216
diff changeset
    57
            System.out.println(NetworkConfiguration.interfaceInformation(nif));
1b665a4f343a 8207404: MulticastSocket tests failing on AIX
clanger
parents: 47216
diff changeset
    58
            ms.setNetworkInterface(nif);
1b665a4f343a 8207404: MulticastSocket tests failing on AIX
clanger
parents: 47216
diff changeset
    59
            NetworkInterface msNetIf = ms.getNetworkInterface();
1b665a4f343a 8207404: MulticastSocket tests failing on AIX
clanger
parents: 47216
diff changeset
    60
            if (nif.equals(msNetIf)) {
1b665a4f343a 8207404: MulticastSocket tests failing on AIX
clanger
parents: 47216
diff changeset
    61
                System.out.println(" OK");
19866
f5e8a8275078 6458027: Disabling IPv6 on a specific network interface causes problems
msheppar
parents:
diff changeset
    62
            } else {
53426
1b665a4f343a 8207404: MulticastSocket tests failing on AIX
clanger
parents: 47216
diff changeset
    63
                System.out.println("FAILED!!!");
1b665a4f343a 8207404: MulticastSocket tests failing on AIX
clanger
parents: 47216
diff changeset
    64
                System.out.println(NetworkConfiguration.interfaceInformation(msNetIf));
1b665a4f343a 8207404: MulticastSocket tests failing on AIX
clanger
parents: 47216
diff changeset
    65
                throw new RuntimeException("Test Fail");
19866
f5e8a8275078 6458027: Disabling IPv6 on a specific network interface causes problems
msheppar
parents:
diff changeset
    66
            }
53426
1b665a4f343a 8207404: MulticastSocket tests failing on AIX
clanger
parents: 47216
diff changeset
    67
            System.out.println("------------------");
1b665a4f343a 8207404: MulticastSocket tests failing on AIX
clanger
parents: 47216
diff changeset
    68
        } catch (IOException e) {
1b665a4f343a 8207404: MulticastSocket tests failing on AIX
clanger
parents: 47216
diff changeset
    69
            throw new UncheckedIOException(e);
19866
f5e8a8275078 6458027: Disabling IPv6 on a specific network interface causes problems
msheppar
parents:
diff changeset
    70
        }
f5e8a8275078 6458027: Disabling IPv6 on a specific network interface causes problems
msheppar
parents:
diff changeset
    71
    }
f5e8a8275078 6458027: Disabling IPv6 on a specific network interface causes problems
msheppar
parents:
diff changeset
    72
}