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

Comparing jsr166/src/test/tck/ArrayBlockingQueueTest.java (file contents):
Revision 1.24 by jsr166, Sat Nov 21 22:00:46 2009 UTC vs.
Revision 1.25 by jsr166, Sun Nov 22 00:17:37 2009 UTC

# Line 296 | Line 296 | public class ArrayBlockingQueueTest exte
296      public void testBlockingPut() throws InterruptedException {
297          final ArrayBlockingQueue q = new ArrayBlockingQueue(SIZE);
298          Thread t = new Thread(new CheckedRunnable() {
299 <            public void realRun() {
300 <                int added = 0;
299 >            public void realRun() throws InterruptedException {
300 >                for (int i = 0; i < SIZE; ++i)
301 >                    q.put(i);
302 >                assertEquals(SIZE, q.size());
303 >                assertEquals(0, q.remainingCapacity());
304                  try {
305 <                    for (int i = 0; i < SIZE; ++i) {
306 <                        q.put(new Integer(i));
307 <                        ++added;
308 <                    }
306 <                    q.put(new Integer(SIZE));
307 <                    threadShouldThrow();
308 <                } catch (InterruptedException success) {
309 <                    threadAssertEquals(added, SIZE);
310 <                }}});
305 >                    q.put(99);
306 >                    shouldThrow();
307 >                } catch (InterruptedException success) {}
308 >            }});
309  
310          t.start();
311 <        Thread.sleep(MEDIUM_DELAY_MS);
311 >        Thread.sleep(SHORT_DELAY_MS);
312          t.interrupt();
313          t.join();
314 +        assertEquals(SIZE, q.size());
315 +        assertEquals(0, q.remainingCapacity());
316      }
317  
318      /**
# Line 373 | Line 373 | public class ArrayBlockingQueueTest exte
373      public void testTake() throws InterruptedException {
374          ArrayBlockingQueue q = populatedQueue(SIZE);
375          for (int i = 0; i < SIZE; ++i) {
376 <            assertEquals(i, ((Integer)q.take()).intValue());
376 >            assertEquals(i, q.take());
377          }
378      }
379  
# Line 397 | Line 397 | public class ArrayBlockingQueueTest exte
397       * Take removes existing elements until empty, then blocks interruptibly
398       */
399      public void testBlockingTake() throws InterruptedException {
400 <        Thread t = new ThreadShouldThrow(InterruptedException.class) {
400 >        final ArrayBlockingQueue q = populatedQueue(SIZE);
401 >        Thread t = new Thread(new CheckedRunnable() {
402              public void realRun() throws InterruptedException {
402                ArrayBlockingQueue q = populatedQueue(SIZE);
403                  for (int i = 0; i < SIZE; ++i) {
404 <                    threadAssertEquals(i, ((Integer)q.take()).intValue());
404 >                    assertEquals(i, q.take());
405                  }
406 <                q.take();
407 <            }};
406 >                try {
407 >                    q.take();
408 >                    shouldThrow();
409 >                } catch (InterruptedException success) {}
410 >            }});
411  
412          t.start();
413 <            Thread.sleep(SHORT_DELAY_MS);
414 <            t.interrupt();
415 <            t.join();
413 >        Thread.sleep(SHORT_DELAY_MS);
414 >        t.interrupt();
415 >        t.join();
416      }
417  
418  
# Line 419 | Line 422 | public class ArrayBlockingQueueTest exte
422      public void testPoll() {
423          ArrayBlockingQueue q = populatedQueue(SIZE);
424          for (int i = 0; i < SIZE; ++i) {
425 <            assertEquals(i, ((Integer)q.poll()).intValue());
425 >            assertEquals(i, q.poll());
426          }
427          assertNull(q.poll());
428      }
# Line 430 | Line 433 | public class ArrayBlockingQueueTest exte
433      public void testTimedPoll0() throws InterruptedException {
434          ArrayBlockingQueue q = populatedQueue(SIZE);
435          for (int i = 0; i < SIZE; ++i) {
436 <            assertEquals(i, ((Integer)q.poll(0, MILLISECONDS)).intValue());
436 >            assertEquals(i, q.poll(0, MILLISECONDS));
437          }
438          assertNull(q.poll(0, MILLISECONDS));
439      }
# Line 441 | Line 444 | public class ArrayBlockingQueueTest exte
444      public void testTimedPoll() throws InterruptedException {
445          ArrayBlockingQueue q = populatedQueue(SIZE);
446          for (int i = 0; i < SIZE; ++i) {
447 <            assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue());
447 >            assertEquals(i, q.poll(SHORT_DELAY_MS, MILLISECONDS));
448          }
449          assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
450      }
# Line 455 | Line 458 | public class ArrayBlockingQueueTest exte
458              public void realRun() throws InterruptedException {
459                  ArrayBlockingQueue q = populatedQueue(SIZE);
460                  for (int i = 0; i < SIZE; ++i) {
461 <                    assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue());
461 >                    assertEquals(i, q.poll(SHORT_DELAY_MS, MILLISECONDS));;
462                  }
463                  try {
464                      q.poll(SMALL_DELAY_MS, MILLISECONDS);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines