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.59 by dl, Fri Oct 5 19:01:35 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 +
842 +    
843 +    public void testReentrantComputeIfAbsent() {
844 +        ConcurrentHashMap<Integer, Integer> map = new ConcurrentHashMap<>(16);
845 +        try {
846 +            for (int i = 0; i < 100; i++) { // force a resize
847 +                map.computeIfAbsent(i, key -> findValue(map, key));
848 +            }
849 +            fail("recursive computeIfAbsent");
850 +        } catch (IllegalStateException ex) {
851 +        }
852 +    }
853 +
854 +    private Integer findValue(ConcurrentHashMap<Integer, Integer> map,
855 +                              Integer key) {
856 +        return (key % 5 == 0) ?  key :
857 +            map.computeIfAbsent(key + 1, k -> findValue(map, k));
858 +    }
859 +    
860   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines