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.17 by jsr166, Sat Nov 21 22:00:46 2009 UTC vs.
Revision 1.23 by jsr166, Thu Sep 16 00:52:49 2010 UTC

# Line 15 | Line 15 | import java.io.*;
15   public class SynchronousQueueTest extends JSR166TestCase {
16  
17      public static void main(String[] args) {
18 <        junit.textui.TestRunner.run (suite());
18 >        junit.textui.TestRunner.run(suite());
19      }
20  
21      public static Test suite() {
# Line 119 | Line 119 | public class SynchronousQueueTest extend
119              shouldThrow();
120          } catch (NullPointerException success) {}
121      }
122 +
123      /**
124       * addAll throws ISE if no active taker
125       */
# Line 169 | Line 170 | public class SynchronousQueueTest extend
170              public void realRun() throws InterruptedException {
171                  int added = 0;
172                  try {
173 <                    q.put(new Object());
174 <                    ++added;
175 <                    q.put(new Object());
176 <                    ++added;
176 <                    q.put(new Object());
177 <                    ++added;
178 <                    q.put(new Object());
179 <                    ++added;
180 <                    threadShouldThrow();
173 >                    while (true) {
174 >                        q.put(added);
175 >                        ++added;
176 >                    }
177                  } catch (InterruptedException success) {
178 <                    assertTrue(added >= 1);
178 >                    assertEquals(1, added);
179                  }
180              }});
181  
182          t.start();
183          Thread.sleep(SHORT_DELAY_MS);
184 <        q.take();
184 >        assertEquals(0, q.take());
185          Thread.sleep(SHORT_DELAY_MS);
186          t.interrupt();
187          t.join();
# Line 251 | Line 247 | public class SynchronousQueueTest extend
247              public void realRun() throws InterruptedException {
248                  int added = 0;
249                  try {
250 <                    q.put(new Object());
251 <                    ++added;
252 <                    q.put(new Object());
253 <                    ++added;
258 <                    q.put(new Object());
259 <                    ++added;
260 <                    q.put(new Object());
261 <                    ++added;
262 <                    threadShouldThrow();
250 >                    while (true) {
251 >                        q.put(added);
252 >                        ++added;
253 >                    }
254                  } catch (InterruptedException success) {
255 <                    assertTrue(added >= 1);
255 >                    assertEquals(1, added);
256                  }
257              }});
258  
259          t.start();
260          Thread.sleep(SHORT_DELAY_MS);
261 <        q.take();
261 >        assertEquals(0, q.take());
262          Thread.sleep(SHORT_DELAY_MS);
263          t.interrupt();
264          t.join();
# Line 280 | Line 271 | public class SynchronousQueueTest extend
271          final SynchronousQueue q = new SynchronousQueue(true);
272          Thread t = new Thread(new CheckedInterruptedRunnable() {
273              public void realRun() throws InterruptedException {
274 <                threadAssertFalse(q.offer(new Object(), SHORT_DELAY_MS, MILLISECONDS));
274 >                assertFalse(q.offer(new Object(), SHORT_DELAY_MS, MILLISECONDS));
275                  q.offer(new Object(), LONG_DELAY_MS, MILLISECONDS);
276              }});
277  
# Line 524 | Line 515 | public class SynchronousQueueTest extend
515       * toArray(null) throws NPE
516       */
517      public void testToArray_BadArg() {
518 +        SynchronousQueue q = new SynchronousQueue();
519          try {
528            SynchronousQueue q = new SynchronousQueue();
520              Object o[] = q.toArray(null);
521              shouldThrow();
522          } catch (NullPointerException success) {}
# Line 573 | Line 564 | public class SynchronousQueueTest extend
564      public void testOfferInExecutor() {
565          final SynchronousQueue q = new SynchronousQueue();
566          ExecutorService executor = Executors.newFixedThreadPool(2);
576        final Integer one = new Integer(1);
567  
568          executor.execute(new CheckedRunnable() {
569              public void realRun() throws InterruptedException {
570 <                threadAssertFalse(q.offer(one));
571 <                threadAssertTrue(q.offer(one, MEDIUM_DELAY_MS, MILLISECONDS));
572 <                threadAssertEquals(0, q.remainingCapacity());
570 >                assertFalse(q.offer(one));
571 >                assertTrue(q.offer(one, MEDIUM_DELAY_MS, MILLISECONDS));
572 >                assertEquals(0, q.remainingCapacity());
573              }});
574  
575          executor.execute(new CheckedRunnable() {
576              public void realRun() throws InterruptedException {
577                  Thread.sleep(SMALL_DELAY_MS);
578 <                threadAssertEquals(one, q.take());
578 >                assertSame(one, q.take());
579              }});
580  
581          joinPool(executor);
592
582      }
583  
584      /**
# Line 600 | Line 589 | public class SynchronousQueueTest extend
589          ExecutorService executor = Executors.newFixedThreadPool(2);
590          executor.execute(new CheckedRunnable() {
591              public void realRun() throws InterruptedException {
592 <                threadAssertNull(q.poll());
593 <                threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, MILLISECONDS));
594 <                threadAssertTrue(q.isEmpty());
592 >                assertNull(q.poll());
593 >                assertSame(one, q.poll(MEDIUM_DELAY_MS, MILLISECONDS));
594 >                assertTrue(q.isEmpty());
595              }});
596  
597          executor.execute(new CheckedRunnable() {
598              public void realRun() throws InterruptedException {
599 <                Thread.sleep(SMALL_DELAY_MS);
600 <                q.put(new Integer(1));
599 >                Thread.sleep(SHORT_DELAY_MS);
600 >                q.put(one);
601              }});
602  
603          joinPool(executor);
# Line 728 | Line 717 | public class SynchronousQueueTest extend
717          ArrayList l = new ArrayList();
718          Thread.sleep(SHORT_DELAY_MS);
719          q.drainTo(l, 1);
720 <        assertTrue(l.size() == 1);
720 >        assertEquals(1, l.size());
721          q.drainTo(l, 1);
722 <        assertTrue(l.size() == 2);
722 >        assertEquals(2, l.size());
723          assertTrue(l.contains(one));
724          assertTrue(l.contains(two));
725          t1.join();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines