Skip to content

Commit

Permalink
Backport a9f92be
Browse files Browse the repository at this point in the history
  • Loading branch information
duke committed Sep 24, 2021
1 parent 3d21c7c commit 9f2d6da
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 75 deletions.
130 changes: 60 additions & 70 deletions test/jdk/java/net/MulticastSocket/MulticastAddresses.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2019, 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 All @@ -22,76 +22,32 @@
*/

/*
*
* @test
* @bug 4488458
* @library /test/lib
* @summary Test that MutlicastSocket.joinGroup is working for
* various multicast and non-multicast addresses.
*/

import jdk.test.lib.NetworkConfiguration;

import java.net.*;
import java.util.Enumeration;
import java.io.IOException;
import java.util.stream.Collectors;

public class MulticastAddresses {

public static void main(String args[]) throws Exception {

boolean ipv6_available = false;
NetworkInterface ni = null;

/*
* Examine the network interfaces and determine :-
*
* 1. If host has IPv6 support
* 2. Get reference to a non-loopback interface
*/
Enumeration nifs = NetworkInterface.getNetworkInterfaces();
while (nifs.hasMoreElements()) {
NetworkInterface this_ni = (NetworkInterface)nifs.nextElement();

Enumeration addrs = this_ni.getInetAddresses();
while (addrs.hasMoreElements()) {
InetAddress addr = (InetAddress)addrs.nextElement();
if (addr instanceof Inet6Address) {
ipv6_available = true;
}

if (!addr.isLoopbackAddress() && ni == null) {
ni = this_ni;
}
}

if (ipv6_available) {
break;
}
}

public static void runTest(NetworkInterface ni,
String[] multicasts,
String[] nonMulticasts) throws Exception {
int failures = 0;

String multicasts[] = {
"224.80.80.80",
"ff01::1",
"ff02::1234",
"ff05::a",
"ff0e::1234:a" };

String non_multicasts[] = {
"129.1.1.1",
"::1",
"::129.1.1.1",
"fe80::a00:20ff:fee5:bc02" };

MulticastSocket s = new MulticastSocket();

/* test valid multicast addresses */

for (int i=0; i<multicasts.length; i++) {
for (int i = 0; i < multicasts.length; i++) {
InetAddress ia = InetAddress.getByName(multicasts[i]);
if (ia instanceof Inet6Address && !ipv6_available) {
continue;
}

System.out.println("Test: " + ia);

System.out.println("Test: " + ia + " " + " ni: " + ni);
try {

System.out.print(" joinGroup(InetAddress) ");
Expand All @@ -100,8 +56,8 @@ public static void main(String args[]) throws Exception {
System.out.println(" Passed.");

System.out.print(" joinGroup(InetAddress,NetworkInterface) ");
s.joinGroup(new InetSocketAddress(ia,0), ni);
s.leaveGroup(new InetSocketAddress(ia,0), ni);
s.joinGroup(new InetSocketAddress(ia, 0), ni);
s.leaveGroup(new InetSocketAddress(ia, 0), ni);
System.out.println(" Passed.");
} catch (IOException e) {
failures++;
Expand All @@ -111,13 +67,8 @@ public static void main(String args[]) throws Exception {
}

/* test non-multicast addresses */

for (int i=0; i<non_multicasts.length; i++) {
InetAddress ia = InetAddress.getByName(non_multicasts[i]);
if (ia instanceof Inet6Address && !ipv6_available) {
continue;
}

for (int i = 0; i < nonMulticasts.length; i++) {
InetAddress ia = InetAddress.getByName(nonMulticasts[i]);
boolean failed = false;

System.out.println("Test: " + ia + " ");
Expand All @@ -130,20 +81,59 @@ public static void main(String args[]) throws Exception {
} catch (IOException e) {
System.out.println(" Passed: " + e.getMessage());
}

if (failed) {
s.leaveGroup(ia);
failures++;
}
}

/* done */

s.close();

if (failures > 0) {
throw new Exception(failures + " test(s) failed - see log file.");
}
}


public static void main(String args[]) throws Exception {

String[] multicastIPv4 = {
"224.80.80.80",
};
String[] multicastIPv6 = {
"ff01::1",
"ff02::1234",
"ff05::a",
"ff0e::1234:a"};

String[] nonMulticastIPv4 = {
"129.1.1.1"
};

String[] nonMulticastIPv6 = {
"::1",
"::129.1.1.1",
"fe80::a00:20ff:fee5:bc02"};

/*
* Examine the network interfaces and determine :-
*
* 1. If host has IPv6 support
* 2. Get reference to a non-loopback interface
*/
NetworkConfiguration nc = NetworkConfiguration.probe();
var ipv6List = nc.ip6MulticastInterfaces(false)
.collect(Collectors.toList());

var ipv4List = nc.ip4MulticastInterfaces(false)
.collect(Collectors.toList());

if (ipv6List.retainAll(ipv4List)) {
runTest(ipv6List.get(0), multicastIPv4, nonMulticastIPv4);
runTest(ipv6List.get(0), multicastIPv6, nonMulticastIPv6);
} else {
if (!ipv4List.isEmpty())
runTest(ipv4List.get(0), multicastIPv4, nonMulticastIPv4);
if (!ipv6List.isEmpty())
runTest(ipv6List.get(0), multicastIPv6, nonMulticastIPv6);
}
}
}
7 changes: 6 additions & 1 deletion test/jdk/java/net/MulticastSocket/Reuse.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2019, 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 All @@ -24,6 +24,11 @@
import java.net.MulticastSocket;
import java.net.BindException;

/*
* @test
* @summary Check if MulticastSocket sets SO_REUSEADDR
*/

public class Reuse {
public static void main(String[] args) throws Exception {
MulticastSocket s1, s2;
Expand Down
13 changes: 9 additions & 4 deletions test/jdk/java/net/URLClassLoader/GetURLsTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2019, 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 All @@ -25,19 +25,24 @@
import java.io.*;

/*
* Regression test for URLClassLoader getURLs() and addURL() methods.
* @test
* @summary Regression test for URLClassLoader getURLs() and addURL() methods.
* See RFE 4102580: Need URLClassLoader.getURLs() method
*/
class GetURLsTest {
public class GetURLsTest {
static final String TEST_DIR = System.getProperty("test.src", ".");

public static void main(String[] args) throws Exception {
File testJars = new File(TEST_DIR, "jars");

MyURLClassLoader ucl =
new MyURLClassLoader(new URL[] { new File(".").toURL() });
p("initial urls = ", ucl.getURLs());
URL u = ucl.getResource("GetURLsTest.java");
if (u != null) {
p("found resource = " + u);
}
ucl.addURL(new File("jars", "class_path_test.jar").toURL());
ucl.addURL(new File(testJars, "class_path_test.jar").toURL());
p("new urls = ", ucl.getURLs());
Class c = ucl.loadClass("Foo");
p("found class = " + c);
Expand Down

0 comments on commit 9f2d6da

Please sign in to comment.