/*
* 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 4607272 6814948 6842687
* @summary Unit test for AsynchronousFileChannel#lock method
*/
public class Lock {
}
try {
// create temporary file
blah.deleteOnExit();
// run tests
// eagerly clean-up
} finally {
}
}
// test locking protocol
throws Exception
{
// slave VM opens file and acquires exclusive lock
// this VM tries to acquire lock
// (lock should not be acquire until released by slave VM)
try {
throw new RuntimeException("Timeout expected");
} catch (TimeoutException x) {
}
// slave VM releases lock
// this VM should now acquire lock
// slave VM acquires lock on range
// this VM acquires lock on non-overlapping range
// done
}
// test close of channel with outstanding lock operation
// slave VM opens file and acquires exclusive lock
for (int i=0; i<100; i++) {
// try to lock file (should not complete because file is locked by slave)
try {
throw new RuntimeException("Timeout expected");
} catch (TimeoutException x) {
}
// close channel with lock operation outstanding
// operation should complete with AsynchronousCloseException
try {
throw new RuntimeException("ExecutionException expected");
} catch (ExecutionException x) {
if (!(x.getCause() instanceof AsynchronousCloseException)) {
x.getCause().printStackTrace();
throw new RuntimeException("AsynchronousCloseException expected");
}
}
}
}
// starts a "lock slave" in another process, returning a mirror object to
// control the slave
if (testClasses != null)
// wait for slave to connect
return new LockSlaveMirror(sc);
}
// commands that the slave understands
// provides a proxy to a "lock slave"
static class LockSlaveMirror {
}
throws IOException
{
cmd += " " + s;
}
cmd += TERMINATOR;
while (buf.hasRemaining()) {
}
// wait for ack
if (n != 1)
throw new RuntimeException("Reply expected");
throw new RuntimeException("Terminated expected");
}
return this;
}
}
return this;
}
throws IOException
{
return this;
}
return this;
}
}
}
// Helper class to direct process output to the parent System.out
}
}
public void run() {
try {
byte b[] = new byte[100];
for (;;) {
if (n < 0) return;
for (int i=0; i<n; i++) {
}
}
} catch (IOException ioe) { }
}
}
// slave process that responds to simple commands a socket connection
// establish connection to parent
try {
for (;;) {
// read command (ends with ";")
int n, last = 0;
do {
if (n < 0)
return;
if (n == 0)
throw new AssertionError();
last += n;
// decode into command and optional parameter
// execute
throw new RuntimeException("File already open");
}
throw new RuntimeException("No file open");
}
throw new RuntimeException("Already holding lock");
} else {
throw new RuntimeException("Lock parameter invalid");
}
}
throw new RuntimeException("Not holding lock");
}
// send reply
byte[] reply = { TERMINATOR };
}
} finally {
}
}
}