package com.hazelcast.map.mapstore;

import com.hazelcast.config.Config;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IMap;
import com.hazelcast.query.Predicates;
import com.hazelcast.test.HazelcastSerialClassRunner;
import com.hazelcast.test.HazelcastTestSupport;
import com.hazelcast.test.annotation.QuickTest;
import com.hazelcast.test.annotation.Repeat;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import static com.hazelcast.map.mapstore.MapStoreTest.newConfig;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

@RunWith(HazelcastSerialClassRunner.class)
@Category(QuickTest.class)
@Repeat(20)
public class MapStoreWithPredicateTest extends HazelcastTestSupport {

    @Test
    public void testKeySetWithPredicate_checksMapStoreLoad() throws InterruptedException {
        MapStoreTest.TestEventBasedMapStore testMapStore = new MapStoreTest.TestEventBasedMapStore();

        Map mapForStore = new HashMap();
        mapForStore.put("key1", 17);
        mapForStore.put("key2", 37);
        mapForStore.put("key3", 47);
        testMapStore.getStore().putAll(mapForStore);

        Config config = newConfig(testMapStore, 0);
        HazelcastInstance instance = createHazelcastInstance(config);
        IMap map = instance.getMap("default");

        Set expected = map.keySet(Predicates.greaterThan("value", 1));
        assertEquals(3, expected.size());
        assertTrue(expected.contains("key1"));
        assertTrue(expected.contains("key2"));
        assertTrue(expected.contains("key3"));
    }


    @Test
    public void testValuesWithPredicate_checksMapStoreLoad() throws InterruptedException {
        MapStoreTest.TestEventBasedMapStore testMapStore = new MapStoreTest.TestEventBasedMapStore();

        Map mapForStore = new HashMap();
        mapForStore.put("key1", 17);
        mapForStore.put("key2", 37);
        mapForStore.put("key3", 47);
        testMapStore.getStore().putAll(mapForStore);

        Config config = newConfig(testMapStore, 0);
        HazelcastInstance instance = createHazelcastInstance(config);
        IMap map = instance.getMap("default");

        final Collection values = map.values(Predicates.greaterThan("value", 1));
        assertEquals(3, values.size());
        assertTrue(values.contains(17));
        assertTrue(values.contains(37));
        assertTrue(values.contains(47));
    }

    @Test
    public void testEntrySetWithPredicate_checksMapStoreLoad() throws InterruptedException {
        MapStoreTest.TestEventBasedMapStore testMapStore = new MapStoreTest.TestEventBasedMapStore();

        Map mapForStore = new HashMap();
        mapForStore.put("key1", 17);
        mapForStore.put("key2", 37);
        mapForStore.put("key3", 47);
        testMapStore.getStore().putAll(mapForStore);

        Config config = newConfig(testMapStore, 0);
        HazelcastInstance instance = createHazelcastInstance(config);
        IMap map = instance.getMap("default");

        final Set<Map.Entry> entrySet = map.entrySet(Predicates.greaterThan("value", 1));

        assertEquals(3, entrySet.size());
    }
}

@@ -336,53 +336,8 @@
 st;%0A
-import com.hazelcast.test.annotation.Repeat;%0A
 impo
@@ -768,20 +768,8 @@
 ss)%0A
-@Repeat(20)%0A
 publ

IMap methods which uses predicates should check if map store loaded. cont