8181393: Refactor shell test Selector/lots_of_updates.sh and SocketChannel/Open.sh to java

Reviewed-by: psandoz
This commit is contained in:
Amy Lu 2017-06-05 14:07:07 +08:00
parent ee7be117f9
commit 143bb171a7
6 changed files with 107 additions and 97 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -21,8 +21,10 @@
* questions.
*/
import java.nio.channels.*;
import java.io.IOException;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.SocketChannel;
public class LotsOfUpdates {
public static void main(String[] args) throws IOException {

View File

@ -0,0 +1,49 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6824477
* @summary Selector.select can fail with IOException "Invalid argument" on
* Solaris if maximum number of file descriptors is less than 10000
* @requires (os.family != "windows")
* @library /test/lib
* @build LotsOfUpdates
* @run main LotsOfUpdatesTest
*/
import jdk.test.lib.process.ProcessTools;
public class LotsOfUpdatesTest {
//hard limit needs to be less than 10000 for this bug
private static final String ULIMIT_SET_CMD = "ulimit -n 2048";
private static final String JAVA_CMD = ProcessTools.getCommandLine(
ProcessTools.createJavaProcessBuilder(LotsOfUpdates.class.getName()));
public static void main(String[] args) throws Throwable {
ProcessTools.executeCommand("sh", "-c", ULIMIT_SET_CMD + " && " + JAVA_CMD)
.shouldHaveExitValue(0);
}
}

View File

@ -1,49 +0,0 @@
#
# Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#
# @test
# @bug 6824477
# @summary Selector.select can fail with IOException "Invalid argument" on
# Solaris if maximum number of file descriptors is less than 10000
# @build LotsOfUpdates
# @run shell lots_of_updates.sh
OS=`uname -s`
case "$OS" in
Windows_* | CYGWIN* )
echo "ulimit not on Windows"
exit 0
;;
* )
CLASSPATH=${TESTCLASSES}:${TESTSRC}
;;
esac
export CLASSPATH
# hard limit needs to be less than 10000 for this bug
NOFILES=`ulimit -n -H`
if [ "$NOFILES" = "unlimited" ] || [ $NOFILES -ge 10000 ]; then
ulimit -n 2048
fi
${TESTJAVA}/bin/java ${TESTVMOPTS} LotsOfUpdates

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2007, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -21,16 +21,11 @@
* questions.
*/
/* @test
* @bug 4614065
* @summary Test SocketChannel gc after running out of fds
* @build Open
* @run shell Open.sh
*/
import java.net.*;
import java.nio.*;
import java.nio.channels.*;
import java.net.SocketException;
import java.nio.channels.DatagramChannel;
import java.nio.channels.Pipe;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.nio.channels.spi.SelectorProvider;
public class Open {

View File

@ -1,35 +0,0 @@
#! /bin/sh
#
# Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#
#
OS=`uname -s`
case "$OS" in
SunOS )
ulimit -n 100
$TESTJAVA/bin/java ${TESTVMOPTS} -classpath $TESTCLASSES Open ;;
* )
echo "unrecognized system: $OS" ;;
esac

View File

@ -0,0 +1,48 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 4614065
* @summary Test SocketChannel gc after running out of fds
* @requires (os.family == "solaris")
* @library /test/lib
* @build Open
* @run main OpenSocketChannelTest
*/
import jdk.test.lib.process.ProcessTools;
public class OpenSocketChannelTest {
//hard limit needs to be small for this bug
private static final String ULIMIT_SET_CMD = "ulimit -n 100";
private static final String JAVA_CMD = ProcessTools.getCommandLine(
ProcessTools.createJavaProcessBuilder(Open.class.getName()));
public static void main(String[] args) throws Throwable {
ProcessTools.executeCommand("sh", "-c", ULIMIT_SET_CMD + " && " + JAVA_CMD)
.shouldHaveExitValue(0);
}
}