Path: blob/master/test/jdk/java/net/SocketOption/SupportedOptionsSet.java
41149 views
/*1* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.io.IOException;24import java.net.ServerSocket;25import java.net.Socket;26import java.util.Set;27import static java.lang.System.out;28import jdk.test.lib.net.IPSupport;2930/*31* @test32* @bug 814392333* @library /test/lib34* @summary java.net socket supportedOptions set depends on call order35* @run main/othervm SupportedOptionsSet first36* @run main/othervm SupportedOptionsSet second37* @run main/othervm -Djava.net.preferIPv4Stack=true SupportedOptionsSet first38* @run main/othervm -Djava.net.preferIPv4Stack=true SupportedOptionsSet second39*/4041// Run with othervm as the implementation of the supported options sets, once42// calculated, stores them in a private static fields.4344public class SupportedOptionsSet {4546public static void main(String[] args) throws IOException {47IPSupport.throwSkippedExceptionIfNonOperational();4849if (args[0].equals("first"))50first();51else if (args[0].equals("second"))52second();53}5455static void first() throws IOException {56try (Socket s = new Socket();57ServerSocket ss = new ServerSocket())58{59Set<?> first = s.supportedOptions();60Set<?> second = ss.supportedOptions();61assertNotEqual(first, second,62"Socket and ServerSocket should have different options.");63}64}6566/** Tests with the order of access to supportedOptions reversed. */67static void second() throws IOException {68try (ServerSocket ss = new ServerSocket();69Socket s = new Socket())70{71Set<?> first = ss.supportedOptions();72Set<?> second = s.supportedOptions();73assertNotEqual(first, second,74"ServerSocket and Socket should have different options.");75}76}7778static void assertNotEqual(Set<?> s1, Set<?> s2, String message) {79if (s1.equals(s2)) {80out.println("s1: " + s1);81out.println("s2: " + s2);82throw new RuntimeException(message);83}84}85}868788