use of com.hazelcast.cache.impl.CachePartitionSegment in project hazelcast by hazelcast.
the class CacheReplicationOperationTest method sendsConfigObjectOverWire.
@Test
public void sendsConfigObjectOverWire() throws Exception {
// new config
CacheConfig config = new CacheConfig("test-cache");
// add config to cache service
NodeEngineImpl nodeEngineImpl = getNodeEngineImpl(createHazelcastInstance());
CacheService cacheService = nodeEngineImpl.getService(CacheService.SERVICE_NAME);
cacheService.putCacheConfigIfAbsent(config);
CachePartitionSegment segment = new CachePartitionSegment(cacheService, 0);
segment.getOrCreateRecordStore(config.getNameWithPrefix());
Collection<ServiceNamespace> namespaces = segment.getAllNamespaces(0);
assertEquals(1, namespaces.size());
// create operation
CacheReplicationOperation operation = new CacheReplicationOperation();
operation.prepare(segment, namespaces, 0);
// serialize & deserialize operation
Data data = nodeEngineImpl.toData(operation);
CacheReplicationOperation cacheReplicationOperation = (CacheReplicationOperation) nodeEngineImpl.toObject(data);
// new operation instance should have previously added config.
assertContains(cacheReplicationOperation.getConfigs(), config);
}
use of com.hazelcast.cache.impl.CachePartitionSegment in project hazelcast by hazelcast.
the class CacheClearExpiredOperation method run.
@Override
public void run() throws Exception {
if (getNodeEngine().getLocalMember().isLiteMember()) {
// when converting a data-member to lite-member during merge operations.
return;
}
if (!isOwner()) {
return;
}
CacheService service = getService();
CachePartitionSegment segment = service.getSegment(getPartitionId());
Iterator<ICacheRecordStore> iterator = segment.recordStoreIterator();
while (iterator.hasNext()) {
ICacheRecordStore store = iterator.next();
if (store.size() > 0) {
store.evictExpiredEntries(expirationPercentage);
}
}
}
use of com.hazelcast.cache.impl.CachePartitionSegment in project hazelcast by hazelcast.
the class CacheClearExpiredOperation method prepareForNextCleanup.
protected void prepareForNextCleanup() {
CacheService service = getService();
CachePartitionSegment segment = service.getSegment(getPartitionId());
segment.setRunningCleanupOperation(false);
segment.setLastCleanupTime(Clock.currentTimeMillis());
}
use of com.hazelcast.cache.impl.CachePartitionSegment in project hazelcast by hazelcast.
the class CacheSerializationTest method test_CacheReplicationOperation_serialization.
@Test
public void test_CacheReplicationOperation_serialization() throws Exception {
TestHazelcastInstanceFactory factory = new TestHazelcastInstanceFactory(1);
HazelcastInstance hazelcastInstance = factory.newHazelcastInstance();
try {
CachingProvider provider = createServerCachingProvider(hazelcastInstance);
CacheManager manager = provider.getCacheManager();
CompleteConfiguration configuration = new MutableConfiguration();
Cache cache1 = manager.createCache("cache1", configuration);
Cache cache2 = manager.createCache("cache2", configuration);
Cache cache3 = manager.createCache("cache3", configuration);
for (int i = 0; i < 1000; i++) {
cache1.put("key" + i, i);
cache2.put("key" + i, i);
cache3.put("key" + i, i);
}
HazelcastInstanceProxy proxy = (HazelcastInstanceProxy) hazelcastInstance;
Field original = HazelcastInstanceProxy.class.getDeclaredField("original");
original.setAccessible(true);
HazelcastInstanceImpl impl = (HazelcastInstanceImpl) original.get(proxy);
NodeEngineImpl nodeEngine = impl.node.nodeEngine;
CacheService cacheService = nodeEngine.getService(CacheService.SERVICE_NAME);
int partitionCount = nodeEngine.getPartitionService().getPartitionCount();
for (int partitionId = 0; partitionId < partitionCount; partitionId++) {
CachePartitionSegment segment = cacheService.getSegment(partitionId);
int replicaIndex = 1;
Collection<ServiceNamespace> namespaces = segment.getAllNamespaces(replicaIndex);
if (CollectionUtil.isEmpty(namespaces)) {
continue;
}
CacheReplicationOperation operation = new CacheReplicationOperation();
operation.prepare(segment, namespaces, replicaIndex);
Data serialized = service.toData(operation);
try {
service.toObject(serialized);
} catch (Exception e) {
throw new Exception("Partition: " + partitionId, e);
}
}
} finally {
factory.shutdownAll();
}
}
Aggregations