Search in sources :

Example 56 with IndexConfig

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

the class IndexTest method testIt.

private void testIt(boolean ordered) {
    IndexType type = ordered ? IndexType.SORTED : IndexType.HASH;
    IndexConfig config = IndexUtils.createTestIndexConfig(type, QueryConstants.THIS_ATTRIBUTE_NAME.value());
    IndexImpl index = new IndexImpl(config, ss, newExtractor(), copyBehavior, PerIndexStats.EMPTY, MemberPartitionStateImpl.DEFAULT_PARTITION_COUNT);
    assertEquals(0, index.getRecords(0L).size());
    assertEquals(0, index.getRecords(0L, true, 1000L, true).size());
    CachedQueryEntry<?, ?> record5 = newRecord(5L, 55L);
    index.putEntry(record5, null, record5, Index.OperationSource.USER);
    assertEquals(Collections.<QueryableEntry>singleton(record5), index.getRecords(55L));
    CachedQueryEntry<?, ?> record6 = newRecord(6L, 66L);
    index.putEntry(record6, null, record6, Index.OperationSource.USER);
    assertEquals(Collections.<QueryableEntry>singleton(record6), index.getRecords(66L));
    CachedQueryEntry<?, ?> newRecord5 = newRecord(5L, 555L);
    index.putEntry(newRecord5, record5, newRecord5, Index.OperationSource.USER);
    record5 = newRecord5;
    assertEquals(0, index.getRecords(55L).size());
    assertEquals(Collections.<QueryableEntry>singleton(record5), index.getRecords(555L));
    assertEquals(1, index.getRecords(555L).size());
    assertEquals(2, index.getRecords(55L, true, 555L, true).size());
    assertEquals(2, index.getRecords(66L, true, 555L, true).size());
    assertEquals(1, index.getRecords(555L, true, 555L, true).size());
    CachedQueryEntry<?, ?> record50 = newRecord(50L, 555L);
    index.putEntry(record50, null, record50, Index.OperationSource.USER);
    assertEquals(new HashSet<QueryableEntry>(asList(record5, record50)), index.getRecords(555L));
    Map<Data, QueryableEntry> records = getRecordMap(index, 555L);
    assertNotNull(records);
    assertEquals(2, records.size());
    assertEquals(record5, records.get(record5.getKeyData()));
    assertEquals(record50, records.get(record50.getKeyData()));
    assertEquals(2, index.getRecords(555L).size());
    assertEquals(3, index.getRecords(55L, true, 555L, true).size());
    assertEquals(3, index.getRecords(66L, true, 555L, true).size());
    assertEquals(2, index.getRecords(555L, true, 555L, true).size());
    assertEquals(0, index.getRecords(Comparison.LESS, 66L).size());
    assertEquals(1, index.getRecords(Comparison.LESS_OR_EQUAL, 66L).size());
    assertEquals(1, index.getRecords(Comparison.LESS_OR_EQUAL, 67L).size());
    assertEquals(2, index.getRecords(Comparison.GREATER, 66L).size());
    assertEquals(3, index.getRecords(Comparison.GREATER_OR_EQUAL, 66L).size());
    assertEquals(3, index.getRecords(Comparison.GREATER_OR_EQUAL, 61L).size());
    assertEquals(3, index.getRecords(new Comparable[] { 66L, 555L, 34234L }).size());
    assertEquals(2, index.getRecords(new Comparable[] { 555L, 34234L }).size());
    index.removeEntry(record5, Index.OperationSource.USER);
    assertEquals(Collections.<QueryableEntry>singleton(record50), index.getRecords(555L));
    records = getRecordMap(index, 555L);
    assertNotNull(records);
    assertNull(records.get(5L));
    assertEquals(record50, records.get(toData(50L)));
    assertEquals(1, index.getRecords(555L).size());
    assertEquals(2, index.getRecords(55L, true, 555L, true).size());
    assertEquals(2, index.getRecords(66L, true, 555L, true).size());
    assertEquals(1, index.getRecords(555L, true, 555L, true).size());
    assertEquals(0, index.getRecords(Comparison.LESS, 66L).size());
    assertEquals(1, index.getRecords(Comparison.LESS_OR_EQUAL, 66L).size());
    assertEquals(1, index.getRecords(Comparison.LESS_OR_EQUAL, 67L).size());
    assertEquals(1, index.getRecords(Comparison.GREATER, 66L).size());
    assertEquals(2, index.getRecords(Comparison.GREATER_OR_EQUAL, 66L).size());
    assertEquals(2, index.getRecords(Comparison.GREATER_OR_EQUAL, 61L).size());
    index.removeEntry(record50, Index.OperationSource.USER);
    assertEquals(0, index.getRecords(555L).size());
    records = getRecordMap(index, 555L);
    assertNull(records);
    assertEquals(0, index.getRecords(555L).size());
    assertEquals(1, index.getRecords(55L, true, 555L, true).size());
    assertEquals(1, index.getRecords(66L, true, 555L, true).size());
    assertEquals(0, index.getRecords(555L, true, 555L, true).size());
    index.removeEntry(record6, Index.OperationSource.USER);
    assertEquals(0, index.getRecords(66L).size());
    assertNull(getRecordMap(index, 66L));
    assertEquals(0, index.getRecords(555L).size());
    assertEquals(0, index.getRecords(55L, true, 555L, true).size());
    assertEquals(0, index.getRecords(66L, true, 555L, true).size());
    assertEquals(0, index.getRecords(555L, true, 555L, true).size());
}
Also used : IndexConfig(com.hazelcast.config.IndexConfig) TestUtil.toData(com.hazelcast.instance.impl.TestUtil.toData) Data(com.hazelcast.internal.serialization.Data) IndexType(com.hazelcast.config.IndexType)

Example 57 with IndexConfig

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

the class AttributeIndexRegistryTest method index.

private static InternalIndex index(IndexType type, String... components) {
    IndexConfig config = IndexUtils.createTestIndexConfig(type, components);
    config = IndexUtils.validateAndNormalize(UUID.randomUUID().toString(), config);
    InternalIndex index = Mockito.mock(InternalIndex.class);
    when(index.getName()).thenReturn(config.getName());
    when(index.getComponents()).thenReturn(IndexUtils.getComponents(config));
    assert type == SORTED || type == HASH || type == BITMAP;
    when(index.isOrdered()).thenReturn(type == SORTED);
    when(index.getConfig()).thenReturn(config);
    return index;
}
Also used : IndexConfig(com.hazelcast.config.IndexConfig)

Example 58 with IndexConfig

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

the class AbstractDynamicConfigGeneratorTest method testMap.

// UTILITY - TESTS
private void testMap(MapStoreConfig mapStoreConfig) {
    AttributeConfig attrConfig = new AttributeConfig().setName("power").setExtractorClassName("com.car.PowerExtractor");
    EvictionConfig evictionConfig1 = new EvictionConfig().setSize(10).setMaxSizePolicy(MaxSizePolicy.FREE_NATIVE_MEMORY_SIZE);
    IndexConfig indexConfig = new IndexConfig().addAttribute("attribute").setType(IndexType.SORTED);
    EntryListenerConfig listenerConfig = new EntryListenerConfig("com.hazelcast.entrylistener", false, false);
    EvictionConfig evictionConfig2 = new EvictionConfig().setMaxSizePolicy(MaxSizePolicy.FREE_NATIVE_MEMORY_SIZE).setSize(100).setComparatorClassName("comparatorClassName").setEvictionPolicy(EvictionPolicy.LRU);
    PredicateConfig predicateConfig1 = new PredicateConfig();
    predicateConfig1.setClassName("className");
    PredicateConfig predicateConfig2 = new PredicateConfig();
    predicateConfig2.setSql("sqlQuery");
    QueryCacheConfig queryCacheConfig1 = new QueryCacheConfig().setName("queryCache1").setPredicateConfig(predicateConfig1).addEntryListenerConfig(listenerConfig).setBatchSize(230).setDelaySeconds(20).setPopulate(false).setBufferSize(8).setInMemoryFormat(InMemoryFormat.BINARY).setEvictionConfig(evictionConfig2).setIncludeValue(false).setCoalesce(false).addIndexConfig(indexConfig);
    QueryCacheConfig queryCacheConfig2 = new QueryCacheConfig().setName("queryCache2").setPredicateConfig(predicateConfig2).addEntryListenerConfig(listenerConfig).setBatchSize(500).setDelaySeconds(10).setPopulate(true).setBufferSize(10).setInMemoryFormat(InMemoryFormat.OBJECT).setEvictionConfig(evictionConfig2).setIncludeValue(true).setCoalesce(true).addIndexConfig(indexConfig);
    MapConfig expectedConfig = newMapConfig().setName("carMap").setEvictionConfig(evictionConfig1).setInMemoryFormat(InMemoryFormat.NATIVE).setMetadataPolicy(MetadataPolicy.CREATE_ON_UPDATE).setMaxIdleSeconds(100).setTimeToLiveSeconds(1000).setCacheDeserializedValues(CacheDeserializedValues.ALWAYS).setStatisticsEnabled(true).setPerEntryStatsEnabled(false).setReadBackupData(true).setBackupCount(2).setAsyncBackupCount(3).setMapStoreConfig(mapStoreConfig).setWanReplicationRef(wanReplicationRef()).setPartitioningStrategyConfig(new PartitioningStrategyConfig("partitionStrategyClass")).setMerkleTreeConfig(merkleTreeConfig()).setEventJournalConfig(eventJournalConfig()).setDataPersistenceConfig(dataPersistenceConfig()).addEntryListenerConfig(listenerConfig).setIndexConfigs(singletonList(indexConfig)).addAttributeConfig(attrConfig).setPartitionLostListenerConfigs(singletonList(new MapPartitionLostListenerConfig("partitionLostListener")));
    expectedConfig.setQueryCacheConfigs(asList(queryCacheConfig1, queryCacheConfig2));
    Config config = new Config().addMapConfig(expectedConfig);
    Config decConfig = getNewConfigViaGenerator(config);
    MapConfig actualConfig = decConfig.getMapConfig("carMap");
    AttributeConfig decAttrConfig = actualConfig.getAttributeConfigs().get(0);
    assertEquals(attrConfig.getName(), decAttrConfig.getName());
    assertEquals(attrConfig.getExtractorClassName(), decAttrConfig.getExtractorClassName());
    ConfigCompatibilityChecker.checkMapConfig(expectedConfig, actualConfig);
}
Also used : PartitioningStrategyConfig(com.hazelcast.config.PartitioningStrategyConfig) IndexConfig(com.hazelcast.config.IndexConfig) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) MapPartitionLostListenerConfig(com.hazelcast.config.MapPartitionLostListenerConfig) EvictionConfig(com.hazelcast.config.EvictionConfig) PredicateConfig(com.hazelcast.config.PredicateConfig) ListConfig(com.hazelcast.config.ListConfig) EventJournalConfig(com.hazelcast.config.EventJournalConfig) AwsConfig(com.hazelcast.config.AwsConfig) ReliableTopicConfig(com.hazelcast.config.ReliableTopicConfig) CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) MapConfig(com.hazelcast.config.MapConfig) PredicateConfig(com.hazelcast.config.PredicateConfig) MultiMapConfig(com.hazelcast.config.MultiMapConfig) PartitioningStrategyConfig(com.hazelcast.config.PartitioningStrategyConfig) ExecutorConfig(com.hazelcast.config.ExecutorConfig) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) DiskTierConfig(com.hazelcast.config.DiskTierConfig) IndexConfig(com.hazelcast.config.IndexConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) QueueStoreConfig(com.hazelcast.config.QueueStoreConfig) ItemListenerConfig(com.hazelcast.config.ItemListenerConfig) MergePolicyConfig(com.hazelcast.config.MergePolicyConfig) CacheSimpleEntryListenerConfig(com.hazelcast.config.CacheSimpleEntryListenerConfig) RingbufferStoreConfig(com.hazelcast.config.RingbufferStoreConfig) WanConsumerConfig(com.hazelcast.config.WanConsumerConfig) AttributeConfig(com.hazelcast.config.AttributeConfig) SetConfig(com.hazelcast.config.SetConfig) PNCounterConfig(com.hazelcast.config.PNCounterConfig) QueueConfig(com.hazelcast.config.QueueConfig) ListenerConfig(com.hazelcast.config.ListenerConfig) CardinalityEstimatorConfig(com.hazelcast.config.CardinalityEstimatorConfig) WanCustomPublisherConfig(com.hazelcast.config.WanCustomPublisherConfig) WanBatchPublisherConfig(com.hazelcast.config.WanBatchPublisherConfig) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) RingbufferConfig(com.hazelcast.config.RingbufferConfig) EvictionConfig(com.hazelcast.config.EvictionConfig) TieredStoreConfig(com.hazelcast.config.TieredStoreConfig) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) ScheduledExecutorConfig(com.hazelcast.config.ScheduledExecutorConfig) TopicConfig(com.hazelcast.config.TopicConfig) Config(com.hazelcast.config.Config) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) CachePartitionLostListenerConfig(com.hazelcast.config.CachePartitionLostListenerConfig) DataPersistenceConfig(com.hazelcast.config.DataPersistenceConfig) DurableExecutorConfig(com.hazelcast.config.DurableExecutorConfig) MapPartitionLostListenerConfig(com.hazelcast.config.MapPartitionLostListenerConfig) WanReplicationConfig(com.hazelcast.config.WanReplicationConfig) FlakeIdGeneratorConfig(com.hazelcast.config.FlakeIdGeneratorConfig) MerkleTreeConfig(com.hazelcast.config.MerkleTreeConfig) MemoryTierConfig(com.hazelcast.config.MemoryTierConfig) ReplicatedMapConfig(com.hazelcast.config.ReplicatedMapConfig) MapConfig(com.hazelcast.config.MapConfig) MultiMapConfig(com.hazelcast.config.MultiMapConfig) ReplicatedMapConfig(com.hazelcast.config.ReplicatedMapConfig) CacheSimpleEntryListenerConfig(com.hazelcast.config.CacheSimpleEntryListenerConfig) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) AttributeConfig(com.hazelcast.config.AttributeConfig)

Example 59 with IndexConfig

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

the class DynamicConfigTest method getMapConfig.

private MapConfig getMapConfig() {
    MapConfig mapConfig = new MapConfig(name);
    mapConfig.setAsyncBackupCount(3).setBackupCount(2).setCacheDeserializedValues(CacheDeserializedValues.ALWAYS).setMerkleTreeConfig(new MerkleTreeConfig().setEnabled(true).setDepth(15)).setEventJournalConfig(new EventJournalConfig().setEnabled(true).setCapacity(42).setTimeToLiveSeconds(52)).setHotRestartConfig(new HotRestartConfig().setEnabled(true).setFsync(true)).setInMemoryFormat(InMemoryFormat.OBJECT).setMergePolicyConfig(new MergePolicyConfig(NON_DEFAULT_MERGE_POLICY, NON_DEFAULT_MERGE_BATCH_SIZE)).setTimeToLiveSeconds(220).setMaxIdleSeconds(110).setSplitBrainProtectionName(randomString()).addAttributeConfig(new AttributeConfig("attributeName", "com.attribute.extractor")).addIndexConfig(new IndexConfig(IndexType.SORTED, "attr")).setMetadataPolicy(MetadataPolicy.OFF).setReadBackupData(true).setStatisticsEnabled(false).setPerEntryStatsEnabled(true);
    mapConfig.getEvictionConfig().setEvictionPolicy(EvictionPolicy.RANDOM).setSize(4096).setMaxSizePolicy(MaxSizePolicy.PER_NODE);
    return mapConfig;
}
Also used : MergePolicyConfig(com.hazelcast.config.MergePolicyConfig) HotRestartConfig(com.hazelcast.config.HotRestartConfig) IndexConfig(com.hazelcast.config.IndexConfig) MapConfig(com.hazelcast.config.MapConfig) MultiMapConfig(com.hazelcast.config.MultiMapConfig) ReplicatedMapConfig(com.hazelcast.config.ReplicatedMapConfig) MerkleTreeConfig(com.hazelcast.config.MerkleTreeConfig) AttributeConfig(com.hazelcast.config.AttributeConfig) EventJournalConfig(com.hazelcast.config.EventJournalConfig)

Example 60 with IndexConfig

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

the class GetMapConfigOperationTest method testMapWithoutPreconfiguredIndexes_addedIndex.

@Test
public void testMapWithoutPreconfiguredIndexes_addedIndex() throws Exception {
    client.getMap("map-without-indexes").addIndex(new IndexConfig(IndexType.HASH, "second"));
    MCGetMapConfigCodec.ResponseParameters actual = runCommand(client, hz, "map-without-indexes").get(ASSERT_TRUE_EVENTUALLY_TIMEOUT, SECONDS);
    assertThat(actual.globalIndexes).usingElementComparatorIgnoringFields("name").containsExactlyInAnyOrder(new IndexConfig(IndexType.HASH, "second"));
}
Also used : IndexConfig(com.hazelcast.config.IndexConfig) MCGetMapConfigCodec(com.hazelcast.client.impl.protocol.codec.MCGetMapConfigCodec) 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