[cvs] / jsr166 / src / test / tck / ArrayBlockingQueueTest.java Repository:
ViewVC logotype

Diff of /jsr166/src/test/tck/ArrayBlockingQueueTest.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.26, Sun Nov 22 18:57:16 2009 UTC revision 1.27, Tue Dec 1 06:03:49 2009 UTC
# Line 319  Line 319 
319       * put blocks waiting for take when full       * put blocks waiting for take when full
320       */       */
321      public void testPutWithTake() throws InterruptedException {      public void testPutWithTake() throws InterruptedException {
322          final ArrayBlockingQueue q = new ArrayBlockingQueue(2);          final int capacity = 2;
323            final ArrayBlockingQueue q = new ArrayBlockingQueue(capacity);
324          Thread t = new Thread(new CheckedRunnable() {          Thread t = new Thread(new CheckedRunnable() {
325              public void realRun() {              public void realRun() throws InterruptedException {
326                  int added = 0;                  for (int i = 0; i < capacity + 1; i++)
327                        q.put(i);
328                  try {                  try {
329                      q.put(new Object());                      q.put(99);
330                      ++added;                      shouldThrow();
331                      q.put(new Object());                  } catch (InterruptedException success) {}
                     ++added;  
                     q.put(new Object());  
                     ++added;  
                     q.put(new Object());  
                     ++added;  
                     threadShouldThrow();  
                 } catch (InterruptedException success) {  
                     threadAssertTrue(added >= 2);  
                 }  
332              }});              }});
333    
334          t.start();          t.start();
335          Thread.sleep(SHORT_DELAY_MS);          Thread.sleep(SHORT_DELAY_MS);
336          q.take();          assertEquals(q.remainingCapacity(), 0);
337            assertEquals(0, q.take());
338            Thread.sleep(SHORT_DELAY_MS);
339          t.interrupt();          t.interrupt();
340          t.join();          t.join();
341            assertEquals(q.remainingCapacity(), 0);
342      }      }
343    
344      /**      /**
# Line 761  Line 757 
757          ExecutorService executor = Executors.newFixedThreadPool(2);          ExecutorService executor = Executors.newFixedThreadPool(2);
758          executor.execute(new CheckedRunnable() {          executor.execute(new CheckedRunnable() {
759              public void realRun() throws InterruptedException {              public void realRun() throws InterruptedException {
760                  threadAssertFalse(q.offer(three));                  assertFalse(q.offer(three));
761                  threadAssertTrue(q.offer(three, MEDIUM_DELAY_MS, MILLISECONDS));                  assertTrue(q.offer(three, MEDIUM_DELAY_MS, MILLISECONDS));
762                  threadAssertEquals(0, q.remainingCapacity());                  assertEquals(0, q.remainingCapacity());
763              }});              }});
764    
765          executor.execute(new CheckedRunnable() {          executor.execute(new CheckedRunnable() {
766              public void realRun() throws InterruptedException {              public void realRun() throws InterruptedException {
767                  Thread.sleep(SMALL_DELAY_MS);                  Thread.sleep(SMALL_DELAY_MS);
768                  threadAssertEquals(one, q.take());                  assertSame(one, q.take());
769              }});              }});
770    
771          joinPool(executor);          joinPool(executor);
# Line 784  Line 780 
780          ExecutorService executor = Executors.newFixedThreadPool(2);          ExecutorService executor = Executors.newFixedThreadPool(2);
781          executor.execute(new CheckedRunnable() {          executor.execute(new CheckedRunnable() {
782              public void realRun() throws InterruptedException {              public void realRun() throws InterruptedException {
783                  threadAssertNull(q.poll());                  assertNull(q.poll());
784                  threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, MILLISECONDS));                  assertSame(one, q.poll(MEDIUM_DELAY_MS, MILLISECONDS));
785                  threadAssertTrue(q.isEmpty());                  assertTrue(q.isEmpty());
786              }});              }});
787    
788          executor.execute(new CheckedRunnable() {          executor.execute(new CheckedRunnable() {

Legend:
Removed from v.1.26  
changed lines
  Added in v.1.27

Doug Lea
ViewVC Help
Powered by ViewVC 1.0.8