Search in sources :

Example 26 with ClassDefinition

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

the class SqlPortableTest method beforeClass.

@BeforeClass
public static // reusing ClassDefinitions as schema does not change
void beforeClass() {
    initialize(1, null);
    sqlService = instance().getSql();
    serializationService = Util.getSerializationService(instance());
    personIdClassDefinition = new ClassDefinitionBuilder(PERSON_ID_FACTORY_ID, PERSON_ID_CLASS_ID, PERSON_ID_CLASS_VERSION).addIntField("id").build();
    serializationService.getPortableContext().registerClassDefinition(personIdClassDefinition);
    personClassDefinition = new ClassDefinitionBuilder(PERSON_FACTORY_ID, PERSON_CLASS_ID, PERSON_CLASS_VERSION).addIntField("id").addStringField("name").build();
    serializationService.getPortableContext().registerClassDefinition(personClassDefinition);
    ClassDefinition evolvedPersonClassDefinition = new ClassDefinitionBuilder(PERSON_FACTORY_ID, PERSON_CLASS_ID, PERSON_CLASS_VERSION + 1).addIntField("id").addStringField("name").addLongField("ssn").build();
    serializationService.getPortableContext().registerClassDefinition(evolvedPersonClassDefinition);
    ClassDefinition allTypesValueClassDefinition = new ClassDefinitionBuilder(ALL_TYPES_FACTORY_ID, ALL_TYPES_CLASS_ID, ALL_TYPES_CLASS_VERSION).addCharField("character").addStringField("string").addBooleanField("boolean").addByteField("byte").addShortField("short").addIntField("int").addLongField("long").addFloatField("float").addDoubleField("double").addDecimalField("decimal").addTimeField("time").addDateField("date").addTimestampField("timestamp").addTimestampWithTimezoneField("timestampTz").addPortableField("object", personClassDefinition).build();
    serializationService.getPortableContext().registerClassDefinition(allTypesValueClassDefinition);
    emptyClassDefinition = new ClassDefinitionBuilder(EMPTY_TYPES_FACTORY_ID, EMPTY_TYPES_CLASS_ID, EMPTY_TYPES_CLASS_VERSION).build();
    serializationService.getPortableContext().registerClassDefinition(emptyClassDefinition);
}
Also used : ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition) ClassDefinitionBuilder(com.hazelcast.nio.serialization.ClassDefinitionBuilder) BeforeClass(org.junit.BeforeClass)

Example 27 with ClassDefinition

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

the class BinaryCompatibilityTest method createSerializationService.

private SerializationService createSerializationService() {
    SerializerConfig customByteArraySerializerConfig = new SerializerConfig().setImplementation(new CustomByteArraySerializer()).setTypeClass(CustomByteArraySerializable.class);
    SerializerConfig customStreamSerializerConfig = new SerializerConfig().setImplementation(new CustomStreamSerializer()).setTypeClass(CustomStreamSerializable.class);
    SerializationConfig config = new SerializationConfig().addSerializerConfig(customByteArraySerializerConfig).addSerializerConfig(customStreamSerializerConfig).setAllowUnsafe(allowUnsafe).setByteOrder(byteOrder);
    ClassDefinition classDefinition = new ClassDefinitionBuilder(PORTABLE_FACTORY_ID, INNER_PORTABLE_CLASS_ID).addIntField("i").addFloatField("f").build();
    InternalSerializationService serializationService = new DefaultSerializationServiceBuilder().setVersion(version).addPortableFactory(PORTABLE_FACTORY_ID, new APortableFactory()).addDataSerializableFactory(IDENTIFIED_DATA_SERIALIZABLE_FACTORY_ID, new ADataSerializableFactory()).setConfig(config).addClassDefinition(classDefinition).build();
    assumeConfiguredByteOrder(serializationService, byteOrder);
    return serializationService;
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) SerializerConfig(com.hazelcast.config.SerializerConfig) SerializationConfig(com.hazelcast.config.SerializationConfig) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition) ClassDefinitionBuilder(com.hazelcast.nio.serialization.ClassDefinitionBuilder)

Example 28 with ClassDefinition

use of com.hazelcast.nio.serialization.ClassDefinition 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 keyClassDefinition = new ClassDefinitionBuilder(KeySerializationCountingData.FACTORY_ID, KeySerializationCountingData.CLASS_ID).addBooleanField("b").build();
    serializationConfig.addClassDefinition(keyClassDefinition);
    ClassDefinition valueClassDefinition = new ClassDefinitionBuilder(ValueSerializationCountingData.FACTORY_ID, ValueSerializationCountingData.CLASS_ID).addBooleanField("b").build();
    serializationConfig.addClassDefinition(valueClassDefinition);
    serializationConfig.addPortableFactory(KeySerializationCountingData.FACTORY_ID, new PortableFactory() {

        @Override
        public Portable create(int classId) {
            return new KeySerializationCountingData();
        }
    });
    serializationConfig.addPortableFactory(ValueSerializationCountingData.FACTORY_ID, new PortableFactory() {

        @Override
        public Portable create(int classId) {
            return new ValueSerializationCountingData();
        }
    });
}
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 29 with ClassDefinition

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

the class AbstractGenericRecordIntegrationTest method createGenericRecord.

@Nonnull
private GenericRecord createGenericRecord(MainPortable expectedPortable) {
    InnerPortable inner = expectedPortable.p;
    ClassDefinition namedPortableClassDefinition = new ClassDefinitionBuilder(TestSerializationConstants.PORTABLE_FACTORY_ID, TestSerializationConstants.NAMED_PORTABLE).addStringField("name").addIntField("myint").build();
    ClassDefinition innerPortableClassDefinition = new ClassDefinitionBuilder(TestSerializationConstants.PORTABLE_FACTORY_ID, TestSerializationConstants.INNER_PORTABLE).addByteArrayField("b").addCharArrayField("c").addShortArrayField("s").addIntArrayField("i").addLongArrayField("l").addFloatArrayField("f").addDoubleArrayField("d").addPortableArrayField("nn", namedPortableClassDefinition).addDecimalArrayField("bigDecimals").addTimeArrayField("localTimes").addDateArrayField("localDates").addTimestampArrayField("localDateTimes").addTimestampWithTimezoneArrayField("offsetDateTimes").build();
    ClassDefinition mainPortableClassDefinition = new ClassDefinitionBuilder(PortableTest.PORTABLE_FACTORY_ID, TestSerializationConstants.MAIN_PORTABLE).addByteField("b").addBooleanField("bool").addCharField("c").addShortField("s").addIntField("i").addLongField("l").addFloatField("f").addDoubleField("d").addStringField("str").addPortableField("p", innerPortableClassDefinition).addDecimalField("bigDecimal").addTimeField("localTime").addDateField("localDate").addTimestampField("localDateTime").addTimestampWithTimezoneField("offsetDateTime").build();
    GenericRecord[] namedRecords = new GenericRecord[inner.nn.length];
    int i = 0;
    for (NamedPortable namedPortable : inner.nn) {
        GenericRecord namedRecord = GenericRecordBuilder.portable(namedPortableClassDefinition).setString("name", inner.nn[i].name).setInt32("myint", inner.nn[i].myint).build();
        namedRecords[i++] = namedRecord;
    }
    GenericRecord innerRecord = GenericRecordBuilder.portable(innerPortableClassDefinition).setArrayOfInt8("b", inner.bb).setArrayOfChar("c", inner.cc).setArrayOfInt16("s", inner.ss).setArrayOfInt32("i", inner.ii).setArrayOfInt64("l", inner.ll).setArrayOfFloat32("f", inner.ff).setArrayOfFloat64("d", inner.dd).setArrayOfGenericRecord("nn", namedRecords).setArrayOfDecimal("bigDecimals", inner.bigDecimals).setArrayOfTime("localTimes", inner.localTimes).setArrayOfDate("localDates", inner.localDates).setArrayOfTimestamp("localDateTimes", inner.localDateTimes).setArrayOfTimestampWithTimezone("offsetDateTimes", inner.offsetDateTimes).build();
    return GenericRecordBuilder.portable(mainPortableClassDefinition).setInt8("b", expectedPortable.b).setBoolean("bool", expectedPortable.bool).setChar("c", expectedPortable.c).setInt16("s", expectedPortable.s).setInt32("i", expectedPortable.i).setInt64("l", expectedPortable.l).setFloat32("f", expectedPortable.f).setFloat64("d", expectedPortable.d).setString("str", expectedPortable.str).setGenericRecord("p", innerRecord).setDecimal("bigDecimal", expectedPortable.bigDecimal).setTime("localTime", expectedPortable.localTime).setDate("localDate", expectedPortable.localDate).setTimestamp("localDateTime", expectedPortable.localDateTime).setTimestampWithTimezone("offsetDateTime", expectedPortable.offsetDateTime).build();
}
Also used : InnerPortable(com.hazelcast.internal.serialization.impl.portable.InnerPortable) ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition) GenericRecord(com.hazelcast.nio.serialization.GenericRecord) ClassDefinitionBuilder(com.hazelcast.nio.serialization.ClassDefinitionBuilder) NamedPortable(com.hazelcast.internal.serialization.impl.portable.NamedPortable) Nonnull(javax.annotation.Nonnull)

Example 30 with ClassDefinition

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

the class AbstractGenericRecordIntegrationTest method getInconsistentGenericRecords.

private BiTuple<GenericRecord, GenericRecord> getInconsistentGenericRecords() {
    ClassDefinition namedPortableClassDefinition = new ClassDefinitionBuilder(TestSerializationConstants.PORTABLE_FACTORY_ID, TestSerializationConstants.NAMED_PORTABLE).addStringField("name").addIntField("myint").build();
    ClassDefinition inConsistentNamedPortableClassDefinition = new ClassDefinitionBuilder(TestSerializationConstants.PORTABLE_FACTORY_ID, TestSerializationConstants.NAMED_PORTABLE).addStringField("WrongName").addIntField("myint").build();
    GenericRecord record = GenericRecordBuilder.portable(namedPortableClassDefinition).setString("name", "foo").setInt32("myint", 123).build();
    GenericRecord inConsistentNamedRecord = GenericRecordBuilder.portable(inConsistentNamedPortableClassDefinition).setString("WrongName", "foo").setInt32("myint", 123).build();
    return BiTuple.of(record, inConsistentNamedRecord);
}
Also used : ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition) GenericRecord(com.hazelcast.nio.serialization.GenericRecord) ClassDefinitionBuilder(com.hazelcast.nio.serialization.ClassDefinitionBuilder)

Aggregations

ClassDefinition (com.hazelcast.nio.serialization.ClassDefinition)70 ClassDefinitionBuilder (com.hazelcast.nio.serialization.ClassDefinitionBuilder)37 Test (org.junit.Test)25 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)16 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)15 QuickTest (com.hazelcast.test.annotation.QuickTest)15 HazelcastSerializationException (com.hazelcast.nio.serialization.HazelcastSerializationException)10 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)10 FieldDefinition (com.hazelcast.nio.serialization.FieldDefinition)7 GenericRecordBuilder (com.hazelcast.nio.serialization.GenericRecordBuilder)7 Parameters (junitparams.Parameters)7 GenericRecord (com.hazelcast.nio.serialization.GenericRecord)6 MappingField (com.hazelcast.sql.impl.schema.MappingField)6 Portable (com.hazelcast.nio.serialization.Portable)5 PortableFactory (com.hazelcast.nio.serialization.PortableFactory)4 ParallelTest (com.hazelcast.test.annotation.ParallelTest)4 SerializationConfig (com.hazelcast.config.SerializationConfig)3 BufferObjectDataInput (com.hazelcast.internal.nio.BufferObjectDataInput)3 Data (com.hazelcast.internal.serialization.Data)3 BufferObjectDataInput (com.hazelcast.nio.BufferObjectDataInput)3