Search in sources :

Example 21 with CacheService

use of com.hazelcast.cache.impl.CacheService 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 = 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();
    }
}
Also used : HazelcastInstanceImpl(com.hazelcast.instance.HazelcastInstanceImpl) NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) CachePartitionSegment(com.hazelcast.cache.impl.CachePartitionSegment) CacheReplicationOperation(com.hazelcast.cache.impl.operation.CacheReplicationOperation) Data(com.hazelcast.nio.serialization.Data) CachePartitionEventData(com.hazelcast.cache.impl.CachePartitionEventData) HazelcastInstanceProxy(com.hazelcast.instance.HazelcastInstanceProxy) MutableConfiguration(javax.cache.configuration.MutableConfiguration) UnknownHostException(java.net.UnknownHostException) Field(java.lang.reflect.Field) HazelcastInstance(com.hazelcast.core.HazelcastInstance) CompleteConfiguration(javax.cache.configuration.CompleteConfiguration) CacheManager(javax.cache.CacheManager) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) Cache(javax.cache.Cache) CacheService(com.hazelcast.cache.impl.CacheService) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

CacheService (com.hazelcast.cache.impl.CacheService)21 CacheEventHandler (com.hazelcast.cache.impl.CacheEventHandler)6 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)6 HazelcastServerCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider)5 MetaDataGenerator (com.hazelcast.internal.nearcache.impl.invalidation.MetaDataGenerator)5 ParallelTest (com.hazelcast.test.annotation.ParallelTest)5 QuickTest (com.hazelcast.test.annotation.QuickTest)5 CacheManager (javax.cache.CacheManager)5 Test (org.junit.Test)5 ClientEndpoint (com.hazelcast.client.ClientEndpoint)4 CacheConfig (com.hazelcast.config.CacheConfig)4 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 Data (com.hazelcast.nio.serialization.Data)4 CachingProvider (javax.cache.spi.CachingProvider)4 CacheContext (com.hazelcast.cache.impl.CacheContext)3 ICacheService (com.hazelcast.cache.impl.ICacheService)3 IPartitionLostEvent (com.hazelcast.spi.partition.IPartitionLostEvent)3 ICache (com.hazelcast.cache.ICache)2 CacheOperationProvider (com.hazelcast.cache.impl.CacheOperationProvider)2 CachePartitionSegment (com.hazelcast.cache.impl.CachePartitionSegment)2