863 |
|
} |
864 |
|
} |
865 |
|
|
866 |
< |
|
866 |
> |
/** A helper class for uninterruptible wait tests */ |
867 |
> |
class UninterruptableThread extends Thread { |
868 |
> |
private ReentrantLock lock; |
869 |
> |
private Condition c; |
870 |
> |
|
871 |
> |
public volatile boolean canAwake = false; |
872 |
> |
public volatile boolean interrupted = false; |
873 |
> |
public volatile boolean lockStarted = false; |
874 |
> |
|
875 |
> |
public UninterruptableThread(ReentrantLock lock, Condition c) { |
876 |
> |
this.lock = lock; |
877 |
> |
this.c = c; |
878 |
> |
} |
879 |
> |
|
880 |
> |
public synchronized void run() { |
881 |
> |
lock.lock(); |
882 |
> |
lockStarted = true; |
883 |
> |
|
884 |
> |
while (!canAwake) { |
885 |
> |
c.awaitUninterruptibly(); |
886 |
> |
} |
887 |
> |
|
888 |
> |
interrupted = isInterrupted(); |
889 |
> |
lock.unlock(); |
890 |
> |
} |
891 |
> |
} |
892 |
|
|
893 |
|
/** |
894 |
|
* awaitUninterruptibly doesn't abort on interrupt |
895 |
|
*/ |
896 |
|
public void testAwaitUninterruptibly() { |
897 |
< |
final ReentrantLock lock = new ReentrantLock(); |
897 |
> |
final ReentrantLock lock = new ReentrantLock(); |
898 |
|
final Condition c = lock.newCondition(); |
899 |
< |
Thread t = new Thread(new Runnable() { |
875 |
< |
public void run() { |
876 |
< |
lock.lock(); |
877 |
< |
c.awaitUninterruptibly(); |
878 |
< |
lock.unlock(); |
879 |
< |
} |
880 |
< |
}); |
899 |
> |
UninterruptableThread thread = new UninterruptableThread(lock, c); |
900 |
|
|
901 |
|
try { |
902 |
< |
t.start(); |
903 |
< |
Thread.sleep(SHORT_DELAY_MS); |
904 |
< |
t.interrupt(); |
902 |
> |
thread.start(); |
903 |
> |
|
904 |
> |
while (!thread.lockStarted) { |
905 |
> |
Thread.sleep(100); |
906 |
> |
} |
907 |
> |
|
908 |
|
lock.lock(); |
909 |
< |
c.signal(); |
910 |
< |
lock.unlock(); |
911 |
< |
assertTrue(t.isInterrupted()); |
912 |
< |
t.join(SHORT_DELAY_MS); |
913 |
< |
assertFalse(t.isAlive()); |
914 |
< |
} |
915 |
< |
catch (Exception ex) { |
909 |
> |
try { |
910 |
> |
thread.interrupt(); |
911 |
> |
thread.canAwake = true; |
912 |
> |
c.signal(); |
913 |
> |
} finally { |
914 |
> |
lock.unlock(); |
915 |
> |
} |
916 |
> |
|
917 |
> |
thread.join(); |
918 |
> |
assertTrue(thread.interrupted); |
919 |
> |
assertFalse(thread.isAlive()); |
920 |
> |
} catch (Exception ex) { |
921 |
|
unexpectedException(); |
922 |
|
} |
923 |
|
} |