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

Comparing jsr166/src/test/tck/LinkedBlockingQueueTest.java (file contents):
Revision 1.5 by dl, Thu Sep 25 11:02:41 2003 UTC vs.
Revision 1.9 by dl, Wed Jan 7 01:13:50 2004 UTC

# Line 1 | Line 1
1   /*
2 < * Written by members of JCP JSR-166 Expert Group and released to the
3 < * public domain. Use, modify, and redistribute this code in any way
4 < * without acknowledgement. Other contributors include Andrew Wright,
5 < * Jeffrey Hayes, Pat Fischer, Mike Judd.
2 > * Written by Doug Lea with assistance from members of JCP JSR-166
3 > * Expert Group and released to the public domain, as explained at
4 > * http://creativecommons.org/licenses/publicdomain
5 > * Other contributors include Andrew Wright, Jeffrey Hayes,
6 > * Pat Fisher, Mike Judd.
7   */
8  
9   import junit.framework.*;
# Line 152 | Line 153 | public class LinkedBlockingQueueTest ext
153      }
154  
155      /**
156 +     * add(null) throws NPE
157 +     */
158 +    public void testAddNull() {
159 +        try {
160 +            LinkedBlockingQueue q = new LinkedBlockingQueue(1);
161 +            q.add(null);
162 +            shouldThrow();
163 +        } catch (NullPointerException success) { }  
164 +    }
165 +
166 +    /**
167       * Offer succeeds if not full; fails if full
168       */
169      public void testOffer() {
# Line 186 | Line 198 | public class LinkedBlockingQueueTest ext
198          }
199          catch (NullPointerException success) {}
200      }
201 +
202 +    /**
203 +     * addAll(this) throws IAE
204 +     */
205 +    public void testAddAllSelf() {
206 +        try {
207 +            LinkedBlockingQueue q = populatedQueue(SIZE);
208 +            q.addAll(q);
209 +            shouldThrow();
210 +        }
211 +        catch (IllegalArgumentException success) {}
212 +    }
213 +
214      /**
215       * addAll of a collection with null elements throws NPE
216       */
# Line 694 | Line 719 | public class LinkedBlockingQueueTest ext
719              unexpectedException();
720          }    
721      }
722 +
723 +    /**
724 +     * toArray(null) throws NPE
725 +     */
726 +    public void testToArray_BadArg() {
727 +        try {
728 +            LinkedBlockingQueue q = populatedQueue(SIZE);
729 +            Object o[] = q.toArray(null);
730 +            shouldThrow();
731 +        } catch(NullPointerException success){}
732 +    }
733 +
734 +    /**
735 +     * toArray with incompatible array type throws CCE
736 +     */
737 +    public void testToArray1_BadArg() {
738 +        try {
739 +            LinkedBlockingQueue q = populatedQueue(SIZE);
740 +            Object o[] = q.toArray(new String[10] );
741 +            shouldThrow();
742 +        } catch(ArrayStoreException  success){}
743 +    }
744 +
745      
746      /**
747       * iterator iterates through all elements
# Line 873 | Line 921 | public class LinkedBlockingQueueTest ext
921          }
922      }
923  
924 +    /**
925 +     * drainTo(null) throws NPE
926 +     */
927 +    public void testDrainToNull() {
928 +        LinkedBlockingQueue q = populatedQueue(SIZE);
929 +        try {
930 +            q.drainTo(null);
931 +            shouldThrow();
932 +        } catch(NullPointerException success) {
933 +        }
934 +    }
935 +
936 +    /**
937 +     * drainTo(this) throws IAE
938 +     */
939 +    public void testDrainToSelf() {
940 +        LinkedBlockingQueue q = populatedQueue(SIZE);
941 +        try {
942 +            q.drainTo(q);
943 +            shouldThrow();
944 +        } catch(IllegalArgumentException success) {
945 +        }
946 +    }
947 +
948 +    /**
949 +     * drainTo(c) empties queue into another collection c
950 +     */
951 +    public void testDrainTo() {
952 +        LinkedBlockingQueue q = populatedQueue(SIZE);
953 +        ArrayList l = new ArrayList();
954 +        q.drainTo(l);
955 +        assertEquals(q.size(), 0);
956 +        assertEquals(l.size(), SIZE);
957 +        for (int i = 0; i < SIZE; ++i)
958 +            assertEquals(l.get(i), new Integer(i));
959 +    }
960 +
961 +    /**
962 +     * drainTo empties full queue, unblocking a waiting put.
963 +     */
964 +    public void testDrainToWithActivePut() {
965 +        final LinkedBlockingQueue q = populatedQueue(SIZE);
966 +        Thread t = new Thread(new Runnable() {
967 +                public void run() {
968 +                    try {
969 +                        q.put(new Integer(SIZE+1));
970 +                    } catch (InterruptedException ie){
971 +                        threadUnexpectedException();
972 +                    }
973 +                }
974 +            });
975 +        try {
976 +            t.start();
977 +            ArrayList l = new ArrayList();
978 +            q.drainTo(l);
979 +            assertTrue(l.size() >= SIZE);
980 +            for (int i = 0; i < SIZE; ++i)
981 +                assertEquals(l.get(i), new Integer(i));
982 +            t.join();
983 +            assertTrue(q.size() + l.size() >= SIZE);
984 +        } catch(Exception e){
985 +            unexpectedException();
986 +        }
987 +    }
988 +
989 +    /**
990 +     * drainTo(null, n) throws NPE
991 +     */
992 +    public void testDrainToNullN() {
993 +        LinkedBlockingQueue q = populatedQueue(SIZE);
994 +        try {
995 +            q.drainTo(null, 0);
996 +            shouldThrow();
997 +        } catch(NullPointerException success) {
998 +        }
999 +    }
1000 +
1001 +    /**
1002 +     * drainTo(this, n) throws IAE
1003 +     */
1004 +    public void testDrainToSelfN() {
1005 +        LinkedBlockingQueue q = populatedQueue(SIZE);
1006 +        try {
1007 +            q.drainTo(q, 0);
1008 +            shouldThrow();
1009 +        } catch(IllegalArgumentException success) {
1010 +        }
1011 +    }
1012 +
1013 +    /**
1014 +     * drainTo(c, n) empties first max {n, size} elements of queue into c
1015 +     */
1016 +    public void testDrainToN() {
1017 +        for (int i = 0; i < SIZE + 2; ++i) {
1018 +            LinkedBlockingQueue q = populatedQueue(SIZE);
1019 +            ArrayList l = new ArrayList();
1020 +            q.drainTo(l, i);
1021 +            int k = (i < SIZE)? i : SIZE;
1022 +            assertEquals(q.size(), SIZE-k);
1023 +            assertEquals(l.size(), k);
1024 +            for (int j = 0; j < k; ++j)
1025 +                assertEquals(l.get(j), new Integer(j));
1026 +        }
1027 +    }
1028 +
1029   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines