Search in sources :

Example 51 with PartitionIdSet

use of com.hazelcast.internal.util.collection.PartitionIdSet in project hazelcast by hazelcast.

the class MapFetchIndexOperationTest method testMultipleRanges.

@Test
public void testMultipleRanges() throws ExecutionException, InterruptedException {
    PartitionIdSet partitions = getLocalPartitions(instance);
    IndexIterationPointer[] pointers = new IndexIterationPointer[2];
    pointers[0] = IndexIterationPointer.create(30, true, 40, true, false, null);
    pointers[1] = IndexIterationPointer.create(50, true, 60, true, false, null);
    MapOperationProvider operationProvider = getOperationProvider(map);
    MapOperation operation = operationProvider.createFetchIndexOperation(mapName, orderedIndexName, pointers, partitions, 5);
    Address address = instance.getCluster().getLocalMember().getAddress();
    OperationServiceImpl operationService = getOperationService(instance);
    MapFetchIndexOperationResult result = operationService.createInvocationBuilder(MapService.SERVICE_NAME, operation, address).<MapFetchIndexOperationResult>invoke().get();
    assertResultSorted(result, Arrays.asList(new Person("person2", 39, "Dep1"), new Person("person3", 60, "Dep1")));
}
Also used : Address(com.hazelcast.cluster.Address) IndexIterationPointer(com.hazelcast.internal.iteration.IndexIterationPointer) PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) MapFetchIndexOperationResult(com.hazelcast.map.impl.operation.MapFetchIndexOperation.MapFetchIndexOperationResult) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 52 with PartitionIdSet

use of com.hazelcast.internal.util.collection.PartitionIdSet in project hazelcast by hazelcast.

the class MapKeySetTest method whenSelectingPartitionSubset.

@Test
public void whenSelectingPartitionSubset() {
    PartitionIdSet partitionSubset = new PartitionIdSet(4, asList(1, 3));
    Set<String> matchingKeys = new HashSet<>();
    for (int i = 0; i < 5; i++) {
        String key = generateKeyForPartition(instance, i);
        map.put(key, key);
        if (partitionSubset.contains(i)) {
            matchingKeys.add(key);
        }
    }
    Set<String> result = ((MapProxyImpl<String, String>) map).keySet(Predicates.alwaysTrue(), partitionSubset);
    assertEquals(matchingKeys, result);
}
Also used : PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) MapProxyImpl(com.hazelcast.map.impl.proxy.MapProxyImpl) HashSet(java.util.HashSet) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 53 with PartitionIdSet

use of com.hazelcast.internal.util.collection.PartitionIdSet in project hazelcast by hazelcast.

the class MapKeySetTest method when_selectingPartitionSubset_and_partitionPredicate.

@Test
public void when_selectingPartitionSubset_and_partitionPredicate() {
    PartitionIdSet partitionSubset = new PartitionIdSet(4, asList(1, 3));
    Set<String> matchingKeys = new HashSet<>();
    String key1 = null;
    for (int i = 0; i < 5; i++) {
        String key = generateKeyForPartition(instance, i);
        if (i == 1) {
            key1 = key;
        }
        map.put(key, key);
        if (partitionSubset.contains(i)) {
            matchingKeys.add(key);
        }
    }
    Set<String> result = ((MapProxyImpl<String, String>) map).keySet(partitionPredicate(key1, Predicates.alwaysTrue()), partitionSubset);
    assertEquals(Collections.singleton(key1), result);
}
Also used : PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) MapProxyImpl(com.hazelcast.map.impl.proxy.MapProxyImpl) HashSet(java.util.HashSet) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 54 with PartitionIdSet

use of com.hazelcast.internal.util.collection.PartitionIdSet in project hazelcast by hazelcast.

the class MapFetchIndexOperationTest method getLocalPartitions.

private static PartitionIdSet getLocalPartitions(HazelcastInstance member) {
    PartitionService partitionService = member.getPartitionService();
    PartitionIdSet res = new PartitionIdSet(partitionService.getPartitions().size());
    for (Partition partition : partitionService.getPartitions()) {
        if (partition.getOwner().localMember()) {
            res.add(partition.getPartitionId());
        }
    }
    return res;
}
Also used : Partition(com.hazelcast.partition.Partition) PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) PartitionService(com.hazelcast.partition.PartitionService)

Example 55 with PartitionIdSet

use of com.hazelcast.internal.util.collection.PartitionIdSet in project hazelcast by hazelcast.

the class MapProjectionTest method projection_3Nodes_objectValue_withPartitionSet.

@Test
public void projection_3Nodes_objectValue_withPartitionSet() {
    IMap<String, Person> map = getMapWithNodeCount(3);
    populateMapWithPersons(map);
    PartitionIdSet partitionSubset = new PartitionIdSet(3, asList(0, 1));
    Collection<Double> result = ((MapProxyImpl<String, Person>) map).project(new ObjectValueIncrementingProjection(), Predicates.alwaysTrue(), partitionSubset);
    assertThat(result, containsInAnyOrder(2.0d, 5.0d));
}
Also used : PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) MapProxyImpl(com.hazelcast.map.impl.proxy.MapProxyImpl) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

PartitionIdSet (com.hazelcast.internal.util.collection.PartitionIdSet)55 QuickTest (com.hazelcast.test.annotation.QuickTest)24 Test (org.junit.Test)24 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)23 MapProxyImpl (com.hazelcast.map.impl.proxy.MapProxyImpl)13 Address (com.hazelcast.cluster.Address)12 IndexIterationPointer (com.hazelcast.internal.iteration.IndexIterationPointer)11 OperationServiceImpl (com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl)11 MapFetchIndexOperationResult (com.hazelcast.map.impl.operation.MapFetchIndexOperation.MapFetchIndexOperationResult)10 HashSet (java.util.HashSet)10 Predicate (com.hazelcast.query.Predicate)7 ArrayList (java.util.ArrayList)7 Data (com.hazelcast.internal.serialization.Data)5 UUID (java.util.UUID)5 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 IPartitionService (com.hazelcast.internal.partition.IPartitionService)4 Indexes (com.hazelcast.query.impl.Indexes)4 List (java.util.List)4 SetUtil.singletonPartitionIdSet (com.hazelcast.internal.util.SetUtil.singletonPartitionIdSet)3 QueryResultSizeExceededException (com.hazelcast.map.QueryResultSizeExceededException)3