ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/ReentrantReadWriteLockTest.java
(Generate patch)

Comparing jsr166/src/test/tck/ReentrantReadWriteLockTest.java (file contents):
Revision 1.71 by jsr166, Fri Feb 27 21:43:18 2015 UTC vs.
Revision 1.77 by jsr166, Fri Jul 3 01:25:15 2015 UTC

# Line 23 | Line 23 | import junit.framework.TestSuite;
23  
24   public class ReentrantReadWriteLockTest extends JSR166TestCase {
25      public static void main(String[] args) {
26 <        junit.textui.TestRunner.run(suite());
26 >        main(suite(), args);
27      }
28      public static Test suite() {
29          return new TestSuite(ReentrantReadWriteLockTest.class);
# Line 155 | Line 155 | public class ReentrantReadWriteLockTest
155      enum AwaitMethod { await, awaitTimed, awaitNanos, awaitUntil }
156  
157      /**
158 <     * Awaits condition using the specified AwaitMethod.
158 >     * Awaits condition "indefinitely" using the specified AwaitMethod.
159       */
160      void await(Condition c, AwaitMethod awaitMethod)
161              throws InterruptedException {
162 +        long timeoutMillis = 2 * LONG_DELAY_MS;
163          switch (awaitMethod) {
164          case await:
165              c.await();
166              break;
167          case awaitTimed:
168 <            assertTrue(c.await(2 * LONG_DELAY_MS, MILLISECONDS));
168 >            assertTrue(c.await(timeoutMillis, MILLISECONDS));
169              break;
170          case awaitNanos:
171 <            long nanosRemaining = c.awaitNanos(MILLISECONDS.toNanos(2 * LONG_DELAY_MS));
172 <            assertTrue(nanosRemaining > 0);
171 >            long timeoutNanos = MILLISECONDS.toNanos(timeoutMillis);
172 >            long nanosRemaining = c.awaitNanos(timeoutNanos);
173 >            assertTrue(nanosRemaining > timeoutNanos / 2);
174 >            assertTrue(nanosRemaining <= timeoutNanos);
175              break;
176          case awaitUntil:
177 <            java.util.Date d = new java.util.Date();
175 <            assertTrue(c.awaitUntil(new java.util.Date(d.getTime() + 2 * LONG_DELAY_MS)));
177 >            assertTrue(c.awaitUntil(delayedDate(timeoutMillis)));
178              break;
179          default:
180              throw new AssertionError();
# Line 236 | Line 238 | public class ReentrantReadWriteLockTest
238          }
239          for (int i = SIZE; i > 0; i--) {
240              lock.writeLock().unlock();
241 <            assertEquals(i-1,lock.getWriteHoldCount());
241 >            assertEquals(i - 1,lock.getWriteHoldCount());
242          }
243      }
244  
# Line 253 | Line 255 | public class ReentrantReadWriteLockTest
255          }
256          for (int i = SIZE; i > 0; i--) {
257              lock.writeLock().unlock();
258 <            assertEquals(i-1,lock.writeLock().getHoldCount());
258 >            assertEquals(i - 1,lock.writeLock().getHoldCount());
259          }
260      }
261  
# Line 270 | Line 272 | public class ReentrantReadWriteLockTest
272          }
273          for (int i = SIZE; i > 0; i--) {
274              lock.readLock().unlock();
275 <            assertEquals(i-1,lock.getReadHoldCount());
275 >            assertEquals(i - 1,lock.getReadHoldCount());
276          }
277      }
278  
# Line 830 | Line 832 | public class ReentrantReadWriteLockTest
832              new PublicReentrantReadWriteLock(fair);
833          try {
834              lock.writeLock().lockInterruptibly();
835 <        } catch (InterruptedException ie) {
834 <            threadUnexpectedException(ie);
835 <        }
835 >        } catch (InterruptedException fail) { threadUnexpectedException(fail); }
836          Thread t = newStartedThread(new CheckedInterruptedRunnable() {
837              public void realRun() throws InterruptedException {
838                  lock.writeLock().lockInterruptibly();
# Line 857 | Line 857 | public class ReentrantReadWriteLockTest
857              lock.readLock().lockInterruptibly();
858              lock.readLock().unlock();
859              lock.writeLock().lockInterruptibly();
860 <        } catch (InterruptedException ie) {
861 <            threadUnexpectedException(ie);
862 <        }
860 >        } catch (InterruptedException fail) { threadUnexpectedException(fail); }
861          Thread t = newStartedThread(new CheckedInterruptedRunnable() {
862              public void realRun() throws InterruptedException {
863                  lock.readLock().lockInterruptibly();
# Line 885 | Line 883 | public class ReentrantReadWriteLockTest
883                  await(c, awaitMethod);
884                  shouldThrow();
885              } catch (IllegalMonitorStateException success) {
886 <            } catch (InterruptedException e) { threadUnexpectedException(e); }
886 >            } catch (InterruptedException fail) {
887 >                threadUnexpectedException(fail);
888 >            }
889              assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
890          }
891      }
# Line 936 | Line 936 | public class ReentrantReadWriteLockTest
936              assertTrue(nanosRemaining <= 0);
937              assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
938              lock.writeLock().unlock();
939 <        } catch (InterruptedException e) {
940 <            threadUnexpectedException(e);
941 <        }
939 >        } catch (InterruptedException fail) { threadUnexpectedException(fail); }
940      }
941  
942      /**
# Line 972 | Line 970 | public class ReentrantReadWriteLockTest
970              final Condition c = lock.writeLock().newCondition();
971              lock.writeLock().lock();
972              long startTime = System.nanoTime();
973 <            long timeoutMillis = 10;
974 <            java.util.Date d = new java.util.Date();
977 <            assertFalse(c.awaitUntil(new java.util.Date(d.getTime() + timeoutMillis)));
978 <            assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
973 >            assertFalse(c.awaitUntil(delayedDate(timeoutMillis())));
974 >            assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
975              lock.writeLock().unlock();
976          } catch (InterruptedException fail) { threadUnexpectedException(fail); }
977      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines