Search in sources :

Example 6 with HazelcastCacheManager

use of com.hazelcast.cache.HazelcastCacheManager in project hazelcast by hazelcast.

the class InternalCacheRecordStoreTest method ownerStateShouldBeUpdatedAfterMigration.

/**
     * Test for issue: https://github.com/hazelcast/hazelcast/issues/6983
     */
@Test
public void ownerStateShouldBeUpdatedAfterMigration() throws Exception {
    HazelcastCacheManager hzCacheManager = (HazelcastCacheManager) cacheManager;
    HazelcastInstance instance1 = hzCacheManager.getHazelcastInstance();
    Node node1 = TestUtil.getNode(instance1);
    NodeEngineImpl nodeEngine1 = node1.getNodeEngine();
    InternalPartitionService partitionService1 = nodeEngine1.getPartitionService();
    int partitionCount = partitionService1.getPartitionCount();
    String cacheName = randomName();
    CacheConfig cacheConfig = new CacheConfig().setName(cacheName);
    Cache<String, String> cache = cacheManager.createCache(cacheName, cacheConfig);
    String fullCacheName = hzCacheManager.getCacheNameWithPrefix(cacheName);
    for (int i = 0; i < partitionCount; i++) {
        String key = generateKeyForPartition(instance1, i);
        cache.put(key, "Value");
    }
    for (int i = 0; i < partitionCount; i++) {
        verifyPrimaryState(node1, fullCacheName, i, true);
    }
    HazelcastInstance instance2 = getHazelcastInstance();
    Node node2 = TestUtil.getNode(instance2);
    warmUpPartitions(instance1, instance2);
    waitAllForSafeState(instance1, instance2);
    for (int i = 0; i < partitionCount; i++) {
        boolean ownedByNode1 = partitionService1.isPartitionOwner(i);
        if (ownedByNode1) {
            verifyPrimaryState(node1, fullCacheName, i, true);
            verifyPrimaryState(node2, fullCacheName, i, false);
        } else {
            verifyPrimaryState(node1, fullCacheName, i, false);
            verifyPrimaryState(node2, fullCacheName, i, true);
        }
    }
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) HazelcastCacheManager(com.hazelcast.cache.HazelcastCacheManager) HazelcastInstance(com.hazelcast.core.HazelcastInstance) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) Node(com.hazelcast.instance.Node) CacheConfig(com.hazelcast.config.CacheConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest) CacheFromDifferentNodesTest(com.hazelcast.cache.CacheFromDifferentNodesTest)

Aggregations

HazelcastCacheManager (com.hazelcast.cache.HazelcastCacheManager)6 QuickTest (com.hazelcast.test.annotation.QuickTest)6 Test (org.junit.Test)6 URI (java.net.URI)4 Properties (java.util.Properties)4 CacheFromDifferentNodesTest (com.hazelcast.cache.CacheFromDifferentNodesTest)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 Node (com.hazelcast.instance.Node)2 ParallelTest (com.hazelcast.test.annotation.ParallelTest)2 CacheConfig (com.hazelcast.config.CacheConfig)1 ExpiryPolicyFactoryConfig (com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig)1 DurationConfig (com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.DurationConfig)1 TimedExpiryPolicyFactoryConfig (com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig)1 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)1 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)1 MutableCacheEntryListenerConfiguration (javax.cache.configuration.MutableCacheEntryListenerConfiguration)1