use of com.hazelcast.config.NearCacheConfig in project hazelcast by hazelcast.
the class StaleReadDetectorTest method createConfigWithNearCache.
private Config createConfigWithNearCache(boolean invalidateOnChange) {
Config config = getConfig();
config.setProperty(PARTITION_COUNT.getName(), "1");
NearCacheConfig nearCacheConfig = new NearCacheConfig();
nearCacheConfig.setCacheLocalEntries(true);
nearCacheConfig.setInvalidateOnChange(invalidateOnChange);
MapConfig mapConfig = config.getMapConfig(MAP_NAME);
mapConfig.setNearCacheConfig(nearCacheConfig);
return config;
}
use of com.hazelcast.config.NearCacheConfig in project hazelcast by hazelcast.
the class NearCacheRecordStoreTest method doEvictionWithEntryCountMaxSizePolicy.
private void doEvictionWithEntryCountMaxSizePolicy(InMemoryFormat inMemoryFormat, EvictionPolicy evictionPolicy) {
int maxSize = DEFAULT_RECORD_COUNT / 2;
EvictionConfig evictionConfig = new EvictionConfig().setMaxSizePolicy(MaxSizePolicy.ENTRY_COUNT).setSize(maxSize).setEvictionPolicy(evictionPolicy == null ? EvictionConfig.DEFAULT_EVICTION_POLICY : evictionPolicy);
NearCacheConfig nearCacheConfig = createNearCacheConfig(DEFAULT_NEAR_CACHE_NAME, inMemoryFormat).setEvictionConfig(evictionConfig);
NearCacheRecordStore<Integer, String> nearCacheRecordStore = createNearCacheRecordStore(nearCacheConfig, inMemoryFormat);
for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
nearCacheRecordStore.put(i, null, "Record-" + i, null);
nearCacheRecordStore.doEviction(false);
assertTrue(maxSize >= nearCacheRecordStore.size());
}
}
use of com.hazelcast.config.NearCacheConfig in project hazelcast by hazelcast.
the class NearCacheRecordStoreTestSupport method clearRecordsOrDestroyStore.
void clearRecordsOrDestroyStore(InMemoryFormat inMemoryFormat, boolean destroy) {
NearCacheConfig nearCacheConfig = createNearCacheConfig(DEFAULT_NEAR_CACHE_NAME, inMemoryFormat);
NearCacheRecordStore<Integer, String> nearCacheRecordStore = createNearCacheRecordStore(nearCacheConfig, inMemoryFormat);
for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
nearCacheRecordStore.put(i, null, "Record-" + i, null);
// ensure that they are stored
assertNotNull(nearCacheRecordStore.get(i));
}
if (destroy) {
nearCacheRecordStore.destroy();
} else {
nearCacheRecordStore.clear();
}
assertEquals(0, nearCacheRecordStore.size());
}
use of com.hazelcast.config.NearCacheConfig in project hazelcast by hazelcast.
the class NearCacheRecordStoreTestSupport method statsCalculated.
void statsCalculated(InMemoryFormat inMemoryFormat) {
long creationStartTime = System.currentTimeMillis();
NearCacheConfig nearCacheConfig = createNearCacheConfig(DEFAULT_NEAR_CACHE_NAME, inMemoryFormat);
NearCacheRecordStore<Integer, String> nearCacheRecordStore = createNearCacheRecordStore(nearCacheConfig, inMemoryFormat);
long creationEndTime = System.currentTimeMillis();
int expectedEntryCount = 0;
int expectedHits = 0;
int expectedMisses = 0;
for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
nearCacheRecordStore.put(i, null, "Record-" + i, null);
expectedEntryCount++;
}
for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
if (nearCacheRecordStore.get(i * 3) != null) {
expectedHits++;
} else {
expectedMisses++;
}
}
NearCacheStats nearCacheStats = nearCacheRecordStore.getNearCacheStats();
long memoryCostWhenFull = nearCacheStats.getOwnedEntryMemoryCost();
// Note that System.currentTimeMillis() is not monotonically increasing.
// Below assertions can fail anytime but for testing purposes we can use `assertTrueEventually`.
long nearCacheStatsCreationTime = nearCacheStats.getCreationTime();
assertTrue("nearCacheStatsCreationTime=" + nearCacheStatsCreationTime + ", and creationStartTime=" + creationStartTime, nearCacheStatsCreationTime >= creationStartTime);
assertTrue("nearCacheStatsCreationTime=" + nearCacheStatsCreationTime + ", and creationEndTime=" + creationEndTime, nearCacheStatsCreationTime <= creationEndTime);
assertEquals(expectedHits, nearCacheStats.getHits());
assertEquals(expectedMisses, nearCacheStats.getMisses());
assertEquals(expectedEntryCount, nearCacheStats.getOwnedEntryCount());
switch(inMemoryFormat) {
case NATIVE:
case BINARY:
assertTrue(memoryCostWhenFull > 0);
break;
case OBJECT:
assertEquals(0, memoryCostWhenFull);
break;
default:
}
int sizeBefore = nearCacheRecordStore.size();
for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
nearCacheRecordStore.invalidate(i * 3);
}
int sizeAfter = nearCacheRecordStore.size();
int invalidatedSize = sizeBefore - sizeAfter;
expectedEntryCount -= invalidatedSize;
assertEquals(expectedEntryCount, nearCacheStats.getOwnedEntryCount());
switch(inMemoryFormat) {
case NATIVE:
case BINARY:
assertTrue(nearCacheStats.getOwnedEntryMemoryCost() > 0);
assertTrue(nearCacheStats.getOwnedEntryMemoryCost() < memoryCostWhenFull);
break;
case OBJECT:
assertEquals(0, nearCacheStats.getOwnedEntryMemoryCost());
break;
default:
}
nearCacheRecordStore.clear();
assertEquals(0, nearCacheStats.getOwnedEntryMemoryCost());
}
use of com.hazelcast.config.NearCacheConfig in project hazelcast by hazelcast.
the class NearCacheRecordStoreTestSupport method ttlEvaluated.
void ttlEvaluated(InMemoryFormat inMemoryFormat) {
int ttlSeconds = 3;
NearCacheConfig nearCacheConfig = createNearCacheConfig(DEFAULT_NEAR_CACHE_NAME, inMemoryFormat).setTimeToLiveSeconds(ttlSeconds);
NearCacheRecordStore<Integer, String> nearCacheRecordStore = createNearCacheRecordStore(nearCacheConfig, inMemoryFormat);
for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
nearCacheRecordStore.put(i, null, "Record-" + i, null);
}
for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
assertNotNull(nearCacheRecordStore.get(i));
}
sleepSeconds(ttlSeconds + 1);
for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
assertNull(nearCacheRecordStore.get(i));
}
}
Aggregations