72 check(e.getValue() == 2); 73 } 74 } catch (Throwable t) {unexpected(t);} 75 76 try { 77 m.clear(); 78 check(m.isEmpty()); 79 m.put(1,2); 80 Iterator<Map.Entry<Integer,Integer>> it = m.entrySet().iterator(); 81 if (it.hasNext()) { 82 m.put(1,3); // sneaky 83 Map.Entry<Integer, Integer> e = it.next(); 84 check(e.getKey() == 1); 85 check(e.getValue() == 2 || e.getValue() == 3); 86 if (m instanceof ConcurrentHashMap) { 87 e.setValue(4); 88 check(m.get(1) == 4); 89 } 90 } 91 } catch (Throwable t) {unexpected(t);} 92 } 93 94 public static void main(String[] args) { 95 test(new ConcurrentHashMap<Integer,Integer>()); 96 test(new ConcurrentSkipListMap<Integer,Integer>()); 97 98 System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed); 99 if (failed > 0) throw new Error("Some tests failed"); 100 } 101 } | 72 check(e.getValue() == 2); 73 } 74 } catch (Throwable t) {unexpected(t);} 75 76 try { 77 m.clear(); 78 check(m.isEmpty()); 79 m.put(1,2); 80 Iterator<Map.Entry<Integer,Integer>> it = m.entrySet().iterator(); 81 if (it.hasNext()) { 82 m.put(1,3); // sneaky 83 Map.Entry<Integer, Integer> e = it.next(); 84 check(e.getKey() == 1); 85 check(e.getValue() == 2 || e.getValue() == 3); 86 if (m instanceof ConcurrentHashMap) { 87 e.setValue(4); 88 check(m.get(1) == 4); 89 } 90 } 91 } catch (Throwable t) {unexpected(t);} 92 93 try { 94 if (m instanceof ConcurrentSkipListMap) { 95 m.clear(); 96 check(m.isEmpty()); 97 m.put(1,2); 98 check(m.size() == 1); 99 ConcurrentSkipListMap mc = ((ConcurrentSkipListMap) m).clone(); 100 check(m.size() == 1); 101 check(mc.size() == 1); 102 m.put(2,3); 103 check(m.size() == 2); 104 check(mc.size() == 1); 105 } 106 } catch (Throwable t) {unexpected(t);} 107 } 108 109 public static void main(String[] args) { 110 test(new ConcurrentHashMap<Integer,Integer>()); 111 test(new ConcurrentSkipListMap<Integer,Integer>()); 112 113 System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed); 114 if (failed > 0) throw new Error("Some tests failed"); 115 } 116 } |