同样的测试代码,原本用Google Collections 1.0测试通过,升级到Guava 14.0便不行了。
@Test public void testWeakRef() throws Exception{ MapMaker maker = new MapMaker(); ConcurrentMap<Object, Object> map = maker .weakKeys() .weakValues() .<Object, Object>makeMap(); map.put(new Object(), new int[]{1,2,3}); System.out.println(map.size()); System.gc(); TimeUnit.SECONDS.sleep(1L); System.out.println(map.size()); Assert.assertTrue(map.isEmpty()); this.createData(map); this.testOutOfMemory(map); Assert.assertTrue(map.isEmpty()); }
尝试改用com.google.common.cache.CacheBuilder依然无效,都卡在第一个断言,求解?