@Test
 public void testWANClusteringActivePassive() throws Exception {
   Config c1 = new Config();
   Config c2 = new Config();
   c1.getGroupConfig().setName("newyork");
   c1.addWanReplicationConfig(
       new WanReplicationConfig()
           .setName("my-wan")
           .addTargetClusterConfig(
               new WanTargetClusterConfig().addEndpoint("127.0.0.1:5702").setGroupName("london")));
   c1.getMapConfig("default")
       .setWanReplicationRef(
           new WanReplicationRef().setName("my-wan").setMergePolicy(PassThroughMergePolicy.NAME));
   c2.getGroupConfig().setName("london");
   c2.getMapConfig("default")
       .setWanReplicationRef(
           new WanReplicationRef().setName("my-wan").setMergePolicy(PassThroughMergePolicy.NAME));
   HazelcastInstance h10 = Hazelcast.newHazelcastInstance(c1);
   HazelcastInstance h20 = Hazelcast.newHazelcastInstance(c2);
   int size = 1000;
   MergeLatch mergeLatch2 = new MergeLatch(size);
   getConcurrentMapManager(h20).addWanMergeListener(mergeLatch2);
   for (int i = 0; i < size; i++) {
     h10.getMap("default").put(i, "value" + i);
   }
   assertTrue("Latch state: " + mergeLatch2, mergeLatch2.await(60, TimeUnit.SECONDS));
   Thread.sleep(1000);
   assertEquals(size, mergeLatch2.totalOperations());
   assertEquals(size, h10.getMap("default").size());
   assertEquals(size, h20.getMap("default").size());
   for (int i = 0; i < size; i++) {
     assertEquals("value" + i, h20.getMap("default").get(i));
   }
 }
Exemple #2
0
 @Test
 public void testNearCacheEvictionByUsingMapTTLEviction() throws InterruptedException {
   final int instanceCount = 3;
   final int ttl = 1;
   final int size = 1000;
   final Config cfg = new Config();
   final String mapName = "_testNearCacheEvictionByUsingMapTTLEviction_";
   final NearCacheConfig nearCacheConfig = new NearCacheConfig();
   nearCacheConfig.setInvalidateOnChange(true);
   nearCacheConfig.setInMemoryFormat(InMemoryFormat.OBJECT);
   cfg.getMapConfig(mapName).setNearCacheConfig(nearCacheConfig);
   final MapConfig mapConfig = cfg.getMapConfig(mapName);
   mapConfig.setTimeToLiveSeconds(ttl);
   final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(instanceCount);
   final HazelcastInstance instance1 = factory.newHazelcastInstance(cfg);
   final HazelcastInstance instance2 = factory.newHazelcastInstance(cfg);
   final HazelcastInstance instance3 = factory.newHazelcastInstance(cfg);
   final IMap map1 = instance1.getMap(mapName);
   final IMap map2 = instance2.getMap(mapName);
   final IMap map3 = instance3.getMap(mapName);
   // observe eviction
   final CountDownLatch latch = new CountDownLatch(size);
   map1.addEntryListener(
       new EntryAdapter() {
         public void entryEvicted(EntryEvent event) {
           latch.countDown();
         }
       },
       false);
   // populate map
   for (int i = 0; i < size; i++) {
     // populate.
     map1.put(i, i);
     // bring near caches. -- here is a time window
     // that "i" already evicted. so a "get" brings
     // a NULL object to the near cache.
     map1.get(i);
     map2.get(i);
     map3.get(i);
   }
   // wait operations to complete
   assertOpenEventually(latch);
   // check map size after eviction.
   assertEquals(0, map1.size());
   assertEquals(0, map2.size());
   assertEquals(0, map3.size());
   // near cache sizes should be zero after eviction.
   assertEquals(0, countNotNullValuesInNearCache(mapName, instance1));
   assertEquals(0, countNotNullValuesInNearCache(mapName, instance2));
   assertEquals(0, countNotNullValuesInNearCache(mapName, instance3));
 }
Exemple #3
0
  @Test
  public void testMapRecordEviction() throws InterruptedException {
    int size = 100000;
    Config cfg = new Config();
    MapConfig mc = cfg.getMapConfig("testMapRecordEviction");
    mc.setTimeToLiveSeconds(1);
    final CountDownLatch latch = new CountDownLatch(size);
    mc.addEntryListenerConfig(
        new EntryListenerConfig()
            .setImplementation(
                new EntryAdapter() {
                  public void entryEvicted(EntryEvent event) {
                    latch.countDown();
                  }
                })
            .setLocal(true));

    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    final HazelcastInstance[] instances = factory.newInstances(cfg);

    IMap map = instances[0].getMap("testMapRecordEviction");
    for (int i = 0; i < size; i++) {
      map.put(i, i);
    }
    assertTrue(latch.await(5, TimeUnit.MINUTES));
    assertEquals(0, map.size());
  }
Exemple #4
0
  @Test
  public void testGetAsyncIssue1863() throws Exception {
    final String mapName = "testGetAsyncWithNearCacheIssue1863";
    Config config = new Config();
    final NearCacheConfig nearCacheConfig = new NearCacheConfig();
    nearCacheConfig.setCacheLocalEntries(true);
    config.getMapConfig(mapName).setNearCacheConfig(nearCacheConfig);
    final TestHazelcastInstanceFactory hazelcastInstanceFactory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance1 = hazelcastInstanceFactory.newHazelcastInstance(config);
    HazelcastInstance instance2 = hazelcastInstanceFactory.newHazelcastInstance(config);

    IMap<Integer, Integer> map = instance1.getMap(mapName);
    HashSet keys = new HashSet();
    int size = 1000;
    // populate near cache   -- cache local entries mode on.
    for (int i = 0; i < size; i++) {
      map.get(i);
      keys.add(i);
    }

    for (int i = 0; i < size; i++) {
      final Future<Integer> async = map.getAsync(i);
      assertNull(async.get());
    }

    NearCacheStats stats = map.getLocalMapStats().getNearCacheStats();
    assertEquals(size, stats.getHits());
  }
Exemple #5
0
  @Test
  public void testGetAsync() throws Exception {
    final String mapName = "testGetAsyncWithNearCache";
    Config config = new Config();
    config
        .getMapConfig(mapName)
        .setNearCacheConfig(new NearCacheConfig().setInvalidateOnChange(false));
    final TestHazelcastInstanceFactory hazelcastInstanceFactory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance1 = hazelcastInstanceFactory.newHazelcastInstance(config);
    HazelcastInstance instance2 = hazelcastInstanceFactory.newHazelcastInstance(config);

    IMap<Integer, Integer> map = instance1.getMap(mapName);
    HashSet keys = new HashSet();
    int size = 1000;
    for (int i = 0; i < size; i++) {
      map.put(i, i);
      keys.add(i);
    }
    // populate near cache
    for (int i = 0; i < size; i++) {
      map.get(i);
    }

    for (int i = 0; i < size; i++) {
      final Future<Integer> async = map.getAsync(i);
    }

    NearCacheStats stats2 = map.getLocalMapStats().getNearCacheStats();
    assertTrue("hits", 400 < stats2.getHits());
  }
Exemple #6
0
  @Test
  public void testCacheLocalEntries() {
    int n = 2;
    String mapName = "test";

    Config config = new Config();
    final NearCacheConfig nearCacheConfig = new NearCacheConfig();
    nearCacheConfig.setCacheLocalEntries(true);
    nearCacheConfig.setInvalidateOnChange(false);
    final MapConfig mapConfig = config.getMapConfig(mapName);
    mapConfig.setNearCacheConfig(nearCacheConfig);
    HazelcastInstance instance = createHazelcastInstanceFactory(n).newInstances(config)[0];

    IMap<String, String> map = instance.getMap(mapName);

    int noOfEntries = 100;

    for (int i = 0; i < noOfEntries; i++) {
      map.put("key" + i, "value" + i);
    }

    // warm-up cache
    for (int i = 0; i < noOfEntries; i++) {
      map.get("key" + i);
    }

    NearCache nearCache = getNearCache(mapName, instance);
    assertEquals(noOfEntries, nearCache.size());
  }
Exemple #7
0
  @Test
  public void testMapContainsKey_withNearCache() {
    int n = 3;
    String mapName = "test";

    Config config = new Config();
    config
        .getMapConfig(mapName)
        .setNearCacheConfig(new NearCacheConfig().setInvalidateOnChange(true));
    HazelcastInstance instance = createHazelcastInstanceFactory(n).newInstances(config)[0];

    IMap<String, String> map = instance.getMap("mapName");
    map.put("key1", "value1");
    map.put("key2", "value2");
    map.put("key3", "value3");

    map.get("key1");
    map.get("key2");
    map.get("key3");
    assertEquals(map.containsKey("key1"), true);
    assertEquals(map.containsKey("key5"), false);
    map.remove("key1");
    assertEquals(map.containsKey("key1"), false);
    assertEquals(map.containsKey("key2"), true);
    assertEquals(map.containsKey("key5"), false);
  }
Exemple #8
0
  @Test
  public void testNearCacheStats() throws Exception {
    String mapName = "NearCacheStatsTest";
    Config config = new Config();
    config
        .getMapConfig(mapName)
        .setNearCacheConfig(new NearCacheConfig().setInvalidateOnChange(true));
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance[] instances = factory.newInstances(config);
    IMap<Integer, Integer> map = instances[0].getMap("NearCacheStatsTest");

    for (int i = 0; i < 1000; i++) {
      map.put(i, i);
    }
    // populate near cache
    for (int i = 0; i < 1000; i++) {
      map.get(i);
    }

    NearCacheStats stats = map.getLocalMapStats().getNearCacheStats();

    assertTrue("owned Entries", 400 < stats.getOwnedEntryCount());
    assertTrue("misses", 1000 == stats.getMisses());
    // make some hits
    for (int i = 0; i < 1000; i++) {
      map.get(i);
    }
    NearCacheStats stats2 = map.getLocalMapStats().getNearCacheStats();

    assertTrue("hits", 400 < stats2.getHits());
    assertTrue("misses", 400 < stats2.getMisses());
    assertTrue("hits+misses", 2000 == stats2.getHits() + stats2.getMisses());
  }
Exemple #9
0
  @Test
  public void testZeroResetsTTL() throws InterruptedException {
    Config cfg = new Config();
    MapConfig mc = cfg.getMapConfig("testZeroResetsTTL");
    int ttl = 5;
    mc.setTimeToLiveSeconds(ttl);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(1);
    HazelcastInstance instance = factory.newHazelcastInstance(cfg);
    IMap<Object, Object> map = instance.getMap("testZeroResetsTTL");
    final CountDownLatch latch = new CountDownLatch(1);
    map.addEntryListener(
        new EntryAdapter<Object, Object>() {
          public void entryEvicted(EntryEvent event) {
            latch.countDown();
          }
        },
        false);

    map.put(1, 1);
    map.put(2, 2);
    map.put(1, 2, 0, TimeUnit.SECONDS);
    latch.await(10, TimeUnit.SECONDS);
    assertNull(map.get(2));
    assertEquals(2, map.get(1));
  }
  @Test(timeout = 120000)
  public void testMapStoreNotCalledFromEntryProcessorBackup() throws Exception {
    final String mapName = "testMapStoreNotCalledFromEntryProcessorBackup_" + randomString();
    final int instanceCount = 2;
    Config config = getConfig();
    // Configure map with one backup and dummy map store
    MapConfig mapConfig = config.getMapConfig(mapName);
    mapConfig.setBackupCount(1);
    MapStoreConfig mapStoreConfig = new MapStoreConfig();
    MapStoreWithStoreCount mapStore = new MapStoreWithStoreCount(1, 120);
    mapStoreConfig.setImplementation(mapStore);
    mapConfig.setMapStoreConfig(mapStoreConfig);

    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(instanceCount);
    HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(config);
    HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(config);

    final IMap<String, String> map = instance1.getMap(mapName);
    final String key = "key";
    final String value = "value";
    // executeOnKey
    map.executeOnKey(key, new ValueSetterEntryProcessor(value));
    mapStore.awaitStores();

    assertEquals(value, map.get(key));
    assertEquals(1, mapStore.getCount());
  }
  @Test(timeout = 120000)
  public void testInitialLoadModeEagerMultipleThread() {
    final String mapName = "default";
    final int instanceCount = 2;
    final int size = 10000;
    final TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(instanceCount);
    final CountDownLatch countDownLatch = new CountDownLatch(instanceCount - 1);
    final Config config = getConfig();
    GroupConfig groupConfig = new GroupConfig("testEager");
    config.setGroupConfig(groupConfig);
    MapStoreConfig mapStoreConfig = new MapStoreConfig();
    mapStoreConfig.setEnabled(true);
    mapStoreConfig.setImplementation(new SimpleMapLoader(size, true));
    mapStoreConfig.setInitialLoadMode(MapStoreConfig.InitialLoadMode.EAGER);
    config.getMapConfig(mapName).setMapStoreConfig(mapStoreConfig);

    HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(config);
    Runnable runnable =
        new Runnable() {
          public void run() {
            HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(config);
            final IMap<Object, Object> map = instance2.getMap(mapName);
            assertEquals(size, map.size());
            countDownLatch.countDown();
          }
        };
    new Thread(runnable).start();

    assertOpenEventually(countDownLatch, 120);
    IMap map = instance1.getMap(mapName);
    assertEquals(size, map.size());
  }
Exemple #12
0
 @Test
 public void testNearCacheEvictionByUsingMapClear() throws InterruptedException {
   final Config cfg = new Config();
   final String mapName = "testNearCacheEviction";
   final NearCacheConfig nearCacheConfig = new NearCacheConfig();
   nearCacheConfig.setInvalidateOnChange(true);
   cfg.getMapConfig(mapName).setNearCacheConfig(nearCacheConfig);
   final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
   final HazelcastInstance hazelcastInstance1 = factory.newHazelcastInstance(cfg);
   final HazelcastInstance hazelcastInstance2 = factory.newHazelcastInstance(cfg);
   final IMap map1 = hazelcastInstance1.getMap(mapName);
   final IMap map2 = hazelcastInstance2.getMap(mapName);
   final int size = 10;
   // populate map.
   for (int i = 0; i < size; i++) {
     map1.put(i, i);
   }
   // populate near cache
   for (int i = 0; i < size; i++) {
     map1.get(i);
     map2.get(i);
   }
   // clear map should trigger near cache eviction.
   map1.clear();
   for (int i = 0; i < size; i++) {
     assertNull(map1.get(i));
   }
 }
 @Test(timeout = 120000)
 public void testIssue583MapReplaceShouldTriggerMapStore() {
   final ConcurrentMap<String, Long> store = new ConcurrentHashMap<String, Long>();
   final MapStore<String, Long> myMapStore = new SimpleMapStore<String, Long>(store);
   Config config = getConfig();
   config
       .getMapConfig("myMap")
       .setMapStoreConfig(new MapStoreConfig().setImplementation(myMapStore));
   TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(3);
   HazelcastInstance hc = nodeFactory.newHazelcastInstance(config);
   IMap<String, Long> myMap = hc.getMap("myMap");
   myMap.put("one", 1L);
   assertEquals(1L, myMap.get("one").longValue());
   assertEquals(1L, store.get("one").longValue());
   myMap.putIfAbsent("two", 2L);
   assertEquals(2L, myMap.get("two").longValue());
   assertEquals(2L, store.get("two").longValue());
   myMap.putIfAbsent("one", 5L);
   assertEquals(1L, myMap.get("one").longValue());
   assertEquals(1L, store.get("one").longValue());
   myMap.replace("one", 1L, 111L);
   assertEquals(111L, myMap.get("one").longValue());
   assertEquals(111L, store.get("one").longValue());
   myMap.replace("one", 1L);
   assertEquals(1L, myMap.get("one").longValue());
   assertEquals(1L, store.get("one").longValue());
 }
 @Test
 public void testCaseInsensitivityOfSettings() {
   String xml =
       "<hazelcast xmlns=\"http://www.hazelcast.com/schema/config\">\n"
           + "<map name=\"testCaseInsensitivity\">"
           + "<in-memory-format>BINARY</in-memory-format>     "
           + "<backup-count>1</backup-count>                 "
           + "<async-backup-count>0</async-backup-count>    "
           + "<time-to-live-seconds>0</time-to-live-seconds>"
           + "<max-idle-seconds>0</max-idle-seconds>    "
           + "<eviction-policy>NONE</eviction-policy>  "
           + "<max-size policy=\"per_partition\">0</max-size>"
           + "<eviction-percentage>25</eviction-percentage>"
           + "<merge-policy>com.hazelcast.map.merge.PassThroughMergePolicy</merge-policy>"
           + "</map>"
           + "</hazelcast>";
   final Config config = buildConfig(xml);
   final MapConfig mapConfig = config.getMapConfig("testCaseInsensitivity");
   assertTrue(mapConfig.getInMemoryFormat().equals(InMemoryFormat.BINARY));
   assertTrue(mapConfig.getEvictionPolicy().equals(EvictionPolicy.NONE));
   assertTrue(
       mapConfig
           .getMaxSizeConfig()
           .getMaxSizePolicy()
           .equals(MaxSizeConfig.MaxSizePolicy.PER_PARTITION));
 }
 @Test
 public void testMapWanReplicationRef() {
   String mapName = "testMapWanReplicationRef";
   String refName = "test";
   String mergePolicy = "TestMergePolicy";
   String xml =
       HAZELCAST_START_TAG
           + "  <map name=\""
           + mapName
           + "\">\n"
           + "    <wan-replication-ref name=\"test\">\n"
           + "      <merge-policy>TestMergePolicy</merge-policy>\n"
           + "      <filters>\n"
           + "        <filter-impl>com.example.SampleFilter</filter-impl>\n"
           + "      </filters>\n"
           + "    </wan-replication-ref>\n"
           + "  </map>\n"
           + "</hazelcast>";
   final Config config = buildConfig(xml);
   System.out.println("config = " + config);
   WanReplicationRef wanRef = config.getMapConfig(mapName).getWanReplicationRef();
   assertEquals(refName, wanRef.getName());
   assertEquals(mergePolicy, wanRef.getMergePolicy());
   assertTrue(wanRef.isRepublishingEnabled());
   assertEquals(1, wanRef.getFilters().size());
   assertEquals("com.example.SampleFilter", wanRef.getFilters().get(0));
 }
  @Test(timeout = 120000)
  public void testIssue991EvictedNullIssue() throws InterruptedException {
    MapStoreConfig mapStoreConfig = new MapStoreConfig();
    mapStoreConfig.setEnabled(true);
    mapStoreConfig.setImplementation(
        new MapLoader<String, String>() {
          @Override
          public String load(String key) {
            return null;
          }

          @Override
          public Map<String, String> loadAll(Collection<String> keys) {
            return null;
          }

          @Override
          public Set<String> loadAllKeys() {
            return null;
          }
        });
    Config config = getConfig();
    config.getMapConfig("testIssue991EvictedNullIssue").setMapStoreConfig(mapStoreConfig);
    HazelcastInstance hc = createHazelcastInstance(config);
    IMap<Object, Object> map = hc.getMap("testIssue991EvictedNullIssue");
    map.get("key");
    assertNull(map.get("key"));
    map.put("key", "value");
    Thread.sleep(2000);
    assertEquals("value", map.get("key"));
  }
  @Test(timeout = 120000)
  public void testIssue1142ExceptionWhenLoadAllReturnsNull() {
    Config config = getConfig();
    String mapname = "testIssue1142ExceptionWhenLoadAllReturnsNull";
    MapStoreConfig mapStoreConfig = new MapStoreConfig();
    mapStoreConfig.setImplementation(
        new MapStoreAdapter<String, String>() {
          @Override
          public Set<String> loadAllKeys() {
            Set keys = new HashSet();
            keys.add("key");
            return keys;
          }

          public Map loadAll(Collection keys) {
            return null;
          }
        });
    config.getMapConfig(mapname).setMapStoreConfig(mapStoreConfig);
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance = nodeFactory.newHazelcastInstance(config);
    HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(config);
    final IMap map = instance.getMap(mapname);
    for (int i = 0; i < 300; i++) {
      map.put(i, i);
    }
    assertEquals(300, map.size());
  }
  @Test(timeout = 120000)
  public void testSlowStore() throws Exception {
    final TestMapStore store = new WaitingOnFirstTestMapStore();
    Config config = getConfig();
    MapStoreConfig mapStoreConfig = new MapStoreConfig();
    mapStoreConfig.setEnabled(true);
    mapStoreConfig.setWriteDelaySeconds(1);
    mapStoreConfig.setImplementation(store);
    config.getMapConfig("default").setMapStoreConfig(mapStoreConfig);
    HazelcastInstance h1 = createHazelcastInstance(config);
    final IMap<Integer, Integer> map = h1.getMap("testSlowStore");
    int count = 1000;
    for (int i = 0; i < count; i++) {
      map.put(i, 1);
    }
    Thread.sleep(2000); // sleep for scheduling following puts to a different second
    for (int i = 0; i < count; i++) {
      map.put(i, 2);
    }
    for (int i = 0; i < count; i++) {
      final int index = i;
      assertTrueEventually(
          new AssertTask() {
            @Override
            public void run() throws Exception {
              final Integer valueInMap = map.get(index);
              final Integer valueInStore = (Integer) store.getStore().get(index);

              assertEquals(valueInMap, valueInStore);
            }
          });
    }
  }
  @Test
  public void testFullQueryCacheConfig() throws Exception {
    MapConfig mapConfig = config.getMapConfig("map-with-query-cache");
    QueryCacheConfig queryCacheConfig = mapConfig.getQueryCacheConfigs().get(0);
    EntryListenerConfig entryListenerConfig = queryCacheConfig.getEntryListenerConfigs().get(0);

    assertTrue(entryListenerConfig.isIncludeValue());
    assertFalse(entryListenerConfig.isLocal());

    assertEquals("com.hazelcast.spring.DummyEntryListener", entryListenerConfig.getClassName());
    assertFalse(queryCacheConfig.isIncludeValue());

    assertEquals("my-query-cache-1", queryCacheConfig.getName());
    assertEquals(12, queryCacheConfig.getBatchSize());
    assertEquals(33, queryCacheConfig.getBufferSize());
    assertEquals(12, queryCacheConfig.getDelaySeconds());
    assertEquals(InMemoryFormat.OBJECT, queryCacheConfig.getInMemoryFormat());
    assertTrue(queryCacheConfig.isCoalesce());
    assertFalse(queryCacheConfig.isPopulate());
    assertIndexesEqual(queryCacheConfig);
    assertEquals("__key > 12", queryCacheConfig.getPredicateConfig().getSql());
    assertEquals(EvictionPolicy.LRU, queryCacheConfig.getEvictionConfig().getEvictionPolicy());
    assertEquals(
        EvictionConfig.MaxSizePolicy.ENTRY_COUNT,
        queryCacheConfig.getEvictionConfig().getMaximumSizePolicy());
    assertEquals(111, queryCacheConfig.getEvictionConfig().getSize());
  }
  @Test(timeout = 120000)
  public void issue587CallMapLoaderDuringRemoval() {
    final AtomicInteger loadCount = new AtomicInteger(0);
    final AtomicInteger storeCount = new AtomicInteger(0);
    final AtomicInteger deleteCount = new AtomicInteger(0);
    class SimpleMapStore2 extends SimpleMapStore<String, Long> {

      SimpleMapStore2(ConcurrentMap<String, Long> store) {
        super(store);
      }

      public Long load(String key) {
        loadCount.incrementAndGet();
        return super.load(key);
      }

      public void store(String key, Long value) {
        storeCount.incrementAndGet();
        super.store(key, value);
      }

      public void delete(String key) {
        deleteCount.incrementAndGet();
        super.delete(key);
      }
    }
    final ConcurrentMap<String, Long> store = new ConcurrentHashMap<String, Long>();
    final MapStore<String, Long> myMapStore = new SimpleMapStore2(store);
    Config config = getConfig();
    config
        .getMapConfig("myMap")
        .setMapStoreConfig(new MapStoreConfig().setImplementation(myMapStore));
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(3);
    HazelcastInstance hc = nodeFactory.newHazelcastInstance(config);
    store.put("one", 1l);
    store.put("two", 2l);
    assertEquals(0, loadCount.get());
    assertEquals(0, storeCount.get());
    assertEquals(0, deleteCount.get());
    IMap<String, Long> myMap = hc.getMap("myMap");
    assertEquals(1l, myMap.get("one").longValue());
    assertEquals(2l, myMap.get("two").longValue());
    //        assertEquals(2, loadCount.get());
    assertEquals(0, storeCount.get());
    assertEquals(0, deleteCount.get());
    assertNull(myMap.remove("ten"));
    //        assertEquals(3, loadCount.get());
    assertEquals(0, storeCount.get());
    assertEquals(0, deleteCount.get());
    myMap.put("three", 3L);
    myMap.put("four", 4L);
    //        assertEquals(5, loadCount.get());
    assertEquals(2, storeCount.get());
    assertEquals(0, deleteCount.get());
    myMap.remove("one");
    assertEquals(2, storeCount.get());
    assertEquals(1, deleteCount.get());
    //        assertEquals(5, loadCount.get());
  }
 @Test
 public void testMapConfig_minEvictionCheckMillis_defaultValue() {
   String xml = HAZELCAST_START_TAG + "<map name=\"mymap\">" + "</map>" + "</hazelcast>";
   final Config config = buildConfig(xml);
   final MapConfig mapConfig = config.getMapConfig("mymap");
   assertEquals(
       MapConfig.DEFAULT_MIN_EVICTION_CHECK_MILLIS, mapConfig.getMinEvictionCheckMillis());
 }
  @Test
  public void testMapNativeMaxSizePolicy() {
    MapConfig mapConfig = config.getMapConfig("map-with-native-max-size-policy");
    MaxSizeConfig maxSizeConfig = mapConfig.getMaxSizeConfig();

    assertEquals(
        MaxSizeConfig.MaxSizePolicy.USED_NATIVE_MEMORY_PERCENTAGE,
        maxSizeConfig.getMaxSizePolicy());
  }
  @Test(timeout = 120000)
  public void testMapGetAll() throws InterruptedException {

    final Map<String, String> _map = new HashMap<String, String>();
    _map.put("key1", "value1");
    _map.put("key2", "value2");
    _map.put("key3", "value3");

    final AtomicBoolean loadAllCalled = new AtomicBoolean(false);
    final AtomicBoolean loadCalled = new AtomicBoolean(false);

    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
    Config config = getConfig();
    MapStoreConfig mapStoreConfig = new MapStoreConfig();
    mapStoreConfig.setEnabled(true);
    mapStoreConfig.setImplementation(
        new MapLoader<String, String>() {

          public String load(String key) {
            loadCalled.set(true);
            return _map.get(key);
          }

          public Map<String, String> loadAll(Collection<String> keys) {
            loadAllCalled.set(true);
            final HashMap<String, String> temp = new HashMap<String, String>();
            for (String key : keys) {
              temp.put(key, _map.get(key));
            }
            return temp;
          }

          public Set<String> loadAllKeys() {
            return _map.keySet();
          }
        });
    String mapName = "default";
    config.getMapConfig(mapName).setMapStoreConfig(mapStoreConfig);

    HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(config);
    HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(config);

    IMap map = instance1.getMap(mapName);

    final HashSet<String> keys = new HashSet<String>(3);
    keys.add("key1");
    keys.add("key3");
    keys.add("key4");

    final Map subMap = map.getAll(keys);
    assertEquals(2, subMap.size());
    assertEquals("value1", subMap.get("key1"));
    assertEquals("value3", subMap.get("key3"));

    assertTrue(loadAllCalled.get());
    assertFalse(loadCalled.get());
  }
  @Test
  public void testMapPartitionLostListenerConfig() {
    String mapName = "map1";
    String listenerName = "DummyMapPartitionLostListenerImpl";
    String xml = createMapPartitionLostListenerConfiguredXml(mapName, listenerName);

    Config config = buildConfig(xml);
    MapConfig mapConfig = config.getMapConfig("map1");
    assertMapPartitionLostListener(listenerName, mapConfig);
  }
 @Test
 public void testMapConfig_cacheValueConfig_defaultValue() {
   String xml =
       "<hazelcast xmlns=\"http://www.hazelcast.com/schema/config\">"
           + "<map name=\"mymap\">"
           + "</map>"
           + "</hazelcast>";
   final Config config = buildConfig(xml);
   final MapConfig mapConfig = config.getMapConfig("mymap");
   assertEquals(CacheDeserializedValues.INDEX_ONLY, mapConfig.getCacheDeserializedValues());
 }
 @Test
 public void testMapConfig_optimizeQueries_defaultValue() {
   String xml =
       "<hazelcast xmlns=\"http://www.hazelcast.com/schema/config\">"
           + "<map name=\"mymap\">"
           + "</map>"
           + "</hazelcast>";
   final Config config = buildConfig(xml);
   final MapConfig mapConfig = config.getMapConfig("mymap");
   assertFalse(mapConfig.isOptimizeQueries());
 }
  @Test
  public void testQueryCacheFullConfig() throws Exception {
    String xml =
        "<hazelcast xmlns=\"http://www.hazelcast.com/schema/config\">"
            + "<map name=\"test\">"
            + "<query-caches>"
            + "<query-cache name=\"cache-name\">"
            + "<entry-listeners>"
            + "<entry-listener include-value=\"true\" "
            + "local=\"false\">com.hazelcast.examples.EntryListener</entry-listener>"
            + "</entry-listeners>"
            + "<include-value>true</include-value>"
            + "<batch-size>1</batch-size>"
            + "<buffer-size>16</buffer-size>"
            + "<delay-seconds>0</delay-seconds>"
            + "<in-memory-format>BINARY</in-memory-format>"
            + "<coalesce>false</coalesce>"
            + "<populate>true</populate>"
            + "<indexes>"
            + "<index ordered=\"false\">name</index>"
            + "</indexes>"
            + "<predicate type=\"class-name\"> "
            + "com.hazelcast.examples.SimplePredicate"
            + "</predicate>"
            + "<eviction eviction-policy=\"LRU\" max-size-policy=\"ENTRY_COUNT\" size=\"133\"/>"
            + "</query-cache>"
            + "</query-caches>"
            + "</map>"
            + "</hazelcast>";
    Config config = buildConfig(xml);
    QueryCacheConfig queryCacheConfig = config.getMapConfig("test").getQueryCacheConfigs().get(0);
    EntryListenerConfig entryListenerConfig = queryCacheConfig.getEntryListenerConfigs().get(0);

    assertEquals("cache-name", queryCacheConfig.getName());
    assertTrue(entryListenerConfig.isIncludeValue());
    assertFalse(entryListenerConfig.isLocal());
    assertEquals("com.hazelcast.examples.EntryListener", entryListenerConfig.getClassName());
    assertTrue(queryCacheConfig.isIncludeValue());
    assertEquals(1, queryCacheConfig.getBatchSize());
    assertEquals(16, queryCacheConfig.getBufferSize());
    assertEquals(0, queryCacheConfig.getDelaySeconds());
    assertEquals(InMemoryFormat.BINARY, queryCacheConfig.getInMemoryFormat());
    assertFalse(queryCacheConfig.isCoalesce());
    assertTrue(queryCacheConfig.isPopulate());
    assertIndexesEqual(queryCacheConfig);
    assertEquals(
        "com.hazelcast.examples.SimplePredicate",
        queryCacheConfig.getPredicateConfig().getClassName());
    assertEquals(EvictionPolicy.LRU, queryCacheConfig.getEvictionConfig().getEvictionPolicy());
    assertEquals(
        EvictionConfig.MaxSizePolicy.ENTRY_COUNT,
        queryCacheConfig.getEvictionConfig().getMaximumSizePolicy());
    assertEquals(133, queryCacheConfig.getEvictionConfig().getSize());
  }
 @Test
 public void testMapConfig_cacheValueConfig_always() {
   String xml =
       "<hazelcast xmlns=\"http://www.hazelcast.com/schema/config\">"
           + "<map name=\"mymap\">"
           + "<cache-deserialized-values>ALWAYS</cache-deserialized-values>"
           + "</map>"
           + "</hazelcast>";
   final Config config = buildConfig(xml);
   final MapConfig mapConfig = config.getMapConfig("mymap");
   assertEquals(CacheDeserializedValues.ALWAYS, mapConfig.getCacheDeserializedValues());
 }
 @Test
 public void testMapConfig_minEvictionCheckMillis() {
   String xml =
       "<hazelcast xmlns=\"http://www.hazelcast.com/schema/config\">\n"
           + "<map name=\"mymap\">"
           + "<min-eviction-check-millis>123456789</min-eviction-check-millis>"
           + "</map>"
           + "</hazelcast>";
   final Config config = buildConfig(xml);
   final MapConfig mapConfig = config.getMapConfig("mymap");
   assertEquals(123456789L, mapConfig.getMinEvictionCheckMillis());
 }
 @Test
 public void testMapConfig_minEvictionCheckMillis_defaultValue() {
   String xml =
       "<hazelcast xmlns=\"http://www.hazelcast.com/schema/config\">\n"
           + "<map name=\"mymap\">"
           + "</map>"
           + "</hazelcast>";
   final Config config = buildConfig(xml);
   final MapConfig mapConfig = config.getMapConfig("mymap");
   assertEquals(
       MapConfig.DEFAULT_MIN_EVICTION_CHECK_MILLIS, mapConfig.getMinEvictionCheckMillis());
 }