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());
}
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;
}
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);
}
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;
}
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"));
}
Aggregations