test/jdk/java/net/MulticastSocket/NoLoopbackPackets.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 57884 85fbdb87baad
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
55649
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
     2
 * Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5143
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5143
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5143
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug 4742177
54770
62b6e7587b1f 8220673: Add test library support for determining platform IP support
aeubanks
parents: 47216
diff changeset
    27
 * @library /test/lib
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @summary Re-test IPv6 (and specifically MulticastSocket) with latest Linux & USAGI code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.net.*;
57884
85fbdb87baad 8229706: java/net/MulticastSocket/NoLoopbackPackets.java fails on some AIX machines
mbaesken
parents: 55649
diff changeset
    32
import jdk.test.lib.NetworkConfiguration;
54770
62b6e7587b1f 8220673: Add test library support for determining platform IP support
aeubanks
parents: 47216
diff changeset
    33
import jdk.test.lib.net.IPSupport;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
public class NoLoopbackPackets {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    private static String osname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    static boolean isWindows() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
        if (osname == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
            osname = System.getProperty("os.name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
        return osname.contains("Windows");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
55649
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
    44
    private static final String MESSAGE = "hello world (" + System.nanoTime() + ")";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        if (isWindows()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
            System.out.println("The test only run on non-Windows OS. Bye.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
5143
a1682a41e70f 6933618: java/net/MulticastSocket/NoLoopbackPackets.java fails when rerun
chegar
parents: 2
diff changeset
    51
        MulticastSocket msock = null;
a1682a41e70f 6933618: java/net/MulticastSocket/NoLoopbackPackets.java fails when rerun
chegar
parents: 2
diff changeset
    52
        List<SocketAddress> failedGroups = new ArrayList<SocketAddress>();
40534
bc3e5bbcb65e 8164592: java/net/MulticastSocket/NoLoopbackPackets.java tests may leave a daemon thread
asmotrak
parents: 7668
diff changeset
    53
        Sender sender = null;
55649
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
    54
        Thread senderThread = null;
5143
a1682a41e70f 6933618: java/net/MulticastSocket/NoLoopbackPackets.java fails when rerun
chegar
parents: 2
diff changeset
    55
        try {
a1682a41e70f 6933618: java/net/MulticastSocket/NoLoopbackPackets.java fails when rerun
chegar
parents: 2
diff changeset
    56
            msock = new MulticastSocket();
a1682a41e70f 6933618: java/net/MulticastSocket/NoLoopbackPackets.java fails when rerun
chegar
parents: 2
diff changeset
    57
            int port = msock.getLocalPort();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
5143
a1682a41e70f 6933618: java/net/MulticastSocket/NoLoopbackPackets.java fails when rerun
chegar
parents: 2
diff changeset
    59
            // we will send packets to three multicast groups :-
a1682a41e70f 6933618: java/net/MulticastSocket/NoLoopbackPackets.java fails when rerun
chegar
parents: 2
diff changeset
    60
            // 224.1.1.1, ::ffff:224.1.1.2, and ff02::1:1
a1682a41e70f 6933618: java/net/MulticastSocket/NoLoopbackPackets.java fails when rerun
chegar
parents: 2
diff changeset
    61
            //
a1682a41e70f 6933618: java/net/MulticastSocket/NoLoopbackPackets.java fails when rerun
chegar
parents: 2
diff changeset
    62
            List<SocketAddress> groups = new ArrayList<SocketAddress>();
54770
62b6e7587b1f 8220673: Add test library support for determining platform IP support
aeubanks
parents: 47216
diff changeset
    63
            if (IPSupport.hasIPv4()) {
62b6e7587b1f 8220673: Add test library support for determining platform IP support
aeubanks
parents: 47216
diff changeset
    64
                groups.add(new InetSocketAddress(InetAddress.getByName("224.1.1.1"), port));
62b6e7587b1f 8220673: Add test library support for determining platform IP support
aeubanks
parents: 47216
diff changeset
    65
            }
57884
85fbdb87baad 8229706: java/net/MulticastSocket/NoLoopbackPackets.java fails on some AIX machines
mbaesken
parents: 55649
diff changeset
    66
85fbdb87baad 8229706: java/net/MulticastSocket/NoLoopbackPackets.java fails on some AIX machines
mbaesken
parents: 55649
diff changeset
    67
            NetworkConfiguration nc = NetworkConfiguration.probe();
85fbdb87baad 8229706: java/net/MulticastSocket/NoLoopbackPackets.java fails on some AIX machines
mbaesken
parents: 55649
diff changeset
    68
            if (IPSupport.hasIPv6() && nc.hasTestableIPv6Address()) {
54770
62b6e7587b1f 8220673: Add test library support for determining platform IP support
aeubanks
parents: 47216
diff changeset
    69
                groups.add(new InetSocketAddress(InetAddress.getByName("::ffff:224.1.1.2"), port));
62b6e7587b1f 8220673: Add test library support for determining platform IP support
aeubanks
parents: 47216
diff changeset
    70
                groups.add(new InetSocketAddress(InetAddress.getByName("ff02::1:1"), port));
62b6e7587b1f 8220673: Add test library support for determining platform IP support
aeubanks
parents: 47216
diff changeset
    71
            }
62b6e7587b1f 8220673: Add test library support for determining platform IP support
aeubanks
parents: 47216
diff changeset
    72
            if (groups.isEmpty()) {
62b6e7587b1f 8220673: Add test library support for determining platform IP support
aeubanks
parents: 47216
diff changeset
    73
                System.err.println("Nothing to test: there are no network interfaces");
62b6e7587b1f 8220673: Add test library support for determining platform IP support
aeubanks
parents: 47216
diff changeset
    74
            }
5143
a1682a41e70f 6933618: java/net/MulticastSocket/NoLoopbackPackets.java fails when rerun
chegar
parents: 2
diff changeset
    75
40534
bc3e5bbcb65e 8164592: java/net/MulticastSocket/NoLoopbackPackets.java tests may leave a daemon thread
asmotrak
parents: 7668
diff changeset
    76
            sender = new Sender(groups);
55649
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
    77
            senderThread = new Thread(sender);
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
    78
            senderThread.start();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
5143
a1682a41e70f 6933618: java/net/MulticastSocket/NoLoopbackPackets.java fails when rerun
chegar
parents: 2
diff changeset
    80
            // Now try to receive multicast packets. we should not see any of them
a1682a41e70f 6933618: java/net/MulticastSocket/NoLoopbackPackets.java fails when rerun
chegar
parents: 2
diff changeset
    81
            // since we disable loopback mode.
a1682a41e70f 6933618: java/net/MulticastSocket/NoLoopbackPackets.java fails when rerun
chegar
parents: 2
diff changeset
    82
            //
a1682a41e70f 6933618: java/net/MulticastSocket/NoLoopbackPackets.java fails when rerun
chegar
parents: 2
diff changeset
    83
            msock.setSoTimeout(5000);       // 5 seconds
a1682a41e70f 6933618: java/net/MulticastSocket/NoLoopbackPackets.java fails when rerun
chegar
parents: 2
diff changeset
    84
a1682a41e70f 6933618: java/net/MulticastSocket/NoLoopbackPackets.java fails when rerun
chegar
parents: 2
diff changeset
    85
            byte[] buf = new byte[1024];
55649
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
    86
            for (int i = 0; i < buf.length; i++) {
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
    87
                buf[i] = (byte) 'z';
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
    88
            }
5143
a1682a41e70f 6933618: java/net/MulticastSocket/NoLoopbackPackets.java fails when rerun
chegar
parents: 2
diff changeset
    89
            DatagramPacket packet = new DatagramPacket(buf, 0, buf.length);
55649
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
    90
            byte[] expected = MESSAGE.getBytes();
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
    91
            assert expected.length <= buf.length;
5143
a1682a41e70f 6933618: java/net/MulticastSocket/NoLoopbackPackets.java fails when rerun
chegar
parents: 2
diff changeset
    92
            for (SocketAddress group : groups) {
55649
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
    93
                System.out.println("joining group: " + group);
5143
a1682a41e70f 6933618: java/net/MulticastSocket/NoLoopbackPackets.java fails when rerun
chegar
parents: 2
diff changeset
    94
                msock.joinGroup(group, null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
5143
a1682a41e70f 6933618: java/net/MulticastSocket/NoLoopbackPackets.java fails when rerun
chegar
parents: 2
diff changeset
    96
                try {
55649
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
    97
                    do {
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
    98
                        for (int i = 0; i < buf.length; i++) {
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
    99
                            buf[i] = (byte) 'a';
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
   100
                        }
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
   101
                        msock.receive(packet);
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
   102
                        byte[] data = packet.getData();
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
   103
                        int len = packet.getLength();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
55649
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
   105
                        if (expected(data, len, expected)) {
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
   106
                            failedGroups.add(group);
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
   107
                            break;
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
   108
                        } else {
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
   109
                            System.err.println("WARNING: Unexpected packet received from "
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
   110
                                               + group + ": "
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
   111
                                               + len + " bytes");
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
   112
                            System.err.println("\t as text: " + new String(data, 0, len));
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
   113
                        }
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
   114
                    } while (true);
5143
a1682a41e70f 6933618: java/net/MulticastSocket/NoLoopbackPackets.java fails when rerun
chegar
parents: 2
diff changeset
   115
                } catch (SocketTimeoutException e) {
a1682a41e70f 6933618: java/net/MulticastSocket/NoLoopbackPackets.java fails when rerun
chegar
parents: 2
diff changeset
   116
                    // we expect this
55649
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
   117
                    System.out.println("Received expected exception from " + group + ": " + e);
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
   118
                } finally {
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
   119
                    msock.leaveGroup(group, null);
5143
a1682a41e70f 6933618: java/net/MulticastSocket/NoLoopbackPackets.java fails when rerun
chegar
parents: 2
diff changeset
   120
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            }
5143
a1682a41e70f 6933618: java/net/MulticastSocket/NoLoopbackPackets.java fails when rerun
chegar
parents: 2
diff changeset
   122
        } finally {
a1682a41e70f 6933618: java/net/MulticastSocket/NoLoopbackPackets.java fails when rerun
chegar
parents: 2
diff changeset
   123
            if (msock != null) try { msock.close(); } catch (Exception e) {}
40534
bc3e5bbcb65e 8164592: java/net/MulticastSocket/NoLoopbackPackets.java tests may leave a daemon thread
asmotrak
parents: 7668
diff changeset
   124
            if (sender != null) {
bc3e5bbcb65e 8164592: java/net/MulticastSocket/NoLoopbackPackets.java tests may leave a daemon thread
asmotrak
parents: 7668
diff changeset
   125
                sender.stop();
bc3e5bbcb65e 8164592: java/net/MulticastSocket/NoLoopbackPackets.java tests may leave a daemon thread
asmotrak
parents: 7668
diff changeset
   126
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        }
55649
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
   128
        try {
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
   129
            if (failedGroups.size() > 0) {
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
   130
                System.out.println("We should not receive anything from following groups, but we did:");
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
   131
                for (SocketAddress group : failedGroups)
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
   132
                    System.out.println(group);
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
   133
                throw new RuntimeException("test failed.");
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
   134
            }
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
   135
        } finally {
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
   136
            if (senderThread != null) {
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
   137
                senderThread.join();
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
   138
            }
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
   139
        }
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
   140
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
55649
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
   142
    static boolean expected(byte[] data, int len, byte[] expected) {
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
   143
        if (len != expected.length) return false;
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
   144
        for (int i = 0; i < len; i++) {
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
   145
            if (data[i] != expected[i]) return false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        }
55649
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
   147
        return true;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
5143
a1682a41e70f 6933618: java/net/MulticastSocket/NoLoopbackPackets.java fails when rerun
chegar
parents: 2
diff changeset
   149
a1682a41e70f 6933618: java/net/MulticastSocket/NoLoopbackPackets.java fails when rerun
chegar
parents: 2
diff changeset
   150
    static class Sender implements Runnable {
a1682a41e70f 6933618: java/net/MulticastSocket/NoLoopbackPackets.java fails when rerun
chegar
parents: 2
diff changeset
   151
        private List<SocketAddress> sendToGroups;
40534
bc3e5bbcb65e 8164592: java/net/MulticastSocket/NoLoopbackPackets.java tests may leave a daemon thread
asmotrak
parents: 7668
diff changeset
   152
        private volatile boolean stop;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
5143
a1682a41e70f 6933618: java/net/MulticastSocket/NoLoopbackPackets.java fails when rerun
chegar
parents: 2
diff changeset
   154
        public Sender(List<SocketAddress> groups) {
a1682a41e70f 6933618: java/net/MulticastSocket/NoLoopbackPackets.java fails when rerun
chegar
parents: 2
diff changeset
   155
            sendToGroups = groups;
a1682a41e70f 6933618: java/net/MulticastSocket/NoLoopbackPackets.java fails when rerun
chegar
parents: 2
diff changeset
   156
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
5143
a1682a41e70f 6933618: java/net/MulticastSocket/NoLoopbackPackets.java fails when rerun
chegar
parents: 2
diff changeset
   158
        public void run() {
55649
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
   159
            byte[] buf = MESSAGE.getBytes();
5143
a1682a41e70f 6933618: java/net/MulticastSocket/NoLoopbackPackets.java fails when rerun
chegar
parents: 2
diff changeset
   160
            List<DatagramPacket> packets = new ArrayList<DatagramPacket>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
55649
ad8e3b295615 8227539: Replace wildcard address with loopback or local host in tests - part 20
dfuchs
parents: 54770
diff changeset
   162
            try (MulticastSocket msock = new MulticastSocket()) {
5143
a1682a41e70f 6933618: java/net/MulticastSocket/NoLoopbackPackets.java fails when rerun
chegar
parents: 2
diff changeset
   163
                for (SocketAddress group : sendToGroups) {
a1682a41e70f 6933618: java/net/MulticastSocket/NoLoopbackPackets.java fails when rerun
chegar
parents: 2
diff changeset
   164
                    DatagramPacket packet = new DatagramPacket(buf, buf.length, group);
a1682a41e70f 6933618: java/net/MulticastSocket/NoLoopbackPackets.java fails when rerun
chegar
parents: 2
diff changeset
   165
                    packets.add(packet);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
5143
a1682a41e70f 6933618: java/net/MulticastSocket/NoLoopbackPackets.java fails when rerun
chegar
parents: 2
diff changeset
   168
                msock.setLoopbackMode(true);    // disable loopback mode
40534
bc3e5bbcb65e 8164592: java/net/MulticastSocket/NoLoopbackPackets.java tests may leave a daemon thread
asmotrak
parents: 7668
diff changeset
   169
                while (!stop) {
5143
a1682a41e70f 6933618: java/net/MulticastSocket/NoLoopbackPackets.java fails when rerun
chegar
parents: 2
diff changeset
   170
                    for (DatagramPacket packet : packets) {
a1682a41e70f 6933618: java/net/MulticastSocket/NoLoopbackPackets.java fails when rerun
chegar
parents: 2
diff changeset
   171
                        msock.send(packet);
a1682a41e70f 6933618: java/net/MulticastSocket/NoLoopbackPackets.java fails when rerun
chegar
parents: 2
diff changeset
   172
                    }
a1682a41e70f 6933618: java/net/MulticastSocket/NoLoopbackPackets.java fails when rerun
chegar
parents: 2
diff changeset
   173
a1682a41e70f 6933618: java/net/MulticastSocket/NoLoopbackPackets.java fails when rerun
chegar
parents: 2
diff changeset
   174
                    Thread.sleep(1000);     // 1 second
a1682a41e70f 6933618: java/net/MulticastSocket/NoLoopbackPackets.java fails when rerun
chegar
parents: 2
diff changeset
   175
                }
a1682a41e70f 6933618: java/net/MulticastSocket/NoLoopbackPackets.java fails when rerun
chegar
parents: 2
diff changeset
   176
            } catch (Exception e) {
a1682a41e70f 6933618: java/net/MulticastSocket/NoLoopbackPackets.java fails when rerun
chegar
parents: 2
diff changeset
   177
                throw new RuntimeException(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        }
40534
bc3e5bbcb65e 8164592: java/net/MulticastSocket/NoLoopbackPackets.java tests may leave a daemon thread
asmotrak
parents: 7668
diff changeset
   180
bc3e5bbcb65e 8164592: java/net/MulticastSocket/NoLoopbackPackets.java tests may leave a daemon thread
asmotrak
parents: 7668
diff changeset
   181
        void stop() {
bc3e5bbcb65e 8164592: java/net/MulticastSocket/NoLoopbackPackets.java tests may leave a daemon thread
asmotrak
parents: 7668
diff changeset
   182
            stop = true;
bc3e5bbcb65e 8164592: java/net/MulticastSocket/NoLoopbackPackets.java tests may leave a daemon thread
asmotrak
parents: 7668
diff changeset
   183
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
}