public void testRemoveHead() throws Exception { NewLRUClockHand clock = getAClockHand( getARegion(), new TestEnableLRU() ); LRUTestEntry[] nodes = new LRUTestEntry[10]; int i = 0; for( i = 0; i < 10; i++ ) { nodes[i] = getANode( i ); clock.appendEntry( nodes[i] ); } clock.unlinkEntry(nodes[0]); for( i = 1; i < 10; i ++ ) { LRUTestEntry n = (LRUTestEntry) clock.getLRUEntry( ); assertTrue( "expected nodes[" + nodes[i].id() + "], found nodes[" + n.id() + "]", n == nodes[i] ); } assertEquals(null, clock.getLRUEntry( )); }
public void testRemoveTail() throws Exception { NewLRUClockHand clock = getAClockHand( getARegion(), new TestEnableLRU() ); LRUTestEntry[] nodes = new LRUTestEntry[10]; int i = 0; for( i = 0; i < 10; i++ ) { nodes[i] = getANode( i ); clock.appendEntry( nodes[i] ); } clock.unlinkEntry(nodes[9]); for( i = 0; i < 9; i ++ ) { LRUTestEntry n = (LRUTestEntry) clock.getLRUEntry( ); assertTrue( "expected nodes[" + nodes[i].id() + "], found nodes[" + n.id() + "]", n == nodes[i] ); } assertEquals(null, clock.getLRUEntry( )); }
public void testEvicted() throws Exception { NewLRUClockHand clock = getAClockHand( getARegion(), new TestEnableLRU() ); // getLRUEntry( maxScan ) LRUTestEntry[] nodes = new LRUTestEntry[10]; int i = 0; for( i = 0; i < 10; i++ ) { nodes[i] = getANode( i ); clock.appendEntry( nodes[i] ); } for( i = 0; i < 10; i += 2 ) { clock.unlinkEntry( nodes[i] ); } // getLRUEntry until empty... verify order of results. for( i = 1; i < 10; i += 2 ) { LRUTestEntry n = (LRUTestEntry) clock.getLRUEntry( ); assertTrue( "expected nodes[" + nodes[i].id() + "], found nodes[" + n.id() + "]", n == nodes[i] ); } assertTrue( "expected null", clock.getLRUEntry( ) == null ); }
@Override protected final void lruEntryDestroy(RegionEntry re) { final LRUEntry e = (LRUEntry)re; if (logger.isTraceEnabled(LogMarker.LRU)) { logger.trace(LogMarker.LRU, "lruEntryDestroy for key={}; list size is: {}; actual size is: {}; map size is: {}; entry size: {}; in lru clock: {}", re.getKey(), getTotalEntrySize(), this._getLruList().getExpensiveListCount(), size(), e.getEntrySize(), !e.testEvicted()); } // if (this.lruCreatedKey == re.getKey()) { // String method = Thread.currentThread().getStackTrace()[5].getMethodName(); // } // boolean wasEvicted = e.testEvicted(); /*boolean removed = */_getLruList().unlinkEntry(e); // if (removed || wasEvicted) { // evicted entries have already been removed from the list changeTotalEntrySize(-1 * e.getEntrySize());// subtract the size. Token vTok = re.getValueAsToken(); if (vTok == Token.DESTROYED || vTok == Token.TOMBSTONE) { // OFFHEAP noop TODO: use re.isDestroyedOrTombstone // if in token mode we need to recalculate the size of the entry since it's // staying in the map and may be resurrected e.updateEntrySize(_getCCHelper()); } // } else if (debug) { // debugLogging("entry not removed from LRU list"); // } } /** Called by DiskEntry.Helper.faultInValue
public void testRemoveMiddle() throws Exception { NewLRUClockHand clock = getAClockHand( getARegion(), new TestEnableLRU() ); LRUTestEntry[] nodes = new LRUTestEntry[10]; int i = 0; for( i = 0; i < 10; i++ ) { nodes[i] = getANode( i ); clock.appendEntry( nodes[i] ); } clock.unlinkEntry(nodes[5]); for( i = 0; i < 5; i ++ ) { LRUTestEntry n = (LRUTestEntry) clock.getLRUEntry( ); assertTrue( "expected nodes[" + nodes[i].id() + "], found nodes[" + n.id() + "]", n == nodes[i] ); } for( i = 6; i < 10; i ++ ) { LRUTestEntry n = (LRUTestEntry) clock.getLRUEntry( ); assertTrue( "expected nodes[" + nodes[i].id() + "], found nodes[" + n.id() + "]", n == nodes[i] ); } assertEquals(null, clock.getLRUEntry( )); }
/*boolean removed = */_getLruList().unlinkEntry(e);