use of com.hazelcast.config.IndexConfig in project hazelcast by hazelcast.
the class IMap method addIndex.
/**
* Convenient method to add an index to this map with the given type and attributes.
* Attributes are indexed in ascending order.
* <p>
*
* @param type Index type.
* @param attributes Attributes to be indexed.
* @see #addIndex(IndexConfig)
*/
default void addIndex(IndexType type, String... attributes) {
IndexConfig config = IndexUtils.createIndexConfig(type, attributes);
addIndex(config);
}
use of com.hazelcast.config.IndexConfig in project hazelcast by hazelcast.
the class MapProxySupport method addIndex.
@Override
public void addIndex(IndexConfig indexConfig) {
checkNotNull(indexConfig, "Index config cannot be null.");
checkFalse(isNativeMemoryAndBitmapIndexingEnabled(indexConfig.getType()), "BITMAP indexes are not supported by NATIVE storage");
IndexConfig indexConfig0 = IndexUtils.validateAndNormalize(name, indexConfig);
try {
AddIndexOperation addIndexOperation = new AddIndexOperation(name, indexConfig0);
operationService.invokeOnAllPartitions(SERVICE_NAME, new BinaryOperationFactory(addIndexOperation, getNodeEngine()));
} catch (Throwable t) {
throw rethrow(t);
}
}
use of com.hazelcast.config.IndexConfig in project hazelcast by hazelcast.
the class ClientMapWithIndexCreationTest method test_createMapWithIndexes_whenProxyCreatedOnMemberOtherThanClientOwner.
/**
* Given a two members (A, B) cluster, a non-smart client connected to B attempts to create a map proxy targeting member A.
*/
@Test
public void test_createMapWithIndexes_whenProxyCreatedOnMemberOtherThanClientOwner() {
Config config = new XmlConfigBuilder().build();
MapConfig mapConfig = config.getMapConfig("test");
List<IndexConfig> indexConfigs = mapConfig.getIndexConfigs();
IndexConfig indexConfig = new IndexConfig();
indexConfig.addAttribute("name");
indexConfig.setType(IndexType.SORTED);
indexConfigs.add(indexConfig);
HazelcastInstance hz1 = factory.newHazelcastInstance(config);
HazelcastInstance hz2 = factory.newHazelcastInstance(config);
ClientConfig clientConfig = new ClientConfig();
// ProxyManager#findNextAddressToSendCreateRequest uses the configured load balancer to find the next address
// to which proxy creation request will be sent. We want this to be member hz1.
clientConfig.setLoadBalancer(new StaticLB((Member) hz1.getLocalEndpoint()));
clientConfig.getNetworkConfig().setSmartRouting(false);
// the client only connects to member hz2.
clientConfig.getNetworkConfig().addAddress(hz2.getCluster().getLocalMember().getAddress().getHost() + ":" + hz2.getCluster().getLocalMember().getAddress().getPort());
HazelcastInstance client = factory.newHazelcastClient(clientConfig);
IMap<String, SampleTestObjects.Employee> test = client.getMap("test");
test.put("foo", new SampleTestObjects.Employee(1, "name", "age", 32, true, 230));
}
use of com.hazelcast.config.IndexConfig in project hazelcast by hazelcast.
the class TestFullApplicationContext method testMapConfig.
@Test
public void testMapConfig() {
assertNotNull(config);
long mapConfigSize = config.getMapConfigs().keySet().stream().filter(name -> !name.startsWith(INTERNAL_JET_OBJECTS_PREFIX)).count();
assertEquals(27, mapConfigSize);
MapConfig testMapConfig = config.getMapConfig("testMap");
assertNotNull(testMapConfig);
assertEquals("testMap", testMapConfig.getName());
assertEquals(2, testMapConfig.getBackupCount());
assertEquals(EvictionPolicy.NONE, testMapConfig.getEvictionConfig().getEvictionPolicy());
assertEquals(Integer.MAX_VALUE, testMapConfig.getEvictionConfig().getSize());
assertEquals(0, testMapConfig.getTimeToLiveSeconds());
assertTrue(testMapConfig.getMerkleTreeConfig().isEnabled());
assertEquals(20, testMapConfig.getMerkleTreeConfig().getDepth());
assertTrue(testMapConfig.getDataPersistenceConfig().isEnabled());
assertTrue(testMapConfig.getDataPersistenceConfig().isFsync());
EventJournalConfig journalConfig = testMapConfig.getEventJournalConfig();
assertTrue(journalConfig.isEnabled());
assertEquals(123, journalConfig.getCapacity());
assertEquals(321, journalConfig.getTimeToLiveSeconds());
assertEquals(MetadataPolicy.OFF, testMapConfig.getMetadataPolicy());
assertTrue(testMapConfig.isReadBackupData());
assertEquals(2, testMapConfig.getIndexConfigs().size());
for (IndexConfig index : testMapConfig.getIndexConfigs()) {
if ("name".equals(index.getAttributes().get(0))) {
assertEquals(IndexType.HASH, index.getType());
assertNull(index.getName());
} else if ("age".equals(index.getAttributes().get(0))) {
assertEquals(IndexType.SORTED, index.getType());
assertEquals("sortedIndex", index.getName());
assertEquals("name", index.getAttributes().get(1));
} else {
fail("unknown index!");
}
}
assertEquals(2, testMapConfig.getAttributeConfigs().size());
for (AttributeConfig attribute : testMapConfig.getAttributeConfigs()) {
if ("power".equals(attribute.getName())) {
assertEquals("com.car.PowerExtractor", attribute.getExtractorClassName());
} else if ("weight".equals(attribute.getName())) {
assertEquals("com.car.WeightExtractor", attribute.getExtractorClassName());
} else {
fail("unknown attribute!");
}
}
assertEquals("my-split-brain-protection", testMapConfig.getSplitBrainProtectionName());
MergePolicyConfig mergePolicyConfig = testMapConfig.getMergePolicyConfig();
assertNotNull(mergePolicyConfig);
assertEquals("PassThroughMergePolicy", mergePolicyConfig.getPolicy());
assertEquals(2342, mergePolicyConfig.getBatchSize());
// test that the testMapConfig has a mapStoreConfig and it is correct
MapStoreConfig testMapStoreConfig = testMapConfig.getMapStoreConfig();
assertNotNull(testMapStoreConfig);
assertEquals("com.hazelcast.spring.DummyStore", testMapStoreConfig.getClassName());
assertTrue(testMapStoreConfig.isEnabled());
assertEquals(0, testMapStoreConfig.getWriteDelaySeconds());
assertEquals(10, testMapStoreConfig.getWriteBatchSize());
assertTrue(testMapStoreConfig.isWriteCoalescing());
assertEquals(MapStoreConfig.InitialLoadMode.EAGER, testMapStoreConfig.getInitialLoadMode());
// test that the testMapConfig has a nearCacheConfig and it is correct
NearCacheConfig testNearCacheConfig = testMapConfig.getNearCacheConfig();
assertNotNull(testNearCacheConfig);
assertEquals(0, testNearCacheConfig.getTimeToLiveSeconds());
assertEquals(60, testNearCacheConfig.getMaxIdleSeconds());
assertEquals(EvictionPolicy.LRU, testNearCacheConfig.getEvictionConfig().getEvictionPolicy());
assertEquals(5000, testNearCacheConfig.getEvictionConfig().getSize());
assertTrue(testNearCacheConfig.isInvalidateOnChange());
assertFalse(testNearCacheConfig.isSerializeKeys());
// test that the testMapConfig2's mapStoreConfig implementation
MapConfig testMapConfig2 = config.getMapConfig("testMap2");
assertNotNull(testMapConfig2.getMapStoreConfig().getImplementation());
assertEquals(dummyMapStore, testMapConfig2.getMapStoreConfig().getImplementation());
assertEquals(MapStoreConfig.InitialLoadMode.LAZY, testMapConfig2.getMapStoreConfig().getInitialLoadMode());
// test testMapConfig2's WanReplicationConfig
WanReplicationRef wanReplicationRef = testMapConfig2.getWanReplicationRef();
assertEquals("testWan", wanReplicationRef.getName());
assertEquals("PutIfAbsentMergePolicy", wanReplicationRef.getMergePolicyClassName());
assertTrue(wanReplicationRef.isRepublishingEnabled());
assertEquals(1000, testMapConfig2.getEvictionConfig().getSize());
assertEquals(MaxSizePolicy.PER_NODE, testMapConfig2.getEvictionConfig().getMaxSizePolicy());
assertEquals(2, testMapConfig2.getEntryListenerConfigs().size());
for (EntryListenerConfig listener : testMapConfig2.getEntryListenerConfigs()) {
if (listener.getClassName() != null) {
assertNull(listener.getImplementation());
assertTrue(listener.isIncludeValue());
assertFalse(listener.isLocal());
} else {
assertNotNull(listener.getImplementation());
assertEquals(entryListener, listener.getImplementation());
assertTrue(listener.isLocal());
assertTrue(listener.isIncludeValue());
}
}
MapConfig simpleMapConfig = config.getMapConfig("simpleMap");
assertNotNull(simpleMapConfig);
assertEquals("simpleMap", simpleMapConfig.getName());
assertEquals(3, simpleMapConfig.getBackupCount());
assertEquals(1, simpleMapConfig.getAsyncBackupCount());
assertEquals(EvictionPolicy.LRU, simpleMapConfig.getEvictionConfig().getEvictionPolicy());
assertEquals(10, simpleMapConfig.getEvictionConfig().getSize());
assertEquals(1, simpleMapConfig.getTimeToLiveSeconds());
// test that the simpleMapConfig does NOT have a nearCacheConfig
assertNull(simpleMapConfig.getNearCacheConfig());
MapConfig testMapConfig3 = config.getMapConfig("testMap3");
assertEquals("com.hazelcast.spring.DummyStoreFactory", testMapConfig3.getMapStoreConfig().getFactoryClassName());
assertFalse(testMapConfig3.getMapStoreConfig().getProperties().isEmpty());
assertEquals(testMapConfig3.getMapStoreConfig().getProperty("dummy.property"), "value");
MapConfig testMapConfig4 = config.getMapConfig("testMap4");
assertEquals(dummyMapStoreFactory, testMapConfig4.getMapStoreConfig().getFactoryImplementation());
MapConfig mapWithValueCachingSetToNever = config.getMapConfig("mapWithValueCachingSetToNever");
assertEquals(CacheDeserializedValues.NEVER, mapWithValueCachingSetToNever.getCacheDeserializedValues());
MapConfig mapWithValueCachingSetToAlways = config.getMapConfig("mapWithValueCachingSetToAlways");
assertEquals(CacheDeserializedValues.ALWAYS, mapWithValueCachingSetToAlways.getCacheDeserializedValues());
MapConfig mapWithDefaultValueCaching = config.getMapConfig("mapWithDefaultValueCaching");
assertEquals(CacheDeserializedValues.INDEX_ONLY, mapWithDefaultValueCaching.getCacheDeserializedValues());
MapConfig testMapWithPartitionLostListenerConfig = config.getMapConfig("mapWithPartitionLostListener");
List<MapPartitionLostListenerConfig> partitionLostListenerConfigs = testMapWithPartitionLostListenerConfig.getPartitionLostListenerConfigs();
assertEquals(1, partitionLostListenerConfigs.size());
assertEquals("DummyMapPartitionLostListenerImpl", partitionLostListenerConfigs.get(0).getClassName());
MapConfig testMapWithPartitionStrategyConfig = config.getMapConfig("mapWithPartitionStrategy");
assertEquals("com.hazelcast.spring.DummyPartitionStrategy", testMapWithPartitionStrategyConfig.getPartitioningStrategyConfig().getPartitioningStrategyClass());
MapConfig testMapConfig5 = config.getMapConfig("testMap5");
TieredStoreConfig tieredStoreConfig = testMapConfig5.getTieredStoreConfig();
assertTrue(tieredStoreConfig.isEnabled());
MemoryTierConfig memoryTierConfig = tieredStoreConfig.getMemoryTierConfig();
assertEquals(MemoryUnit.MEGABYTES, memoryTierConfig.getCapacity().getUnit());
assertEquals(128L, memoryTierConfig.getCapacity().getValue());
DiskTierConfig diskTierConfig = tieredStoreConfig.getDiskTierConfig();
assertTrue(diskTierConfig.isEnabled());
assertEquals("the-local0751", diskTierConfig.getDeviceName());
}
use of com.hazelcast.config.IndexConfig in project hazelcast by hazelcast.
the class ConfigDataSerializerHook method createFactory.
@Override
public DataSerializableFactory createFactory() {
ConstructorFunction<Integer, IdentifiedDataSerializable>[] constructors = new ConstructorFunction[LEN];
constructors[WAN_REPLICATION_CONFIG] = arg -> new WanReplicationConfig();
constructors[WAN_CONSUMER_CONFIG] = arg -> new WanConsumerConfig();
constructors[WAN_CUSTOM_PUBLISHER_CONFIG] = arg -> new WanCustomPublisherConfig();
constructors[WAN_BATCH_PUBLISHER_CONFIG] = arg -> new WanBatchPublisherConfig();
constructors[NEAR_CACHE_CONFIG] = arg -> new NearCacheConfig();
constructors[NEAR_CACHE_PRELOADER_CONFIG] = arg -> new NearCachePreloaderConfig();
constructors[ADD_DYNAMIC_CONFIG_OP] = arg -> new AddDynamicConfigOperation();
constructors[DYNAMIC_CONFIG_PRE_JOIN_OP] = arg -> new DynamicConfigPreJoinOperation();
constructors[MULTIMAP_CONFIG] = arg -> new MultiMapConfig();
constructors[LISTENER_CONFIG] = arg -> new ListenerConfig();
constructors[ENTRY_LISTENER_CONFIG] = arg -> new EntryListenerConfig();
constructors[MAP_CONFIG] = arg -> new MapConfig();
constructors[MAP_STORE_CONFIG] = arg -> new MapStoreConfig();
constructors[MAP_PARTITION_LOST_LISTENER_CONFIG] = arg -> new MapPartitionLostListenerConfig();
constructors[INDEX_CONFIG] = arg -> new IndexConfig();
constructors[MAP_ATTRIBUTE_CONFIG] = arg -> new AttributeConfig();
constructors[QUERY_CACHE_CONFIG] = arg -> new QueryCacheConfig();
constructors[PREDICATE_CONFIG] = arg -> new PredicateConfig();
constructors[PARTITION_STRATEGY_CONFIG] = arg -> new PartitioningStrategyConfig();
constructors[HOT_RESTART_CONFIG] = arg -> new HotRestartConfig();
constructors[TOPIC_CONFIG] = arg -> new TopicConfig();
constructors[RELIABLE_TOPIC_CONFIG] = arg -> new ReliableTopicConfig();
constructors[ITEM_LISTENER_CONFIG] = arg -> new ItemListenerConfig();
constructors[QUEUE_STORE_CONFIG] = arg -> new QueueStoreConfig();
constructors[QUEUE_CONFIG] = arg -> new QueueConfig();
constructors[LIST_CONFIG] = arg -> new ListConfig();
constructors[SET_CONFIG] = arg -> new SetConfig();
constructors[EXECUTOR_CONFIG] = arg -> new ExecutorConfig();
constructors[DURABLE_EXECUTOR_CONFIG] = arg -> new DurableExecutorConfig();
constructors[SCHEDULED_EXECUTOR_CONFIG] = arg -> new ScheduledExecutorConfig();
constructors[REPLICATED_MAP_CONFIG] = arg -> new ReplicatedMapConfig();
constructors[RINGBUFFER_CONFIG] = arg -> new RingbufferConfig();
constructors[RINGBUFFER_STORE_CONFIG] = arg -> new RingbufferStoreConfig();
constructors[CARDINALITY_ESTIMATOR_CONFIG] = arg -> new CardinalityEstimatorConfig();
constructors[SIMPLE_CACHE_CONFIG] = arg -> new CacheSimpleConfig();
constructors[SIMPLE_CACHE_CONFIG_EXPIRY_POLICY_FACTORY_CONFIG] = arg -> new CacheSimpleConfig.ExpiryPolicyFactoryConfig();
constructors[SIMPLE_CACHE_CONFIG_TIMED_EXPIRY_POLICY_FACTORY_CONFIG] = arg -> new CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig();
constructors[SIMPLE_CACHE_CONFIG_DURATION_CONFIG] = arg -> new CacheSimpleConfig.ExpiryPolicyFactoryConfig.DurationConfig();
constructors[SPLIT_BRAIN_PROTECTION_CONFIG] = arg -> new SplitBrainProtectionConfig();
constructors[EVENT_JOURNAL_CONFIG] = arg -> new EventJournalConfig();
constructors[SPLIT_BRAIN_PROTECTION_LISTENER_CONFIG] = arg -> new SplitBrainProtectionListenerConfig();
constructors[CACHE_PARTITION_LOST_LISTENER_CONFIG] = arg -> new CachePartitionLostListenerConfig();
constructors[SIMPLE_CACHE_ENTRY_LISTENER_CONFIG] = arg -> new CacheSimpleEntryListenerConfig();
constructors[FLAKE_ID_GENERATOR_CONFIG] = arg -> new FlakeIdGeneratorConfig();
constructors[MERGE_POLICY_CONFIG] = arg -> new MergePolicyConfig();
constructors[PN_COUNTER_CONFIG] = arg -> new PNCounterConfig();
constructors[MERKLE_TREE_CONFIG] = arg -> new MerkleTreeConfig();
constructors[WAN_SYNC_CONFIG] = arg -> new WanSyncConfig();
constructors[KUBERNETES_CONFIG] = arg -> new KubernetesConfig();
constructors[EUREKA_CONFIG] = arg -> new EurekaConfig();
constructors[GCP_CONFIG] = arg -> new GcpConfig();
constructors[AZURE_CONFIG] = arg -> new AzureConfig();
constructors[AWS_CONFIG] = arg -> new AwsConfig();
constructors[DISCOVERY_CONFIG] = arg -> new DiscoveryConfig();
constructors[DISCOVERY_STRATEGY_CONFIG] = arg -> new DiscoveryStrategyConfig();
constructors[WAN_REPLICATION_REF] = arg -> new WanReplicationRef();
constructors[EVICTION_CONFIG] = arg -> new EvictionConfig();
constructors[PERMISSION_CONFIG] = arg -> new PermissionConfig();
constructors[BITMAP_INDEX_OPTIONS] = arg -> new BitmapIndexOptions();
constructors[DATA_PERSISTENCE_CONFIG] = arg -> new DataPersistenceConfig();
constructors[TIERED_STORE_CONFIG] = arg -> new TieredStoreConfig();
constructors[MEMORY_TIER_CONFIG] = arg -> new MemoryTierConfig();
constructors[DISK_TIER_CONFIG] = arg -> new DiskTierConfig();
return new ArrayDataSerializableFactory(constructors);
}
Aggregations