@Override protected OperationFactory createOperationFactory() { CacheOperationProvider operationProvider = getOperationProvider(parameters.name); CacheService service = getService(getServiceName()); ExpiryPolicy expiryPolicy = (ExpiryPolicy) service.toObject(parameters.expiryPolicy); return operationProvider.createGetAllOperationFactory( (Set<Data>) parameters.keys, expiryPolicy); }
@Override public void beforeRun() throws Exception { // //migrate CacheConfigs first CacheService service = getService(); for (CacheConfig config : configs) { service.createCacheConfigIfAbsent(config); } }
@Test public void test_CacheReplicationOperation_serialization() throws Exception { TestHazelcastInstanceFactory factory = new TestHazelcastInstanceFactory(1); HazelcastInstance hazelcastInstance = factory.newHazelcastInstance(); try { CachingProvider provider = HazelcastServerCachingProvider.createCachingProvider(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); CacheReplicationOperation operation = new CacheReplicationOperation(segment, 1); Data serialized = service.toData(operation); try { service.toObject(serialized); } catch (Exception e) { throw new Exception("Partition: " + partitionId, e); } } } finally { factory.shutdownAll(); } }
@Override public void run() throws Exception { CacheService service = getService(); for (Map.Entry<String, Map<Data, CacheRecord>> entry : data.entrySet()) { ICacheRecordStore cache = service.getOrCreateCache(entry.getKey(), getPartitionId()); Map<Data, CacheRecord> map = entry.getValue(); Iterator<Map.Entry<Data, CacheRecord>> iter = map.entrySet().iterator(); while (iter.hasNext()) { Map.Entry<Data, CacheRecord> next = iter.next(); Data key = next.getKey(); CacheRecord record = next.getValue(); iter.remove(); cache.setRecord(key, record); } } data.clear(); }
private ICacheRecordStore getRecordStore( CacheService cacheService, String cacheName, int partitionId) { try { return cacheService.getOrCreateRecordStore("/hz/" + cacheName, partitionId); } catch (Exception e) { fail("CacheRecordStore not yet initialized!!!"); } return null; }