use of com.hazelcast.config.CacheSimpleConfig in project hazelcast by hazelcast.
the class CacheStatsTest method testEvictions.
@Test
public void testEvictions() {
int partitionCount = 2;
int maxEntryCount = 2;
// with given parameters, the eviction checker expects 6 entries per partition to kick-in
// see EntryCountCacheEvictionChecker#calculateMaxPartitionSize for actual calculation
int calculatedMaxEntriesPerPartition = 6;
factory.terminateAll();
// configure members with 2 partitions, cache with eviction on max size 2
CacheSimpleConfig cacheConfig = new CacheSimpleConfig();
cacheConfig.setName("*").setBackupCount(1).setStatisticsEnabled(true).setEvictionConfig(new EvictionConfig().setSize(maxEntryCount).setMaxSizePolicy(MaxSizePolicy.ENTRY_COUNT).setEvictionPolicy(EvictionPolicy.LFU));
Config config = new Config();
config.setProperty(ClusterProperty.PARTITION_COUNT.getName(), Integer.toString(partitionCount));
config.addCacheConfig(cacheConfig);
HazelcastInstance hz1 = getHazelcastInstance(config);
HazelcastInstance hz2 = getHazelcastInstance(config);
ICache<String, String> cache1 = hz1.getCacheManager().getCache("cache1");
ICache<String, String> cache2 = hz2.getCacheManager().getCache("cache1");
// put 5 entries in a single partition
while (cache1.size() < calculatedMaxEntriesPerPartition) {
String key = generateKeyForPartition(hz1, 0);
cache1.put(key, randomString());
}
String key = generateKeyForPartition(hz1, 0);
// this put must trigger eviction
cache1.put(key, "foo");
try {
// number of evictions on primary and backup must be 1
assertEquals(1, cache1.getLocalCacheStatistics().getCacheEvictions() + cache2.getLocalCacheStatistics().getCacheEvictions());
} finally {
cache1.destroy();
cache2.destroy();
}
}
use of com.hazelcast.config.CacheSimpleConfig in project hazelcast by hazelcast.
the class ClientCacheHelperTest method setUp.
@Before
public void setUp() {
CacheSimpleConfig cacheSimpleConfig = new CacheSimpleConfig();
cacheSimpleConfig.setName(SIMPLE_CACHE_NAME);
Config config = new Config();
config.addCacheConfig(cacheSimpleConfig);
hazelcastFactory.newHazelcastInstance(config);
client = getHazelcastClientInstanceImpl(hazelcastFactory.newHazelcastClient());
exceptionThrowingClient = mock(HazelcastClientInstanceImpl.class, RETURNS_DEEP_STUBS);
when(exceptionThrowingClient.getClientPartitionService()).thenThrow(new IllegalArgumentException("expected"));
newCacheConfig = new CacheConfig<String, String>(CACHE_NAME);
cacheConfig = new CacheConfig<String, String>(CACHE_NAME);
configs = new ConcurrentHashMap<String, CacheConfig>(singletonMap(CACHE_NAME, cacheConfig));
}
use of com.hazelcast.config.CacheSimpleConfig in project hazelcast by hazelcast.
the class TestFullApplicationContext method testCacheConfig.
@Test
public void testCacheConfig() {
assertNotNull(config);
assertEquals(1, config.getCacheConfigs().size());
CacheSimpleConfig cacheConfig = config.getCacheConfig("testCache");
assertEquals("testCache", cacheConfig.getName());
assertTrue(cacheConfig.isDisablePerEntryInvalidationEvents());
assertTrue(cacheConfig.getDataPersistenceConfig().isEnabled());
assertTrue(cacheConfig.getDataPersistenceConfig().isFsync());
EventJournalConfig journalConfig = cacheConfig.getEventJournalConfig();
assertTrue(journalConfig.isEnabled());
assertEquals(123, journalConfig.getCapacity());
assertEquals(321, journalConfig.getTimeToLiveSeconds());
WanReplicationRef wanRef = cacheConfig.getWanReplicationRef();
assertEquals("testWan", wanRef.getName());
assertEquals("PutIfAbsentMergePolicy", wanRef.getMergePolicyClassName());
assertEquals(1, wanRef.getFilters().size());
assertEquals("com.example.SampleFilter", wanRef.getFilters().get(0));
assertTrue(cacheConfig.getMerkleTreeConfig().isEnabled());
assertEquals(20, cacheConfig.getMerkleTreeConfig().getDepth());
}
use of com.hazelcast.config.CacheSimpleConfig in project hazelcast by hazelcast.
the class TestJCache method cacheConfigXmlTest_TimedModifiedExpiryPolicyFactory.
@Test
public void cacheConfigXmlTest_TimedModifiedExpiryPolicyFactory() {
Config config = instance1.getConfig();
CacheSimpleConfig cacheWithTimedModifiedExpiryPolicyFactoryConfig = config.getCacheConfig("cacheWithTimedModifiedExpiryPolicyFactory");
ExpiryPolicyFactoryConfig expiryPolicyFactoryConfig = cacheWithTimedModifiedExpiryPolicyFactoryConfig.getExpiryPolicyFactoryConfig();
TimedExpiryPolicyFactoryConfig timedExpiryPolicyFactoryConfig = expiryPolicyFactoryConfig.getTimedExpiryPolicyFactoryConfig();
DurationConfig durationConfig = timedExpiryPolicyFactoryConfig.getDurationConfig();
assertNotNull(expiryPolicyFactoryConfig);
assertNotNull(timedExpiryPolicyFactoryConfig);
assertNotNull(durationConfig);
assertNull(expiryPolicyFactoryConfig.getClassName());
assertEquals(ExpiryPolicyType.MODIFIED, timedExpiryPolicyFactoryConfig.getExpiryPolicyType());
assertEquals(3, durationConfig.getDurationAmount());
assertEquals(TimeUnit.MINUTES, durationConfig.getTimeUnit());
}
use of com.hazelcast.config.CacheSimpleConfig in project hazelcast by hazelcast.
the class TestJCache method cacheConfigXmlTest_ClusterSplitBrainProtection.
@Test
public void cacheConfigXmlTest_ClusterSplitBrainProtection() {
assertNotNull(instance1);
CacheSimpleConfig simpleConfig = instance1.getConfig().getCacheConfig("cacheWithSplitBrainProtectionRef");
assertNotNull(simpleConfig);
assertEquals("cacheSplitBrainProtectionRefString", simpleConfig.getSplitBrainProtectionName());
}
Aggregations