@Test(timeout = 120000) public void testOneMemberFlush() throws Exception { TestMapStore testMapStore = new TestMapStore(1, 1, 1); testMapStore.setLoadAllKeys(false); int size = 100; Config config = newConfig(testMapStore, 200); TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(3); HazelcastInstance h1 = nodeFactory.newHazelcastInstance(config); IMap map = h1.getMap("default"); assertEquals(0, map.size()); for (int i = 0; i < size; i++) { map.put(i, i); } assertEquals(size, map.size()); assertEquals(0, testMapStore.getStore().size()); assertEquals(size, map.getLocalMapStats().getDirtyEntryCount()); map.flush(); assertEquals(size, testMapStore.getStore().size()); assertEquals(0, map.getLocalMapStats().getDirtyEntryCount()); assertEquals(size, map.size()); for (int i = 0; i < size / 2; i++) { map.remove(i); } assertEquals(size / 2, map.size()); assertEquals(size, testMapStore.getStore().size()); map.flush(); assertEquals(size / 2, testMapStore.getStore().size()); assertEquals(size / 2, map.size()); }
@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()); }
@Override public String getDescription() { return "HCMap(" + getName() + "):" + cache.getLocalMapStats(); // TODO we really want the cluster stats }
@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 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(timeout = 120000) public void testMapCreation__notAffectedByUnresponsiveLoader() throws Exception { final UnresponsiveLoader unresponsiveLoader = new UnresponsiveLoader<Integer, Integer>(); final IMap map = TestMapUsingMapStoreBuilder.create() .withMapStore(unresponsiveLoader) .withNodeCount(1) .withNodeFactory(createHazelcastInstanceFactory(1)) .withPartitionCount(1) .build(); final LocalMapStats stats = map.getLocalMapStats(); final long ownedEntryCount = stats.getOwnedEntryCount(); assertEquals(0, ownedEntryCount); }
@Test(timeout = 120000) public void issue614() { final ConcurrentMap<Long, String> STORE = new ConcurrentHashMap<Long, String>(); STORE.put(1l, "Event1"); STORE.put(2l, "Event2"); STORE.put(3l, "Event3"); STORE.put(4l, "Event4"); STORE.put(5l, "Event5"); STORE.put(6l, "Event6"); Config config = getConfig(); config .getMapConfig("map") .setMapStoreConfig( new MapStoreConfig() .setWriteDelaySeconds(1) .setImplementation(new SimpleMapStore<Long, String>(STORE))); TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(3); HazelcastInstance h = nodeFactory.newHazelcastInstance(config); IMap map = h.getMap("map"); Collection collection = map.values(); LocalMapStats localMapStats = map.getLocalMapStats(); assertEquals(0, localMapStats.getDirtyEntryCount()); }
// issue 1570 @Test public void testNullValueNearCache() { int n = 2; String mapName = "testNullValueNearCache"; Config config = new Config(); config.getMapConfig(mapName).setNearCacheConfig(new NearCacheConfig()); HazelcastInstance instance = createHazelcastInstanceFactory(n).newInstances(config)[0]; IMap<String, String> map = instance.getMap(mapName); int size = 100; for (int i = 0; i < size; i++) { assertNull(map.get("key" + i)); } for (int i = 0; i < size; i++) { assertNull(map.get("key" + i)); } assertTrue(map.getLocalMapStats().getGetOperationCount() < size * 2); }