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());
}
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());
}
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());
}
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());
}
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();
}
}
}
Aggregations