838 |
|
assertEquals(mapSize, map.size()); |
839 |
|
} |
840 |
|
|
841 |
– |
|
842 |
– |
|
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"); |
848 |
< |
} catch (IllegalStateException ex) { |
851 |
< |
} |
847 |
> |
fail("recursive computeIfAbsent should throw IllegalStateException"); |
848 |
> |
} catch (IllegalStateException success) {} |
849 |
|
} |
850 |
|
|
851 |
|
private Integer findValue(ConcurrentHashMap<Integer, Integer> map, |
853 |
|
return (key % 5 == 0) ? key : |
854 |
|
map.computeIfAbsent(key + 1, k -> findValue(map, k)); |
855 |
|
} |
856 |
< |
|
856 |
> |
|
857 |
|
} |