【发布时间】:2018-10-03 15:02:51
【问题描述】:
这个简单的 JUnit 测试总是失败(Hazelcast 3.9.1):
测试类是:
public class TestHZ {
@Test
public void testEviction() {
Config config = new XmlConfigBuilder(getXml()).build();
config.setInstanceName("myTestInstance");
HazelcastInstance hz = Hazelcast.newHazelcastInstance(config);
IMap<Integer, Integer> cache2 = hz.getMap("MyTest2");
cache2.put(123, 456);
assertNotNull(cache2.get(123)); // <--- ALWAYS OK: conf LRU and 6000 entries
IMap<Integer, Integer> cache = hz.getMap("MyTest");
cache.put(123, 456);
assertNotNull(cache.get(123)); // <--- ALWAYS ERROR: conf LRU and 200 entries
}
private InputStream getXml() {
System.out.println(MY_CONF_XML);
return new ByteArrayInputStream(MY_CONF_XML.getBytes());
}
以及具有此值的配置常量:
private static final String MY_CONF_XML =
"<hazelcast xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n" +
" xsi:schemaLocation=\"http://www.hazelcast.com/schema/config http://www.hazelcast.com/schema/config/hazelcast-config-3.9.xsd\"\r\n" +
" xmlns=\"http://www.hazelcast.com/schema/config\">\r\n" +
"\r\n" +
" <map name=\"MyTest\">\r\n" +
" <eviction-policy>LRU</eviction-policy>\r\n" +
" <max-size policy=\"PER_NODE\">200</max-size>\r\n" +
" </map>\r\n" +
"\r\n" +
" <map name=\"MyTest2\">\r\n" +
" <eviction-policy>LRU</eviction-policy>\r\n" +
" <max-size policy=\"PER_NODE\">6000</max-size>\r\n" +
" </map>\r\n" +
"\r\n" +
"</hazelcast>\r\n" +
"";
当地图配置包含最大大小为 200 个条目时,我总是无法尝试离开第一个条目。
其他人有同样的错误吗?
为什么,配置 6000 时总是顺利,而配置 200 时总是出错?
【问题讨论】: