Search in sources :

Example 16 with PortableFactory

use of com.hazelcast.nio.serialization.PortableFactory in project hazelcast by hazelcast.

the class DefaultSerializationServiceBuilder method registerPortableFactories.

private void registerPortableFactories(Map<Integer, PortableFactory> portableFactories, SerializationConfig config) {
    for (Map.Entry<Integer, PortableFactory> entry : config.getPortableFactories().entrySet()) {
        int factoryId = entry.getKey();
        PortableFactory factory = entry.getValue();
        if (factoryId <= 0) {
            throw new IllegalArgumentException("PortableFactory factoryId must be positive! -> " + factory);
        }
        if (portableFactories.containsKey(factoryId)) {
            throw new IllegalArgumentException("PortableFactory with factoryId '" + factoryId + "' is already registered!");
        }
        portableFactories.put(factoryId, factory);
    }
}
Also used : HashMap(java.util.HashMap) Map(java.util.Map) PortableFactory(com.hazelcast.nio.serialization.PortableFactory)

Example 17 with PortableFactory

use of com.hazelcast.nio.serialization.PortableFactory 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 18 with PortableFactory

use of com.hazelcast.nio.serialization.PortableFactory in project hazelcast by hazelcast.

the class MorphingPortableReaderTest method before.

@Before
public void before() throws Exception {
    service1 = (SerializationServiceV1) new DefaultSerializationServiceBuilder().addPortableFactory(TestSerializationConstants.PORTABLE_FACTORY_ID, new PortableFactory() {

        public Portable create(int classId) {
            return new MorphingBasePortable();
        }
    }).build();
    service2 = (SerializationServiceV1) new DefaultSerializationServiceBuilder().addPortableFactory(TestSerializationConstants.PORTABLE_FACTORY_ID, new PortableFactory() {

        public Portable create(int classId) {
            return new MorphingPortable();
        }
    }).build();
    Data data = service1.toData(new MorphingBasePortable((byte) 1, true, (char) 2, (short) 3, 4, 5, 1f, 2d, "test"));
    BufferObjectDataInput in = service2.createObjectDataInput(data);
    PortableSerializer portableSerializer = service2.getPortableSerializer();
    reader = portableSerializer.createMorphingReader(in);
}
Also used : MorphingBasePortable(com.hazelcast.nio.serialization.MorphingBasePortable) MorphingPortable(com.hazelcast.nio.serialization.MorphingPortable) Data(com.hazelcast.nio.serialization.Data) PortableFactory(com.hazelcast.nio.serialization.PortableFactory) BufferObjectDataInput(com.hazelcast.nio.BufferObjectDataInput) Before(org.junit.Before)

Aggregations

PortableFactory (com.hazelcast.nio.serialization.PortableFactory)18 Portable (com.hazelcast.nio.serialization.Portable)9 QuickTest (com.hazelcast.test.annotation.QuickTest)9 Test (org.junit.Test)9 ParallelTest (com.hazelcast.test.annotation.ParallelTest)8 ClientConfig (com.hazelcast.client.config.ClientConfig)6 Config (com.hazelcast.config.Config)6 HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 MapStoreConfig (com.hazelcast.config.MapStoreConfig)4 SerializationConfig (com.hazelcast.config.SerializationConfig)3 SqlPredicate (com.hazelcast.query.SqlPredicate)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Before (org.junit.Before)3 MapIndexConfig (com.hazelcast.config.MapIndexConfig)2 ClassDefinition (com.hazelcast.nio.serialization.ClassDefinition)2 HazelcastSerializationException (com.hazelcast.nio.serialization.HazelcastSerializationException)2 PortableEmployee (com.hazelcast.query.SampleObjects.PortableEmployee)2 NightlyTest (com.hazelcast.test.annotation.NightlyTest)2 Collection (java.util.Collection)2