author | aefimov |
Fri, 16 Aug 2013 18:41:35 +0400 | |
changeset 19433 | 2dade0de0206 |
permissions | -rw-r--r-- |
19433
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
1 |
/* |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
4 |
* |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
8 |
* |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
13 |
* accompanied this code). |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
14 |
* |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
18 |
* |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
21 |
* questions. |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
22 |
*/ |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
23 |
|
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
24 |
/* |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
25 |
* @test |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
26 |
* @bug 8021820 |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
27 |
* @summary The total number of file descriptors is limited to |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
28 |
* 1024(FDSET_SIZE) on MacOSX (the size of fd array passed to select() |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
29 |
* call in java.net classes is limited to this value). |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
30 |
* @run main/othervm SelectFdsLimit |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
31 |
* @author aleksej.efimov@oracle.com |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
32 |
*/ |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
33 |
|
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
34 |
import java.io.File; |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
35 |
import java.io.FileInputStream; |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
36 |
import java.io.FileNotFoundException; |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
37 |
import java.io.IOException; |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
38 |
import java.io.InputStream; |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
39 |
import java.net.ServerSocket; |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
40 |
import java.net.SocketTimeoutException; |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
41 |
|
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
42 |
|
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
43 |
/* |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
44 |
* Test must be run in othervm mode to ensure that all files |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
45 |
* opened by openFiles() are closed propertly. |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
46 |
*/ |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
47 |
public class SelectFdsLimit { |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
48 |
static final int FDTOOPEN = 1023; |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
49 |
static final String TESTFILE = "testfile"; |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
50 |
static FileInputStream [] testFIS; |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
51 |
|
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
52 |
static void prepareTestEnv() throws IOException { |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
53 |
File fileToCreate = new File(TESTFILE); |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
54 |
if (!fileToCreate.exists()) |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
55 |
if (!fileToCreate.createNewFile()) |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
56 |
throw new RuntimeException("Can't create test file"); |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
57 |
} |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
58 |
|
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
59 |
//If there will be some problem (i.e. ulimits on number of opened files will fail) |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
60 |
//then this method will fail with exception and test will be considered as |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
61 |
//failed. But allocated fds will be released because the test is executed by |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
62 |
//dedicated VM (@run main/othervm). |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
63 |
static void openFiles(int fn, File f) throws FileNotFoundException, IOException { |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
64 |
testFIS = new FileInputStream[FDTOOPEN]; |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
65 |
for (;;) { |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
66 |
if (0 == fn) |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
67 |
break; |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
68 |
FileInputStream fis = new FileInputStream(f); |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
69 |
testFIS[--fn] = fis; |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
70 |
} |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
71 |
} |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
72 |
|
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
73 |
public static void main(String [] args) throws IOException, FileNotFoundException { |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
74 |
|
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
75 |
//The bug 8021820 is a Mac specific and because of that test will pass on all |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
76 |
//other platforms |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
77 |
if (!System.getProperty("os.name").contains("OS X")) { |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
78 |
return; |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
79 |
} |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
80 |
|
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
81 |
//Create test directory with test files |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
82 |
prepareTestEnv(); |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
83 |
|
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
84 |
//Consume FD ids for this java process to overflow the 1024 |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
85 |
openFiles(FDTOOPEN,new File(TESTFILE)); |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
86 |
|
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
87 |
//Wait for incoming connection and make the select() used in java.net |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
88 |
//classes fail the limitation on FDSET_SIZE |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
89 |
ServerSocket socket = new ServerSocket(0); |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
90 |
|
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
91 |
//Set the minimal timeout, no one is |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
92 |
//going to connect to this server socket |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
93 |
socket.setSoTimeout(1); |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
94 |
|
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
95 |
// The accept() call will throw SocketException if the |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
96 |
// select() has failed due to limitation on fds size, |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
97 |
// indicating test failure. A SocketTimeoutException |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
98 |
// is expected, so it is caught and ignored, and the test |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
99 |
// passes. |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
100 |
try { |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
101 |
socket.accept(); |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
102 |
} catch (SocketTimeoutException e) { } |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
103 |
} |
2dade0de0206
8021820: Number of opened files used in select() is limited to 1024 [macosx]
aefimov
parents:
diff
changeset
|
104 |
} |