@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); } }); } }
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; }
@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; }