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

Comparing jsr166/src/test/tck/ConcurrentSkipListMapTest.java (file contents):
Revision 1.12 by jsr166, Sat Nov 21 02:07:26 2009 UTC vs.
Revision 1.19 by jsr166, Wed Sep 1 20:12:39 2010 UTC

# Line 11 | Line 11 | import java.io.*;
11  
12   public class ConcurrentSkipListMapTest extends JSR166TestCase {
13      public static void main(String[] args) {
14 <        junit.textui.TestRunner.run (suite());
14 >        junit.textui.TestRunner.run(suite());
15      }
16      public static Test suite() {
17          return new TestSuite(ConcurrentSkipListMapTest.class);
# Line 427 | Line 427 | public class ConcurrentSkipListMapTest e
427          map.remove(four, "A");
428          assertEquals(4, map.size());
429          assertTrue(map.containsKey(four));
430
430      }
431  
432      /**
# Line 446 | Line 445 | public class ConcurrentSkipListMapTest e
445  
446          Map.Entry e4 = map.lowerEntry(zero);
447          assertNull(e4);
449
448      }
449  
450      /**
# Line 465 | Line 463 | public class ConcurrentSkipListMapTest e
463  
464          Map.Entry e4 = map.higherEntry(six);
465          assertNull(e4);
468
466      }
467  
468      /**
# Line 484 | Line 481 | public class ConcurrentSkipListMapTest e
481  
482          Map.Entry e4 = map.floorEntry(zero);
483          assertNull(e4);
487
484      }
485  
486      /**
# Line 503 | Line 499 | public class ConcurrentSkipListMapTest e
499  
500          Map.Entry e4 = map.ceilingEntry(six);
501          assertNull(e4);
506
502      }
503  
504      /**
505       * lowerEntry, higherEntry, ceilingEntry, and floorEntry return
506 <     * imutable entries
506 >     * immutable entries
507       */
508      public void testEntryImmutablity() {
509          ConcurrentSkipListMap map = map5();
# Line 516 | Line 511 | public class ConcurrentSkipListMapTest e
511          assertEquals(two, e.getKey());
512          try {
513              e.setValue("X");
514 <            fail();
514 >            shouldThrow();
515          } catch (UnsupportedOperationException success) {}
516          e = map.higherEntry(zero);
517          assertEquals(one, e.getKey());
518          try {
519              e.setValue("X");
520 <            fail();
520 >            shouldThrow();
521          } catch (UnsupportedOperationException success) {}
522          e = map.floorEntry(one);
523          assertEquals(one, e.getKey());
524          try {
525              e.setValue("X");
526 <            fail();
526 >            shouldThrow();
527          } catch (UnsupportedOperationException success) {}
528          e = map.ceilingEntry(five);
529          assertEquals(five, e.getKey());
530          try {
531              e.setValue("X");
532 <            fail();
532 >            shouldThrow();
533          } catch (UnsupportedOperationException success) {}
534      }
535  
# Line 556 | Line 551 | public class ConcurrentSkipListMapTest e
551  
552          Object e4 = q.lowerKey(zero);
553          assertNull(e4);
559
554      }
555  
556      /**
# Line 575 | Line 569 | public class ConcurrentSkipListMapTest e
569  
570          Object e4 = q.higherKey(six);
571          assertNull(e4);
578
572      }
573  
574      /**
# Line 594 | Line 587 | public class ConcurrentSkipListMapTest e
587  
588          Object e4 = q.floorKey(zero);
589          assertNull(e4);
597
590      }
591  
592      /**
# Line 613 | Line 605 | public class ConcurrentSkipListMapTest e
605  
606          Object e4 = q.ceilingKey(six);
607          assertNull(e4);
616
608      }
609  
610      /**
# Line 638 | Line 629 | public class ConcurrentSkipListMapTest e
629          try {
630              e.setValue("A");
631              shouldThrow();
632 <        } catch (Exception ok) {
642 <        }
632 >        } catch (UnsupportedOperationException success) {}
633          e = map.pollFirstEntry();
634          assertNull(e);
635      }
# Line 666 | Line 656 | public class ConcurrentSkipListMapTest e
656          try {
657              e.setValue("E");
658              shouldThrow();
659 <        } catch (Exception ok) {
670 <        }
659 >        } catch (UnsupportedOperationException success) {}
660          e = map.pollLastEntry();
661          assertNull(e);
662      }
# Line 703 | Line 692 | public class ConcurrentSkipListMapTest e
692              ConcurrentSkipListMap c = map5();
693              c.get(null);
694              shouldThrow();
695 <        } catch (NullPointerException e) {}
695 >        } catch (NullPointerException success) {}
696      }
697  
698      /**
# Line 714 | Line 703 | public class ConcurrentSkipListMapTest e
703              ConcurrentSkipListMap c = map5();
704              c.containsKey(null);
705              shouldThrow();
706 <        } catch (NullPointerException e) {}
706 >        } catch (NullPointerException success) {}
707      }
708  
709      /**
# Line 725 | Line 714 | public class ConcurrentSkipListMapTest e
714              ConcurrentSkipListMap c = new ConcurrentSkipListMap();
715              c.containsValue(null);
716              shouldThrow();
717 <        } catch (NullPointerException e) {}
717 >        } catch (NullPointerException success) {}
718      }
719  
720  
# Line 737 | Line 726 | public class ConcurrentSkipListMapTest e
726              ConcurrentSkipListMap c = map5();
727              c.put(null, "whatever");
728              shouldThrow();
729 <        } catch (NullPointerException e) {}
729 >        } catch (NullPointerException success) {}
730      }
731  
732      /**
# Line 748 | Line 737 | public class ConcurrentSkipListMapTest e
737              ConcurrentSkipListMap c = map5();
738              c.putIfAbsent(null, "whatever");
739              shouldThrow();
740 <        } catch (NullPointerException e) {}
740 >        } catch (NullPointerException success) {}
741      }
742  
743      /**
# Line 759 | Line 748 | public class ConcurrentSkipListMapTest e
748              ConcurrentSkipListMap c = map5();
749              c.replace(null, "whatever");
750              shouldThrow();
751 <        } catch (NullPointerException e) {}
751 >        } catch (NullPointerException success) {}
752      }
753  
754      /**
# Line 770 | Line 759 | public class ConcurrentSkipListMapTest e
759              ConcurrentSkipListMap c = map5();
760              c.replace(null, one, "whatever");
761              shouldThrow();
762 <        } catch (NullPointerException e) {}
762 >        } catch (NullPointerException success) {}
763      }
764  
765      /**
# Line 782 | Line 771 | public class ConcurrentSkipListMapTest e
771              c.put("sadsdf", "asdads");
772              c.remove(null);
773              shouldThrow();
774 <        } catch (NullPointerException e) {}
774 >        } catch (NullPointerException success) {}
775      }
776  
777      /**
# Line 794 | Line 783 | public class ConcurrentSkipListMapTest e
783              c.put("sadsdf", "asdads");
784              c.remove(null, "whatever");
785              shouldThrow();
786 <        } catch (NullPointerException e) {}
786 >        } catch (NullPointerException success) {}
787      }
788  
789      /**
790       * remove(x, null) returns false
791       */
792      public void testRemove3() {
793 <        try {
794 <            ConcurrentSkipListMap c = new ConcurrentSkipListMap();
795 <            c.put("sadsdf", "asdads");
807 <            assertFalse(c.remove("sadsdf", null));
808 <        } catch (NullPointerException e) {
809 <            fail();
810 <        }
793 >        ConcurrentSkipListMap c = new ConcurrentSkipListMap();
794 >        c.put("sadsdf", "asdads");
795 >        assertFalse(c.remove("sadsdf", null));
796      }
797  
798      /**
799       * A deserialized map equals original
800       */
801 <    public void testSerialization() {
801 >    public void testSerialization() throws Exception {
802          ConcurrentSkipListMap q = map5();
803  
804 <        try {
805 <            ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
806 <            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
807 <            out.writeObject(q);
808 <            out.close();
809 <
810 <            ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
811 <            ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
812 <            ConcurrentSkipListMap r = (ConcurrentSkipListMap)in.readObject();
813 <            assertEquals(q.size(), r.size());
814 <            assertTrue(q.equals(r));
830 <            assertTrue(r.equals(q));
831 <        } catch (Exception e) {
832 <            e.printStackTrace();
833 <            unexpectedException();
834 <        }
804 >        ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
805 >        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
806 >        out.writeObject(q);
807 >        out.close();
808 >
809 >        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
810 >        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
811 >        ConcurrentSkipListMap r = (ConcurrentSkipListMap)in.readObject();
812 >        assertEquals(q.size(), r.size());
813 >        assertTrue(q.equals(r));
814 >        assertTrue(r.equals(q));
815      }
816  
817  
# Line 872 | Line 852 | public class ConcurrentSkipListMapTest e
852          assertEquals(1, sm.size());
853          assertEquals(three, sm.firstKey());
854          assertEquals(three, sm.lastKey());
855 <        assertTrue(sm.remove(three) != null);
855 >        assertEquals("C", sm.remove(three));
856          assertTrue(sm.isEmpty());
857          assertEquals(3, map.size());
858      }
# Line 905 | Line 885 | public class ConcurrentSkipListMapTest e
885          assertEquals(4, map.size());
886          assertEquals(0, sm.size());
887          assertTrue(sm.isEmpty());
888 <        assertTrue(sm.remove(three) == null);
888 >        assertSame(sm.remove(three), null);
889          assertEquals(4, map.size());
890      }
891  
# Line 987 | Line 967 | public class ConcurrentSkipListMapTest e
967          NavigableMap ssm = sm.tailMap(four, true);
968          assertEquals(four, ssm.firstKey());
969          assertEquals(five, ssm.lastKey());
970 <        assertTrue(ssm.remove(four) != null);
970 >        assertEquals("D", ssm.remove(four));
971          assertEquals(1, ssm.size());
972          assertEquals(3, sm.size());
973          assertEquals(4, map.size());
# Line 999 | Line 979 | public class ConcurrentSkipListMapTest e
979      /**
980       * Submaps of submaps subdivide correctly
981       */
982 <    public void testRecursiveSubMaps() {
982 >    public void testRecursiveSubMaps() throws Exception {
983          int mapSize = 1000;
984          Class cl = ConcurrentSkipListMap.class;
985          NavigableMap<Integer, Integer> map = newMap(cl);
# Line 1017 | Line 997 | public class ConcurrentSkipListMapTest e
997                     0, mapSize - 1, true);
998      }
999  
1000 <    static NavigableMap<Integer, Integer> newMap(Class cl) {
1001 <        NavigableMap<Integer, Integer> result = null;
1002 <        try {
1023 <            result = (NavigableMap<Integer, Integer>) cl.newInstance();
1024 <        } catch (Exception e) {
1025 <            fail();
1026 <        }
1000 >    static NavigableMap<Integer, Integer> newMap(Class cl) throws Exception {
1001 >        NavigableMap<Integer, Integer> result =
1002 >            (NavigableMap<Integer, Integer>) cl.newInstance();
1003          assertEquals(result.size(), 0);
1004          assertFalse(result.keySet().iterator().hasNext());
1005          return result;
# Line 1086 | Line 1062 | public class ConcurrentSkipListMapTest e
1062              } else {
1063                  try {
1064                      map.put(key, 2 * key);
1065 <                    fail();
1066 <                } catch (IllegalArgumentException e) {
1091 <                    // expected
1092 <                }
1065 >                    shouldThrow();
1066 >                } catch (IllegalArgumentException success) {}
1067              }
1068          }
1069      }
# Line 1218 | Line 1192 | public class ConcurrentSkipListMapTest e
1192                  // BitSet should support this! Test would run much faster
1193                  while (key >= min) {
1194                      if (bs.get(key))
1195 <                        return(key);
1195 >                        return key;
1196                      key--;
1197                  }
1198                  return -1;
# Line 1284 | Line 1258 | public class ConcurrentSkipListMapTest e
1258              assertEq(rs.last(),  -1);
1259              try {
1260                  map.firstKey();
1261 <                fail();
1262 <            } catch (NoSuchElementException e) {
1289 <                // expected
1290 <            }
1261 >                shouldThrow();
1262 >            } catch (NoSuchElementException success) {}
1263              try {
1264                  map.lastKey();
1265 <                fail();
1266 <            } catch (NoSuchElementException e) {
1295 <                // expected
1296 <            }
1265 >                shouldThrow();
1266 >            } catch (NoSuchElementException success) {}
1267          }
1268      }
1269  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines