Search in sources :

Example 1 with IdAwareReference

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;
        }
    });
}
Also used : Reference(java.lang.ref.Reference) IdAwareReference(org.ovirt.engine.core.utils.ReapedMap.IdAwareReference) InvocationOnMock(org.mockito.invocation.InvocationOnMock) IdAwareReference(org.ovirt.engine.core.utils.ReapedMap.IdAwareReference)

Aggregations

Reference (java.lang.ref.Reference)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 IdAwareReference (org.ovirt.engine.core.utils.ReapedMap.IdAwareReference)1