test/jdk/java/nio/channels/AsynchronousSocketChannel/Basic.java
changeset 50303 7164c3bb55df
parent 49840 799e6e42b95f
equal deleted inserted replaced
50302:fd2fccf3b079 50303:7164c3bb55df
    23 
    23 
    24 /* @test
    24 /* @test
    25  * @bug 4607272 6842687 6878369 6944810 7023403
    25  * @bug 4607272 6842687 6878369 6944810 7023403
    26  * @summary Unit test for AsynchronousSocketChannel(use -Dseed=X to set PRNG seed)
    26  * @summary Unit test for AsynchronousSocketChannel(use -Dseed=X to set PRNG seed)
    27  * @library /test/lib
    27  * @library /test/lib
       
    28  * @modules jdk.net
       
    29  * @key randomness intermittent
    28  * @build jdk.test.lib.RandomFactory jdk.test.lib.Utils
    30  * @build jdk.test.lib.RandomFactory jdk.test.lib.Utils
    29  * @run main/othervm/timeout=600 Basic -skipSlowConnectTest
    31  * @run main/othervm/timeout=600 Basic -skipSlowConnectTest
    30  * @key randomness intermittent
       
    31  */
    32  */
    32 
    33 
    33 import java.io.Closeable;
    34 import java.io.Closeable;
    34 import java.io.IOException;
    35 import java.io.IOException;
    35 import java.net.*;
    36 import java.net.*;
    39 import java.util.Random;
    40 import java.util.Random;
    40 import java.util.Set;
    41 import java.util.Set;
    41 import java.util.concurrent.*;
    42 import java.util.concurrent.*;
    42 import java.util.concurrent.atomic.*;
    43 import java.util.concurrent.atomic.*;
    43 import jdk.test.lib.RandomFactory;
    44 import jdk.test.lib.RandomFactory;
       
    45 import java.util.List;
       
    46 import static jdk.net.ExtendedSocketOptions.TCP_KEEPCOUNT;
       
    47 import static jdk.net.ExtendedSocketOptions.TCP_KEEPIDLE;
       
    48 import static jdk.net.ExtendedSocketOptions.TCP_KEEPINTERVAL;
    44 
    49 
    45 public class Basic {
    50 public class Basic {
    46     private static final Random RAND = RandomFactory.getRandom();
    51     private static final Random RAND = RandomFactory.getRandom();
    47 
    52 
    48     static boolean skipSlowConnectTest = false;
    53     static boolean skipSlowConnectTest = false;
   181                 if (ch.getOption(SO_REUSEPORT))
   186                 if (ch.getOption(SO_REUSEPORT))
   182                     throw new RuntimeException("Default of SO_REUSEPORT should be 'false'");
   187                     throw new RuntimeException("Default of SO_REUSEPORT should be 'false'");
   183                 if (!ch.setOption(SO_REUSEPORT, true).getOption(SO_REUSEPORT))
   188                 if (!ch.setOption(SO_REUSEPORT, true).getOption(SO_REUSEPORT))
   184                     throw new RuntimeException("SO_REUSEPORT did not change");
   189                     throw new RuntimeException("SO_REUSEPORT did not change");
   185             }
   190             }
   186         }
   191             List<? extends SocketOption> extOptions = List.of(TCP_KEEPCOUNT,
   187     }
   192                     TCP_KEEPIDLE, TCP_KEEPINTERVAL);
   188 
   193             if (options.containsAll(extOptions)) {
       
   194                 ch.setOption(TCP_KEEPIDLE, 1234);
       
   195                 checkOption(ch, TCP_KEEPIDLE, 1234);
       
   196                 ch.setOption(TCP_KEEPINTERVAL, 123);
       
   197                 checkOption(ch, TCP_KEEPINTERVAL, 123);
       
   198                 ch.setOption(TCP_KEEPCOUNT, 7);
       
   199                 checkOption(ch, TCP_KEEPCOUNT, 7);
       
   200             }
       
   201         }
       
   202     }
       
   203 
       
   204     static void checkOption(AsynchronousSocketChannel sc, SocketOption name, Object expectedValue)
       
   205             throws IOException {
       
   206         Object value = sc.getOption(name);
       
   207         if (!value.equals(expectedValue)) {
       
   208             throw new RuntimeException("value not as expected");
       
   209         }
       
   210     }
   189     static void testConnect() throws Exception {
   211     static void testConnect() throws Exception {
   190         System.out.println("-- connect --");
   212         System.out.println("-- connect --");
   191 
   213 
   192         SocketAddress address;
   214         SocketAddress address;
   193 
   215