use of com.hazelcast.config.CacheConfig in project hazelcast by hazelcast.
the class CacheBackupTest method entrySuccessfullyRetrievedFromBackup.
private void entrySuccessfullyRetrievedFromBackup(int backupCount, boolean sync) {
final String KEY = "key";
final String VALUE = "value";
final int nodeCount = backupCount + 1;
final TestHazelcastInstanceFactory instanceFactory = createHazelcastInstanceFactory(nodeCount);
final HazelcastInstance[] instances = new HazelcastInstance[nodeCount];
for (int i = 0; i < instances.length; i++) {
instances[i] = instanceFactory.newHazelcastInstance();
}
final HazelcastInstance hz = instances[0];
final CachingProvider cachingProvider = HazelcastServerCachingProvider.createCachingProvider(hz);
final CacheManager cacheManager = cachingProvider.getCacheManager();
final String cacheName = randomName();
final CacheConfig cacheConfig = new CacheConfig().setName(cacheName);
if (sync) {
cacheConfig.setBackupCount(backupCount);
} else {
cacheConfig.setAsyncBackupCount(backupCount);
}
final Cache cache = cacheManager.createCache(cacheName, cacheConfig);
warmUpPartitions(instances);
waitAllForSafeState(instances);
cache.put(KEY, VALUE);
final Node node = getNode(hz);
final InternalPartitionService partitionService = node.getPartitionService();
final int keyPartitionId = partitionService.getPartitionId(KEY);
for (int i = 1; i <= backupCount; i++) {
final Node backupNode = getNode(instances[i]);
final SerializationService serializationService = backupNode.getSerializationService();
final ICacheService cacheService = backupNode.getNodeEngine().getService(ICacheService.SERVICE_NAME);
if (sync) {
checkSavedRecordOnBackup(KEY, VALUE, cacheName, keyPartitionId, serializationService, cacheService);
} else {
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
checkSavedRecordOnBackup(KEY, VALUE, cacheName, keyPartitionId, serializationService, cacheService);
}
});
}
}
}
use of com.hazelcast.config.CacheConfig in project hazelcast by hazelcast.
the class CacheClearTest method testInvalidationListenerCallCount.
@Test
public void testInvalidationListenerCallCount() {
final ICache<String, String> cache = createCache();
Map<String, String> entries = createAndFillEntries();
for (Map.Entry<String, String> entry : entries.entrySet()) {
cache.put(entry.getKey(), entry.getValue());
}
// Verify that put works
for (Map.Entry<String, String> entry : entries.entrySet()) {
String key = entry.getKey();
String expectedValue = entries.get(key);
String actualValue = cache.get(key);
assertEquals(expectedValue, actualValue);
}
final AtomicInteger counter = new AtomicInteger(0);
final CacheConfig config = cache.getConfiguration(CacheConfig.class);
registerInvalidationListener(new CacheEventListener() {
@Override
public void handleEvent(Object eventObject) {
if (eventObject instanceof Invalidation) {
Invalidation event = (Invalidation) eventObject;
if (null == event.getKey() && config.getNameWithPrefix().equals(event.getName())) {
counter.incrementAndGet();
}
}
}
}, config.getNameWithPrefix());
cache.clear();
// Make sure that one event is received
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(1, counter.get());
}
}, 5);
// Make sure that the callback is not called for a while
assertTrueAllTheTime(new AssertTask() {
@Override
public void run() throws Exception {
assertTrue(counter.get() <= 1);
}
}, 3);
}
use of com.hazelcast.config.CacheConfig in project hazelcast by hazelcast.
the class CacheDestroyTest method testInvalidationListenerCallCount.
@Test
public void testInvalidationListenerCallCount() {
final ICache<String, String> cache = createCache();
final AtomicInteger counter = new AtomicInteger(0);
final CacheConfig config = cache.getConfiguration(CacheConfig.class);
registerInvalidationListener(new CacheEventListener() {
@Override
public void handleEvent(Object eventObject) {
if (eventObject instanceof Invalidation) {
Invalidation event = (Invalidation) eventObject;
if (null == event.getKey() && config.getNameWithPrefix().equals(event.getName())) {
counter.incrementAndGet();
}
}
}
}, config.getNameWithPrefix());
cache.destroy();
// Make sure that at least 1 invalidation event has been received
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertTrue(counter.get() >= 1);
}
}, 2);
// Make sure that no more than INSTNACE_COUNT events are received ever
assertTrueAllTheTime(new AssertTask() {
@Override
public void run() throws Exception {
assertTrue(counter.get() <= INSTANCE_COUNT);
}
}, 3);
}
use of com.hazelcast.config.CacheConfig in project hazelcast by hazelcast.
the class CacheEvictionTest method setup.
@Before
public void setup() {
instance = createHazelcastInstance();
provider = HazelcastServerCachingProvider.createCachingProvider(instance);
CacheManager cacheManager = provider.getCacheManager();
String cacheName = randomString();
cache = cacheManager.createCache(cacheName, new CacheConfig());
}
use of com.hazelcast.config.CacheConfig in project hazelcast by hazelcast.
the class CacheFromDifferentNodesTest method testJSRExample1.
@Test
public void testJSRExample1() throws InterruptedException {
final String cacheName = randomString();
CacheManager cacheManager = cachingProvider1.getCacheManager();
assertNotNull(cacheManager);
assertNull(cacheManager.getCache(cacheName));
CacheConfig<Integer, String> config = new CacheConfig<Integer, String>();
Cache<Integer, String> cache = cacheManager.createCache(cacheName, config);
assertNotNull(cache);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
CacheManager cm2 = cachingProvider2.getCacheManager();
assertNotNull(cm2.getCache(cacheName));
}
});
Integer key = 1;
String value1 = "value";
cache.put(key, value1);
String value2 = cache.get(key);
assertEquals(value1, value2);
cache.remove(key);
assertNull(cache.get(key));
Cache<Integer, String> cache2 = cacheManager.getCache(cacheName);
assertNotNull(cache2);
key = 1;
value1 = "value";
cache.put(key, value1);
value2 = cache.get(key);
assertEquals(value1, value2);
cache.remove(key);
assertNull(cache.get(key));
cacheManager.destroyCache(cacheName);
cacheManager.close();
}
Aggregations