Search in sources :

Example 1 with IndexConfig

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

the class ExternalizableDeserializationProtectionTest method testExternalizableProtectedOnMember.

@Test
public void testExternalizableProtectedOnMember() {
    JavaSerializationFilterConfig javaSerializationFilterConfig = new JavaSerializationFilterConfig().setDefaultsDisabled(true);
    javaSerializationFilterConfig.getBlacklist().addClasses(TestExternalizableDeserialized.class.getName());
    Config config = smallInstanceConfig();
    config.getSerializationConfig().setJavaSerializationFilterConfig(javaSerializationFilterConfig);
    // the index will force deserialization
    config.getMapConfig("test").addIndexConfig(new IndexConfig(IndexType.HASH, "name"));
    hazelcastFactory.newHazelcastInstance(config);
    HazelcastInstance client = hazelcastFactory.newHazelcastClient();
    expected.expect(HazelcastSerializationException.class);
    client.getMap("test").put("key", new TestExternalizableDeserialized());
}
Also used : TestExternalizableDeserialized(example.serialization.TestExternalizableDeserialized) IndexConfig(com.hazelcast.config.IndexConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) IndexConfig(com.hazelcast.config.IndexConfig) JavaSerializationFilterConfig(com.hazelcast.config.JavaSerializationFilterConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) JavaSerializationFilterConfig(com.hazelcast.config.JavaSerializationFilterConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with IndexConfig

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

the class TestClientApplicationContext method testFullQueryCacheConfig.

@Test
public void testFullQueryCacheConfig() throws Exception {
    ClientConfig config = client6.getClientConfig();
    QueryCacheConfig queryCacheConfig = getQueryCacheConfig(config);
    EntryListenerConfig entryListenerConfig = queryCacheConfig.getEntryListenerConfigs().get(0);
    assertTrue(entryListenerConfig.isIncludeValue());
    assertFalse(entryListenerConfig.isLocal());
    assertEquals("com.hazelcast.spring.DummyEntryListener", entryListenerConfig.getClassName());
    assertFalse(queryCacheConfig.isIncludeValue());
    assertEquals("my-query-cache-1", queryCacheConfig.getName());
    assertEquals(12, queryCacheConfig.getBatchSize());
    assertEquals(33, queryCacheConfig.getBufferSize());
    assertEquals(12, queryCacheConfig.getDelaySeconds());
    assertEquals(InMemoryFormat.OBJECT, queryCacheConfig.getInMemoryFormat());
    assertTrue(queryCacheConfig.isCoalesce());
    assertFalse(queryCacheConfig.isPopulate());
    assertEquals("__key > 12", queryCacheConfig.getPredicateConfig().getSql());
    assertEquals(EvictionPolicy.LRU, queryCacheConfig.getEvictionConfig().getEvictionPolicy());
    assertEquals(MaxSizePolicy.ENTRY_COUNT, queryCacheConfig.getEvictionConfig().getMaxSizePolicy());
    assertEquals(111, queryCacheConfig.getEvictionConfig().getSize());
    assertEquals(2, queryCacheConfig.getIndexConfigs().size());
    IndexConfig hashIndex = queryCacheConfig.getIndexConfigs().get(0);
    assertEquals(IndexType.HASH, hashIndex.getType());
    assertNull(hashIndex.getName());
    assertEquals(1, hashIndex.getAttributes().size());
    assertEquals("name", hashIndex.getAttributes().get(0));
    IndexConfig sortedIndex = queryCacheConfig.getIndexConfigs().get(1);
    assertEquals(IndexType.SORTED, sortedIndex.getType());
    assertEquals("sortedIndex", sortedIndex.getName());
    assertEquals(2, sortedIndex.getAttributes().size());
    assertEquals("age", sortedIndex.getAttributes().get(0));
    assertEquals("name", sortedIndex.getAttributes().get(1));
}
Also used : IndexConfig(com.hazelcast.config.IndexConfig) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with IndexConfig

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

the class TestFullApplicationContext method assertIndexesEqual.

private void assertIndexesEqual(QueryCacheConfig queryCacheConfig) {
    for (IndexConfig indexConfig : queryCacheConfig.getIndexConfigs()) {
        assertEquals("name", indexConfig.getAttributes().get(0));
        assertFalse(indexConfig.getType() == IndexType.SORTED);
    }
}
Also used : IndexConfig(com.hazelcast.config.IndexConfig)

Example 4 with IndexConfig

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

the class PlanExecutor method execute.

SqlResult execute(CreateIndexPlan plan) {
    if (!plan.ifNotExists()) {
        // If `IF NOT EXISTS` isn't specified, we do a simple check for the existence of the index. This is not
        // OK if two clients concurrently try to create the index (they could both succeed), but covers the
        // common case. There's no atomic operation to create an index in IMDG, so it's not easy to
        // implement.
        MapContainer mapContainer = getMapContainer(hazelcastInstance.getMap(plan.mapName()));
        if (mapContainer.getIndexes().getIndex(plan.indexName()) != null) {
            throw QueryException.error("Can't create index: index '" + plan.indexName() + "' already exists");
        }
    }
    IndexConfig indexConfig = new IndexConfig(plan.indexType(), plan.attributes()).setName(plan.indexName());
    if (plan.indexType().equals(IndexType.BITMAP)) {
        Map<String, String> options = plan.options();
        String uniqueKey = options.get(UNIQUE_KEY);
        if (uniqueKey == null) {
            uniqueKey = DEFAULT_UNIQUE_KEY;
        }
        String uniqueKeyTransform = options.get(UNIQUE_KEY_TRANSFORMATION);
        if (uniqueKeyTransform == null) {
            uniqueKeyTransform = DEFAULT_UNIQUE_KEY_TRANSFORMATION;
        }
        BitmapIndexOptions bitmapIndexOptions = new BitmapIndexOptions();
        bitmapIndexOptions.setUniqueKey(uniqueKey);
        bitmapIndexOptions.setUniqueKeyTransformation(UniqueKeyTransformation.fromName(uniqueKeyTransform));
        indexConfig.setBitmapIndexOptions(bitmapIndexOptions);
    }
    // The `addIndex()` call does nothing, if an index with the same name already exists.
    // Even if its config is different.
    hazelcastInstance.getMap(plan.mapName()).addIndex(indexConfig);
    return UpdateSqlResultImpl.createUpdateCountResult(0);
}
Also used : IndexConfig(com.hazelcast.config.IndexConfig) BitmapIndexOptions(com.hazelcast.config.BitmapIndexOptions) MapContainer(com.hazelcast.map.impl.MapContainer)

Example 5 with IndexConfig

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

the class MapReplicationStateHolder method prepare.

void prepare(PartitionContainer container, Collection<ServiceNamespace> namespaces, int replicaIndex) {
    storesByMapName = createHashMap(namespaces.size());
    loaded = createHashMap(namespaces.size());
    mapIndexInfos = new ArrayList<>(namespaces.size());
    for (ServiceNamespace namespace : namespaces) {
        ObjectNamespace mapNamespace = (ObjectNamespace) namespace;
        String mapName = mapNamespace.getObjectName();
        RecordStore recordStore = container.getExistingRecordStore(mapName);
        if (recordStore == null) {
            continue;
        }
        MapContainer mapContainer = recordStore.getMapContainer();
        MapConfig mapConfig = mapContainer.getMapConfig();
        if (mapConfig.getTotalBackupCount() < replicaIndex) {
            continue;
        }
        loaded.put(mapName, recordStore.isLoaded());
        storesByMapName.put(mapName, recordStore);
        statsByMapName.put(mapName, mapContainer.getMapServiceContext().getLocalMapStatsProvider().getLocalMapStatsImpl(mapName).getReplicationStats());
        Set<IndexConfig> indexConfigs = new HashSet<>();
        if (mapContainer.isGlobalIndexEnabled()) {
            // global-index
            final Indexes indexes = mapContainer.getIndexes();
            for (Index index : indexes.getIndexes()) {
                indexConfigs.add(index.getConfig());
            }
            indexConfigs.addAll(indexes.getIndexDefinitions());
        } else {
            // partitioned-index
            final Indexes indexes = mapContainer.getIndexes(container.getPartitionId());
            if (indexes != null && indexes.haveAtLeastOneIndexOrDefinition()) {
                for (Index index : indexes.getIndexes()) {
                    indexConfigs.add(index.getConfig());
                }
                indexConfigs.addAll(indexes.getIndexDefinitions());
            }
        }
        MapIndexInfo mapIndexInfo = new MapIndexInfo(mapName);
        mapIndexInfo.addIndexCofigs(indexConfigs);
        mapIndexInfos.add(mapIndexInfo);
    }
}
Also used : ServiceNamespace(com.hazelcast.internal.services.ServiceNamespace) MapIndexInfo(com.hazelcast.query.impl.MapIndexInfo) InternalIndex(com.hazelcast.query.impl.InternalIndex) Index(com.hazelcast.query.impl.Index) Indexes(com.hazelcast.query.impl.Indexes) MapContainer(com.hazelcast.map.impl.MapContainer) IndexConfig(com.hazelcast.config.IndexConfig) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) MapConfig(com.hazelcast.config.MapConfig) ObjectNamespace(com.hazelcast.internal.services.ObjectNamespace) HashSet(java.util.HashSet)

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