Ejemplo n.º 1
0
  @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);
            }
          });
    }
  }
Ejemplo n.º 2
0
  @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());
  }
Ejemplo n.º 3
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"));
  }
Ejemplo n.º 4
0
  @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());
  }
Ejemplo n.º 5
0
  @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());
  }
Ejemplo n.º 6
0
 private void initializeMapStoreLoad() {
   MapStoreConfig mapStoreConfig = getMapConfig().getMapStoreConfig();
   if (mapStoreConfig != null && mapStoreConfig.isEnabled()) {
     MapStoreConfig.InitialLoadMode initialLoadMode = mapStoreConfig.getInitialLoadMode();
     if (MapStoreConfig.InitialLoadMode.EAGER.equals(initialLoadMode)) {
       waitUntilLoaded();
     }
   }
 }
Ejemplo n.º 7
0
  @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());
  }
  private static Config createConfig(String mapName, MapStoreTest.SimpleMapStore store) {
    MapStoreConfig mapStoreConfig = new MapStoreConfig();
    mapStoreConfig
        .setImplementation(store)
        .setWriteDelaySeconds(100)
        .setWriteBatchSize(1)
        .setWriteCoalescing(false);

    Config config = new Config();
    config.getMapConfig(mapName).setBackupCount(1).setMapStoreConfig(mapStoreConfig);

    return config;
  }
Ejemplo n.º 9
0
  private Config createMapConfig(String mapName, SampleIndexableObjectMapLoader loader) {
    Config config = getConfig();

    MapConfig mapConfig = config.getMapConfig(mapName);
    List<MapIndexConfig> indexConfigs = mapConfig.getMapIndexConfigs();
    indexConfigs.add(new MapIndexConfig("name", true));

    MapStoreConfig storeConfig = new MapStoreConfig();
    storeConfig.setFactoryImplementation(loader);
    storeConfig.setEnabled(true);
    mapConfig.setMapStoreConfig(storeConfig);

    return config;
  }
Ejemplo n.º 10
0
  private Config createChunkedMapLoaderConfig(
      String mapName, int chunkSize, ChunkedLoader chunkedLoader) {
    Config cfg = getConfig();
    cfg.setProperty(GroupProperty.PARTITION_COUNT, "1");
    cfg.setProperty(GroupProperty.MAP_LOAD_CHUNK_SIZE, String.valueOf(chunkSize));

    MapStoreConfig mapStoreConfig = new MapStoreConfig();
    mapStoreConfig.setEnabled(true);
    mapStoreConfig.setImplementation(chunkedLoader);

    MapConfig mapConfig = cfg.getMapConfig(mapName);
    mapConfig.setMapStoreConfig(mapStoreConfig);
    return cfg;
  }
  public Config getConfig() {

    final Config cfg = new Config();
    cfg.setInstanceName(instanceName);

    final Properties props = new Properties();
    props.put("hazelcast.rest.enabled", false);
    props.put("hazelcast.logging.type", "slf4j");
    props.put("hazelcast.connect.all.wait.seconds", 45);
    props.put("hazelcast.operation.call.timeout.millis", 30000);

    // group configuration
    cfg.setGroupConfig(new GroupConfig(Constants.HC_GROUP_NAME, Constants.HC_GROUP_PASSWORD));
    // network configuration initialization
    final NetworkConfig netCfg = new NetworkConfig();
    netCfg.setPortAutoIncrement(true);
    netCfg.setPort(Constants.HC_PORT);
    // multicast
    final MulticastConfig mcCfg = new MulticastConfig();
    mcCfg.setEnabled(false);
    // tcp
    final TcpIpConfig tcpCfg = new TcpIpConfig();
    tcpCfg.addMember("127.0.0.1");
    tcpCfg.setEnabled(true);
    // network join configuration
    final JoinConfig joinCfg = new JoinConfig();
    joinCfg.setMulticastConfig(mcCfg);
    joinCfg.setTcpIpConfig(tcpCfg);
    netCfg.setJoin(joinCfg);
    // ssl
    netCfg.setSSLConfig(new SSLConfig().setEnabled(false));

    // Adding mapstore
    final MapConfig mapCfg = cfg.getMapConfig(storeType);

    final MapStoreConfig mapStoreCfg = new MapStoreConfig();
    mapStoreCfg.setImplementation(store);
    mapStoreCfg.setWriteDelaySeconds(1);
    // to load all map at same time
    mapStoreCfg.setInitialLoadMode(MapStoreConfig.InitialLoadMode.EAGER);
    mapCfg.setMapStoreConfig(mapStoreCfg);
    cfg.addMapConfig(mapCfg);
    return cfg;
  }
Ejemplo n.º 12
0
  // https://github.com/hazelcast/hazelcast/issues/1770
  @Test
  public void test1770() throws InterruptedException {
    Config config = getConfig();
    config.getManagementCenterConfig().setEnabled(true);
    config.getManagementCenterConfig().setUrl("http://127.0.0.1:8090/mancenter");

    MapConfig mapConfig = config.getMapConfig("foo");

    final AtomicBoolean loadAllCalled = new AtomicBoolean();
    MapLoader<Object, Object> mapLoader =
        new MapLoader<Object, Object>() {
          @Override
          public Object load(Object key) {
            return null;
          }

          @Override
          public Map<Object, Object> loadAll(Collection keys) {
            loadAllCalled.set(true);
            return new HashMap<Object, Object>();
          }

          @Override
          public Set<Object> loadAllKeys() {
            return new HashSet<Object>(Collections.singletonList(1));
          }
        };
    MapStoreConfig mapStoreConfig = new MapStoreConfig();
    mapStoreConfig.setEnabled(true);
    mapStoreConfig.setImplementation(mapLoader);
    mapConfig.setMapStoreConfig(mapStoreConfig);

    HazelcastInstance hz = createHazelcastInstance(config);
    hz.getMap(mapConfig.getName());

    assertTrueAllTheTime(
        new AssertTask() {
          @Override
          public void run() {
            assertFalse("LoadAll should not have been called", loadAllCalled.get());
          }
        },
        10);
  }
Ejemplo n.º 13
0
  @Bean
  public Config config() {
    MapConfig map =
        new MapConfig()
            .setName("test-map")
            .setEvictionPolicy(EvictionPolicy.LRU)
            .setTimeToLiveSeconds(2400);

    MapStoreConfig ms = new MapStoreConfig();
    ms.setClassName("com.ikentoo.test.hazelcast.LoggingMapStore");
    ms.setEnabled(true);
    ms.setWriteDelaySeconds(30);
    ms.setWriteCoalescing(true);

    map.setMapStoreConfig(ms);

    Config c = new Config().addMapConfig(map).setProperty("hazelcast.logging.type", "slf4j");
    return c;
  }
Ejemplo n.º 14
0
 private static Object getStoreFromClassOrNull(
     MapStoreConfig mapStoreConfig, ClassLoader classLoader) {
   Object store;
   String mapStoreClassName = mapStoreConfig.getClassName();
   try {
     store = ClassLoaderUtil.newInstance(classLoader, mapStoreClassName);
   } catch (Exception e) {
     throw ExceptionUtil.rethrow(e);
   }
   return store;
 }
Ejemplo n.º 15
0
  @Test(timeout = 120000)
  public void testInitialLoadModeEager() {
    int size = 10000;
    String mapName = "default";
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);

    Config config = getConfig();
    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);
    HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(config);

    IMap map = instance1.getMap(mapName);

    assertSizeEventually(size, map);
  }
Ejemplo n.º 16
0
  @Test(timeout = 120000)
  public void testInitialLoadModeEagerWhileStoppigOneNode() throws InterruptedException {
    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("testInitialLoadModeEagerWhileStoppigOneNode")
        .setMapStoreConfig(mapStoreConfig);
    final HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(config);
    final HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(config);
    new Thread(
            new Runnable() {
              @Override
              public void run() {
                sleepSeconds(3);
                instance1.getLifecycleService().shutdown();
                sleepSeconds(3);
                final IMap<Object, Object> map =
                    instance2.getMap("testInitialLoadModeEagerWhileStoppigOneNode");
                assertEquals(size, map.size());
                countDownLatch.countDown();
              }
            })
        .start();

    assertOpenEventually(countDownLatch);

    final IMap<Object, Object> map2 =
        instance2.getMap("testInitialLoadModeEagerWhileStoppigOneNode");
    final int map2Size = map2.size();
    assertEquals(size, map2Size);
  }
Ejemplo n.º 17
0
  private static Object getStoreFromFactoryOrNull(
      String name, MapStoreConfig mapStoreConfig, ClassLoader classLoader) {
    MapStoreFactory factory = (MapStoreFactory) mapStoreConfig.getFactoryImplementation();
    if (factory == null) {
      final String factoryClassName = mapStoreConfig.getFactoryClassName();
      if (isNullOrEmpty(factoryClassName)) {
        return null;
      }

      try {
        factory = ClassLoaderUtil.newInstance(classLoader, factoryClassName);
      } catch (Exception e) {
        throw ExceptionUtil.rethrow(e);
      }
    }
    if (factory == null) {
      return null;
    }

    final Properties properties = mapStoreConfig.getProperties();
    return factory.newMapStore(name, properties);
  }
Ejemplo n.º 18
0
  // bug: store is called twice on loadAll
  @Test(timeout = 120000)
  public void testIssue1070() {
    final String mapName = randomMapName();
    final Config config = getConfig();
    final MapConfig mapConfig = config.getMapConfig(mapName);
    final MapStoreConfig mapStoreConfig = new MapStoreConfig();
    final NoDuplicateMapStore myMapStore = new NoDuplicateMapStore();
    final MapStoreConfig implementation = mapStoreConfig.setImplementation(myMapStore);
    mapConfig.setMapStoreConfig(implementation);

    myMapStore.store.put(1, 2);

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

    IMap<Object, Object> map = instance1.getMap(mapName);
    for (int i = 0; i < 271; i++) {
      map.get(i);
    }
    assertFalse(myMapStore.failed);
  }
Ejemplo n.º 19
0
  @Test(timeout = 240000)
  public void testMapInitialLoad() throws InterruptedException {
    int size = 10000;
    String mapName = randomMapName();
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(3);

    Config config = getConfig();
    MapStoreConfig mapStoreConfig = new MapStoreConfig();
    mapStoreConfig.setEnabled(true);
    mapStoreConfig.setImplementation(new SimpleMapLoader(size, true));

    MapConfig mc = config.getMapConfig(mapName);
    mc.setMapStoreConfig(mapStoreConfig);

    HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(config);
    HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(config);
    IMap map = instance1.getMap(mapName);

    // trigger initial loads by touching partitions.
    for (int i = 0; i < size; i++) {
      assertEquals(i, map.get(i));
    }

    assertSizeEventually(size, map);
    for (int i = 0; i < size; i++) {
      assertEquals(i, map.get(i));
    }

    assertNull(map.put(size, size));
    assertEquals(size, map.remove(size));
    assertNull(map.get(size));

    HazelcastInstance instance3 = nodeFactory.newHazelcastInstance(config);
    for (int i = 0; i < size; i++) {
      assertEquals(i, map.get(i));
    }
  }
Ejemplo n.º 20
0
  @Test
  public void testSenderAndBackupTerminates_AfterInitialLoad() throws InterruptedException {
    String name = randomString();
    Config config = new Config();
    MapConfig mapConfig = config.getMapConfig(name);
    MapStoreConfig mapStoreConfig = new MapStoreConfig();
    mapStoreConfig.setEnabled(true);
    mapStoreConfig.setImplementation(new DummyMapLoader());
    mapStoreConfig.setInitialLoadMode(MapStoreConfig.InitialLoadMode.EAGER);
    mapConfig.setMapStoreConfig(mapStoreConfig);
    TestHazelcastInstanceFactory instanceFactory = createHazelcastInstanceFactory(5);
    HazelcastInstance[] instances = instanceFactory.newInstances(config);

    IMap<Object, Object> map = instances[0].getMap(name);
    map.clear();

    HazelcastInstance[] ownerAndReplicas = findOwnerAndReplicas(instances, name);
    ownerAndReplicas[0].getLifecycleService().terminate();
    ownerAndReplicas[1].getLifecycleService().terminate();

    map = ownerAndReplicas[3].getMap(name);
    map.loadAll(false);
    assertEquals(DummyMapLoader.SIZE, map.size());
  }
Ejemplo n.º 21
0
 protected boolean isMapStoreEnabled() {
   MapStoreConfig mapStoreConfig = mapConfig.getMapStoreConfig();
   return mapStoreConfig != null && mapStoreConfig.isEnabled();
 }
Ejemplo n.º 22
0
 private static Object getStoreFromImplementationOrNull(MapStoreConfig mapStoreConfig) {
   return mapStoreConfig.getImplementation();
 }
  @Test
  public void testMapConfig() {
    assertNotNull(config);
    assertEquals(10, config.getMapConfigs().size());

    MapConfig testMapConfig = config.getMapConfig("testMap");
    assertNotNull(testMapConfig);
    assertEquals("testMap", testMapConfig.getName());
    assertEquals(2, testMapConfig.getBackupCount());
    assertEquals(EvictionPolicy.NONE, testMapConfig.getEvictionPolicy());
    assertEquals(Integer.MAX_VALUE, testMapConfig.getMaxSizeConfig().getSize());
    assertEquals(30, testMapConfig.getEvictionPercentage());
    assertEquals(0, testMapConfig.getTimeToLiveSeconds());
    assertEquals(1000, testMapConfig.getMinEvictionCheckMillis());
    assertEquals("PUT_IF_ABSENT", testMapConfig.getMergePolicy());
    assertTrue(testMapConfig.isReadBackupData());
    assertEquals(2, testMapConfig.getMapIndexConfigs().size());
    for (MapIndexConfig index : testMapConfig.getMapIndexConfigs()) {
      if ("name".equals(index.getAttribute())) {
        assertFalse(index.isOrdered());
      } else if ("age".equals(index.getAttribute())) {
        assertTrue(index.isOrdered());
      } else {
        fail("unknown index!");
      }
    }
    assertEquals("my-quorum", testMapConfig.getQuorumName());

    // Test that the testMapConfig has a mapStoreConfig and it is correct
    MapStoreConfig testMapStoreConfig = testMapConfig.getMapStoreConfig();
    assertNotNull(testMapStoreConfig);
    assertEquals("com.hazelcast.spring.DummyStore", testMapStoreConfig.getClassName());
    assertTrue(testMapStoreConfig.isEnabled());
    assertEquals(0, testMapStoreConfig.getWriteDelaySeconds());
    assertEquals(10, testMapStoreConfig.getWriteBatchSize());
    assertTrue(testMapStoreConfig.isWriteCoalescing());
    assertEquals(MapStoreConfig.InitialLoadMode.EAGER, testMapStoreConfig.getInitialLoadMode());

    // Test that the testMapConfig has a nearCacheConfig and it is correct
    NearCacheConfig testNearCacheConfig = testMapConfig.getNearCacheConfig();
    assertNotNull(testNearCacheConfig);
    assertEquals(0, testNearCacheConfig.getTimeToLiveSeconds());
    assertEquals(60, testNearCacheConfig.getMaxIdleSeconds());
    assertEquals("LRU", testNearCacheConfig.getEvictionPolicy());
    assertEquals(5000, testNearCacheConfig.getMaxSize());
    assertTrue(testNearCacheConfig.isInvalidateOnChange());

    // Test that the testMapConfig2's mapStoreConfig implementation
    MapConfig testMapConfig2 = config.getMapConfig("testMap2");
    assertNotNull(testMapConfig2.getMapStoreConfig().getImplementation());
    assertEquals(dummyMapStore, testMapConfig2.getMapStoreConfig().getImplementation());
    assertEquals(
        MapStoreConfig.InitialLoadMode.LAZY,
        testMapConfig2.getMapStoreConfig().getInitialLoadMode());

    // Test testMapConfig2's WanReplicationConfig
    WanReplicationRef wanReplicationRef = testMapConfig2.getWanReplicationRef();
    assertEquals("testWan", wanReplicationRef.getName());
    assertEquals("PUT_IF_ABSENT", wanReplicationRef.getMergePolicy());
    assertTrue(wanReplicationRef.isRepublishingEnabled());

    assertEquals(1000, testMapConfig2.getMaxSizeConfig().getSize());
    assertEquals(
        MaxSizeConfig.MaxSizePolicy.PER_NODE, testMapConfig2.getMaxSizeConfig().getMaxSizePolicy());
    assertEquals(2, testMapConfig2.getEntryListenerConfigs().size());
    for (EntryListenerConfig listener : testMapConfig2.getEntryListenerConfigs()) {
      if (listener.getClassName() != null) {
        assertNull(listener.getImplementation());
        assertTrue(listener.isIncludeValue());
        assertFalse(listener.isLocal());
      } else {
        assertNotNull(listener.getImplementation());
        assertEquals(entryListener, listener.getImplementation());
        assertTrue(listener.isLocal());
        assertTrue(listener.isIncludeValue());
      }
    }

    MapConfig simpleMapConfig = config.getMapConfig("simpleMap");
    assertNotNull(simpleMapConfig);
    assertEquals("simpleMap", simpleMapConfig.getName());
    assertEquals(3, simpleMapConfig.getBackupCount());
    assertEquals(1, simpleMapConfig.getAsyncBackupCount());
    assertEquals(EvictionPolicy.LRU, simpleMapConfig.getEvictionPolicy());
    assertEquals(10, simpleMapConfig.getMaxSizeConfig().getSize());
    assertEquals(50, simpleMapConfig.getEvictionPercentage());
    assertEquals(1, simpleMapConfig.getTimeToLiveSeconds());
    assertEquals("LATEST_UPDATE", simpleMapConfig.getMergePolicy());
    // Test that the simpleMapConfig does NOT have a mapStoreConfig
    assertNull(simpleMapConfig.getMapStoreConfig());
    // Test that the simpleMapConfig does NOT have a nearCacheConfig
    assertNull(simpleMapConfig.getNearCacheConfig());

    MapConfig testMapConfig3 = config.getMapConfig("testMap3");
    assertEquals(
        "com.hazelcast.spring.DummyStoreFactory",
        testMapConfig3.getMapStoreConfig().getFactoryClassName());
    assertFalse(testMapConfig3.getMapStoreConfig().getProperties().isEmpty());
    assertEquals(testMapConfig3.getMapStoreConfig().getProperty("dummy.property"), "value");

    MapConfig testMapConfig4 = config.getMapConfig("testMap4");
    assertEquals(
        dummyMapStoreFactory, testMapConfig4.getMapStoreConfig().getFactoryImplementation());

    MapConfig mapWithOptimizedQueriesConfig = config.getMapConfig("mapWithOptimizedQueries");
    assertTrue(mapWithOptimizedQueriesConfig.isOptimizeQueries());

    MapConfig mapWithNotOptimizedQueriesConfig = config.getMapConfig("mapWithNotOptimizedQueries");
    assertFalse(mapWithNotOptimizedQueriesConfig.isOptimizeQueries());

    MapConfig mapWithDefaultOptimizedQueriesConfig =
        config.getMapConfig("mapWithDefaultOptimizedQueries");
    assertFalse(mapWithDefaultOptimizedQueriesConfig.isOptimizeQueries());
  }
Ejemplo n.º 24
0
  @Test(timeout = 120000)
  public void testIssue1115EnablingMapstoreMutatingValue() throws InterruptedException {
    Config config = getConfig();
    String mapName = "testIssue1115";
    MapStore mapStore = new ProcessingStore();
    MapStoreConfig mapStoreConfig = new MapStoreConfig();
    mapStoreConfig.setEnabled(true);
    mapStoreConfig.setImplementation(mapStore);
    config.getMapConfig(mapName).setMapStoreConfig(mapStoreConfig);
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(config);
    HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(config);
    IMap<Integer, Employee> map = instance1.getMap(mapName);
    Random random = new Random();
    // testing put with new object
    for (int i = 0; i < 10; i++) {
      Employee emp = new Employee();
      emp.setAge(random.nextInt(20) + 20);
      map.put(i, emp);
    }

    for (int i = 0; i < 10; i++) {
      Employee employee = map.get(i);
      assertEquals(employee.getAge() * 1000, employee.getSalary(), 0);
    }

    // testing put with existing object
    for (int i = 0; i < 10; i++) {
      Employee emp = map.get(i);
      emp.setAge(random.nextInt(20) + 20);
      map.put(i, emp);
    }

    for (int i = 0; i < 10; i++) {
      Employee employee = map.get(i);
      assertEquals(employee.getAge() * 1000, employee.getSalary(), 0);
    }

    // testing put with replace
    for (int i = 0; i < 10; i++) {
      Employee emp = map.get(i);
      emp.setAge(random.nextInt(20) + 20);
      map.replace(i, emp);
    }

    for (int i = 0; i < 10; i++) {
      Employee employee = map.get(i);
      assertEquals(employee.getAge() * 1000, employee.getSalary(), 0);
    }

    // testing put with putIfAbsent
    for (int i = 10; i < 20; i++) {
      Employee emp = new Employee();
      emp.setAge(random.nextInt(20) + 20);
      map.putIfAbsent(i, emp);
    }

    for (int i = 10; i < 20; i++) {
      Employee employee = map.get(i);
      assertEquals(employee.getAge() * 1000, employee.getSalary(), 0);
    }
  }