Search in sources :

Example 16 with InternalPartitionService

use of com.hazelcast.internal.partition.InternalPartitionService in project hazelcast by hazelcast.

the class AdvancedClusterStateTest method partitionAssignment_shouldFail_whenTriggered_inFrozenState.

@Test(expected = IllegalStateException.class)
public void partitionAssignment_shouldFail_whenTriggered_inFrozenState() {
    Config config = new Config();
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
    HazelcastInstance[] instances = factory.newInstances(config);
    HazelcastInstance hz1 = instances[0];
    HazelcastInstance hz2 = instances[1];
    HazelcastInstance hz3 = instances[2];
    hz2.getCluster().changeClusterState(ClusterState.FROZEN);
    InternalPartitionService partitionService = getPartitionService(hz1);
    partitionService.getPartitionOwnerOrWait(1);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) Config(com.hazelcast.config.Config) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 17 with InternalPartitionService

use of com.hazelcast.internal.partition.InternalPartitionService in project hazelcast by hazelcast.

the class MigrationCommitTest method getOwnedPartition.

private InternalPartition getOwnedPartition(HazelcastInstance instance) {
    InternalPartitionService partitionService = getPartitionService(instance);
    Address address = getAddress(instance);
    if (address.equals(partitionService.getPartitionOwner(0))) {
        return partitionService.getPartition(0);
    } else if (address.equals(partitionService.getPartitionOwner(1))) {
        return partitionService.getPartition(1);
    }
    return null;
}
Also used : Address(com.hazelcast.nio.Address) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService)

Example 18 with InternalPartitionService

use of com.hazelcast.internal.partition.InternalPartitionService in project hazelcast by hazelcast.

the class MigrationCommitServiceTest method setup.

@Before
public void setup() throws Exception {
    blockMigrationStartLatch = new CountDownLatch(1);
    factory = createHazelcastInstanceFactory(NODE_COUNT);
    instances = factory.newInstances(createConfig(), NODE_COUNT);
    warmUpPartitions(instances);
    waitAllForSafeState(instances);
    InternalOperationService operationService = getOperationService(instances[0]);
    for (int partitionId = 0; partitionId < PARTITION_COUNT; partitionId++) {
        operationService.invokeOnPartition(null, new TestIncrementOperation(), partitionId).get();
    }
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            for (int partitionId = 0; partitionId < PARTITION_COUNT; partitionId++) {
                InternalPartitionService partitionService = getPartitionService(instances[0]);
                InternalPartition partition = partitionService.getPartition(partitionId);
                for (int i = 0; i <= BACKUP_COUNT; i++) {
                    Address replicaAddress = partition.getReplicaAddress(i);
                    if (replicaAddress != null) {
                        TestMigrationAwareService service = getService(replicaAddress);
                        assertNotNull(service.get(partitionId));
                    }
                }
            }
        }
    });
    for (HazelcastInstance instance : instances) {
        TestMigrationAwareService service = getNodeEngineImpl(instance).getService(TestMigrationAwareService.SERVICE_NAME);
        service.clearEvents();
    }
}
Also used : TestMigrationAwareService(com.hazelcast.internal.partition.service.TestMigrationAwareService) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.nio.Address) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) AssertTask(com.hazelcast.test.AssertTask) TestIncrementOperation(com.hazelcast.internal.partition.service.TestIncrementOperation) InternalOperationService(com.hazelcast.spi.impl.operationservice.InternalOperationService) InternalPartition(com.hazelcast.internal.partition.InternalPartition) CountDownLatch(java.util.concurrent.CountDownLatch) ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) Before(org.junit.Before)

Example 19 with InternalPartitionService

use of com.hazelcast.internal.partition.InternalPartitionService in project hazelcast by hazelcast.

the class LocalMapStatsTest method testHits_whenMultipleNodes.

@Test
public void testHits_whenMultipleNodes() throws InterruptedException {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    final HazelcastInstance[] instances = factory.newInstances(getConfig());
    MultiMap<Object, Object> multiMap0 = instances[0].getMultiMap("testHits_whenMultipleNodes");
    MultiMap<Object, Object> multiMap1 = instances[1].getMultiMap("testHits_whenMultipleNodes");
    // InternalPartitionService is used in order to determine owners of these keys that we will use.
    InternalPartitionService partitionService = getNode(instances[0]).getPartitionService();
    Address address = partitionService.getPartitionOwner(partitionService.getPartitionId("test1"));
    boolean inFirstInstance = address.equals(getNode(instances[0]).getThisAddress());
    multiMap0.get("test0");
    multiMap0.put("test1", 1);
    multiMap1.get("test1");
    assertEquals(inFirstInstance ? 1 : 0, multiMap0.getLocalMultiMapStats().getHits());
    assertEquals(inFirstInstance ? 0 : 1, multiMap1.getLocalMultiMapStats().getHits());
    multiMap0.get("test1");
    multiMap1.get("test1");
    assertEquals(inFirstInstance ? 0 : 3, multiMap1.getLocalMultiMapStats().getHits());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.nio.Address) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 20 with InternalPartitionService

use of com.hazelcast.internal.partition.InternalPartitionService in project hazelcast by hazelcast.

the class NearCacheTest method testGetAll.

@Test
public void testGetAll() {
    int mapSize = 1000;
    String mapName = "testGetAllWithNearCache";
    Config config = getConfig();
    NearCacheConfig nearCacheConfig = newNearCacheConfig();
    nearCacheConfig.setInvalidateOnChange(false);
    config.getMapConfig(mapName).setNearCacheConfig(nearCacheConfig);
    TestHazelcastInstanceFactory hazelcastInstanceFactory = createHazelcastInstanceFactory(2);
    HazelcastInstance[] instances = hazelcastInstanceFactory.newInstances(config);
    warmUpPartitions(instances);
    HazelcastInstance hazelcastInstance = instances[0];
    InternalPartitionService partitionService = getPartitionService(hazelcastInstance);
    // populate map
    IMap<Integer, Integer> map = hazelcastInstance.getMap(mapName);
    populateMap(map, mapSize);
    Set<Integer> keys = map.keySet();
    // populate Near Cache
    int expectedHits = 0;
    for (int i = 0; i < mapSize; i++) {
        map.get(i);
        int partitionId = partitionService.getPartitionId(i);
        if (!partitionService.isPartitionOwner(partitionId)) {
            // map proxy stores non-owned entries (belong to partition which its not owner) inside its Near Cache
            expectedHits++;
        }
    }
    // generate Near Cache hits
    Map<Integer, Integer> allEntries = map.getAll(keys);
    for (int i = 0; i < mapSize; i++) {
        assertEquals(i, (int) allEntries.get(i));
    }
    // check Near Cache hits
    long hits = getNearCacheStats(map).getHits();
    assertEquals(format("Near Cache hits should be %d but were %d", expectedHits, hits), expectedHits, hits);
}
Also used : InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) MapConfig(com.hazelcast.config.MapConfig) EvictionConfig(com.hazelcast.config.EvictionConfig) Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)45 Address (com.hazelcast.nio.Address)11 HazelcastInstance (com.hazelcast.core.HazelcastInstance)10 Test (org.junit.Test)10 Node (com.hazelcast.instance.Node)9 ParallelTest (com.hazelcast.test.annotation.ParallelTest)9 QuickTest (com.hazelcast.test.annotation.QuickTest)9 ArrayList (java.util.ArrayList)8 Config (com.hazelcast.config.Config)6 Data (com.hazelcast.nio.serialization.Data)6 IPartition (com.hazelcast.spi.partition.IPartition)6 HashMap (java.util.HashMap)6 InternalPartition (com.hazelcast.internal.partition.InternalPartition)5 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)5 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)5 List (java.util.List)5 Map (java.util.Map)5 ICacheService (com.hazelcast.cache.impl.ICacheService)4 ICacheRecordStore (com.hazelcast.cache.impl.ICacheRecordStore)3 CacheConfig (com.hazelcast.config.CacheConfig)3