本文整理汇总了Java中com.hazelcast.config.NearCacheConfig.setMaxSize方法的典型用法代码示例。如果您正苦于以下问题:Java NearCacheConfig.setMaxSize方法的具体用法?Java NearCacheConfig.setMaxSize怎么用?Java NearCacheConfig.setMaxSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.hazelcast.config.NearCacheConfig
的用法示例。
在下文中一共展示了NearCacheConfig.setMaxSize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testNearCache
import com.hazelcast.config.NearCacheConfig; //导入方法依赖的package包/类
@Test
public void testNearCache() throws Exception {
final Config config = new Config();
NearCacheConfig nearCacheConfig = new NearCacheConfig();
nearCacheConfig.setMaxSize(1000);
config.getMapConfig("default").setNearCacheConfig(nearCacheConfig);
HazelcastInstance h1 = Hazelcast.newHazelcastInstance(config);
IMap m1 = h1.getMap("default");
m1.put("1", "value");
HazelcastInstance h2 = Hazelcast.newHazelcastInstance(config);
IMap m2 = h2.getMap("default");
assertEquals("value", m2.get("1"));
assertEquals("value", m1.get("1"));
HazelcastClient client1 = newHazelcastClient(h1);
HazelcastClient client2 = newHazelcastClient(h2);
for (int i = 0; i < 10; i++) {
assertEquals("value", client1.getMap("default").get("1"));
assertEquals("value", client2.getMap("default").get("1"));
}
}
示例2: testReadFromCache
import com.hazelcast.config.NearCacheConfig; //导入方法依赖的package包/类
@Test
public void testReadFromCache() {
System.setProperty("hazelcast.client.near.cache.enabled", "true");
Config config = new Config();
NearCacheConfig nearCacheConfig = new NearCacheConfig();
nearCacheConfig.setMaxSize(1000);
nearCacheConfig.setMaxIdleSeconds(10);
nearCacheConfig.setTimeToLiveSeconds(20);
config.getMapConfig("default").setNearCacheConfig(nearCacheConfig);
HazelcastInstance h = Hazelcast.newHazelcastInstance(config);
String mapName = "testReadFromCache";
IMap<String, String> mapH = h.getMap(mapName);
mapH.put("a", "a");
HazelcastClient client = HazelcastClient.newHazelcastClient(new ClientConfig());
Map<Object, Object> mapC = client.getMap(mapName);
assertEquals("a", mapC.get("a"));
int hit = mapH.getMapEntry("a").getHits();
mapC.get("a");
assertEquals(mapH.getMapEntry("a").getHits(), hit);
for (int i = 0; i < 100; i++) {
mapC.get("a");
}
assertEquals(mapH.getMapEntry("a").getHits(), hit);
}
开发者ID:health-and-care-developer-network,项目名称:health-and-care-developer-network,代码行数:26,代码来源:ClientMapGuavaCacheTest.java
示例3: testNoNearCacheConfig
import com.hazelcast.config.NearCacheConfig; //导入方法依赖的package包/类
@Test
public void testNoNearCacheConfig() {
System.setProperty("hazelcast.client.near.cache.enabled", "false");
Config config = new Config();
NearCacheConfig nearCacheConfig = new NearCacheConfig();
nearCacheConfig.setMaxSize(1000);
nearCacheConfig.setMaxIdleSeconds(10);
nearCacheConfig.setTimeToLiveSeconds(20);
config.getMapConfig("default").setNearCacheConfig(nearCacheConfig);
HazelcastInstance h = Hazelcast.newHazelcastInstance(config);
String mapName = "testReadFromCache";
IMap<String, String> mapH = h.getMap(mapName);
mapH.put("a", "a");
HazelcastClient client = HazelcastClient.newHazelcastClient(new ClientConfig());
Map<Object, Object> mapC = client.getMap(mapName);
assertEquals("a", mapC.get("a"));
int hit = mapH.getMapEntry("a").getHits();
mapC.get("a");
assertEquals(mapH.getMapEntry("a").getHits(), ++hit);
for (int i = 0; i < 100; i++) {
mapC.get("a");
}
assertEquals(mapH.getMapEntry("a").getHits(), hit + 100);
}
开发者ID:health-and-care-developer-network,项目名称:health-and-care-developer-network,代码行数:26,代码来源:ClientMapGuavaCacheTest.java
示例4: testInvalidateOnChange
import com.hazelcast.config.NearCacheConfig; //导入方法依赖的package包/类
@Test
public void testInvalidateOnChange() throws InterruptedException {
System.setProperty("hazelcast.client.near.cache.enabled", "true");
Config config = new Config();
NearCacheConfig nearCacheConfig = new NearCacheConfig();
nearCacheConfig.setMaxSize(1000);
nearCacheConfig.setInvalidateOnChange(true);
config.getMapConfig("default").setNearCacheConfig(nearCacheConfig);
HazelcastInstance h = Hazelcast.newHazelcastInstance(config);
String mapName = "testInvalidateOnChange";
IMap<String, String> mapH = h.getMap(mapName);
mapH.put("a", "a");
HazelcastClient client = HazelcastClient.newHazelcastClient(new ClientConfig());
Map<Object, Object> mapC = client.getMap(mapName);
int hit = mapH.getMapEntry("a").getHits();
assertEquals("a", mapC.get("a"));
assertEquals(mapH.getMapEntry("a").getHits(), ++hit);
mapC.get("a");
assertEquals(mapH.getMapEntry("a").getHits(), hit);
mapH.put("a", "b");
Thread.sleep(100);
assertEquals("b", mapC.get("a"));
assertEquals(mapH.getMapEntry("a").getHits(), ++hit);
}
开发者ID:health-and-care-developer-network,项目名称:health-and-care-developer-network,代码行数:25,代码来源:ClientMapGuavaCacheTest.java