Search in sources :

Example 26 with NearCache

use of com.hazelcast.internal.nearcache.NearCache in project hazelcast by hazelcast.

the class NearCacheManagerTestSupport method doCreateAndGetNearCache.

void doCreateAndGetNearCache() {
    NearCacheManager nearCacheManager = createNearCacheManager();
    assertNull(nearCacheManager.getNearCache(DEFAULT_NEAR_CACHE_NAME));
    NearCache createdNearCache1 = createNearCache(nearCacheManager, DEFAULT_NEAR_CACHE_NAME);
    assertNotNull(createdNearCache1);
    NearCache createdNearCache2 = createNearCache(nearCacheManager, DEFAULT_NEAR_CACHE_NAME);
    assertNotNull(createdNearCache2);
    assertEquals(createdNearCache1, createdNearCache2);
    Collection<NearCache> nearCaches = nearCacheManager.listAllNearCaches();
    assertEquals(1, nearCaches.size());
    assertEquals(createdNearCache1, nearCaches.iterator().next());
}
Also used : NearCacheManager(com.hazelcast.internal.nearcache.NearCacheManager) NearCache(com.hazelcast.internal.nearcache.NearCache)

Example 27 with NearCache

use of com.hazelcast.internal.nearcache.NearCache in project hazelcast by hazelcast.

the class NearCacheManagerTestSupport method doClearNearCacheAndClearAllNearCaches.

void doClearNearCacheAndClearAllNearCaches() {
    NearCacheManager nearCacheManager = createNearCacheManager();
    for (int i = 0; i < DEFAULT_NEAR_CACHE_COUNT; i++) {
        createNearCache(nearCacheManager, DEFAULT_NEAR_CACHE_NAME + "-" + i);
    }
    Collection<NearCache> nearCaches1 = nearCacheManager.listAllNearCaches();
    assertEquals(DEFAULT_NEAR_CACHE_COUNT, nearCaches1.size());
    for (int i = 0; i < DEFAULT_NEAR_CACHE_COUNT; i++) {
        assertTrue(nearCacheManager.clearNearCache(DEFAULT_NEAR_CACHE_NAME + "-" + i));
    }
    Collection<NearCache> nearCaches2 = nearCacheManager.listAllNearCaches();
    // clear doesn't remove Near Cache, just clears it
    assertEquals(DEFAULT_NEAR_CACHE_COUNT, nearCaches2.size());
    nearCacheManager.clearAllNearCaches();
    Collection<NearCache> nearCaches3 = nearCacheManager.listAllNearCaches();
    // clear all doesn't remove Near Caches, just clears them
    assertEquals(DEFAULT_NEAR_CACHE_COUNT, nearCaches3.size());
    assertFalse(nearCacheManager.clearNearCache(DEFAULT_NEAR_CACHE_NAME + "-" + DEFAULT_NEAR_CACHE_COUNT));
}
Also used : NearCacheManager(com.hazelcast.internal.nearcache.NearCacheManager) NearCache(com.hazelcast.internal.nearcache.NearCache)

Example 28 with NearCache

use of com.hazelcast.internal.nearcache.NearCache in project hazelcast by hazelcast.

the class NearCacheManagerTestSupport method doListNearCaches.

void doListNearCaches() {
    NearCacheManager nearCacheManager = createNearCacheManager();
    Set<String> nearCacheNames = new HashSet<String>();
    Collection<NearCache> nearCaches1 = nearCacheManager.listAllNearCaches();
    assertEquals(0, nearCaches1.size());
    for (int i = 0; i < DEFAULT_NEAR_CACHE_COUNT; i++) {
        String nearCacheName = DEFAULT_NEAR_CACHE_NAME + "-" + i;
        createNearCache(nearCacheManager, nearCacheName);
        nearCacheNames.add(nearCacheName);
    }
    Collection<NearCache> nearCaches2 = nearCacheManager.listAllNearCaches();
    assertEquals(DEFAULT_NEAR_CACHE_COUNT, nearCaches2.size());
    for (NearCache nearCache : nearCaches2) {
        assertContains(nearCacheNames, nearCache.getName());
    }
}
Also used : NearCacheManager(com.hazelcast.internal.nearcache.NearCacheManager) NearCache(com.hazelcast.internal.nearcache.NearCache) HashSet(java.util.HashSet)

Example 29 with NearCache

use of com.hazelcast.internal.nearcache.NearCache in project hazelcast by hazelcast.

the class NearCacheTestSupport method assertNearCacheExpiration.

protected void assertNearCacheExpiration(final IMap<Integer, Integer> map, final int size) {
    assertTrueEventually(() -> {
        NearCache nearCache = getBackingNearCache(map);
        NearCacheStats stats = getNearCacheStats(map);
        // make assertions over near cache's backing map size.
        long nearCacheSize = nearCache.size();
        assertEquals(format("Expected zero near cache size but found: %d, [%s] ", nearCacheSize, stats), 0, nearCacheSize);
        // make assertions over near cache stats.
        long ownedEntryCount = stats.getOwnedEntryCount();
        assertEquals(format("Expected no owned entry but found: %d, [%s]", ownedEntryCount, stats), 0, ownedEntryCount);
        long ownedEntryMemoryCost = stats.getOwnedEntryMemoryCost();
        assertEquals(format("Expected zero memory cost but found: %d, [%s]", ownedEntryMemoryCost, stats), 0, ownedEntryMemoryCost);
        long expiredCount = stats.getExpirations();
        assertEquals(format("Expected to see all entries as expired but found: %d, [%s]", expiredCount, stats), size, expiredCount);
        long evictedCount = stats.getEvictions();
        assertEquals(format("Expiration should not trigger eviction stat but found: %d, [%s]", evictedCount, stats), 0, evictedCount);
    });
}
Also used : NearCacheStats(com.hazelcast.nearcache.NearCacheStats) NearCache(com.hazelcast.internal.nearcache.NearCache)

Example 30 with NearCache

use of com.hazelcast.internal.nearcache.NearCache in project hazelcast by hazelcast.

the class NearCacheTest method testBasicUsage.

@Test
public void testBasicUsage() {
    int clusterSize = 3;
    int mapSize = 5000;
    final String mapName = "testBasicUsage";
    Config config = getConfig();
    config.getMapConfig(mapName).setNearCacheConfig(newNearCacheConfig().setInvalidateOnChange(true));
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(clusterSize);
    final HazelcastInstance[] instances = factory.newInstances(config);
    IMap<Integer, Integer> map = instances[0].getMap(mapName);
    populateMap(map, mapSize);
    for (HazelcastInstance instance : instances) {
        IMap<Integer, Integer> instanceMap = instance.getMap(mapName);
        for (int i = 0; i < mapSize; i++) {
            assertNotNull(instanceMap.get(i));
        }
    }
    for (int i = 0; i < mapSize; i++) {
        map.put(i, i * 2);
    }
    for (HazelcastInstance instance : instances) {
        IMap<Object, Object> m = instance.getMap(mapName);
        for (int i = 0; i < mapSize; i++) {
            assertNotNull(m.get(i));
        }
    }
    for (HazelcastInstance instance : instances) {
        int nearCacheSize = getNearCache(mapName, instance).size();
        assertTrue("Near Cache size should be > 0 but was " + nearCacheSize, nearCacheSize > 0);
    }
    map.clear();
    assertTrueEventually(() -> {
        for (HazelcastInstance instance : instances) {
            NearCache nearCache = getNearCache(mapName, instance);
            int size = nearCache.size();
            assertEquals("Near Cache size should be 0 but was " + size, 0, size);
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) NearCache(com.hazelcast.internal.nearcache.NearCache) EntryObject(com.hazelcast.query.PredicateBuilder.EntryObject) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

NearCache (com.hazelcast.internal.nearcache.NearCache)33 Test (org.junit.Test)17 QuickTest (com.hazelcast.test.annotation.QuickTest)16 AssertTask (com.hazelcast.test.AssertTask)14 Config (com.hazelcast.config.Config)12 NearCacheConfig (com.hazelcast.config.NearCacheConfig)12 HazelcastInstance (com.hazelcast.core.HazelcastInstance)12 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)12 MapConfig (com.hazelcast.config.MapConfig)9 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)9 NearCacheTestUtils.getBaseConfig (com.hazelcast.internal.nearcache.impl.NearCacheTestUtils.getBaseConfig)6 DefaultNearCache (com.hazelcast.internal.nearcache.impl.DefaultNearCache)5 NearCacheStats (com.hazelcast.nearcache.NearCacheStats)5 NearCacheManager (com.hazelcast.internal.nearcache.NearCacheManager)4 ClientConfig (com.hazelcast.client.config.ClientConfig)3 NearCacheRecord (com.hazelcast.internal.nearcache.NearCacheRecord)3 AbstractNearCacheRecordStore (com.hazelcast.internal.nearcache.impl.store.AbstractNearCacheRecordStore)3 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)3 NearCachedMapProxyImpl (com.hazelcast.map.impl.proxy.NearCachedMapProxyImpl)3 NightlyTest (com.hazelcast.test.annotation.NightlyTest)3