/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/* @test
* @bug 6913877
* @summary Stress AsynchronousFileChannel.write
*/
public class LotsOfWrites {
/**
* Asynchronously writes a known pattern to a file up to a given size,
* counting down a latch to release waiters when done.
*/
private final long size;
private volatile long position;
private volatile byte nextByte;
return position;
}
for (int i=0; i<n; i++) {
}
return buf;
}
// close channel and release any waiters
private void done() {
try {
} catch (IOException ignore) { }
}
}
return file;
}
long size() {
return size;
}
// initiate first write
void start() {
}
if (!buf.hasRemaining()) {
// buffer has been completely written; decide if we need to
// write more
done();
return;
}
buf = genNextBuffer();
}
}
done();
}
}
// random number of writers
// initiate writing to each file
for (int i=0; i<count; i++) {
blah.deleteOnExit();
}
// wait for writing to complete
// verify content of each file
boolean failed = false;
byte[] buf = new byte[8192];
for (int i=0; i<count ;i++) {
try {
long size = 0L;
byte expected = 0;
while (nread > 0) {
for (int j=0; j<nread; j++) {
failed = true;
break;
}
expected++;
}
if (failed)
break;
}
failed = true;
}
if (failed)
break;
} finally {
}
}
// clean-up
for (int i=0; i<count; i++) {
}
if (failed)
throw new RuntimeException("Test failed");
}
}