< prev index next >

test/java/nio/channels/spi/SelectorProvider/inheritedChannel/CloseTest.java

Print this page


   1 /*
   2  * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  *
  26  *
  27  * This unit test checks that closing the channel returned by
  28  * System.inheritedChannel closes the underlying network socket.
  29  *
  30  * The test launches the "echo service" with arguments to instruct the
  31  * service to close the channel after it receives a small message. The
  32  * service then delays/lingers for 15 seconds before shuting down. To
  33  * prove that the close works we check that we see EOF (meaning the
  34  * peer has closed the connection) in less than 15 seconds.
  35  */
  36 import java.nio.ByteBuffer;
  37 import java.nio.channels.*;


  38 
  39 public class CloseTest {
  40 
  41     public static void main(String args[]) throws Exception {
  42         String msg = "HELLO";
  43 
  44         // Launch the service with arguments to tell it to close
  45         // the connection after reading 5 bytes ("HELLO"). After
  46         // closing the connection the service should hang around
  47         // for 15 seconds.
  48 
  49         String service_args[] = new String[2];
  50         service_args[0] = String.valueOf(msg.length());
  51         service_args[1] = String.valueOf( 15*1000 );
  52 
  53 
  54         SocketChannel sc = Launcher.launchWithSocketChannel("EchoService", service_args);
  55 
  56         // send message - service will echo the message and close the connection.
  57 


   1 /*
   2  * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  *
  26  *
  27  * This unit test checks that closing the channel returned by
  28  * System.inheritedChannel closes the underlying network socket.
  29  *
  30  * The test launches the "echo service" with arguments to instruct the
  31  * service to close the channel after it receives a small message. The
  32  * service then delays/lingers for 15 seconds before shuting down. To
  33  * prove that the close works we check that we see EOF (meaning the
  34  * peer has closed the connection) in less than 15 seconds.
  35  */
  36 import java.nio.ByteBuffer;
  37 import java.nio.channels.SelectionKey;
  38 import java.nio.channels.Selector;
  39 import java.nio.channels.SocketChannel;
  40 
  41 public class CloseTest {
  42 
  43     public static void main(String args[]) throws Exception {
  44         String msg = "HELLO";
  45 
  46         // Launch the service with arguments to tell it to close
  47         // the connection after reading 5 bytes ("HELLO"). After
  48         // closing the connection the service should hang around
  49         // for 15 seconds.
  50 
  51         String service_args[] = new String[2];
  52         service_args[0] = String.valueOf(msg.length());
  53         service_args[1] = String.valueOf( 15*1000 );
  54 
  55 
  56         SocketChannel sc = Launcher.launchWithSocketChannel("EchoService", service_args);
  57 
  58         // send message - service will echo the message and close the connection.
  59 


< prev index next >