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

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

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

revision 1.10, Tue Jun 14 03:22:38 2011 UTC revision 1.14, Wed Dec 31 20:09:08 2014 UTC
# Line 7  Line 7 
7   * Pat Fisher, Mike Judd.   * Pat Fisher, Mike Judd.
8   */   */
9    
10  import junit.framework.*;  import static java.util.concurrent.TimeUnit.MILLISECONDS;
11    
12  import java.util.ArrayList;  import java.util.ArrayList;
13  import java.util.Arrays;  import java.util.Arrays;
14  import java.util.Collection;  import java.util.Collection;
15  import java.util.Queue;  import java.util.Queue;
16  import java.util.concurrent.BlockingQueue;  import java.util.concurrent.BlockingQueue;
17  import java.util.concurrent.CountDownLatch;  import java.util.concurrent.CountDownLatch;
18  import static java.util.concurrent.TimeUnit.MILLISECONDS;  
19    import junit.framework.Test;
20    import junit.framework.TestSuite;
21    
22  /**  /**
23   * Contains "contract" tests applicable to all BlockingQueue implementations.   * Contains "contract" tests applicable to all BlockingQueue implementations.
# Line 181  Line 184 
184      }      }
185    
186      /**      /**
187       * drainTo(c, -n) returns 0       * drainTo(c, n) returns 0 and does nothing when n <= 0
188       */       */
189      public void testDrainToNegativeMaxElements() {      public void testDrainToNonPositiveMaxElements() {
190          final BlockingQueue q = emptyCollection();          final BlockingQueue q = emptyCollection();
191          assertEquals(0, q.drainTo(new ArrayList(), -42));          final int[] ns = { 0, -1, -42, Integer.MIN_VALUE };
192      }          for (int n : ns)
193                assertEquals(0, q.drainTo(new ArrayList(), n));
194      /**          if (q.remainingCapacity() > 0) {
195       * drainTo(c, 0) returns 0 and does nothing              // Not SynchronousQueue, that is
      */  
     public void testDrainToZeroMaxElements() {  
         final BlockingQueue q = emptyCollection();  
         if (q.remainingCapacity() == 0) {  
             // SynchronousQueue, for example  
             assertEquals(0, q.drainTo(new ArrayList(), 0));  
         } else {  
196              Object one = makeElement(1);              Object one = makeElement(1);
197              q.add(one);              q.add(one);
198              ArrayList c = new ArrayList();              ArrayList c = new ArrayList();
199              assertEquals(0, q.drainTo(c, 0));              for (int n : ns)
200                    assertEquals(0, q.drainTo(new ArrayList(), n));
201              assertEquals(1, q.size());              assertEquals(1, q.size());
202              assertSame(one, q.poll());              assertSame(one, q.poll());
203              assertTrue(c.isEmpty());              assertTrue(c.isEmpty());
# Line 333  Line 330 
330          awaitTermination(t);          awaitTermination(t);
331      }      }
332    
333        /**
334         * remove(x) removes x and returns true if present
335         * TODO: move to superclass CollectionTest.java
336         */
337        public void testRemoveElement() {
338            final BlockingQueue q = emptyCollection();
339            final int size = Math.min(q.remainingCapacity(), SIZE);
340            final Object[] elts = new Object[size];
341            assertFalse(q.contains(makeElement(99)));
342            assertFalse(q.remove(makeElement(99)));
343            checkEmpty(q);
344            for (int i = 0; i < size; i++)
345                q.add(elts[i] = makeElement(i));
346            for (int i = 1; i < size; i += 2) {
347                for (int pass = 0; pass < 2; pass++) {
348                    assertEquals((pass == 0), q.contains(elts[i]));
349                    assertEquals((pass == 0), q.remove(elts[i]));
350                    assertFalse(q.contains(elts[i]));
351                    assertTrue(q.contains(elts[i-1]));
352                    if (i < size - 1)
353                        assertTrue(q.contains(elts[i+1]));
354                }
355            }
356            if (size > 0)
357                assertTrue(q.contains(elts[0]));
358            for (int i = size-2; i >= 0; i -= 2) {
359                assertTrue(q.contains(elts[i]));
360                assertFalse(q.contains(elts[i+1]));
361                assertTrue(q.remove(elts[i]));
362                assertFalse(q.contains(elts[i]));
363                assertFalse(q.remove(elts[i+1]));
364                assertFalse(q.contains(elts[i+1]));
365            }
366            checkEmpty(q);
367        }
368    
369      /** For debugging. */      /** For debugging. */
370      public void XXXXtestFails() {      public void XXXXtestFails() {
371          fail(emptyCollection().getClass().toString());          fail(emptyCollection().getClass().toString());

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.14

Doug Lea
ViewVC Help
Powered by ViewVC 1.0.8