author | bpb |
Fri, 28 Apr 2017 16:14:57 -0700 | |
changeset 44857 | 9b65ef2c7ae9 |
parent 44266 | 2b9cc0e5e79f |
permissions | -rw-r--r-- |
32774 | 1 |
/* |
44266
2b9cc0e5e79f
8176846: (fc) Increase timeouts of and instrument some tests using FileChannel#write
bpb
parents:
44107
diff
changeset
|
2 |
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. |
32774 | 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 |
* @test |
|
32836
68073065a22f
8137230: TEST_BUG: java/nio/channels/FileChannel/LoopingTruncate.java timed out
igerasim
parents:
32774
diff
changeset
|
26 |
* @bug 8137121 8137230 |
32774 | 27 |
* @summary (fc) Infinite loop FileChannel.truncate |
32836
68073065a22f
8137230: TEST_BUG: java/nio/channels/FileChannel/LoopingTruncate.java timed out
igerasim
parents:
32774
diff
changeset
|
28 |
* @library /lib/testlibrary |
68073065a22f
8137230: TEST_BUG: java/nio/channels/FileChannel/LoopingTruncate.java timed out
igerasim
parents:
32774
diff
changeset
|
29 |
* @build jdk.testlibrary.Utils |
44266
2b9cc0e5e79f
8176846: (fc) Increase timeouts of and instrument some tests using FileChannel#write
bpb
parents:
44107
diff
changeset
|
30 |
* @run main/othervm/timeout=300 LoopingTruncate |
32774 | 31 |
*/ |
32 |
||
33 |
import java.nio.ByteBuffer; |
|
34 |
import java.nio.channels.FileChannel; |
|
32836
68073065a22f
8137230: TEST_BUG: java/nio/channels/FileChannel/LoopingTruncate.java timed out
igerasim
parents:
32774
diff
changeset
|
35 |
import java.nio.channels.ClosedByInterruptException; |
32774 | 36 |
import java.nio.file.Files; |
37 |
import java.nio.file.Path; |
|
38 |
import static java.nio.file.StandardOpenOption.*; |
|
44266
2b9cc0e5e79f
8176846: (fc) Increase timeouts of and instrument some tests using FileChannel#write
bpb
parents:
44107
diff
changeset
|
39 |
import java.util.concurrent.TimeUnit; |
32836
68073065a22f
8137230: TEST_BUG: java/nio/channels/FileChannel/LoopingTruncate.java timed out
igerasim
parents:
32774
diff
changeset
|
40 |
import static jdk.testlibrary.Utils.adjustTimeout; |
32774 | 41 |
|
42 |
public class LoopingTruncate { |
|
43 |
||
44 |
// (int)FATEFUL_SIZE == -3 == IOStatus.INTERRUPTED |
|
45 |
static long FATEFUL_SIZE = 0x1FFFFFFFDL; |
|
46 |
||
32836
68073065a22f
8137230: TEST_BUG: java/nio/channels/FileChannel/LoopingTruncate.java timed out
igerasim
parents:
32774
diff
changeset
|
47 |
// At least 20 seconds |
68073065a22f
8137230: TEST_BUG: java/nio/channels/FileChannel/LoopingTruncate.java timed out
igerasim
parents:
32774
diff
changeset
|
48 |
static long TIMEOUT = adjustTimeout(20_000); |
32774 | 49 |
|
50 |
public static void main(String[] args) throws Throwable { |
|
51 |
Path path = Files.createTempFile("LoopingTruncate.tmp", null); |
|
32836
68073065a22f
8137230: TEST_BUG: java/nio/channels/FileChannel/LoopingTruncate.java timed out
igerasim
parents:
32774
diff
changeset
|
52 |
try (FileChannel fc = FileChannel.open(path, CREATE, WRITE)) { |
68073065a22f
8137230: TEST_BUG: java/nio/channels/FileChannel/LoopingTruncate.java timed out
igerasim
parents:
32774
diff
changeset
|
53 |
fc.position(FATEFUL_SIZE + 1L); |
44266
2b9cc0e5e79f
8176846: (fc) Increase timeouts of and instrument some tests using FileChannel#write
bpb
parents:
44107
diff
changeset
|
54 |
System.out.println(" Writing large file..."); |
2b9cc0e5e79f
8176846: (fc) Increase timeouts of and instrument some tests using FileChannel#write
bpb
parents:
44107
diff
changeset
|
55 |
long t0 = System.nanoTime(); |
32836
68073065a22f
8137230: TEST_BUG: java/nio/channels/FileChannel/LoopingTruncate.java timed out
igerasim
parents:
32774
diff
changeset
|
56 |
fc.write(ByteBuffer.wrap(new byte[] {0})); |
44266
2b9cc0e5e79f
8176846: (fc) Increase timeouts of and instrument some tests using FileChannel#write
bpb
parents:
44107
diff
changeset
|
57 |
long t1 = System.nanoTime(); |
2b9cc0e5e79f
8176846: (fc) Increase timeouts of and instrument some tests using FileChannel#write
bpb
parents:
44107
diff
changeset
|
58 |
System.out.printf(" Wrote large file in %d ns (%d ms) %n", |
2b9cc0e5e79f
8176846: (fc) Increase timeouts of and instrument some tests using FileChannel#write
bpb
parents:
44107
diff
changeset
|
59 |
t1 - t0, TimeUnit.NANOSECONDS.toMillis(t1 - t0)); |
32836
68073065a22f
8137230: TEST_BUG: java/nio/channels/FileChannel/LoopingTruncate.java timed out
igerasim
parents:
32774
diff
changeset
|
60 |
|
32774 | 61 |
Thread th = new Thread(() -> { |
32836
68073065a22f
8137230: TEST_BUG: java/nio/channels/FileChannel/LoopingTruncate.java timed out
igerasim
parents:
32774
diff
changeset
|
62 |
try { |
44266
2b9cc0e5e79f
8176846: (fc) Increase timeouts of and instrument some tests using FileChannel#write
bpb
parents:
44107
diff
changeset
|
63 |
System.out.println(" Truncating large file..."); |
2b9cc0e5e79f
8176846: (fc) Increase timeouts of and instrument some tests using FileChannel#write
bpb
parents:
44107
diff
changeset
|
64 |
long t2 = System.nanoTime(); |
32774 | 65 |
fc.truncate(FATEFUL_SIZE); |
44266
2b9cc0e5e79f
8176846: (fc) Increase timeouts of and instrument some tests using FileChannel#write
bpb
parents:
44107
diff
changeset
|
66 |
long t3 = System.nanoTime(); |
2b9cc0e5e79f
8176846: (fc) Increase timeouts of and instrument some tests using FileChannel#write
bpb
parents:
44107
diff
changeset
|
67 |
System.out.printf(" Truncated large file in %d ns (%d ms) %n", |
2b9cc0e5e79f
8176846: (fc) Increase timeouts of and instrument some tests using FileChannel#write
bpb
parents:
44107
diff
changeset
|
68 |
t3 - t2, TimeUnit.NANOSECONDS.toMillis(t3 - t2)); |
32836
68073065a22f
8137230: TEST_BUG: java/nio/channels/FileChannel/LoopingTruncate.java timed out
igerasim
parents:
32774
diff
changeset
|
69 |
} catch (ClosedByInterruptException ignore) { |
32774 | 70 |
} catch (Exception e) { |
71 |
throw new RuntimeException(e); |
|
72 |
}}); |
|
73 |
th.start(); |
|
74 |
th.join(TIMEOUT); |
|
75 |
||
76 |
if (th.isAlive()) { |
|
32836
68073065a22f
8137230: TEST_BUG: java/nio/channels/FileChannel/LoopingTruncate.java timed out
igerasim
parents:
32774
diff
changeset
|
77 |
System.err.println("=== Stack trace of the guilty thread:"); |
68073065a22f
8137230: TEST_BUG: java/nio/channels/FileChannel/LoopingTruncate.java timed out
igerasim
parents:
32774
diff
changeset
|
78 |
for (StackTraceElement el : th.getStackTrace()) { |
68073065a22f
8137230: TEST_BUG: java/nio/channels/FileChannel/LoopingTruncate.java timed out
igerasim
parents:
32774
diff
changeset
|
79 |
System.err.println("\t" + el); |
68073065a22f
8137230: TEST_BUG: java/nio/channels/FileChannel/LoopingTruncate.java timed out
igerasim
parents:
32774
diff
changeset
|
80 |
} |
68073065a22f
8137230: TEST_BUG: java/nio/channels/FileChannel/LoopingTruncate.java timed out
igerasim
parents:
32774
diff
changeset
|
81 |
System.err.println("==="); |
68073065a22f
8137230: TEST_BUG: java/nio/channels/FileChannel/LoopingTruncate.java timed out
igerasim
parents:
32774
diff
changeset
|
82 |
|
32774 | 83 |
th.interrupt(); |
32836
68073065a22f
8137230: TEST_BUG: java/nio/channels/FileChannel/LoopingTruncate.java timed out
igerasim
parents:
32774
diff
changeset
|
84 |
th.join(); |
32774 | 85 |
throw new RuntimeException("Failed to complete on time"); |
86 |
} |
|
87 |
} finally { |
|
88 |
Files.deleteIfExists(path); |
|
89 |
} |
|
43816
1f49172925e2
8175041: Add success message to java/nio/channels/FileChannel/LoopingTruncate.java
bpb
parents:
32836
diff
changeset
|
90 |
|
1f49172925e2
8175041: Add success message to java/nio/channels/FileChannel/LoopingTruncate.java
bpb
parents:
32836
diff
changeset
|
91 |
System.out.println("Test succeeded."); |
1f49172925e2
8175041: Add success message to java/nio/channels/FileChannel/LoopingTruncate.java
bpb
parents:
32836
diff
changeset
|
92 |
System.out.flush(); |
32774 | 93 |
} |
94 |
} |