Search in sources :

Example 76 with CacheSimpleConfig

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();
    }
}
Also used : CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) EvictionConfig(com.hazelcast.config.EvictionConfig) CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) EvictionConfig(com.hazelcast.config.EvictionConfig) Config(com.hazelcast.config.Config) CacheConfig(com.hazelcast.config.CacheConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 77 with CacheSimpleConfig

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));
}
Also used : CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) ClientCacheHelper.createCacheConfig(com.hazelcast.client.cache.impl.ClientCacheHelper.createCacheConfig) ClientCacheHelper.getCacheConfig(com.hazelcast.client.cache.impl.ClientCacheHelper.getCacheConfig) Config(com.hazelcast.config.Config) CacheConfig(com.hazelcast.config.CacheConfig) HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) ClientTestUtil.getHazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.ClientTestUtil.getHazelcastClientInstanceImpl) ClientCacheHelper.createCacheConfig(com.hazelcast.client.cache.impl.ClientCacheHelper.createCacheConfig) ClientCacheHelper.getCacheConfig(com.hazelcast.client.cache.impl.ClientCacheHelper.getCacheConfig) CacheConfig(com.hazelcast.config.CacheConfig) Before(org.junit.Before)

Example 78 with CacheSimpleConfig

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());
}
Also used : CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) WanReplicationRef(com.hazelcast.config.WanReplicationRef) EventJournalConfig(com.hazelcast.config.EventJournalConfig) Test(org.junit.Test) QuickTest(com.hazelcast.test.annotation.QuickTest)

Example 79 with CacheSimpleConfig

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());
}
Also used : ExpiryPolicyFactoryConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig) TimedExpiryPolicyFactoryConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig) CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) TimedExpiryPolicyFactoryConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig) ExpiryPolicyFactoryConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig) CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) EvictionConfig(com.hazelcast.config.EvictionConfig) Config(com.hazelcast.config.Config) TimedExpiryPolicyFactoryConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig) DurationConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.DurationConfig) CachePartitionLostListenerConfig(com.hazelcast.config.CachePartitionLostListenerConfig) MergePolicyConfig(com.hazelcast.config.MergePolicyConfig) DurationConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.DurationConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 80 with CacheSimpleConfig

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());
}
Also used : CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

CacheSimpleConfig (com.hazelcast.config.CacheSimpleConfig)84 Test (org.junit.Test)41 Config (com.hazelcast.config.Config)40 QuickTest (com.hazelcast.test.annotation.QuickTest)37 EvictionConfig (com.hazelcast.config.EvictionConfig)17 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)17 BeforeClass (org.junit.BeforeClass)16 CachePartitionLostListenerConfig (com.hazelcast.config.CachePartitionLostListenerConfig)15 MapConfig (com.hazelcast.config.MapConfig)11 ClientConfig (com.hazelcast.client.config.ClientConfig)10 EventJournalConfig (com.hazelcast.config.EventJournalConfig)10 MergePolicyConfig (com.hazelcast.config.MergePolicyConfig)10 HazelcastInstance (com.hazelcast.core.HazelcastInstance)10 ExpiryPolicyFactoryConfig (com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig)9 QuorumConfig (com.hazelcast.config.QuorumConfig)9 CacheConfig (com.hazelcast.config.CacheConfig)8 TimedExpiryPolicyFactoryConfig (com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig)8 QueueConfig (com.hazelcast.config.QueueConfig)8 CacheSimpleEntryListenerConfig (com.hazelcast.config.CacheSimpleEntryListenerConfig)7 CardinalityEstimatorConfig (com.hazelcast.config.CardinalityEstimatorConfig)7