Search in sources :

Example 11 with CacheSimpleConfig

use of com.hazelcast.config.CacheSimpleConfig in project hazelcast by hazelcast.

the class TestJCache method testConfig.

@Test
public void testConfig() {
    assertNotNull(instance1);
    CacheSimpleConfig simpleConfig = instance1.getConfig().getCacheConfigs().get("cache1");
    assertNotNull(simpleConfig);
    assertEquals(1, simpleConfig.getAsyncBackupCount());
    assertEquals(2, simpleConfig.getBackupCount());
    assertEquals("java.lang.Integer", simpleConfig.getKeyType());
    assertEquals("java.lang.String", simpleConfig.getValueType());
    assertTrue(simpleConfig.isStatisticsEnabled());
    assertTrue(simpleConfig.isManagementEnabled());
    assertTrue(simpleConfig.isReadThrough());
    assertTrue(simpleConfig.isWriteThrough());
    assertEquals("com.hazelcast.cache.MyCacheLoaderFactory", simpleConfig.getCacheLoaderFactory());
    assertEquals("com.hazelcast.cache.MyCacheWriterFactory", simpleConfig.getCacheWriterFactory());
    assertEquals("com.hazelcast.cache.MyExpiryPolicyFactory", simpleConfig.getExpiryPolicyFactoryConfig().getClassName());
    assertEquals(InMemoryFormat.OBJECT, simpleConfig.getInMemoryFormat());
    assertNotNull(simpleConfig.getEvictionConfig());
    assertEquals(50, simpleConfig.getEvictionConfig().getSize());
    assertEquals(MaxSizePolicy.ENTRY_COUNT, simpleConfig.getEvictionConfig().getMaxSizePolicy());
    assertEquals(EvictionPolicy.LRU, simpleConfig.getEvictionConfig().getEvictionPolicy());
}
Also used : CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 12 with CacheSimpleConfig

use of com.hazelcast.config.CacheSimpleConfig in project hazelcast by hazelcast.

the class TestJCache method cacheConfigXmlTest_TimedModifiedTouchedPolicyFactory.

@Test
public void cacheConfigXmlTest_TimedModifiedTouchedPolicyFactory() {
    Config config = instance1.getConfig();
    CacheSimpleConfig cacheWithTimedTouchedExpiryPolicyFactoryConfig = config.getCacheConfig("cacheWithTimedTouchedExpiryPolicyFactory");
    ExpiryPolicyFactoryConfig expiryPolicyFactoryConfig = cacheWithTimedTouchedExpiryPolicyFactoryConfig.getExpiryPolicyFactoryConfig();
    TimedExpiryPolicyFactoryConfig timedExpiryPolicyFactoryConfig = expiryPolicyFactoryConfig.getTimedExpiryPolicyFactoryConfig();
    DurationConfig durationConfig = timedExpiryPolicyFactoryConfig.getDurationConfig();
    assertNotNull(expiryPolicyFactoryConfig);
    assertNotNull(timedExpiryPolicyFactoryConfig);
    assertNotNull(durationConfig);
    assertNull(expiryPolicyFactoryConfig.getClassName());
    assertEquals(ExpiryPolicyType.TOUCHED, timedExpiryPolicyFactoryConfig.getExpiryPolicyType());
    assertEquals(4, durationConfig.getDurationAmount());
    assertEquals(TimeUnit.SECONDS, 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 13 with CacheSimpleConfig

use of com.hazelcast.config.CacheSimpleConfig in project hazelcast by hazelcast.

the class CachePartitionLostListenerConfigTest method cacheConfigXmlTest.

@Test
public void cacheConfigXmlTest() throws IOException {
    String cacheName = "cacheWithPartitionLostListener";
    Config config = new XmlConfigBuilder(configUrl).build();
    CacheSimpleConfig cacheConfig = config.getCacheConfig(cacheName);
    List<CachePartitionLostListenerConfig> configs = cacheConfig.getPartitionLostListenerConfigs();
    assertEquals(1, configs.size());
    assertEquals("DummyCachePartitionLostListenerImpl", configs.get(0).getClassName());
}
Also used : CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) XmlConfigBuilder(com.hazelcast.config.XmlConfigBuilder) CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) Config(com.hazelcast.config.Config) CachePartitionLostListenerConfig(com.hazelcast.config.CachePartitionLostListenerConfig) CachePartitionLostListenerConfig(com.hazelcast.config.CachePartitionLostListenerConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 14 with CacheSimpleConfig

use of com.hazelcast.config.CacheSimpleConfig in project hazelcast by hazelcast.

the class CacheCreationTest method concurrentCacheCreation.

@Test
public void concurrentCacheCreation() throws InterruptedException {
    // see https://github.com/hazelcast/hazelcast/issues/17284
    String cacheName = "myCache";
    int threadCount = Runtime.getRuntime().availableProcessors() * 20;
    Config config = new Config().addCacheConfig(new CacheSimpleConfig().setName(cacheName));
    CacheManager cacheManager = createCachingProvider(config).getCacheManager();
    CountDownLatch startLatch = new CountDownLatch(1);
    AtomicInteger errorCounter = new AtomicInteger();
    Runnable getCache = () -> {
        try {
            startLatch.await();
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
        try {
            Cache<?, ?> cache = cacheManager.getCache(cacheName);
            if (cache == null) {
                System.out.println("getCache() returned null!");
                errorCounter.incrementAndGet();
            }
        } catch (Throwable t) {
            t.printStackTrace();
            errorCounter.incrementAndGet();
        }
    };
    ExecutorService executorService = Executors.newFixedThreadPool(threadCount);
    for (int i = 0; i < threadCount; i++) {
        executorService.submit(getCache);
    }
    // start all threads at once
    startLatch.countDown();
    executorService.shutdown();
    executorService.awaitTermination(1, TimeUnit.MINUTES);
    assertEquals(0, errorCounter.get());
}
Also used : CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) JoinConfig(com.hazelcast.config.JoinConfig) EvictionConfig(com.hazelcast.config.EvictionConfig) Config(com.hazelcast.config.Config) CacheConfig(com.hazelcast.config.CacheConfig) ExecutorService(java.util.concurrent.ExecutorService) CacheManager(javax.cache.CacheManager) CountDownLatch(java.util.concurrent.CountDownLatch) Cache(javax.cache.Cache) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 15 with CacheSimpleConfig

use of com.hazelcast.config.CacheSimpleConfig in project hazelcast by hazelcast.

the class ClientCacheConfigTest method createCacheConfigOnAllNodes.

@Test
public void createCacheConfigOnAllNodes() {
    final String CACHE_NAME = "myCache";
    HazelcastInstance client = null;
    HazelcastInstance server1 = null;
    HazelcastInstance server2 = null;
    try {
        Config config = new Config().setClusterName(getTestMethodName());
        if (isSolaris()) {
            config.setProperty(ClusterProperty.MULTICAST_SOCKET_SET_INTERFACE.getName(), "false");
        }
        CacheSimpleConfig cacheSimpleConfig = new CacheSimpleConfig().setName(CACHE_NAME).setBackupCount(// Be sure that cache put operation is mirrored to backup node
        1);
        config.addCacheConfig(cacheSimpleConfig);
        // Create servers with configured caches
        server1 = Hazelcast.newHazelcastInstance(config);
        server2 = Hazelcast.newHazelcastInstance(config);
        ICacheService cacheService1 = getCacheService(server1);
        ICacheService cacheService2 = getCacheService(server2);
        // Create the hazelcast client instance
        ClientConfig clientConfig = new ClientConfig().setClusterName(getTestMethodName());
        client = HazelcastClient.newHazelcastClient(clientConfig);
        // Create the client cache manager
        CachingProvider cachingProvider = createClientCachingProvider(client);
        CacheManager cacheManager = cachingProvider.getCacheManager();
        Cache<String, String> cache = cacheManager.getCache(CACHE_NAME);
        assertNotNull(cache);
        CacheConfig cacheConfig = cache.getConfiguration(CacheConfig.class);
        assertNotNull(cacheService1.getCacheConfig(cacheConfig.getNameWithPrefix()));
        assertNotNull(cacheService2.getCacheConfig(cacheConfig.getNameWithPrefix()));
        // First attempt to use the cache will trigger to create its record store.
        // So, we are testing also this case. There should not be any exception.
        // In here, we are testing both of nodes since there is a backup,
        // put is also applied to other (backup node).
        cache.put("key", "value");
    } finally {
        if (client != null) {
            client.shutdown();
        }
        if (server1 != null) {
            server1.shutdown();
        }
        if (server2 != null) {
            server2.shutdown();
        }
    }
}
Also used : CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ICacheService(com.hazelcast.cache.impl.ICacheService) CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) Config(com.hazelcast.config.Config) CacheConfig(com.hazelcast.config.CacheConfig) CacheManager(javax.cache.CacheManager) HazelcastClientCacheManager(com.hazelcast.client.cache.impl.HazelcastClientCacheManager) ClientConfig(com.hazelcast.client.config.ClientConfig) CacheConfig(com.hazelcast.config.CacheConfig) HazelcastCachingProvider(com.hazelcast.cache.HazelcastCachingProvider) CacheTestSupport.createClientCachingProvider(com.hazelcast.cache.CacheTestSupport.createClientCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) 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