Search in sources :

Example 1 with SampleableConcurrentHashMap

use of com.hazelcast.internal.util.SampleableConcurrentHashMap in project hazelcast by hazelcast.

the class CacheBasicAbstractTest method testInitableIterator.

@Test
public void testInitableIterator() {
    int testSize = 3007;
    SerializationService serializationService = new DefaultSerializationServiceBuilder().build();
    for (int fetchSize = 1; fetchSize < 102; fetchSize++) {
        SampleableConcurrentHashMap<Data, String> map = new SampleableConcurrentHashMap<>(1000);
        for (int i = 0; i < testSize; i++) {
            Integer key = i;
            Data data = serializationService.toData(key);
            String value1 = "value" + i;
            map.put(data, value1);
        }
        IterationPointer[] pointers = { new IterationPointer(Integer.MAX_VALUE, -1) };
        int total = 0;
        int remaining = testSize;
        while (remaining > 0 && pointers[pointers.length - 1].getIndex() > 0) {
            int size = (Math.min(remaining, fetchSize));
            List<Data> keys = new ArrayList<>(size);
            pointers = map.fetchKeys(pointers, size, keys);
            remaining -= keys.size();
            total += keys.size();
        }
        assertEquals(testSize, total);
    }
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) SampleableConcurrentHashMap(com.hazelcast.internal.util.SampleableConcurrentHashMap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IterationPointer(com.hazelcast.internal.iteration.IterationPointer) ArrayList(java.util.ArrayList) SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data) Test(org.junit.Test)

Aggregations

IterationPointer (com.hazelcast.internal.iteration.IterationPointer)1 Data (com.hazelcast.internal.serialization.Data)1 SerializationService (com.hazelcast.internal.serialization.SerializationService)1 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)1 SampleableConcurrentHashMap (com.hazelcast.internal.util.SampleableConcurrentHashMap)1 ArrayList (java.util.ArrayList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Test (org.junit.Test)1