author | jbhateja |
Tue, 26 Nov 2019 16:09:25 +0300 | |
changeset 59278 | 8375560db76b |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
7177
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
1 |
/* |
14342
8435a30053c1
7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents:
9687
diff
changeset
|
2 |
* Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. |
7177
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
4 |
* |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
8 |
* |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
13 |
* accompanied this code). |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
14 |
* |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
18 |
* |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
21 |
* questions. |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
22 |
*/ |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
23 |
|
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
24 |
/* @test |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
25 |
* @bug 6979009 |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
26 |
* @summary Ensure ClosedByInterruptException is thrown when I/O operation |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
27 |
* interrupted by Thread.interrupt |
30046 | 28 |
* @key randomness |
7177
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
29 |
*/ |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
30 |
|
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
31 |
import java.io.*; |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
32 |
import java.util.Random; |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
33 |
import java.nio.ByteBuffer; |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
34 |
import java.nio.channels.*; |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
35 |
|
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
36 |
public class ClosedByInterrupt { |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
37 |
|
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
38 |
static final int K = 1024; |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
39 |
static final Random rand = new Random(); |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
40 |
|
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
41 |
static volatile boolean failed; |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
42 |
|
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
43 |
public static void main(String[] args) throws Exception { |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
44 |
File f = File.createTempFile("blah", null); |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
45 |
f.deleteOnExit(); |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
46 |
|
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
47 |
// create 1MB file. |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
48 |
byte[] b = new byte[K*K]; |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
49 |
rand.nextBytes(b); |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
50 |
ByteBuffer bb = ByteBuffer.wrap(b); |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
51 |
try (FileChannel fc = new FileOutputStream(f).getChannel()) { |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
52 |
while (bb.hasRemaining()) |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
53 |
fc.write(bb); |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
54 |
} |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
55 |
|
9687
e41f9c6d9c0d
7043425: (fc) ClosedByInterruptException thrown but interrupt status not set
alanb
parents:
7177
diff
changeset
|
56 |
// test with 1-16 concurrent threads |
e41f9c6d9c0d
7043425: (fc) ClosedByInterruptException thrown but interrupt status not set
alanb
parents:
7177
diff
changeset
|
57 |
for (int i=1; i<=16; i++) { |
7177
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
58 |
System.out.format("%d thread(s)%n", i); |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
59 |
test(f, i); |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
60 |
if (failed) |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
61 |
break; |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
62 |
} |
9687
e41f9c6d9c0d
7043425: (fc) ClosedByInterruptException thrown but interrupt status not set
alanb
parents:
7177
diff
changeset
|
63 |
|
e41f9c6d9c0d
7043425: (fc) ClosedByInterruptException thrown but interrupt status not set
alanb
parents:
7177
diff
changeset
|
64 |
if (failed) |
e41f9c6d9c0d
7043425: (fc) ClosedByInterruptException thrown but interrupt status not set
alanb
parents:
7177
diff
changeset
|
65 |
throw new RuntimeException("Test failed"); |
7177
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
66 |
} |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
67 |
|
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
68 |
/** |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
69 |
* Starts "nThreads" that do I/O on the given file concurrently. Continuously |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
70 |
* interrupts one of the threads to cause the file to be closed and |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
71 |
* ClosedByInterruptException to be thrown. The other threads should "fail" with |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
72 |
* ClosedChannelException (or the more specific AsynchronousCloseException). |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
73 |
*/ |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
74 |
static void test(File f, int nThreads) throws Exception { |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
75 |
try (FileChannel fc = new RandomAccessFile(f, "rwd").getChannel()) { |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
76 |
Thread[] threads = new Thread[nThreads]; |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
77 |
|
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
78 |
// start threads |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
79 |
for (int i=0; i<nThreads; i++) { |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
80 |
boolean interruptible = (i==0); |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
81 |
ReaderWriter task = new ReaderWriter(fc, interruptible); |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
82 |
Thread t = new Thread(task); |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
83 |
t.start(); |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
84 |
threads[i] = t; |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
85 |
} |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
86 |
|
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
87 |
// give time for threads to start |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
88 |
Thread.sleep(500 + rand.nextInt(1000)); |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
89 |
|
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
90 |
// interrupt thread until channel is closed |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
91 |
while (fc.isOpen()) { |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
92 |
threads[0].interrupt(); |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
93 |
Thread.sleep(rand.nextInt(50)); |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
94 |
} |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
95 |
|
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
96 |
// wait for test to finish |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
97 |
for (int i=0; i<nThreads; i++) { |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
98 |
threads[i].join(); |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
99 |
} |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
100 |
} |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
101 |
} |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
102 |
|
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
103 |
/** |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
104 |
* A task that continuously reads or writes to random areas of a file |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
105 |
* until the channel is closed. An "interruptible" task expects the |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
106 |
* channel to be closed by an interupt, a "non-interruptible" thread |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
107 |
* does not. |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
108 |
*/ |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
109 |
static class ReaderWriter implements Runnable { |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
110 |
final FileChannel fc; |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
111 |
final boolean interruptible; |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
112 |
final boolean writer; |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
113 |
|
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
114 |
ReaderWriter(FileChannel fc, boolean interruptible) { |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
115 |
this.fc = fc; |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
116 |
this.interruptible = interruptible; |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
117 |
this.writer = rand.nextBoolean(); |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
118 |
} |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
119 |
|
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
120 |
public void run() { |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
121 |
ByteBuffer bb = ByteBuffer.allocate(K); |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
122 |
if (writer) |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
123 |
rand.nextBytes(bb.array()); |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
124 |
|
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
125 |
try { |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
126 |
for (;;) { |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
127 |
long position = rand.nextInt(K*K - bb.capacity()); |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
128 |
if (writer) { |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
129 |
bb.position(0).limit(bb.capacity()); |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
130 |
fc.write(bb, position); |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
131 |
} else { |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
132 |
bb.clear(); |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
133 |
fc.read(bb, position); |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
134 |
} |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
135 |
if (!interruptible) { |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
136 |
// give the interruptible thread a chance |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
137 |
try { |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
138 |
Thread.sleep(rand.nextInt(50)); |
9687
e41f9c6d9c0d
7043425: (fc) ClosedByInterruptException thrown but interrupt status not set
alanb
parents:
7177
diff
changeset
|
139 |
} catch (InterruptedException e) { |
e41f9c6d9c0d
7043425: (fc) ClosedByInterruptException thrown but interrupt status not set
alanb
parents:
7177
diff
changeset
|
140 |
unexpected(e); |
e41f9c6d9c0d
7043425: (fc) ClosedByInterruptException thrown but interrupt status not set
alanb
parents:
7177
diff
changeset
|
141 |
} |
7177
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
142 |
} |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
143 |
} |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
144 |
} catch (ClosedByInterruptException e) { |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
145 |
if (interruptible) { |
9687
e41f9c6d9c0d
7043425: (fc) ClosedByInterruptException thrown but interrupt status not set
alanb
parents:
7177
diff
changeset
|
146 |
if (Thread.interrupted()) { |
7177
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
147 |
expected(e + " thrown and interrupt status set"); |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
148 |
} else { |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
149 |
unexpected(e + " thrown but interrupt status not set"); |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
150 |
} |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
151 |
} else { |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
152 |
unexpected(e); |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
153 |
} |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
154 |
} catch (ClosedChannelException e) { |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
155 |
if (interruptible) { |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
156 |
unexpected(e); |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
157 |
} else { |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
158 |
expected(e); |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
159 |
} |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
160 |
} catch (Exception e) { |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
161 |
unexpected(e); |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
162 |
} |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
163 |
} |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
164 |
} |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
165 |
|
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
166 |
static void expected(Exception e) { |
9687
e41f9c6d9c0d
7043425: (fc) ClosedByInterruptException thrown but interrupt status not set
alanb
parents:
7177
diff
changeset
|
167 |
System.out.format("%s (expected)%n", e); |
7177
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
168 |
} |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
169 |
|
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
170 |
static void expected(String msg) { |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
171 |
System.out.format("%s (expected)%n", msg); |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
172 |
} |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
173 |
|
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
174 |
static void unexpected(Exception e) { |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
175 |
System.err.format("%s (not expected)%n", e); |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
176 |
failed = true; |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
177 |
} |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
178 |
|
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
179 |
static void unexpected(String msg) { |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
180 |
System.err.println(msg); |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
181 |
failed = true; |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
182 |
} |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
diff
changeset
|
183 |
} |