Search in sources :

Example 1 with GridBoundedConcurrentOrderedMap

use of org.apache.ignite.internal.util.GridBoundedConcurrentOrderedMap in project ignite by apache.

the class GridBoundedConcurrentOrderedMapSelfTest method testEvictionListener.

/**
 */
@Test
public void testEvictionListener() {
    GridBoundedConcurrentOrderedMap<Integer, String> m = new GridBoundedConcurrentOrderedMap<>(1);
    final AtomicInteger evicted = new AtomicInteger();
    m.evictionListener(new CI2<Integer, String>() {

        @Override
        public void apply(Integer k, String v) {
            assertEquals(Integer.toString(k), v);
            assertEquals(evicted.getAndIncrement(), k.intValue());
        }
    });
    m.put(0, "0");
    assertEquals(1, m.size());
    for (int i = 1; i <= 10; i++) {
        m.put(i, Integer.toString(i));
        assertEquals(1, m.size());
    }
    assertEquals(1, m.size());
    assertEquals(10, m.lastKey().intValue());
    assertEquals(10, evicted.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridBoundedConcurrentOrderedMap(org.apache.ignite.internal.util.GridBoundedConcurrentOrderedMap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test) GridCommonTest(org.apache.ignite.testframework.junits.common.GridCommonTest)

Aggregations

AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 GridBoundedConcurrentOrderedMap (org.apache.ignite.internal.util.GridBoundedConcurrentOrderedMap)1 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)1 GridCommonTest (org.apache.ignite.testframework.junits.common.GridCommonTest)1 Test (org.junit.Test)1