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.21 by jsr166, Wed Aug 25 00:07:03 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 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 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 524 | Line 514 | public class SynchronousQueueTest extend
514       * toArray(null) throws NPE
515       */
516      public void testToArray_BadArg() {
517 +        SynchronousQueue q = new SynchronousQueue();
518          try {
528            SynchronousQueue q = new SynchronousQueue();
519              Object o[] = q.toArray(null);
520              shouldThrow();
521          } catch (NullPointerException success) {}
# Line 573 | Line 563 | public class SynchronousQueueTest extend
563      public void testOfferInExecutor() {
564          final SynchronousQueue q = new SynchronousQueue();
565          ExecutorService executor = Executors.newFixedThreadPool(2);
576        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);
592
581      }
582  
583      /**
# Line 600 | 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);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines