public class LockTest extends NamingTest
lock
and
unlock
methods.
Properties checked are:
lock
and unlock
methods reject
null
paths and paths to non-existent objects.Modifier and Type | Class and Description |
---|---|
private class |
LockTest.FirstExclusiveUser
First thread in the exclusive access test.
|
private class |
LockTest.LockUser
Base class of threads used for both the rendezvous and the exclusive
access tests.
|
private class |
LockTest.RendezvousUser
Rendezvous test thread.
|
private class |
LockTest.SecondExclusiveUser
Second thread in the exclusive access test.
|
private class |
LockTest.WakeTask
Wakes the first thread in the exclusive access test.
|
Modifier and Type | Field and Description |
---|---|
private Path |
directory |
private boolean |
exclusive_finished
Indicates that the second thread has released the lock, and therefore
the exclusive access test is finished.
|
private boolean |
exclusive_locked
Indicates that the first thread in the exclusive access test has taken
the lock, and therefore the second thread may go on with its attempt to
take it as well.
|
private boolean |
exclusive_resume
Indicates that the first thread in the exclusive access test has
released the lock.
|
private static int |
EXCLUSIVE_TEST_DELAY
Minimum amount of time, in milliseconds, that the first thread in the
exclusive access test holds the lock before releasing it.
|
private Path |
file1 |
private Path |
file2 |
static java.lang.String |
notice
Test notice.
|
static java.lang.Class[] |
prerequisites
Prerequisites.
|
private int |
rendezvous_exits
Number of threads that have completed the rendezvous test.
|
private boolean |
rendezvous_wait
For a rendezvous test, indicates that the next thread to take the lock
is the first thread and should wait for the second.
|
private boolean |
rendezvous_wake
Indicates that the second thread successfully took the lock in the
rendzevous test.
|
private Path |
root |
private TestStorageServer |
storage_server
Storage server used in the test.
|
private boolean |
wake_all
Indicates that the test has completed and all waits are cancelled.
|
registration_stub, service_stub
Constructor and Description |
---|
LockTest() |
Modifier and Type | Method and Description |
---|---|
private java.lang.String |
accessType(boolean exclusive)
Returns a string describing the type of access requested.
|
protected void |
clean()
Stops all servers and wakes all threads.
|
protected void |
initialize()
Initializes the test.
|
protected void |
perform()
Performs the test.
|
private void |
testBadPaths()
Checks that the
lock and unlock methods
reject bad arguments. |
private void |
testExclusion(Path first_path,
boolean first_exclusive,
Path second_path,
boolean second_exclusive)
Checks that two threads are not able to simultaneously lock the two
given objects for the requested kinds of access.
|
private void |
testSharing(Path first_path,
boolean first_exclusive,
Path second_path,
boolean second_exclusive)
Checks that two threads are able to lock the two given paths
simultaneously for the requested kind of access.
|
cleanupFailure, cleanupSuccess, failure, success, task, task
public static final java.lang.String notice
public static final java.lang.Class[] prerequisites
private TestStorageServer storage_server
private final Path root
private final Path directory
private final Path file1
private final Path file2
private boolean rendezvous_wait
private boolean rendezvous_wake
private int rendezvous_exits
private boolean exclusive_locked
private boolean exclusive_resume
private boolean exclusive_finished
private static final int EXCLUSIVE_TEST_DELAY
private boolean wake_all
protected void perform() throws TestFailed
perform
in class Test
TestFailed
private void testSharing(Path first_path, boolean first_exclusive, Path second_path, boolean second_exclusive)
Two threads are started, and each attempts to lock its given object. In order for the test to succeed, the two threads must rendezvous with the lock taken. The first thread to lock an object waits for the second thread to also lock its object. Only after both threads have successfully locked both their objects are they allowed to proceed. The test is successful when both threads have unlocked their respective objects.
The code run by the two threads is identical. What determines their behavior (whether to wait for the second thread, or to wake the first) is the order in which they take the lock.
first_path
- Path to the object to be locked by the first thread.first_exclusive
- true
if the first thread is to take
its object for exclusive access,
false
if the first thread is to
request shared access.second_path
- Path to the object to be locked by the second thread.second_exclusive
- true
if the second thread is to
take its object for exclusive access,
false
if the second thread is to
request shared access.private void testExclusion(Path first_path, boolean first_exclusive, Path second_path, boolean second_exclusive)
Two threads are started. Unlike in the rendzevous test, the two threads are different. There is a thread that is intended to be the first to lock its object, and the other thread should be second. The second thread waits until the first thread signals it has locked its object. In the meantime, the first thread sleeps for a fixed minimum amount of time, in order to make it very likely that the second thread will attempt to lock its object after it is done waiting for the first. If the second thread is able to successfully lock its object during this delay, then the test has failed.
first_path
- Path to the object to be locked by the first thread.first_exclusive
- true
if the first thread is to take
its object for exclusive access,
false
if the first thread is to
request shared access.second_path
- Path to the object to be locked by the second thread.second_exclusive
- true
if the second thread is to
take its object for exclusive access,
false
if the second thread is to
request shared access.private java.lang.String accessType(boolean exclusive)
exclusive
- Access type."exclusive"
if the argument is true
,
"shared"
if the argument is false
.private void testBadPaths() throws TestFailed
lock
and unlock
methods
reject bad arguments.TestFailed
protected void initialize() throws TestFailed
This method starts the storage server, creating a small directory tree on the naming server.
initialize
in class NamingTest
TestFailed
- If the storage server cannot be started.protected void clean()
clean
in class NamingTest