Search in sources :

Example 36 with IndexConfig

use of com.hazelcast.config.IndexConfig in project hazelcast by hazelcast.

the class QueryAdvancedTest method testMapWithIndexAfterShutDown.

@Test
public void testMapWithIndexAfterShutDown() {
    Config config = getConfig();
    String mapName = "default";
    config.getMapConfig(mapName).addIndexConfig(new IndexConfig(IndexType.HASH, "typeName"));
    HazelcastInstance[] instances = createHazelcastInstanceFactory(3).newInstances(config);
    final IMap<Integer, ValueType> map = instances[0].getMap(mapName);
    final int sampleSize1 = 100;
    final int sampleSize2 = 30;
    int totalSize = sampleSize1 + sampleSize2;
    for (int i = 0; i < sampleSize1; i++) {
        map.put(i, new ValueType("type" + i));
    }
    for (int i = sampleSize1; i < totalSize; i++) {
        map.put(i, new ValueType("typex"));
    }
    Collection typexValues = map.values(Predicates.sql("typeName = typex"));
    assertEquals(sampleSize2, typexValues.size());
    instances[1].shutdown();
    assertEquals(totalSize, map.size());
    assertTrueEventually(() -> {
        final Collection values = map.values(Predicates.sql("typeName = typex"));
        assertEquals(sampleSize2, values.size());
    });
    instances[2].shutdown();
    assertEquals(totalSize, map.size());
    assertTrueEventually(() -> {
        final Collection values = map.values(Predicates.sql("typeName = typex"));
        assertEquals(sampleSize2, values.size());
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IndexConfig(com.hazelcast.config.IndexConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ValueType(com.hazelcast.query.SampleTestObjects.ValueType) Config(com.hazelcast.config.Config) IndexConfig(com.hazelcast.config.IndexConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Collection(java.util.Collection) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 37 with IndexConfig

use of com.hazelcast.config.IndexConfig in project hazelcast by hazelcast.

the class MapKeySetTest method setup.

@Before
public void setup() {
    Config config = regularInstanceConfig();
    config.setProperty(QueryEngineImpl.DISABLE_MIGRATION_FALLBACK.getName(), "true");
    config.getMapConfig("indexed").addIndexConfig(new IndexConfig(IndexType.SORTED, "this"));
    instance = createHazelcastInstance(config);
    map = instance.getMap(randomName());
    serializationService = getSerializationService(instance);
}
Also used : IndexConfig(com.hazelcast.config.IndexConfig) Config(com.hazelcast.config.Config) IndexConfig(com.hazelcast.config.IndexConfig) Before(org.junit.Before)

Example 38 with IndexConfig

use of com.hazelcast.config.IndexConfig in project hazelcast by hazelcast.

the class MapFetchIndexOperationTest method testMigration.

// This test has different requirements, therefore depends on local variables.
// Before and After actions are dismissed.
@Test
public void testMigration() {
    HazelcastInstance instance = new CustomTestInstanceFactory().newHazelcastInstance(config);
    PartitionIdSet partitions = getLocalPartitions(instance);
    List<Person> people = new ArrayList<>(Arrays.asList(new Person("person1", 45, null), new Person("person2", 39, null), new Person("person3", 60, null), new Person("person4", 45, null), new Person("person5", 43, null)));
    IMap<String, Person> map = instance.getMap(mapName);
    map.addIndex(new IndexConfig(IndexType.SORTED, "age").setName(orderedIndexName));
    insertIntoMap(map, people);
    IndexIterationPointer[] pointers = new IndexIterationPointer[1];
    pointers[0] = IndexIterationPointer.create(10, true, 100, true, false, null);
    MapOperationProvider operationProvider = getOperationProvider(map);
    MapOperation operation = operationProvider.createFetchIndexOperation(mapName, orderedIndexName, pointers, partitions, 10);
    Address address = instance.getCluster().getLocalMember().getAddress();
    OperationServiceImpl operationService = getOperationService(instance);
    try {
        InvocationFuture<MapFetchIndexOperationResult> future = operationService.createInvocationBuilder(MapService.SERVICE_NAME, operation, address).invoke();
        future.get();
    } catch (Exception e) {
        assertInstanceOf(MissingPartitionException.class, e.getCause());
    } finally {
        instance.shutdown();
    }
}
Also used : Address(com.hazelcast.cluster.Address) IndexIterationPointer(com.hazelcast.internal.iteration.IndexIterationPointer) ArrayList(java.util.ArrayList) MapFetchIndexOperationResult(com.hazelcast.map.impl.operation.MapFetchIndexOperation.MapFetchIndexOperationResult) MissingPartitionException(com.hazelcast.map.impl.operation.MapFetchIndexOperation.MissingPartitionException) ExecutionException(java.util.concurrent.ExecutionException) MissingPartitionException(com.hazelcast.map.impl.operation.MapFetchIndexOperation.MissingPartitionException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) IndexConfig(com.hazelcast.config.IndexConfig) PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) 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 39 with IndexConfig

use of com.hazelcast.config.IndexConfig in project hazelcast by hazelcast.

the class QueryBasicTest method testQueryPortableObjectWithIndex.

@Test
public void testQueryPortableObjectWithIndex() {
    String name = randomMapName();
    Config config = getConfig();
    config.addMapConfig(new MapConfig(name).addIndexConfig(new IndexConfig(IndexType.SORTED, "timestamp")));
    testQueryUsingPortableObject(config, name);
}
Also used : IndexConfig(com.hazelcast.config.IndexConfig) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) IndexConfig(com.hazelcast.config.IndexConfig) MapConfig(com.hazelcast.config.MapConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 40 with IndexConfig

use of com.hazelcast.config.IndexConfig in project hazelcast by hazelcast.

the class QueryBasicTest method testOptionalUnorderedIndexQuerying.

@Test
public void testOptionalUnorderedIndexQuerying() {
    String name = randomMapName();
    Config config = smallInstanceConfig();
    config.getMapConfig(name).addIndexConfig(new IndexConfig(IndexType.HASH, "attribute"));
    HazelcastInstance instance = createHazelcastInstance(config);
    IMap<Integer, ObjectWithOptional<Integer>> map = instance.getMap(name);
    for (int i = 0; i < 10; ++i) {
        map.put(i, new ObjectWithOptional<>(i % 2 == 0 ? i : null));
    }
    Set<Integer> result = map.keySet(Predicates.equal("attribute", null));
    assertEqualSets(result, 1, 3, 5, 7, 9);
    assertEquals(1, map.getLocalMapStats().getIndexedQueryCount());
    result = map.keySet(Predicates.notEqual("attribute", null));
    assertEqualSets(result, 0, 2, 4, 6, 8);
    assertEquals(1, map.getLocalMapStats().getIndexedQueryCount());
    result = map.keySet(Predicates.greaterThan("attribute", 4));
    assertEqualSets(result, 6, 8);
    assertEquals(2, map.getLocalMapStats().getIndexedQueryCount());
}
Also used : IndexConfig(com.hazelcast.config.IndexConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) IndexConfig(com.hazelcast.config.IndexConfig) ObjectWithOptional(com.hazelcast.query.SampleTestObjects.ObjectWithOptional) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

IndexConfig (com.hazelcast.config.IndexConfig)130 Test (org.junit.Test)49 QuickTest (com.hazelcast.test.annotation.QuickTest)45 Config (com.hazelcast.config.Config)42 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)38 MapConfig (com.hazelcast.config.MapConfig)34 HazelcastInstance (com.hazelcast.core.HazelcastInstance)29 ArrayList (java.util.ArrayList)16 Before (org.junit.Before)13 MapStoreConfig (com.hazelcast.config.MapStoreConfig)12 InternalIndex (com.hazelcast.query.impl.InternalIndex)12 AttributeConfig (com.hazelcast.config.AttributeConfig)9 MapContainer (com.hazelcast.map.impl.MapContainer)9 IndexRangeFilter (com.hazelcast.sql.impl.exec.scan.index.IndexRangeFilter)9 QueryCacheConfig (com.hazelcast.config.QueryCacheConfig)8 Node (org.w3c.dom.Node)8 EntryListenerConfig (com.hazelcast.config.EntryListenerConfig)7 IMap (com.hazelcast.map.IMap)7 Indexes (com.hazelcast.query.impl.Indexes)7 ExpressionEvalContext (com.hazelcast.sql.impl.expression.ExpressionEvalContext)7