Search in sources :

Example 26 with PartitionIdSet

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

the class MapFetchIndexOperationTest method testRangeComposite.

@Test
public void testRangeComposite() throws ExecutionException, InterruptedException {
    PartitionIdSet partitions = getLocalPartitions(instance);
    IndexIterationPointer[] pointers = new IndexIterationPointer[1];
    pointers[0] = IndexIterationPointer.create(new CompositeValue(new Comparable[] { 30, CompositeValue.NEGATIVE_INFINITY }), true, new CompositeValue(new Comparable[] { CompositeValue.POSITIVE_INFINITY, CompositeValue.POSITIVE_INFINITY }), true, false, null);
    MapOperationProvider operationProvider = getOperationProvider(map);
    MapOperation operation = operationProvider.createFetchIndexOperation(mapName, compositeOrderedIndexName, pointers, partitions, 10);
    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("person5", 43, "Dep2"), new Person("person1", 45, "Dep1"), new Person("person4", 45, "Dep2"), new Person("person9", 45, "Dep3"), new Person("person10", 45, "Dep4"), new Person("person11", 45, "Dep5"), new Person("person3", 60, "Dep1"), new Person("person8", 79, null)));
}
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) CompositeValue(com.hazelcast.query.impl.CompositeValue) 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 27 with PartitionIdSet

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

the class MapFetchIndexOperationTest method testOneSideRange.

@Test
public void testOneSideRange() throws ExecutionException, InterruptedException {
    PartitionIdSet partitions = getLocalPartitions(instance);
    IndexIterationPointer[] pointers = new IndexIterationPointer[1];
    pointers[0] = IndexIterationPointer.create(null, true, 60, false, true, null);
    MapOperationProvider operationProvider = getOperationProvider(map);
    MapOperation operation = operationProvider.createFetchIndexOperation(mapName, orderedIndexName, pointers, partitions, 10);
    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("person11", 45, "Dep5"), new Person("person10", 45, "Dep4"), new Person("person9", 45, "Dep3"), new Person("person4", 45, "Dep2"), new Person("person1", 45, "Dep1"), new Person("person5", 43, "Dep2"), new Person("person2", 39, "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 28 with PartitionIdSet

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

the class IndexStatsChangingNumberOfMembersTest method awaitStable.

protected void awaitStable(String mapName, HazelcastInstance... instances) {
    // Await for migrations to complete.
    waitAllForSafeState(instances);
    // Make sure that all indexes contain expected partitions.
    final Map<UUID, PartitionIdSet> memberToPartitions = toMemberToPartitionsMap(instances[0]);
    assertTrueEventually(() -> {
        for (HazelcastInstance instance : instances) {
            InternalIndex index = ((MapProxyImpl<?, ?>) instance.getMap(mapName)).getService().getMapServiceContext().getMapContainer(mapName).getIndexes().getIndex(INDEX_NAME);
            assertNotNull(index);
            PartitionIdSet expectedPartitions = memberToPartitions.get(instance.getCluster().getLocalMember().getUuid());
            // Double check: if we still see same partition distribution
            assertEquals(memberToPartitions, toMemberToPartitionsMap(instances[0]));
            assertEquals("MemberPartitions={size=" + expectedPartitions.size() + ", partitions=" + expectedPartitions + "}, " + index, expectedPartitions, index.getPartitionStamp().partitions);
        }
    });
}
Also used : InternalIndex(com.hazelcast.query.impl.InternalIndex) HazelcastInstance(com.hazelcast.core.HazelcastInstance) PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) MapProxyImpl(com.hazelcast.map.impl.proxy.MapProxyImpl) UUID(java.util.UUID)

Example 29 with PartitionIdSet

use of com.hazelcast.internal.util.collection.PartitionIdSet 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 30 with PartitionIdSet

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

the class MapProjectionTest method projection_1Node_objectValue_withPartitionSet.

@Test
public void projection_1Node_objectValue_withPartitionSet() {
    IMap<String, Person> map = getMapWithNodeCount(1);
    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