Package com.hazelcast.core

Examples of com.hazelcast.core.IMap


        });
    }

    @Test
    public void testNearCacheTTLCleanup() {
        final IMap map = client.getMap(randomMapName(NEAR_CACHE_WITH_TTL));

        final int size = 100;
        populateNearCache(map, size);

        NearCacheStats stats = map.getLocalMapStats().getNearCacheStats();
        assertEquals(size, stats.getOwnedEntryCount());

        sleepSeconds(MAX_TTL_SECONDS + 1);
        // map.put() and map.get() triggers near cache eviction/expiration process
        map.put(0, 0);

        HazelcastTestSupport.assertTrueEventually(new AssertTask() {
            public void run() throws Exception {
                NearCacheStats stats = map.getLocalMapStats().getNearCacheStats();
                long ownedEntryCount = stats.getOwnedEntryCount();
                assertTrue(ownedEntryCount < size);
            }
        });
    }
View Full Code Here


        });
    }

    @Test
    public void testNearCacheIdleRecordsEvicted() {
        final IMap map = client.getMap(randomMapName(NEAR_CACHE_WITH_IDLE));

        final int size = 147;
        populateNearCache(map, size);

        //generate near cache hits
        for (int i = 0; i < size; i++) {
            map.get(i);
        }

        NearCacheStats stats = map.getLocalMapStats().getNearCacheStats();
        long hitsBeforeIdleExpire = stats.getHits();

        sleepSeconds(MAX_IDLE_SECONDS + 1);

        for (int i = 0; i < size; i++) {
            map.get(i);
        }
        stats = map.getLocalMapStats().getNearCacheStats();

        assertEquals("as the hits are not equal, the entries were not cleared from near cash after MaxIdleSeconds", hitsBeforeIdleExpire, stats.getHits(), size);
    }
View Full Code Here

    }

    @Test
    public void testNearCacheInvalidateOnChange() {
        final String mapName = randomMapName(NEAR_CACHE_WITH_INVALIDATION);
        final IMap nodeMap = h1.getMap(mapName);
        final IMap clientMap = client.getMap(mapName);

        final int size = 118;
        for (int i = 0; i < size; i++) {
            nodeMap.put(i, i);
        }
        //populate near cache
        for (int i = 0; i < size; i++) {
            clientMap.get(i);
        }

        NearCacheStats stats = clientMap.getLocalMapStats().getNearCacheStats();
        long OwnedEntryCountBeforeInvalidate = stats.getOwnedEntryCount();

        //invalidate near cache from cluster
        for (int i = 0; i < size; i++) {
            nodeMap.put(i, i);
        }

        assertEquals(size, OwnedEntryCountBeforeInvalidate);

        assertTrueEventually(new AssertTask() {
            public void run() throws Exception {
                NearCacheStats stats = clientMap.getLocalMapStats().getNearCacheStats();
                assertEquals(0, stats.getOwnedEntryCount());
            }
        });
    }
View Full Code Here

        });
    }

    @Test(expected = NullPointerException.class)
    public void testNearCacheContainsNullKey() {
        final IMap map = client.getMap(randomMapName(NEAR_CACHE_WITH_INVALIDATION));
        map.containsKey(null);
    }
View Full Code Here

        map.containsKey(null);
    }

    @Test
    public void testNearCacheContainsKey() {
        final IMap map = client.getMap(randomMapName(NEAR_CACHE_WITH_INVALIDATION));
        final Object key = "key";

        map.put(key, "value");
        map.get(key);

        assertTrue(map.containsKey(key));
    }
View Full Code Here

        assertTrue(map.containsKey(key));
    }

    @Test
    public void testNearCacheContainsKey_whenKeyAbsent() {
        final IMap map = client.getMap(randomMapName(NEAR_CACHE_WITH_INVALIDATION));

        assertFalse(map.containsKey("NOT_THERE"));
    }
View Full Code Here

        assertFalse(map.containsKey("NOT_THERE"));
    }

    @Test
    public void testNearCacheContainsKey_afterRemove() {
        final IMap map = client.getMap(randomMapName(NEAR_CACHE_WITH_INVALIDATION));
        final Object key = "key";

        map.put(key, "value");
        map.get(key);
        map.remove(key);

        assertFalse(map.containsKey(key));
    }
View Full Code Here

        nearCacheConfig.setInvalidateOnChange(true);
        cfg.getMapConfig(mapName).setNearCacheConfig(nearCacheConfig);
        final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
        final HazelcastInstance hazelcastInstance1 = factory.newHazelcastInstance(cfg);
        final HazelcastInstance hazelcastInstance2 = factory.newHazelcastInstance(cfg);
        final IMap map1 = hazelcastInstance1.getMap(mapName);
        final IMap map2 = hazelcastInstance2.getMap(mapName);
        final int size = 10;
        //populate map.
        for (int i = 0; i < size; i++) {
            map1.put(i, i);
        }
        //populate near cache
        for (int i = 0; i < size; i++) {
            map1.get(i);
            map2.get(i);
        }
        //clear map should trigger near cache eviction.
        map1.clear();
        for (int i = 0; i < size; i++) {
            assertNull(map1.get(i));
View Full Code Here

        mapConfig.setTimeToLiveSeconds(ttl);
        final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(instanceCount);
        final HazelcastInstance instance1 = factory.newHazelcastInstance(cfg);
        final HazelcastInstance instance2 = factory.newHazelcastInstance(cfg);
        final HazelcastInstance instance3 = factory.newHazelcastInstance(cfg);
        final IMap map1 = instance1.getMap(mapName);
        final IMap map2 = instance2.getMap(mapName);
        final IMap map3 = instance3.getMap(mapName);
        //observe eviction
        final CountDownLatch latch = new CountDownLatch(size);
        map1.addEntryListener(new EntryAdapter() {
            public void entryEvicted(EntryEvent event) {
                latch.countDown();
            }
        }, false);
        //populate map
        for (int i = 0; i < size; i++) {
            //populate.
            map1.put(i, i);
            //bring near caches. -- here is a time window
            //that "i" already evicted. so a "get" brings
            //a NULL object to the near cache.
            map1.get(i);
            map2.get(i);
            map3.get(i);
        }
        //wait operations to complete
        assertOpenEventually(latch);
        //check map size after eviction.
        assertEquals(0, map1.size());
        assertEquals(0, map2.size());
        assertEquals(0, map3.size());
        //near cache sizes should be zero after eviction.
        assertTrueEventually(new AssertTask() {
            @Override
            public void run() throws Exception {
                assertEquals(0, countNotNullValuesInNearCache(mapName, instance1));
View Full Code Here

    }

    @Test
    public void testGetName() {
        String mapName = randomString();
        final IMap map = client.getMap(mapName);
        assertEquals(mapName, map.getName());
    }
View Full Code Here

TOP

Related Classes of com.hazelcast.core.IMap

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.