@Test public void testGetAsync() throws Exception { final String mapName = "testGetAsyncWithNearCache"; Config config = new Config(); config .getMapConfig(mapName) .setNearCacheConfig(new NearCacheConfig().setInvalidateOnChange(false)); final TestHazelcastInstanceFactory hazelcastInstanceFactory = createHazelcastInstanceFactory(2); HazelcastInstance instance1 = hazelcastInstanceFactory.newHazelcastInstance(config); HazelcastInstance instance2 = hazelcastInstanceFactory.newHazelcastInstance(config); IMap<Integer, Integer> map = instance1.getMap(mapName); HashSet keys = new HashSet(); int size = 1000; for (int i = 0; i < size; i++) { map.put(i, i); keys.add(i); } // populate near cache for (int i = 0; i < size; i++) { map.get(i); } for (int i = 0; i < size; i++) { final Future<Integer> async = map.getAsync(i); } NearCacheStats stats2 = map.getLocalMapStats().getNearCacheStats(); assertTrue("hits", 400 < stats2.getHits()); }
@Test public void testGetAsyncIssue1863() throws Exception { final String mapName = "testGetAsyncWithNearCacheIssue1863"; Config config = new Config(); final NearCacheConfig nearCacheConfig = new NearCacheConfig(); nearCacheConfig.setCacheLocalEntries(true); config.getMapConfig(mapName).setNearCacheConfig(nearCacheConfig); final TestHazelcastInstanceFactory hazelcastInstanceFactory = createHazelcastInstanceFactory(2); HazelcastInstance instance1 = hazelcastInstanceFactory.newHazelcastInstance(config); HazelcastInstance instance2 = hazelcastInstanceFactory.newHazelcastInstance(config); IMap<Integer, Integer> map = instance1.getMap(mapName); HashSet keys = new HashSet(); int size = 1000; // populate near cache -- cache local entries mode on. for (int i = 0; i < size; i++) { map.get(i); keys.add(i); } for (int i = 0; i < size; i++) { final Future<Integer> async = map.getAsync(i); assertNull(async.get()); } NearCacheStats stats = map.getLocalMapStats().getNearCacheStats(); assertEquals(size, stats.getHits()); }
@Test public void testNearCacheStats() throws Exception { String mapName = "NearCacheStatsTest"; Config config = new Config(); config .getMapConfig(mapName) .setNearCacheConfig(new NearCacheConfig().setInvalidateOnChange(true)); TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2); HazelcastInstance[] instances = factory.newInstances(config); IMap<Integer, Integer> map = instances[0].getMap("NearCacheStatsTest"); for (int i = 0; i < 1000; i++) { map.put(i, i); } // populate near cache for (int i = 0; i < 1000; i++) { map.get(i); } NearCacheStats stats = map.getLocalMapStats().getNearCacheStats(); assertTrue("owned Entries", 400 < stats.getOwnedEntryCount()); assertTrue("misses", 1000 == stats.getMisses()); // make some hits for (int i = 0; i < 1000; i++) { map.get(i); } NearCacheStats stats2 = map.getLocalMapStats().getNearCacheStats(); assertTrue("hits", 400 < stats2.getHits()); assertTrue("misses", 400 < stats2.getMisses()); assertTrue("hits+misses", 2000 == stats2.getHits() + stats2.getMisses()); }