Search in sources :

Example 6 with Partition

use of com.hazelcast.partition.Partition in project hazelcast by hazelcast.

the class SimpleMapTest method load.

private void load(ExecutorService es) throws InterruptedException {
    if (!load) {
        return;
    }
    final IMap<String, Object> map = instance.getMap(NAMESPACE);
    final Member thisMember = instance.getCluster().getLocalMember();
    List<String> lsOwnedEntries = new LinkedList<String>();
    for (int i = 0; i < entryCount; i++) {
        final String key = String.valueOf(i);
        Partition partition = instance.getPartitionService().getPartition(key);
        if (thisMember.equals(partition.getOwner())) {
            lsOwnedEntries.add(key);
        }
    }
    final CountDownLatch latch = new CountDownLatch(lsOwnedEntries.size());
    for (final String ownedKey : lsOwnedEntries) {
        es.execute(new Runnable() {

            public void run() {
                map.put(ownedKey, createValue());
                latch.countDown();
            }
        });
    }
    latch.await();
}
Also used : Partition(com.hazelcast.partition.Partition) CountDownLatch(java.util.concurrent.CountDownLatch) Member(com.hazelcast.cluster.Member) LinkedList(java.util.LinkedList)

Example 7 with Partition

use of com.hazelcast.partition.Partition in project hazelcast by hazelcast.

the class SimpleMultiMapTest method load.

private static void load(boolean load, ExecutorService es, final MultiMap<String, byte[]> map) {
    if (load) {
        final Member thisMember = instance.getCluster().getLocalMember();
        for (int i = 0; i < entryCount; i++) {
            final String key = String.valueOf(i);
            Partition partition = instance.getPartitionService().getPartition(key);
            if (thisMember.equals(partition.getOwner())) {
                es.execute(new Runnable() {

                    public void run() {
                        map.put(key, new byte[valueSize]);
                    }
                });
            }
        }
    }
}
Also used : Partition(com.hazelcast.partition.Partition) Member(com.hazelcast.cluster.Member)

Example 8 with Partition

use of com.hazelcast.partition.Partition in project hazelcast by hazelcast.

the class EvictionTest method getRecordStore.

private static RecordStore getRecordStore(HazelcastInstance instanceB, String keyOwnedByInstanceA) {
    Partition partition = instanceB.getPartitionService().getPartition(keyOwnedByInstanceA);
    MapService service = getNodeEngineImpl(instanceB).getService(MapService.SERVICE_NAME);
    return service.getMapServiceContext().getPartitionContainer(partition.getPartitionId()).getExistingRecordStore("Test");
}
Also used : Partition(com.hazelcast.partition.Partition) MapService(com.hazelcast.map.impl.MapService)

Example 9 with Partition

use of com.hazelcast.partition.Partition in project hazelcast by hazelcast.

the class IndexStatsChangingNumberOfMembersTest method toMemberToPartitionsMap.

private Map<UUID, PartitionIdSet> toMemberToPartitionsMap(HazelcastInstance instance1) {
    Map<UUID, PartitionIdSet> memberToPartitions = new HashMap<>();
    Set<Partition> partitions = instance1.getPartitionService().getPartitions();
    for (Partition partition : partitions) {
        UUID member = partition.getOwner().getUuid();
        memberToPartitions.computeIfAbsent(member, (key) -> new PartitionIdSet(partitions.size())).add(partition.getPartitionId());
    }
    return memberToPartitions;
}
Also used : ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Indexes(com.hazelcast.query.impl.Indexes) QuickTest(com.hazelcast.test.annotation.QuickTest) Partition(com.hazelcast.partition.Partition) RunWith(org.junit.runner.RunWith) InMemoryFormat(com.hazelcast.config.InMemoryFormat) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PerIndexStats(com.hazelcast.internal.monitor.impl.PerIndexStats) MapProxyImpl(com.hazelcast.map.impl.proxy.MapProxyImpl) IndexType(com.hazelcast.config.IndexType) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) LocalIndexStats(com.hazelcast.query.LocalIndexStats) Parameterized(org.junit.runners.Parameterized) UseParametersRunnerFactory(org.junit.runners.Parameterized.UseParametersRunnerFactory) Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) HazelcastParametrizedRunner(com.hazelcast.test.HazelcastParametrizedRunner) Assert.assertNotNull(org.junit.Assert.assertNotNull) HazelcastTestSupport(com.hazelcast.test.HazelcastTestSupport) Collection(java.util.Collection) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) HazelcastParallelParametersRunnerFactory(com.hazelcast.test.HazelcastParallelParametersRunnerFactory) Test(org.junit.Test) UUID(java.util.UUID) Category(org.junit.experimental.categories.Category) IndexConfig(com.hazelcast.config.IndexConfig) Accessors.getAllIndexes(com.hazelcast.test.Accessors.getAllIndexes) List(java.util.List) Predicates(com.hazelcast.query.Predicates) InternalIndex(com.hazelcast.query.impl.InternalIndex) PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) Assert.assertEquals(org.junit.Assert.assertEquals) Partition(com.hazelcast.partition.Partition) HashMap(java.util.HashMap) PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) UUID(java.util.UUID)

Example 10 with Partition

use of com.hazelcast.partition.Partition in project hazelcast by hazelcast.

the class HazelcastTestSupport method generateKeyForPartition.

public static String generateKeyForPartition(HazelcastInstance instance, int partitionId) {
    Cluster cluster = instance.getCluster();
    checkPartitionCountGreaterOrEqualMemberCount(instance);
    PartitionService partitionService = instance.getPartitionService();
    while (true) {
        String id = randomString();
        Partition partition = partitionService.getPartition(id);
        if (partition.getPartitionId() == partitionId) {
            return id;
        }
    }
}
Also used : IPartition(com.hazelcast.internal.partition.IPartition) Partition(com.hazelcast.partition.Partition) Cluster(com.hazelcast.cluster.Cluster) PartitionService(com.hazelcast.partition.PartitionService) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService)

Aggregations

Partition (com.hazelcast.partition.Partition)28 PartitionService (com.hazelcast.partition.PartitionService)13 Member (com.hazelcast.cluster.Member)12 Test (org.junit.Test)7 HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 QuickTest (com.hazelcast.test.annotation.QuickTest)6 IPartition (com.hazelcast.internal.partition.IPartition)5 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)5 UUID (java.util.UUID)5 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Cluster (com.hazelcast.cluster.Cluster)3 PartitionIdSet (com.hazelcast.internal.util.collection.PartitionIdSet)3 Entry (java.util.Map.Entry)3 Config (com.hazelcast.config.Config)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedList (java.util.LinkedList)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Assert.assertEquals (org.junit.Assert.assertEquals)2