Search in sources :

Example 66 with IndexConfig

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

the class HazelcastSessionConfiguration method hazelcastInstance.

/**
 * Hazelcast instance that is used by the spring session
 * repository to broadcast session events. The name
 * of this bean must be left untouched.
 *
 * @param casProperties              the cas properties
 * @param hazelcastSessionProperties the hazelcast session properties
 * @param sessionProperties          the session properties
 * @param serverProperties           the server properties
 * @return the hazelcast instance
 */
@Bean(destroyMethod = "shutdown")
@RefreshScope(proxyMode = ScopedProxyMode.DEFAULT)
public HazelcastInstance hazelcastInstance(final CasConfigurationProperties casProperties, final HazelcastSessionProperties hazelcastSessionProperties, final SessionProperties sessionProperties, final ServerProperties serverProperties) {
    val hz = casProperties.getWebflow().getSession().getHazelcast();
    val config = HazelcastConfigurationFactory.build(hz);
    val serializerConfig = new SerializerConfig();
    serializerConfig.setImplementation(new HazelcastSessionSerializer()).setTypeClass(MapSession.class);
    config.getSerializationConfig().addSerializerConfig(serializerConfig);
    val duration = (Duration) ObjectUtils.defaultIfNull(sessionProperties.getTimeout(), serverProperties.getServlet().getSession().getTimeout());
    val hazelcastInstance = HazelcastInstanceFactory.getOrCreateHazelcastInstance(config);
    val mapConfig = HazelcastConfigurationFactory.buildMapConfig(hz, hazelcastSessionProperties.getMapName(), duration.toSeconds());
    if (mapConfig instanceof MapConfig) {
        val finalConfig = (MapConfig) mapConfig;
        val attributeConfig = new AttributeConfig();
        attributeConfig.setName(Hazelcast4IndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE);
        attributeConfig.setExtractorClassName(HazelcastSessionPrincipalNameExtractor.class.getName());
        finalConfig.addAttributeConfig(attributeConfig);
        val indexConfig = new IndexConfig();
        indexConfig.addAttribute(Hazelcast4IndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE);
        finalConfig.addIndexConfig(indexConfig);
    }
    HazelcastConfigurationFactory.setConfigMap(mapConfig, hazelcastInstance.getConfig());
    return hazelcastInstance;
}
Also used : lombok.val(lombok.val) SerializerConfig(com.hazelcast.config.SerializerConfig) IndexConfig(com.hazelcast.config.IndexConfig) Duration(java.time.Duration) MapConfig(com.hazelcast.config.MapConfig) HazelcastSessionSerializer(org.springframework.session.hazelcast.HazelcastSessionSerializer) AttributeConfig(com.hazelcast.config.AttributeConfig) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) Bean(org.springframework.context.annotation.Bean)

Example 67 with IndexConfig

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

the class SqlIndexCastTest method before.

@Before
public void before() {
    IndexConfig indexConfig = new IndexConfig().setName("index").setType(IndexType.HASH).addAttribute("field1");
    instance().getMap(MAP_NAME).addIndex(indexConfig);
}
Also used : IndexConfig(com.hazelcast.config.IndexConfig) Before(org.junit.Before)

Example 68 with IndexConfig

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

the class MapIndexScanPTest method test_pointLookup_hashed.

// We also don't test full hash index scan, because such plan aren't allowed to be created.
@Test
public void test_pointLookup_hashed() {
    List<JetSqlRow> expected = new ArrayList<>();
    for (int i = count; i > 0; i--) {
        map.put(i, new Person("value-" + i, i));
    }
    expected.add(jetRow((5), "value-5", 5));
    IndexConfig indexConfig = new IndexConfig(IndexType.HASH, "age").setName(randomName());
    map.addIndex(indexConfig);
    IndexFilter filter = new IndexEqualsFilter(intValue(5));
    MapIndexScanMetadata metadata = metadata(indexConfig.getName(), filter, -1, false);
    TestSupport.verifyProcessor(adaptSupplier(MapIndexScanP.readMapIndexSupplier(metadata))).hazelcastInstance(instance()).jobConfig(new JobConfig().setArgument(SQL_ARGUMENTS_KEY_NAME, emptyList())).outputChecker(LENIENT_SAME_ITEMS_IN_ORDER).disableSnapshots().disableProgressAssertion().expectOutput(expected);
}
Also used : IndexEqualsFilter(com.hazelcast.sql.impl.exec.scan.index.IndexEqualsFilter) IndexConfig(com.hazelcast.config.IndexConfig) ArrayList(java.util.ArrayList) MapIndexScanMetadata(com.hazelcast.sql.impl.exec.scan.MapIndexScanMetadata) JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow) IndexFilter(com.hazelcast.sql.impl.exec.scan.index.IndexFilter) JobConfig(com.hazelcast.jet.config.JobConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 69 with IndexConfig

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

the class MapIndexScanPTest method test_whenFilterExistsWithoutSpecificProjection_sorted.

@Test
public void test_whenFilterExistsWithoutSpecificProjection_sorted() {
    List<JetSqlRow> expected = new ArrayList<>();
    for (int i = count; i > 0; i--) {
        map.put(i, new Person("value-" + i, i));
        if (i > count / 2) {
            expected.add(jetRow((count - i + 1), "value-" + (count - i + 1), (count - i + 1)));
        }
    }
    IndexConfig indexConfig = new IndexConfig(IndexType.SORTED, "age").setName(randomName());
    map.addIndex(indexConfig);
    IndexFilter filter = new IndexRangeFilter(intValue(0), true, intValue(count / 2), true);
    MapIndexScanMetadata metadata = metadata(indexConfig.getName(), filter, 2, false);
    TestSupport.verifyProcessor(adaptSupplier(MapIndexScanP.readMapIndexSupplier(metadata))).hazelcastInstance(instance()).jobConfig(new JobConfig().setArgument(SQL_ARGUMENTS_KEY_NAME, emptyList())).outputChecker(LENIENT_SAME_ITEMS_IN_ORDER).disableSnapshots().disableProgressAssertion().expectOutput(expected);
}
Also used : IndexRangeFilter(com.hazelcast.sql.impl.exec.scan.index.IndexRangeFilter) IndexConfig(com.hazelcast.config.IndexConfig) ArrayList(java.util.ArrayList) MapIndexScanMetadata(com.hazelcast.sql.impl.exec.scan.MapIndexScanMetadata) JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow) IndexFilter(com.hazelcast.sql.impl.exec.scan.index.IndexFilter) JobConfig(com.hazelcast.jet.config.JobConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 70 with IndexConfig

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

the class SqlNoSerializationTest method before.

@Before
public void before() {
    Map<Key, Value> localMap = new HashMap<>();
    for (int i = 0; i < KEY_COUNT; i++) {
        localMap.put(new Key(i), new Value(i));
    }
    createMapping(MAP_NAME, Key.class, Value.class);
    IMap<Key, Value> map = instance().getMap(MAP_NAME);
    map.putAll(localMap);
    // An index may change the behavior due to MapContainer.isUseCachedDeserializedValuesEnabled.
    if (useIndex) {
        map.addIndex(new IndexConfig(IndexType.HASH, "val"));
    }
    failOnSerialization = true;
}
Also used : IndexConfig(com.hazelcast.config.IndexConfig) HashMap(java.util.HashMap) Before(org.junit.Before)

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