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

Comparing jsr166/src/test/tck/SynchronousQueueTest.java (file contents):
Revision 1.14 by jsr166, Sat Nov 21 02:07:27 2009 UTC vs.
Revision 1.20 by jsr166, Tue Dec 1 09:48:12 2009 UTC

# Line 169 | Line 169 | public class SynchronousQueueTest extend
169              public void realRun() throws InterruptedException {
170                  int added = 0;
171                  try {
172 <                    q.put(new Object());
173 <                    ++added;
174 <                    q.put(new Object());
175 <                    ++added;
176 <                    q.put(new Object());
177 <                    ++added;
178 <                    q.put(new Object());
179 <                    ++added;
180 <                    threadShouldThrow();
172 >                    while (true) {
173 >                        q.put(added);
174 >                        ++added;
175 >                    }
176                  } catch (InterruptedException success) {
177 <                    assertTrue(added >= 1);
177 >                    assertTrue(added == 1);
178                  }
179              }});
180  
181          t.start();
182          Thread.sleep(SHORT_DELAY_MS);
183 <        q.take();
183 >        assertEquals(0, q.take());
184          Thread.sleep(SHORT_DELAY_MS);
185          t.interrupt();
186          t.join();
# Line 198 | Line 193 | public class SynchronousQueueTest extend
193          final SynchronousQueue q = new SynchronousQueue();
194          Thread t = new Thread(new CheckedInterruptedRunnable() {
195              public void realRun() throws InterruptedException {
196 <                threadAssertFalse(q.offer(new Object(), SHORT_DELAY_MS, MILLISECONDS));
196 >                assertFalse(q.offer(new Object(), SHORT_DELAY_MS, MILLISECONDS));
197                  q.offer(new Object(), LONG_DELAY_MS, MILLISECONDS);
198              }});
199  
# Line 251 | Line 246 | public class SynchronousQueueTest extend
246              public void realRun() throws InterruptedException {
247                  int added = 0;
248                  try {
249 <                    q.put(new Object());
250 <                    ++added;
251 <                    q.put(new Object());
252 <                    ++added;
258 <                    q.put(new Object());
259 <                    ++added;
260 <                    q.put(new Object());
261 <                    ++added;
262 <                    threadShouldThrow();
249 >                    while (true) {
250 >                        q.put(added);
251 >                        ++added;
252 >                    }
253                  } catch (InterruptedException success) {
254 <                    assertTrue(added >= 1);
254 >                    assertTrue(added == 1);
255                  }
256              }});
257  
258          t.start();
259          Thread.sleep(SHORT_DELAY_MS);
260 <        q.take();
260 >        assertEquals(0, q.take());
261          Thread.sleep(SHORT_DELAY_MS);
262          t.interrupt();
263          t.join();
# Line 280 | Line 270 | public class SynchronousQueueTest extend
270          final SynchronousQueue q = new SynchronousQueue(true);
271          Thread t = new Thread(new CheckedInterruptedRunnable() {
272              public void realRun() throws InterruptedException {
273 <                threadAssertFalse(q.offer(new Object(), SHORT_DELAY_MS, MILLISECONDS));
273 >                assertFalse(q.offer(new Object(), SHORT_DELAY_MS, MILLISECONDS));
274                  q.offer(new Object(), LONG_DELAY_MS, MILLISECONDS);
275              }});
276  
# Line 336 | Line 326 | public class SynchronousQueueTest extend
326       * returning timeout status
327       */
328      public void testInterruptedTimedPoll() throws InterruptedException {
329 +        final SynchronousQueue q = new SynchronousQueue();
330          Thread t = new Thread(new CheckedInterruptedRunnable() {
331              public void realRun() throws InterruptedException {
341                SynchronousQueue q = new SynchronousQueue();
332                  q.poll(SMALL_DELAY_MS, MILLISECONDS);
333              }});
334  
# Line 356 | Line 346 | public class SynchronousQueueTest extend
346          final SynchronousQueue q = new SynchronousQueue();
347          Thread t = new Thread(new CheckedRunnable() {
348              public void realRun() throws InterruptedException {
349 <                threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
349 >                assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
350                  assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS));
351                  try {
352                      q.poll(LONG_DELAY_MS, MILLISECONDS);
353 <                    threadShouldThrow();
353 >                    shouldThrow();
354                  } catch (InterruptedException success) {}
355              }});
356  
# Line 396 | Line 386 | public class SynchronousQueueTest extend
386          final SynchronousQueue q = new SynchronousQueue(true);
387          Thread t = new Thread(new CheckedRunnable() {
388              public void realRun() throws InterruptedException {
389 <                threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
389 >                assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
390                  assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS));
391                  try {
392                      q.poll(LONG_DELAY_MS, MILLISECONDS);
# Line 439 | Line 429 | public class SynchronousQueueTest extend
429          try {
430              q.remove();
431              shouldThrow();
432 <        } catch (NoSuchElementException success) {
443 <        }
432 >        } catch (NoSuchElementException success) {}
433      }
434  
435      /**
# Line 525 | Line 514 | public class SynchronousQueueTest extend
514       * toArray(null) throws NPE
515       */
516      public void testToArray_BadArg() {
517 +        SynchronousQueue q = new SynchronousQueue();
518          try {
529            SynchronousQueue q = new SynchronousQueue();
519              Object o[] = q.toArray(null);
520              shouldThrow();
521          } catch (NullPointerException success) {}
# Line 574 | Line 563 | public class SynchronousQueueTest extend
563      public void testOfferInExecutor() {
564          final SynchronousQueue q = new SynchronousQueue();
565          ExecutorService executor = Executors.newFixedThreadPool(2);
577        final Integer one = new Integer(1);
566  
567          executor.execute(new CheckedRunnable() {
568              public void realRun() throws InterruptedException {
569 <                threadAssertFalse(q.offer(one));
570 <                threadAssertTrue(q.offer(one, MEDIUM_DELAY_MS, MILLISECONDS));
571 <                threadAssertEquals(0, q.remainingCapacity());
569 >                assertFalse(q.offer(one));
570 >                assertTrue(q.offer(one, MEDIUM_DELAY_MS, MILLISECONDS));
571 >                assertEquals(0, q.remainingCapacity());
572              }});
573  
574          executor.execute(new CheckedRunnable() {
575              public void realRun() throws InterruptedException {
576                  Thread.sleep(SMALL_DELAY_MS);
577 <                threadAssertEquals(one, q.take());
577 >                assertSame(one, q.take());
578              }});
579  
580          joinPool(executor);
593
581      }
582  
583      /**
# Line 601 | Line 588 | public class SynchronousQueueTest extend
588          ExecutorService executor = Executors.newFixedThreadPool(2);
589          executor.execute(new CheckedRunnable() {
590              public void realRun() throws InterruptedException {
591 <                threadAssertNull(q.poll());
592 <                threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, MILLISECONDS));
593 <                threadAssertTrue(q.isEmpty());
591 >                assertNull(q.poll());
592 >                assertSame(one, q.poll(MEDIUM_DELAY_MS, MILLISECONDS));
593 >                assertTrue(q.isEmpty());
594              }});
595  
596          executor.execute(new CheckedRunnable() {
597              public void realRun() throws InterruptedException {
598 <                Thread.sleep(SMALL_DELAY_MS);
599 <                q.put(new Integer(1));
598 >                Thread.sleep(SHORT_DELAY_MS);
599 >                q.put(one);
600              }});
601  
602          joinPool(executor);
# Line 706 | Line 693 | public class SynchronousQueueTest extend
693          try {
694              q.drainTo(q, 0);
695              shouldThrow();
696 <        } catch (IllegalArgumentException success) {
710 <        }
696 >        } catch (IllegalArgumentException success) {}
697      }
698  
699      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines