use of org.ovirt.engine.core.utils.ReapedMap.IdAwareReference in project ovirt-engine by oVirt.
the class ReapedMapTest method setUpGCExpectations.
@SuppressWarnings({ "unchecked", "rawtypes" })
private void setUpGCExpectations(final int gcAfter) {
ReferenceQueue<Integer> queue = mock(ReferenceQueue.class);
map = new ReapedMap<>(10000, false, queue);
final IdAwareReference ref = mock(IdAwareReference.class);
when(ref.getKey()).thenReturn("three").thenReturn(null);
// the gcAfter queue poll simulates a GC event and triggers deletion
// on the reapable map
when(queue.poll()).thenAnswer(new Answer<Reference<Integer>>() {
private int times = 0;
@Override
public Reference<Integer> answer(InvocationOnMock invocation) throws Throwable {
return times++ == gcAfter ? ref : null;
}
});
}
Aggregations