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

Comparing jsr166/src/test/tck/SemaphoreTest.java (file contents):
Revision 1.37 by jsr166, Sat May 13 23:50:00 2017 UTC vs.
Revision 1.38 by jsr166, Sun May 14 00:38:16 2017 UTC

# Line 127 | Line 127 | public class SemaphoreTest extends JSR16
127              void acquire(Semaphore s) throws InterruptedException {
128                  assertTrue(s.tryAcquire(2 * LONG_DELAY_MS, MILLISECONDS));
129              }
130 +            Thread.State parkedState() { return Thread.State.TIMED_WAITING; }
131          },
132          tryAcquireTimedN {
133              void acquire(Semaphore s, int permits) throws InterruptedException {
134                  assertTrue(s.tryAcquire(permits, 2 * LONG_DELAY_MS, MILLISECONDS));
135              }
136 +            Thread.State parkedState() { return Thread.State.TIMED_WAITING; }
137          };
138  
139          // Intentionally meta-circular
# Line 145 | Line 147 | public class SemaphoreTest extends JSR16
147              for (int i = 0; i < permits; i++)
148                  acquire(s);
149          }
150 +        Thread.State parkedState() { return Thread.State.WAITING; }
151      }
152  
153      /**
# Line 227 | Line 230 | public class SemaphoreTest extends JSR16
230      public void testInterruptible_tryAcquireTimedN_fair() { testInterruptible(true,  AcquireMethod.tryAcquireTimedN); }
231      public void testInterruptible(boolean fair, final AcquireMethod acquirer) {
232          final PublicSemaphore s = new PublicSemaphore(0, fair);
233 <        final Semaphore pleaseInterrupt = new Semaphore(0, fair);
233 >        final java.util.concurrent.CyclicBarrier pleaseInterrupt
234 >            = new java.util.concurrent.CyclicBarrier(2);
235          Thread t = newStartedThread(new CheckedRunnable() {
236              public void realRun() {
237                  // Interrupt before acquire
# Line 236 | Line 240 | public class SemaphoreTest extends JSR16
240                      acquirer.acquire(s);
241                      shouldThrow();
242                  } catch (InterruptedException success) {}
243 <
240 <                // Interrupt during acquire
241 <                try {
242 <                    acquirer.acquire(s);
243 <                    shouldThrow();
244 <                } catch (InterruptedException success) {}
243 >                assertFalse(Thread.interrupted());
244  
245                  // Interrupt before acquire(N)
246                  Thread.currentThread().interrupt();
# Line 249 | Line 248 | public class SemaphoreTest extends JSR16
248                      acquirer.acquire(s, 3);
249                      shouldThrow();
250                  } catch (InterruptedException success) {}
251 +                assertFalse(Thread.interrupted());
252  
253 <                pleaseInterrupt.release();
253 >                // Interrupt during acquire
254 >                await(pleaseInterrupt);
255 >                try {
256 >                    acquirer.acquire(s);
257 >                    shouldThrow();
258 >                } catch (InterruptedException success) {}
259 >                assertFalse(Thread.interrupted());
260  
261                  // Interrupt during acquire(N)
262 +                await(pleaseInterrupt);
263                  try {
264                      acquirer.acquire(s, 3);
265                      shouldThrow();
266                  } catch (InterruptedException success) {}
267 +                assertFalse(Thread.interrupted());
268              }});
269  
270 <        waitForQueuedThread(s, t);
271 <        t.interrupt();
272 <        await(pleaseInterrupt);
273 <        waitForQueuedThread(s, t);
274 <        t.interrupt();
270 >        for (int n = 2; n-->0; ) {
271 >            await(pleaseInterrupt);
272 >            assertThreadBlocks(t, acquirer.parkedState());
273 >            t.interrupt();
274 >        }
275 >        
276          awaitTermination(t);
277      }
278  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines