Lines 241-246
Link Here
|
241 |
} |
241 |
} |
242 |
} |
242 |
} |
243 |
|
243 |
|
|
|
244 |
|
245 |
/** Test whether the read is forbiden while somebody is writing |
246 |
*/ |
247 |
public void testWriteReadExclusion () throws Exception { |
248 |
checkSetUp(); |
249 |
FileObject fold = getTestFolder1(root); |
250 |
final FileObject fo1 = getTestFile1(fold); |
251 |
|
252 |
String testStr = "text"; |
253 |
|
254 |
try { |
255 |
writeStr(fo1, testStr); |
256 |
} catch (IOException iex) { |
257 |
fsAssert( |
258 |
"expected move will success on writable FS", |
259 |
fs.isReadOnly() || fo1.isReadOnly() |
260 |
); |
261 |
return; |
262 |
} |
263 |
|
264 |
|
265 |
class DoWorkInOtherThread implements Runnable { |
266 |
Exception ex; |
267 |
|
268 |
public void run () { |
269 |
try { |
270 |
FileLock lock = fo1.lock(); |
271 |
|
272 |
OutputStream os = fo1.getOutputStream (lock); |
273 |
os.write (1); |
274 |
os.write (2); |
275 |
os.flush (); |
276 |
|
277 |
synchronized (this) { |
278 |
notify (); |
279 |
// block for a while so the other thread |
280 |
// can do the partial read |
281 |
wait (1000); |
282 |
} |
283 |
|
284 |
os.write (3); |
285 |
os.write (4); |
286 |
os.close (); |
287 |
|
288 |
lock.releaseLock(); |
289 |
} catch (Exception ex) { |
290 |
this.ex = ex; |
291 |
} |
292 |
} |
293 |
|
294 |
public void executeDirectly () throws Exception { |
295 |
synchronized (this) { |
296 |
new RequestProcessor ("Writes with delay").post (this); |
297 |
wait (); |
298 |
} |
299 |
|
300 |
try { |
301 |
InputStream is = fo1.getInputStream (); |
302 |
byte[] arr = new byte[200]; |
303 |
int len = is.read (arr); |
304 |
assertEquals ("Read all four bytes", 4, len); |
305 |
for (int i = 0; i < 4; i++) { |
306 |
assertEquals (i + " th byte is " + i, i, arr[i]); |
307 |
} |
308 |
} catch (InterruptedIOException ex) { |
309 |
// InterruptedIOException is fine, means we could not read the stream |
310 |
} finally { |
311 |
synchronized (this) { |
312 |
// let the writer thread finish |
313 |
notifyAll (); |
314 |
} |
315 |
} |
316 |
} |
317 |
} |
318 |
|
319 |
|
320 |
DoWorkInOtherThread d = new DoWorkInOtherThread (); |
321 |
d.executeDirectly (); |
322 |
} |
323 |
|
244 |
public void testGetPath1() { |
324 |
public void testGetPath1() { |
245 |
checkSetUp(); |
325 |
checkSetUp(); |
246 |
FileObject fold1 = getTestFolder1(root); |
326 |
FileObject fold1 = getTestFolder1(root); |