jdk/test/com/sun/corba/transport/KeepAliveSockets.java
author mchung
Thu, 28 May 2015 10:54:48 -0700
changeset 30820 0d4717a011d3
parent 19801 97f3caac6c77
permissions -rw-r--r--
8081347: Add @modules to jdk_core tests Reviewed-by: alanb, joehw, lancea Contributed-by: alexander.kulyakhtin@oracle.com, alan.bateman@oracle.com, mandy.chung@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
19801
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
     1
/*
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
     4
 *
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
     7
 * published by the Free Software Foundation.
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
     8
 *
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    13
 * accompanied this code).
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    14
 *
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    18
 *
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    21
 * questions.
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    22
 */
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    23
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    24
/*
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    25
 * @test
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    26
 * @bug 8017195
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    27
 * @summary Introduce option to setKeepAlive parameter on CORBA sockets
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    28
 *
30820
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 19801
diff changeset
    29
 * @modules java.corba/com.sun.corba.se.impl.orb java.corba/com.sun.corba.se.impl.transport
19801
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    30
 * @run main/othervm KeepAliveSockets
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    31
 * @run main/othervm -Dcom.sun.CORBA.transport.enableTcpKeepAlive KeepAliveSockets
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    32
 * @run main/othervm -Dcom.sun.CORBA.transport.enableTcpKeepAlive=true KeepAliveSockets
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    33
 * @run main/othervm -Dcom.sun.CORBA.transport.enableTcpKeepAlive=false KeepAliveSockets
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    34
 */
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    35
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    36
import java.lang.*;
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    37
import java.net.InetSocketAddress;
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    38
import java.net.Socket;
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    39
import java.nio.channels.ServerSocketChannel;
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    40
import java.util.*;
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    41
import com.sun.corba.se.impl.orb.*;
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    42
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    43
import com.sun.corba.se.impl.transport.*;
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    44
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    45
public class KeepAliveSockets {
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    46
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    47
    public static void main(String[] args) throws Exception {
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    48
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    49
        boolean keepAlive = false;
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    50
        String prop = System.getProperty("com.sun.CORBA.transport.enableTcpKeepAlive");
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    51
        if (prop != null)
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    52
            keepAlive = !"false".equalsIgnoreCase(prop);
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    53
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    54
        DefaultSocketFactoryImpl sfImpl = new DefaultSocketFactoryImpl();
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    55
        ORBImpl orb = new ORBImpl();
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    56
        orb.set_parameters(null);
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    57
        sfImpl.setORB(orb);
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    58
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    59
        ServerSocketChannel ssc = ServerSocketChannel.open();
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    60
        ssc.socket().bind(new InetSocketAddress(0));
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    61
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    62
        InetSocketAddress isa = new InetSocketAddress("localhost", ssc.socket().getLocalPort());
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    63
        Socket s = sfImpl.createSocket("ignore", isa);
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    64
        System.out.println("Received factory socket" + s);
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    65
        if (keepAlive != s.getKeepAlive())
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    66
            throw new RuntimeException("KeepAlive value not honoured in CORBA socket");
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    67
    }
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    68
97f3caac6c77 8017195: Introduce option to setKeepAlive parameter on CORBA sockets
coffeys
parents:
diff changeset
    69
}