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

Comparing jsr166/src/test/tck/ConcurrentHashMapTest.java (file contents):
Revision 1.57 by jsr166, Sun Jan 7 22:59:18 2018 UTC vs.
Revision 1.61 by jsr166, Fri Oct 5 22:23:34 2018 UTC

# Line 56 | Line 56 | public class ConcurrentHashMapTest exten
56          return map;
57      }
58  
59    /** Re-implement Integer.compare for old java versions */
60    static int compare(int x, int y) {
61        return (x < y) ? -1 : (x > y) ? 1 : 0;
62    }
63
59      // classes for testing Comparable fallbacks
60      static class BI implements Comparable<BI> {
61          private final int value;
62          BI(int value) { this.value = value; }
63          public int compareTo(BI other) {
64 <            return compare(value, other.value);
64 >            return Integer.compare(value, other.value);
65          }
66          public boolean equals(Object x) {
67              return (x instanceof BI) && ((BI)x).value == value;
# Line 100 | Line 95 | public class ConcurrentHashMapTest exten
95                      break;
96              }
97              if (r == 0)
98 <                r = compare(size(), other.size());
98 >                r = Integer.compare(size(), other.size());
99              return r;
100          }
101          private static final long serialVersionUID = 0;
# Line 843 | Line 838 | public class ConcurrentHashMapTest exten
838          assertEquals(mapSize, map.size());
839      }
840  
841 +    public void testReentrantComputeIfAbsent() {
842 +        ConcurrentHashMap<Integer, Integer> map = new ConcurrentHashMap<>(16);
843 +        try {
844 +            for (int i = 0; i < 100; i++) { // force a resize
845 +                map.computeIfAbsent(i, key -> findValue(map, key));
846 +            }
847 +            fail("recursive computeIfAbsent should throw IllegalStateException");
848 +        } catch (IllegalStateException success) {}
849 +    }
850 +
851 +    private Integer findValue(ConcurrentHashMap<Integer, Integer> map,
852 +                              Integer key) {
853 +        return (key % 5 == 0) ?  key :
854 +            map.computeIfAbsent(key + 1, k -> findValue(map, k));
855 +    }
856 +
857   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines