test/jdk/java/nio/channels/spi/SelectorProvider/inheritedChannel/CloseTest.java
changeset 51117 c96c7d08ae49
parent 47216 71c04702a3d5
equal deleted inserted replaced
51116:7e34f3da2293 51117:c96c7d08ae49
     1 /*
     1 /*
     2  * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    36 import java.nio.ByteBuffer;
    36 import java.nio.ByteBuffer;
    37 import java.nio.channels.SelectionKey;
    37 import java.nio.channels.SelectionKey;
    38 import java.nio.channels.Selector;
    38 import java.nio.channels.Selector;
    39 import java.nio.channels.SocketChannel;
    39 import java.nio.channels.SocketChannel;
    40 
    40 
       
    41 import jdk.test.lib.Utils;
       
    42 
    41 public class CloseTest {
    43 public class CloseTest {
    42 
    44 
    43     public static void main(String args[]) throws Exception {
    45     public static void main(String args[]) throws Exception {
    44         String msg = "HELLO";
    46         String msg = "HELLO";
    45 
    47 
    48         // closing the connection the service should hang around
    50         // closing the connection the service should hang around
    49         // for 15 seconds.
    51         // for 15 seconds.
    50 
    52 
    51         String service_args[] = new String[2];
    53         String service_args[] = new String[2];
    52         service_args[0] = String.valueOf(msg.length());
    54         service_args[0] = String.valueOf(msg.length());
    53         service_args[1] = String.valueOf( 15*1000 );
    55         service_args[1] = String.valueOf( Utils.adjustTimeout(15*1000) );
    54 
    56 
    55 
    57 
    56         SocketChannel sc = Launcher.launchWithSocketChannel("EchoService", service_args);
    58         SocketChannel sc = Launcher.launchWithSocketChannel("EchoService", service_args);
    57 
    59 
    58         // send message - service will echo the message and close the connection.
    60         // send message - service will echo the message and close the connection.
    63         ByteBuffer bb = ByteBuffer.allocateDirect(50);
    65         ByteBuffer bb = ByteBuffer.allocateDirect(50);
    64         sc.configureBlocking(false);
    66         sc.configureBlocking(false);
    65         Selector sel = sc.provider().openSelector();
    67         Selector sel = sc.provider().openSelector();
    66         SelectionKey sk = sc.register(sel, SelectionKey.OP_READ);
    68         SelectionKey sk = sc.register(sel, SelectionKey.OP_READ);
    67 
    69 
    68         long to = 12 * 1000;
    70         long to = Utils.adjustTimeout(12*1000);
    69         for (;;) {
    71         for (;;) {
    70             long st = System.currentTimeMillis();
    72             long st = System.currentTimeMillis();
    71             sel.select(to);
    73             sel.select(to);
    72             if (sk.isReadable()) {
    74             if (sk.isReadable()) {
    73                 int n = sc.read(bb);
    75                 int n = sc.read(bb);