Search in sources :

Example 11 with MapIndexConfig

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

the class EntryProcessorTest method testExecuteOnKeysBackupOperationIndexed.

/**
     * Reproducer for https://github.com/hazelcast/hazelcast/issues/1854
     * This one with index which results in an exception.
     */
@Test
public void testExecuteOnKeysBackupOperationIndexed() {
    Config cfg = getConfig();
    cfg.getMapConfig(MAP_NAME).setBackupCount(1).addMapIndexConfig(new MapIndexConfig("attr1", false));
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(cfg);
    HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(cfg);
    IMap<String, TestData> map = instance1.getMap(MAP_NAME);
    map.put("a", new TestData("foo", "bar"));
    map.put("b", new TestData("abc", "123"));
    map.executeOnKeys(map.keySet(), new TestDeleteEntryProcessor());
    // the entry has been removed from the primary store but not the backup,
    // so let's kill the primary and execute the logging processor again
    HazelcastInstance newPrimary;
    String aMemberUiid = instance1.getPartitionService().getPartition("a").getOwner().getUuid();
    if (aMemberUiid.equals(instance1.getCluster().getLocalMember().getUuid())) {
        instance1.shutdown();
        newPrimary = instance2;
    } else {
        instance2.shutdown();
        newPrimary = instance1;
    }
    // make sure there are no entries left
    IMap<String, TestData> map2 = newPrimary.getMap("test");
    Map<String, Object> executedEntries = map2.executeOnEntries(new TestLoggingEntryProcessor());
    assertEquals(0, executedEntries.size());
}
Also used : MapIndexConfig(com.hazelcast.config.MapIndexConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) MapIndexConfig(com.hazelcast.config.MapIndexConfig) EntryObject(com.hazelcast.query.EntryObject) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 12 with MapIndexConfig

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

the class EntryProcessorTest method setupImapForEntryProcessorWithIndex.

private IMap<Long, MyData> setupImapForEntryProcessorWithIndex() {
    Config config = getConfig();
    MapConfig testMapConfig = config.getMapConfig(MAP_NAME);
    testMapConfig.setInMemoryFormat(inMemoryFormat);
    testMapConfig.getMapIndexConfigs().add(new MapIndexConfig("lastValue", true));
    HazelcastInstance instance = createHazelcastInstance(config);
    return instance.getMap(MAP_NAME);
}
Also used : MapIndexConfig(com.hazelcast.config.MapIndexConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) MapIndexConfig(com.hazelcast.config.MapIndexConfig) MapConfig(com.hazelcast.config.MapConfig)

Example 13 with MapIndexConfig

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

the class QueryAdvancedTest method testUnknownPortableField_notCausesQueryException_withIndex.

@Test
public // see: https://github.com/hazelcast/hazelcast/issues/3927
void testUnknownPortableField_notCausesQueryException_withIndex() {
    String mapName = "default";
    Config config = getConfig();
    config.getSerializationConfig().addPortableFactory(666, new PortableFactory() {

        public Portable create(int classId) {
            return new PortableEmployee();
        }
    });
    config.getMapConfig(mapName).addMapIndexConfig(new MapIndexConfig("notExist", false)).addMapIndexConfig(new MapIndexConfig("n", false));
    HazelcastInstance hazelcastInstance = createHazelcastInstance(config);
    IMap<Integer, PortableEmployee> map = hazelcastInstance.getMap(mapName);
    for (int i = 0; i < 5; i++) {
        map.put(i, new PortableEmployee(i, "name_" + i));
    }
    Collection values = map.values(new SqlPredicate("n = name_2 OR notExist = name_0"));
    assertEquals(1, values.size());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Portable(com.hazelcast.nio.serialization.Portable) MapIndexConfig(com.hazelcast.config.MapIndexConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) MapIndexConfig(com.hazelcast.config.MapIndexConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) PortableEmployee(com.hazelcast.query.SampleObjects.PortableEmployee) Collection(java.util.Collection) SqlPredicate(com.hazelcast.query.SqlPredicate) PortableFactory(com.hazelcast.nio.serialization.PortableFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 14 with MapIndexConfig

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

the class QueryBasicTest method testQueryUsingNestedPortableObjectWithIndex.

@Test
public void testQueryUsingNestedPortableObjectWithIndex() {
    String name = randomMapName();
    Config config = getConfig();
    config.addMapConfig(new MapConfig(name).addMapIndexConfig(new MapIndexConfig("child.timestamp", false)).addMapIndexConfig(new MapIndexConfig("child.child.timestamp", true)));
    testQueryUsingNestedPortableObject(config, name);
}
Also used : MapIndexConfig(com.hazelcast.config.MapIndexConfig) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) MapIndexConfig(com.hazelcast.config.MapIndexConfig) MapConfig(com.hazelcast.config.MapConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 15 with MapIndexConfig

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

the class IndexIntegrationTest method putRemove_withIndex_whereAttributeIsNull.

@Test
public void putRemove_withIndex_whereAttributeIsNull() {
    // GIVEN
    MapIndexConfig mapIndexConfig = new MapIndexConfig();
    mapIndexConfig.setAttribute("amount");
    mapIndexConfig.setOrdered(false);
    MapConfig mapConfig = new MapConfig().setName("map");
    mapConfig.addMapIndexConfig(mapIndexConfig);
    Config config = new Config();
    config.addMapConfig(mapConfig);
    Trade trade = new Trade();
    trade.setCurrency("EUR");
    trade.setAmount(null);
    HazelcastInstance instance = createHazelcastInstance(config);
    IMap<Integer, Trade> map = instance.getMap("map");
    // WHEN
    map.put(1, trade);
    map.remove(1);
    EntryObject e = new PredicateBuilder().getEntryObject();
    Predicate predicate = e.get("amount").isNull();
    Collection<Trade> values = map.values(predicate);
    // THEN
    assertEquals(0, values.size());
    assertNull(map.get(1));
}
Also used : MapIndexConfig(com.hazelcast.config.MapIndexConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) EntryObject(com.hazelcast.query.EntryObject) PredicateBuilder(com.hazelcast.query.PredicateBuilder) MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) MapIndexConfig(com.hazelcast.config.MapIndexConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) MapConfig(com.hazelcast.config.MapConfig) Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

MapIndexConfig (com.hazelcast.config.MapIndexConfig)22 Config (com.hazelcast.config.Config)17 MapConfig (com.hazelcast.config.MapConfig)14 QuickTest (com.hazelcast.test.annotation.QuickTest)12 Test (org.junit.Test)12 ParallelTest (com.hazelcast.test.annotation.ParallelTest)10 MapStoreConfig (com.hazelcast.config.MapStoreConfig)9 HazelcastInstance (com.hazelcast.core.HazelcastInstance)9 EntryObject (com.hazelcast.query.EntryObject)3 EntryListenerConfig (com.hazelcast.config.EntryListenerConfig)2 SampleObjects (com.hazelcast.query.SampleObjects)2 SqlPredicate (com.hazelcast.query.SqlPredicate)2 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)2 Collection (java.util.Collection)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 ClientConfig (com.hazelcast.client.config.ClientConfig)1 StaticLB (com.hazelcast.client.util.StaticLB)1 ListenerConfig (com.hazelcast.config.ListenerConfig)1 MapAttributeConfig (com.hazelcast.config.MapAttributeConfig)1 MapPartitionLostListenerConfig (com.hazelcast.config.MapPartitionLostListenerConfig)1