Search in sources :

Example 46 with PartitionIdSet

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

the class MapEntrySetTest method whenSelectingPartitionSubset_withIndex.

@Test
public void whenSelectingPartitionSubset_withIndex() {
    PartitionIdSet partitionSubset = new PartitionIdSet(4, asList(1, 3));
    Set<String> matchingKeys = new HashSet<>();
    map = instance.getMap("indexed");
    for (int i = 0; i < 5; i++) {
        String key = generateKeyForPartition(instance, i);
        map.put(key, key);
        if (partitionSubset.contains(i)) {
            matchingKeys.add(key);
        }
    }
    // "" is sorted before any non-null string - internally all items from all partitions are added
    // to the result (because the index is global), but there's a code that eliminates partitions not
    // in the subset - this test aims to test that code
    Predicate<String, String> predicate = Predicates.greaterThan("this", "");
    Set<Entry<String, String>> result = ((MapProxyImpl<String, String>) map).entrySet(predicate, partitionSubset);
    assertEquals(2, result.size());
    for (String key : matchingKeys) {
        assertResultContains(result, key, key);
    }
}
Also used : SimpleEntry(java.util.AbstractMap.SimpleEntry) Entry(java.util.Map.Entry) 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 47 with PartitionIdSet

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

the class QueryResultSizeLimiterTest method initMocksWithConfiguration.

private void initMocksWithConfiguration(int maxResultSizeLimit, int maxLocalPartitionLimitForPreCheck) {
    Config config = new Config();
    config.setProperty(QUERY_RESULT_SIZE_LIMIT.getName(), valueOf(maxResultSizeLimit));
    config.setProperty(QUERY_MAX_LOCAL_PARTITION_LIMIT_FOR_PRE_CHECK.getName(), valueOf(maxLocalPartitionLimitForPreCheck));
    config.setProperty(ClusterProperty.PARTITION_COUNT.getName(), valueOf(PARTITION_COUNT));
    HazelcastProperties hazelcastProperties = new HazelcastProperties(config);
    InternalPartitionService partitionService = mock(InternalPartitionService.class);
    when(partitionService.getPartitionCount()).thenReturn(PARTITION_COUNT);
    NodeEngine nodeEngine = mock(NodeEngine.class);
    when(nodeEngine.getProperties()).thenReturn(hazelcastProperties);
    when(nodeEngine.getPartitionService()).thenReturn(partitionService);
    RecordStore recordStore = mock(RecordStore.class);
    when(recordStore.size()).then(new RecordStoreAnswer(localPartitions.values()));
    MapServiceContext mapServiceContext = mock(MapServiceContext.class);
    when(mapServiceContext.getNodeEngine()).thenReturn(nodeEngine);
    when(mapServiceContext.getRecordStore(anyInt(), anyString())).thenReturn(recordStore);
    when(mapServiceContext.getOrInitCachedMemberPartitions()).thenReturn(new PartitionIdSet(PARTITION_COUNT, localPartitions.keySet()));
    limiter = new QueryResultSizeLimiter(mapServiceContext, Logger.getLogger(QueryResultSizeLimiterTest.class));
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) HazelcastProperties(com.hazelcast.spi.properties.HazelcastProperties) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) Config(com.hazelcast.config.Config) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) MapServiceContext(com.hazelcast.map.impl.MapServiceContext)

Example 48 with PartitionIdSet

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

the class MapFetchIndexOperationTest method whenSizeLimitIsSmall_thenFetchInMultipleCalls.

@Test
public void whenSizeLimitIsSmall_thenFetchInMultipleCalls() throws ExecutionException, InterruptedException {
    PartitionIdSet partitions = getLocalPartitions(instance);
    IndexIterationPointer[] pointers = new IndexIterationPointer[2];
    pointers[0] = IndexIterationPointer.create(30, true, 50, false, 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("person5", 43, "Dep2"), new Person("person1", 45, "Dep1"), new Person("person4", 45, "Dep2"), new Person("person9", 45, "Dep3")));
    // First pointer is not done yet
    assertEquals(2, result.getPointers().length);
    operation = operationProvider.createFetchIndexOperation(mapName, orderedIndexName, result.getPointers(), partitions, 5);
    result = operationService.createInvocationBuilder(MapService.SERVICE_NAME, operation, address).<MapFetchIndexOperationResult>invoke().get();
    assertResultSorted(result, Arrays.asList(new Person("person10", 45, "Dep4"), new Person("person11", 45, "Dep5"), new Person("person3", 60, "Dep1")));
    assertEquals(0, result.getPointers().length);
}
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 49 with PartitionIdSet

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

the class MapFetchIndexOperationTest method testRange.

@Test
public void testRange() throws ExecutionException, InterruptedException {
    PartitionIdSet partitions = getLocalPartitions(instance);
    IndexIterationPointer[] pointers = new IndexIterationPointer[1];
    pointers[0] = IndexIterationPointer.create(30, true, 60, false, false, null);
    MapOperationProvider operationProvider = getOperationProvider(map);
    MapOperation operation = operationProvider.createFetchIndexOperation(mapName, orderedIndexName, pointers, partitions, 7);
    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")));
}
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 50 with PartitionIdSet

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

the class MapFetchIndexOperationTest method testMultipleLookups.

@Test
public void testMultipleLookups() throws ExecutionException, InterruptedException {
    PartitionIdSet partitions = getLocalPartitions(instance);
    IndexIterationPointer[] pointers = new IndexIterationPointer[3];
    pointers[0] = IndexIterationPointer.create(30, true, 30, true, false, null);
    pointers[1] = IndexIterationPointer.create(39, true, 39, true, false, null);
    pointers[2] = IndexIterationPointer.create(45, true, 45, true, false, null);
    MapOperationProvider operationProvider = getOperationProvider(map);
    MapOperation operation = operationProvider.createFetchIndexOperation(mapName, hashIndexName, 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();
    assertResult(result, Arrays.asList(new Person("person2", 39, "Dep1"), 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")));
}
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)

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