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.62 by jsr166, Sun Sep 29 20:40:48 2019 UTC

# Line 28 | Line 28 | public class ConcurrentHashMapTest exten
28          class Implementation implements MapImplementation {
29              public Class<?> klazz() { return ConcurrentHashMap.class; }
30              public Map emptyMap() { return new ConcurrentHashMap(); }
31            public Object makeKey(int i) { return i; }
32            public Object makeValue(int i) { return i; }
31              public boolean isConcurrent() { return true; }
32              public boolean permitsNullKeys() { return false; }
33              public boolean permitsNullValues() { return false; }
# Line 56 | Line 54 | public class ConcurrentHashMapTest exten
54          return map;
55      }
56  
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
57      // classes for testing Comparable fallbacks
58      static class BI implements Comparable<BI> {
59          private final int value;
60          BI(int value) { this.value = value; }
61          public int compareTo(BI other) {
62 <            return compare(value, other.value);
62 >            return Integer.compare(value, other.value);
63          }
64          public boolean equals(Object x) {
65              return (x instanceof BI) && ((BI)x).value == value;
# Line 100 | Line 93 | public class ConcurrentHashMapTest exten
93                      break;
94              }
95              if (r == 0)
96 <                r = compare(size(), other.size());
96 >                r = Integer.compare(size(), other.size());
97              return r;
98          }
99          private static final long serialVersionUID = 0;
# Line 843 | Line 836 | public class ConcurrentHashMapTest exten
836          assertEquals(mapSize, map.size());
837      }
838  
839 +    public void testReentrantComputeIfAbsent() {
840 +        ConcurrentHashMap<Integer, Integer> map = new ConcurrentHashMap<>(16);
841 +        try {
842 +            for (int i = 0; i < 100; i++) { // force a resize
843 +                map.computeIfAbsent(i, key -> findValue(map, key));
844 +            }
845 +            fail("recursive computeIfAbsent should throw IllegalStateException");
846 +        } catch (IllegalStateException success) {}
847 +    }
848 +
849 +    private Integer findValue(ConcurrentHashMap<Integer, Integer> map,
850 +                              Integer key) {
851 +        return (key % 5 == 0) ?  key :
852 +            map.computeIfAbsent(key + 1, k -> findValue(map, k));
853 +    }
854 +
855   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines