use of com.hazelcast.config.NearCacheConfig in project hazelcast by hazelcast.
the class AbstractNearCachePreloaderTest method getNearCacheConfig.
protected NearCacheConfig getNearCacheConfig(boolean invalidationOnChange, int maxSize, String preloaderDir) {
EvictionConfig evictionConfig = new EvictionConfig().setMaximumSizePolicy(MaxSizePolicy.ENTRY_COUNT).setSize(maxSize).setEvictionPolicy(EvictionPolicy.LRU);
NearCacheConfig nearCacheConfig = createNearCacheConfig(InMemoryFormat.BINARY).setName(defaultNearCache).setInvalidateOnChange(invalidationOnChange).setEvictionConfig(evictionConfig);
nearCacheConfig.getPreloaderConfig().setEnabled(true).setDirectory(preloaderDir);
return nearCacheConfig;
}
use of com.hazelcast.config.NearCacheConfig in project hazelcast by hazelcast.
the class NearCacheRecordStoreTestSupport method createNearCacheWithMaxSizePolicy.
protected void createNearCacheWithMaxSizePolicy(InMemoryFormat inMemoryFormat, EvictionConfig.MaxSizePolicy maxSizePolicy, int size) {
NearCacheConfig nearCacheConfig = createNearCacheConfig(DEFAULT_NEAR_CACHE_NAME, inMemoryFormat);
EvictionConfig evictionConfig = new EvictionConfig();
evictionConfig.setMaximumSizePolicy(maxSizePolicy);
evictionConfig.setSize(size);
nearCacheConfig.setEvictionConfig(evictionConfig);
createNearCacheRecordStore(nearCacheConfig, inMemoryFormat);
}
use of com.hazelcast.config.NearCacheConfig in project hazelcast by hazelcast.
the class NearCacheRecordStoreTestSupport method maxIdleTimeEvaluatedSuccessfully.
protected void maxIdleTimeEvaluatedSuccessfully(InMemoryFormat inMemoryFormat) {
int maxIdleSeconds = 3;
NearCacheConfig nearCacheConfig = createNearCacheConfig(DEFAULT_NEAR_CACHE_NAME, inMemoryFormat);
nearCacheConfig.setMaxIdleSeconds(maxIdleSeconds);
NearCacheRecordStore<Integer, String> nearCacheRecordStore = createNearCacheRecordStore(nearCacheConfig, inMemoryFormat);
for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
nearCacheRecordStore.put(i, "Record-" + i);
}
for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
assertNotNull(nearCacheRecordStore.get(i));
}
sleepSeconds(maxIdleSeconds + 1);
for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
assertNull(nearCacheRecordStore.get(i));
}
}
use of com.hazelcast.config.NearCacheConfig in project hazelcast by hazelcast.
the class NearCacheRecordStoreTestSupport method statsCalculated.
protected 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, "Record-" + i);
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();
assertTrue(nearCacheStats.getCreationTime() >= creationStartTime);
assertTrue(nearCacheStats.getCreationTime() <= creationEndTime);
assertEquals(expectedHits, nearCacheStats.getHits());
assertEquals(expectedMisses, nearCacheStats.getMisses());
assertEquals(expectedEntryCount, nearCacheStats.getOwnedEntryCount());
switch(inMemoryFormat) {
case BINARY:
assertTrue(memoryCostWhenFull > 0);
break;
case OBJECT:
assertEquals(0, memoryCostWhenFull);
}
for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
if (nearCacheRecordStore.remove(i * 3)) {
expectedEntryCount--;
}
}
assertEquals(expectedEntryCount, nearCacheStats.getOwnedEntryCount());
switch(inMemoryFormat) {
case BINARY:
assertTrue(nearCacheStats.getOwnedEntryMemoryCost() > 0);
assertTrue(nearCacheStats.getOwnedEntryMemoryCost() < memoryCostWhenFull);
break;
case OBJECT:
assertEquals(0, nearCacheStats.getOwnedEntryMemoryCost());
break;
}
nearCacheRecordStore.clear();
switch(inMemoryFormat) {
case BINARY:
case OBJECT:
assertEquals(0, nearCacheStats.getOwnedEntryMemoryCost());
break;
}
}
use of com.hazelcast.config.NearCacheConfig in project hazelcast by hazelcast.
the class NearCacheRecordStoreTestSupport method putAndRemoveRecord.
protected void putAndRemoveRecord(InMemoryFormat inMemoryFormat) {
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, "Record-" + i);
// ensure that they are stored
assertNotNull(nearCacheRecordStore.get(i));
}
assertEquals(DEFAULT_RECORD_COUNT, nearCacheRecordStore.size());
for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
nearCacheRecordStore.remove(i);
assertNull(nearCacheRecordStore.get(i));
}
assertEquals(0, nearCacheRecordStore.size());
}
Aggregations