public void testClear() { MapMakerInternalMap<Object, Object, ?, ?> map = makeMap(createMapMaker().concurrencyLevel(1).initialCapacity(1)); Segment<Object, Object, ?, ?> segment = map.segments[0]; AtomicReferenceArray<? extends InternalEntry<Object, Object, ?>> table = segment.table; assertEquals(1, table.length()); Object key = new Object(); Object value = new Object(); int hash = map.hash(key); InternalEntry<Object, Object, ?> entry = segment.newEntryForTesting(key, hash, null); segment.setValueForTesting(entry, value); segment.setTableEntryForTesting(0, entry); segment.readCount.incrementAndGet(); segment.count = 1; assertSame(entry, table.get(0)); segment.clear(); assertNull(table.get(0)); assertEquals(0, segment.readCount.get()); assertEquals(0, segment.count); }
public void testRemoveEntry() { MapMakerInternalMap<Object, Object, ?, ?> map = makeMap(createMapMaker().concurrencyLevel(1).initialCapacity(1)); Segment<Object, Object, ?, ?> segment = map.segments[0]; AtomicReferenceArray<? extends InternalEntry<Object, Object, ?>> table = segment.table; assertEquals(1, table.length()); Object key = new Object(); Object value = new Object(); int hash = map.hash(key); InternalEntry<Object, Object, ?> entry = segment.newEntryForTesting(key, hash, null); segment.setValueForTesting(entry, value); // remove absent assertFalse(segment.removeTableEntryForTesting(entry)); segment.setTableEntryForTesting(0, entry); segment.count = 1; assertTrue(segment.removeTableEntryForTesting(entry)); assertEquals(0, segment.count); assertNull(table.get(0)); }
segment.setValueForTesting(entry, value);
segment.setValueForTesting(entry, value);
int hashOne = map.hash(keyOne); InternalEntry<Object, Object, ?> entryOne = segment.newEntryForTesting(keyOne, hashOne, null); segment.setValueForTesting(entryOne, valueOne); Object keyTwo = new Object(); Object valueTwo = new Object(); InternalEntry<Object, Object, ?> entryTwo = segment.newEntryForTesting(keyTwo, hashTwo, entryOne); segment.setValueForTesting(entryTwo, valueTwo); Object keyThree = new Object(); Object valueThree = new Object(); InternalEntry<Object, Object, ?> entryThree = segment.newEntryForTesting(keyThree, hashThree, entryTwo); segment.setValueForTesting(entryThree, valueThree);
segment.setValueForTesting(entry, value);
public void testClearValue() { MapMakerInternalMap<Object, Object, ?, ?> map = makeMap(createMapMaker().concurrencyLevel(1).initialCapacity(1).weakValues()); Segment<Object, Object, ?, ?> segment = map.segments[0]; AtomicReferenceArray<? extends InternalEntry<Object, Object, ?>> table = segment.table; assertEquals(1, table.length()); Object key = new Object(); Object value = new Object(); int hash = map.hash(key); InternalEntry<Object, Object, ?> entry = segment.newEntryForTesting(key, hash, null); segment.setValueForTesting(entry, value); WeakValueReference<Object, Object, ?> valueRef = segment.getWeakValueReferenceForTesting(entry); // clear absent assertFalse(segment.clearValueForTesting(key, hash, valueRef)); segment.setTableEntryForTesting(0, entry); // don't increment count; this is used during computation assertTrue(segment.clearValueForTesting(key, hash, valueRef)); // no notification sent with clearValue assertEquals(0, segment.count); assertNull(table.get(0)); // clear wrong value reference segment.setTableEntryForTesting(0, entry); WeakValueReference<Object, Object, ?> otherValueRef = segment.newWeakValueReferenceForTesting(entry, value); segment.setWeakValueReferenceForTesting(entry, otherValueRef); assertFalse(segment.clearValueForTesting(key, hash, valueRef)); segment.setWeakValueReferenceForTesting(entry, valueRef); assertTrue(segment.clearValueForTesting(key, hash, valueRef)); }
segment.setValueForTesting(entry, value);
public void testCopyEntry() { for (MapMaker maker : allWeakValueStrengthMakers()) { MapMakerInternalMap<Object, Object, ?, ?> map = makeMap(maker); Segment<Object, Object, ?, ?> segment = map.segments[0]; Object keyOne = new Object(); Object valueOne = new Object(); int hashOne = map.hash(keyOne); InternalEntry<Object, Object, ?> entryOne = segment.newEntryForTesting(keyOne, hashOne, null); segment.setValueForTesting(entryOne, valueOne); Object keyTwo = new Object(); Object valueTwo = new Object(); int hashTwo = map.hash(keyTwo); InternalEntry<Object, Object, ?> entryTwo = segment.newEntryForTesting(keyTwo, hashTwo, null); segment.setValueForTesting(entryTwo, valueTwo); InternalEntry<Object, Object, ?> copyOne = segment.copyForTesting(entryOne, null); assertSame(keyOne, entryOne.getKey()); assertEquals(hashOne, entryOne.getHash()); assertNull(entryOne.getNext()); assertSame(valueOne, copyOne.getValue()); InternalEntry<Object, Object, ?> copyTwo = segment.copyForTesting(entryTwo, copyOne); assertSame(keyTwo, copyTwo.getKey()); assertEquals(hashTwo, copyTwo.getHash()); assertSame(copyOne, copyTwo.getNext()); assertSame(valueTwo, copyTwo.getValue()); } }
public void testClear() { MapMakerInternalMap<Object, Object, ?, ?> map = makeMap(createMapMaker().concurrencyLevel(1).initialCapacity(1)); Segment<Object, Object, ?, ?> segment = map.segments[0]; AtomicReferenceArray<? extends InternalEntry<Object, Object, ?>> table = segment.table; assertEquals(1, table.length()); Object key = new Object(); Object value = new Object(); int hash = map.hash(key); InternalEntry<Object, Object, ?> entry = segment.newEntryForTesting(key, hash, null); segment.setValueForTesting(entry, value); segment.setTableEntryForTesting(0, entry); segment.readCount.incrementAndGet(); segment.count = 1; assertSame(entry, table.get(0)); segment.clear(); assertNull(table.get(0)); assertEquals(0, segment.readCount.get()); assertEquals(0, segment.count); }
public void testRemoveEntry() { MapMakerInternalMap<Object, Object, ?, ?> map = makeMap(createMapMaker().concurrencyLevel(1).initialCapacity(1)); Segment<Object, Object, ?, ?> segment = map.segments[0]; AtomicReferenceArray<? extends InternalEntry<Object, Object, ?>> table = segment.table; assertEquals(1, table.length()); Object key = new Object(); Object value = new Object(); int hash = map.hash(key); InternalEntry<Object, Object, ?> entry = segment.newEntryForTesting(key, hash, null); segment.setValueForTesting(entry, value); // remove absent assertFalse(segment.removeTableEntryForTesting(entry)); segment.setTableEntryForTesting(0, entry); segment.count = 1; assertTrue(segment.removeTableEntryForTesting(entry)); assertEquals(0, segment.count); assertNull(table.get(0)); }
segment.setValueForTesting(entry, value);
int hashOne = map.hash(keyOne); InternalEntry<Object, Object, ?> entryOne = segment.newEntryForTesting(keyOne, hashOne, null); segment.setValueForTesting(entryOne, valueOne); Object keyTwo = new Object(); Object valueTwo = new Object(); InternalEntry<Object, Object, ?> entryTwo = segment.newEntryForTesting(keyTwo, hashTwo, entryOne); segment.setValueForTesting(entryTwo, valueTwo); Object keyThree = new Object(); Object valueThree = new Object(); InternalEntry<Object, Object, ?> entryThree = segment.newEntryForTesting(keyThree, hashThree, entryTwo); segment.setValueForTesting(entryThree, valueThree);
segment.setValueForTesting(entry, value);
public void testClearValue() { MapMakerInternalMap<Object, Object, ?, ?> map = makeMap(createMapMaker().concurrencyLevel(1).initialCapacity(1).weakValues()); Segment<Object, Object, ?, ?> segment = map.segments[0]; AtomicReferenceArray<? extends InternalEntry<Object, Object, ?>> table = segment.table; assertEquals(1, table.length()); Object key = new Object(); Object value = new Object(); int hash = map.hash(key); InternalEntry<Object, Object, ?> entry = segment.newEntryForTesting(key, hash, null); segment.setValueForTesting(entry, value); WeakValueReference<Object, Object, ?> valueRef = segment.getWeakValueReferenceForTesting(entry); // clear absent assertFalse(segment.clearValueForTesting(key, hash, valueRef)); segment.setTableEntryForTesting(0, entry); // don't increment count; this is used during computation assertTrue(segment.clearValueForTesting(key, hash, valueRef)); // no notification sent with clearValue assertEquals(0, segment.count); assertNull(table.get(0)); // clear wrong value reference segment.setTableEntryForTesting(0, entry); WeakValueReference<Object, Object, ?> otherValueRef = segment.newWeakValueReferenceForTesting(entry, value); segment.setWeakValueReferenceForTesting(entry, otherValueRef); assertFalse(segment.clearValueForTesting(key, hash, valueRef)); segment.setWeakValueReferenceForTesting(entry, valueRef); assertTrue(segment.clearValueForTesting(key, hash, valueRef)); }
public void testCopyEntry() { for (MapMaker maker : allWeakValueStrengthMakers()) { MapMakerInternalMap<Object, Object, ?, ?> map = makeMap(maker); Segment<Object, Object, ?, ?> segment = map.segments[0]; Object keyOne = new Object(); Object valueOne = new Object(); int hashOne = map.hash(keyOne); InternalEntry<Object, Object, ?> entryOne = segment.newEntryForTesting(keyOne, hashOne, null); segment.setValueForTesting(entryOne, valueOne); Object keyTwo = new Object(); Object valueTwo = new Object(); int hashTwo = map.hash(keyTwo); InternalEntry<Object, Object, ?> entryTwo = segment.newEntryForTesting(keyTwo, hashTwo, null); segment.setValueForTesting(entryTwo, valueTwo); InternalEntry<Object, Object, ?> copyOne = segment.copyForTesting(entryOne, null); assertSame(keyOne, entryOne.getKey()); assertEquals(hashOne, entryOne.getHash()); assertNull(entryOne.getNext()); assertSame(valueOne, copyOne.getValue()); InternalEntry<Object, Object, ?> copyTwo = segment.copyForTesting(entryTwo, copyOne); assertSame(keyTwo, copyTwo.getKey()); assertEquals(hashTwo, copyTwo.getHash()); assertSame(copyOne, copyTwo.getNext()); assertSame(valueTwo, copyTwo.getValue()); } }