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

Comparing jsr166/src/test/tck/Collection8Test.java (file contents):
Revision 1.43 by jsr166, Thu Dec 15 01:21:22 2016 UTC vs.
Revision 1.47 by jsr166, Mon Aug 21 20:12:36 2017 UTC

# Line 59 | Line 59 | public class Collection8Test extends JSR
59  
60      Object bomb() {
61          return new Object() {
62 <                public boolean equals(Object x) { throw new AssertionError(); }
63 <                public int hashCode() { throw new AssertionError(); }
64 <            };
62 >            public boolean equals(Object x) { throw new AssertionError(); }
63 >            public int hashCode() { throw new AssertionError(); }
64 >        };
65      }
66  
67      /** Checks properties of empty collections. */
# Line 140 | Line 140 | public class Collection8Test extends JSR
140          }
141          if (c instanceof BlockingQueue) {
142              BlockingQueue q = (BlockingQueue) c;
143 <            assertNull(q.poll(0L, MILLISECONDS));
143 >            assertNull(q.poll(randomExpiredTimeout(), randomTimeUnit()));
144          }
145          if (c instanceof BlockingDeque) {
146              BlockingDeque q = (BlockingDeque) c;
147 <            assertNull(q.pollFirst(0L, MILLISECONDS));
148 <            assertNull(q.pollLast(0L, MILLISECONDS));
147 >            assertNull(q.pollFirst(randomExpiredTimeout(), randomTimeUnit()));
148 >            assertNull(q.pollLast(randomExpiredTimeout(), randomTimeUnit()));
149          }
150      }
151  
# Line 541 | Line 541 | public class Collection8Test extends JSR
541          } catch (ConcurrentModificationException ex) {
542              r1 = ConcurrentModificationException.class;
543              assertFalse(impl.isConcurrent());
544        } catch (UnsupportedOperationException ex) {
545            r1 = UnsupportedOperationException.class;
544          }
545          try {
546              it2.forEachRemaining(iteratedForEachRemaining::add);
547              r2 = iteratedForEachRemaining;
548          } catch (ConcurrentModificationException ex) {
549              r2 = ConcurrentModificationException.class;
550 <        } catch (UnsupportedOperationException ex) {
553 <            r2 = UnsupportedOperationException.class;
550 >            assertFalse(impl.isConcurrent());
551          }
552          assertEquals(r1, r2);
553      }
# Line 730 | Line 727 | public class Collection8Test extends JSR
727      }
728  
729      /**
730 +     * Concurrent Spliterators, once exhausted, stay exhausted.
731 +     */
732 +    public void testStickySpliteratorExhaustion() throws Throwable {
733 +        if (!impl.isConcurrent()) return;
734 +        if (!testImplementationDetails) return;
735 +        final ThreadLocalRandom rnd = ThreadLocalRandom.current();
736 +        final Consumer alwaysThrows = e -> { throw new AssertionError(); };
737 +        final Collection c = impl.emptyCollection();
738 +        final Spliterator s = c.spliterator();
739 +        if (rnd.nextBoolean()) {
740 +            assertFalse(s.tryAdvance(alwaysThrows));
741 +        } else {
742 +            s.forEachRemaining(alwaysThrows);
743 +        }
744 +        final Object one = impl.makeElement(1);
745 +        // Spliterator should not notice added element
746 +        c.add(one);
747 +        if (rnd.nextBoolean()) {
748 +            assertFalse(s.tryAdvance(alwaysThrows));
749 +        } else {
750 +            s.forEachRemaining(alwaysThrows);
751 +        }
752 +    }
753 +
754 +    /**
755       * Motley crew of threads concurrently randomly hammer the collection.
756       */
757      public void testDetectRaces() throws Throwable {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines