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);
}
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;
}
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();
}
});
}
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();
}
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);
}
Aggregations