}
public void testBucketToRAFFreeWhileFile() throws IOException {
int len = 4095;
Random r = new Random(21162101);
TempBucket bucket = (TempBucket) factory.makeBucket(1024);
byte[] buf = new byte[len];
r.nextBytes(buf);
OutputStream os = bucket.getOutputStream();
os.write(buf.clone());
os.close();
assertTrue(bucket.isRAMBucket());
assertEquals(len, bucket.size());
bucket.getInputStream().close();
TempRandomAccessBuffer raf = (TempRandomAccessBuffer) bucket.toRandomAccessBuffer();
assertTrue(raf.migrateToDisk());
assertFalse(raf.migrateToDisk());
assertFalse(bucket.migrateToDisk());
assertTrue(raf.hasMigrated());
File f = ((PooledFileRandomAccessBuffer) raf.getUnderlying()).file;
assertTrue(f.exists());
bucket.free();
assertFalse(f.exists());
try {
raf.pread(0, new byte[len], 0, buf.length);
fail();
} catch (IOException e) {
// Ok.
}
try {
bucket.getInputStream();
fail();
} catch(IOException e) {
// Ok.
}
}