Search in sources :

Example 6 with Portable

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

the class ClassDefinitionWriter method writePortableArray.

@Override
public void writePortableArray(String fieldName, Portable[] portables) throws IOException {
    if (portables == null || portables.length == 0) {
        throw new HazelcastSerializationException("Cannot write null portable array without explicitly " + "registering class definition!");
    }
    Portable p = portables[0];
    int classId = p.getClassId();
    for (int i = 1; i < portables.length; i++) {
        if (portables[i].getClassId() != classId) {
            throw new IllegalArgumentException("Detected different class-ids in portable array!");
        }
    }
    int version = SerializationUtil.getPortableVersion(p, context.getVersion());
    ClassDefinition nestedClassDef = createNestedClassDef(p, new ClassDefinitionBuilder(p.getFactoryId(), classId, version));
    builder.addPortableArrayField(fieldName, nestedClassDef);
}
Also used : Portable(com.hazelcast.nio.serialization.Portable) HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition) ClassDefinitionBuilder(com.hazelcast.nio.serialization.ClassDefinitionBuilder)

Example 7 with Portable

use of com.hazelcast.nio.serialization.Portable 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, new PortableFactory() {

        public Portable create(int classId) {
            return 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(new SqlPredicate("notExist = name_0 OR a > 1"));
    assertEquals(3, values.size());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Portable(com.hazelcast.nio.serialization.Portable) 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 8 with Portable

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

the class MapTransactionTest method testKeySet_whenPortableKeysetAndValuesWithPredicates.

@Test
public void testKeySet_whenPortableKeysetAndValuesWithPredicates() throws Exception {
    final String mapName = randomString();
    final Config config = getConfig();
    config.getSerializationConfig().addPortableFactory(666, new PortableFactory() {

        public Portable create(int classId) {
            return new SampleObjects.PortableEmployee();
        }
    });
    final HazelcastInstance instance = createHazelcastInstance(config);
    IMap map = instance.getMap(mapName);
    final SampleObjects.PortableEmployee emp1 = new SampleObjects.PortableEmployee(34, "abc-123-xvz");
    final SampleObjects.PortableEmployee emp2 = new SampleObjects.PortableEmployee(20, "abc-123-xvz");
    map.put(emp1, emp1);
    final TransactionContext context = instance.newTransactionContext();
    context.beginTransaction();
    final TransactionalMap txMap = context.getMap(mapName);
    assertNull(txMap.put(emp2, emp2));
    assertEquals(2, txMap.size());
    assertEquals(2, txMap.keySet().size());
    assertEquals(0, txMap.keySet(new SqlPredicate("a = 10")).size());
    assertEquals(0, txMap.values(new SqlPredicate("a = 10")).size());
    assertEquals(2, txMap.keySet(new SqlPredicate("a >= 10")).size());
    assertEquals(2, txMap.values(new SqlPredicate("a >= 10")).size());
    context.commitTransaction();
    assertEquals(2, map.size());
    assertEquals(2, map.values().size());
}
Also used : TransactionalMap(com.hazelcast.core.TransactionalMap) SampleObjects(com.hazelcast.query.SampleObjects) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) SqlPredicate(com.hazelcast.query.SqlPredicate) Portable(com.hazelcast.nio.serialization.Portable) IMap(com.hazelcast.core.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TransactionContext(com.hazelcast.transaction.TransactionContext) PortableFactory(com.hazelcast.nio.serialization.PortableFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 9 with Portable

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

the class AbstractNearCacheSerializationCountTest method prepareSerializationConfig.

/**
     * Adds the serialization configuration for the used {@link Portable} domain object to the given {@link SerializationConfig}.
     *
     * @param serializationConfig the given {@link SerializationConfig} for the {@link DataStructureAdapter}
     */
protected static void prepareSerializationConfig(SerializationConfig serializationConfig) {
    ClassDefinition classDefinition = new ClassDefinitionBuilder(SerializationCountingData.FACTORY_ID, SerializationCountingData.CLASS_ID).build();
    serializationConfig.addClassDefinition(classDefinition);
    serializationConfig.addPortableFactory(SerializationCountingData.FACTORY_ID, new PortableFactory() {

        @Override
        public Portable create(int classId) {
            return new SerializationCountingData();
        }
    });
}
Also used : Portable(com.hazelcast.nio.serialization.Portable) ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition) PortableFactory(com.hazelcast.nio.serialization.PortableFactory) ClassDefinitionBuilder(com.hazelcast.nio.serialization.ClassDefinitionBuilder)

Example 10 with Portable

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

the class DefaultPortableReaderPerformanceTest method setup.

@Setup
public void setup() throws Exception {
    ss = new DefaultSerializationServiceBuilder().addPortableFactory(DefaultPortableReaderQuickTest.TestPortableFactory.ID, new DefaultPortableReaderQuickTest.TestPortableFactory()).build();
    Portable primitive = new DefaultPortableReaderTestStructure.PrimitivePortable();
    primitiveReader = reader(primitive);
    reader = reader(PORSCHE);
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) Portable(com.hazelcast.nio.serialization.Portable) Setup(org.openjdk.jmh.annotations.Setup)

Aggregations

Portable (com.hazelcast.nio.serialization.Portable)26 QuickTest (com.hazelcast.test.annotation.QuickTest)10 Test (org.junit.Test)10 PortableFactory (com.hazelcast.nio.serialization.PortableFactory)9 ParallelTest (com.hazelcast.test.annotation.ParallelTest)7 GroupPortable (com.hazelcast.nio.serialization.impl.DefaultPortableReaderTestStructure.GroupPortable)6 Portable (com.hazelcast.nio.serialization.impl.DefaultPortableReaderTestStructure.Method.Portable)6 NestedGroupPortable (com.hazelcast.nio.serialization.impl.DefaultPortableReaderTestStructure.NestedGroupPortable)6 PrimitivePortable (com.hazelcast.nio.serialization.impl.DefaultPortableReaderTestStructure.PrimitivePortable)6 HazelcastInstance (com.hazelcast.core.HazelcastInstance)5 ClientConfig (com.hazelcast.client.config.ClientConfig)4 Config (com.hazelcast.config.Config)4 MapStoreConfig (com.hazelcast.config.MapStoreConfig)4 SqlPredicate (com.hazelcast.query.SqlPredicate)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 MapIndexConfig (com.hazelcast.config.MapIndexConfig)2 SerializationConfig (com.hazelcast.config.SerializationConfig)2 ClassDefinition (com.hazelcast.nio.serialization.ClassDefinition)2 ClassDefinitionBuilder (com.hazelcast.nio.serialization.ClassDefinitionBuilder)2 HazelcastSerializationException (com.hazelcast.nio.serialization.HazelcastSerializationException)2