Search in sources :

Example 1 with PortableEmployee

use of com.hazelcast.query.SampleTestObjects.PortableEmployee in project hazelcast by hazelcast.

the class QueryAdvancedTest method testUnknownPortableField_notCausesQueryException_withoutIndex.

@Test
public // see: https://github.com/hazelcast/hazelcast/issues/3927
void testUnknownPortableField_notCausesQueryException_withoutIndex() {
    String mapName = randomMapName();
    Config config = getConfig();
    config.getSerializationConfig().addPortableFactory(666, classId -> new PortableEmployee());
    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(Predicates.sql("notExist = name_0 OR a > 1"));
    assertEquals(3, values.size());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) IndexConfig(com.hazelcast.config.IndexConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) PortableEmployee(com.hazelcast.query.SampleTestObjects.PortableEmployee) Collection(java.util.Collection) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with PortableEmployee

use of com.hazelcast.query.SampleTestObjects.PortableEmployee in project hazelcast by hazelcast.

the class CachedQueryEntryTest method testGetTargetObject_givenValueIsDataAndPortable_whenKeyFlagIsFalse_thenReturnValueData.

@Test
public void testGetTargetObject_givenValueIsDataAndPortable_whenKeyFlagIsFalse_thenReturnValueData() {
    Data key = serializationService.toData("indexedKey");
    Data value = serializationService.toData(new PortableEmployee(30, "peter"));
    QueryableEntry entry = createEntry(key, value, newExtractor());
    Object targetObject = entry.getTargetObject(false);
    assertEquals(value, targetObject);
}
Also used : PortableEmployee(com.hazelcast.query.SampleTestObjects.PortableEmployee) Data(com.hazelcast.internal.serialization.Data) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with PortableEmployee

use of com.hazelcast.query.SampleTestObjects.PortableEmployee in project hazelcast by hazelcast.

the class CachedQueryEntryTest method testGetTargetObject_givenValueIsPortable_whenKeyFlagIsFalse_thenReturnValueData.

@Test
public void testGetTargetObject_givenValueIsPortable_whenKeyFlagIsFalse_thenReturnValueData() {
    Data key = serializationService.toData("indexedKey");
    Portable value = new PortableEmployee(30, "peter");
    QueryableEntry entry = createEntry(key, value, newExtractor());
    Object targetObject = entry.getTargetObject(false);
    assertEquals(serializationService.toData(value), targetObject);
}
Also used : Portable(com.hazelcast.nio.serialization.Portable) PortableEmployee(com.hazelcast.query.SampleTestObjects.PortableEmployee) Data(com.hazelcast.internal.serialization.Data) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with PortableEmployee

use of com.hazelcast.query.SampleTestObjects.PortableEmployee 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, classId -> new PortableEmployee());
    config.getMapConfig(mapName).addIndexConfig(new IndexConfig(IndexType.HASH, "notExist")).addIndexConfig(new IndexConfig(IndexType.HASH, "n"));
    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(Predicates.sql("n = name_2 OR notExist = name_0"));
    assertEquals(1, values.size());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IndexConfig(com.hazelcast.config.IndexConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) IndexConfig(com.hazelcast.config.IndexConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) PortableEmployee(com.hazelcast.query.SampleTestObjects.PortableEmployee) Collection(java.util.Collection) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

PortableEmployee (com.hazelcast.query.SampleTestObjects.PortableEmployee)4 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4 Test (org.junit.Test)4 Config (com.hazelcast.config.Config)2 IndexConfig (com.hazelcast.config.IndexConfig)2 MapStoreConfig (com.hazelcast.config.MapStoreConfig)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 Data (com.hazelcast.internal.serialization.Data)2 Collection (java.util.Collection)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Portable (com.hazelcast.nio.serialization.Portable)1