use of com.hazelcast.config.SerializationConfig in project hazelcast by hazelcast.
the class PortableTest method testClassDefinitionConfig.
@Test
public void testClassDefinitionConfig() throws Exception {
int portableVersion = 1;
SerializationConfig serializationConfig = new SerializationConfig();
serializationConfig.addPortableFactory(PORTABLE_FACTORY_ID, new TestPortableFactory());
serializationConfig.setPortableVersion(portableVersion);
serializationConfig.addClassDefinition(new ClassDefinitionBuilder(PORTABLE_FACTORY_ID, TestSerializationConstants.RAW_DATA_PORTABLE, portableVersion).addLongField("l").addCharArrayField("c").addPortableField("p", createNamedPortableClassDefinition(portableVersion)).build()).addClassDefinition(new ClassDefinitionBuilder(PORTABLE_FACTORY_ID, TestSerializationConstants.NAMED_PORTABLE, portableVersion).addStringField("name").addIntField("myint").build());
SerializationService serializationService = new DefaultSerializationServiceBuilder().setConfig(serializationConfig).build();
RawDataPortable p = new RawDataPortable(System.currentTimeMillis(), "test chars".toCharArray(), new NamedPortable("named portable", 34567), 9876, "Testing raw portable", new ByteArrayDataSerializable("test bytes".getBytes()));
final Data data = serializationService.toData(p);
assertEquals(p, serializationService.toObject(data));
}
use of com.hazelcast.config.SerializationConfig in project hazelcast by hazelcast.
the class CompactStreamSerializerValueReaderQuickTest method reader.
//
// Utilities
//
public GenericRecordQueryReader reader(Car car) throws IOException {
SchemaService schemaService = CompactTestUtil.createInMemorySchemaService();
SerializationConfig serializationConfig = new SerializationConfig();
serializationConfig.setCompactSerializationConfig(new CompactSerializationConfig().setEnabled(true));
InternalSerializationService ss = new DefaultSerializationServiceBuilder().setConfig(serializationConfig).setSchemaService(schemaService).build();
Data data = ss.toData(car);
return new GenericRecordQueryReader(ss.readAsInternalGenericRecord(data));
}
use of com.hazelcast.config.SerializationConfig in project hazelcast by hazelcast.
the class DefaultPortableReaderSpecTest method reader.
//
// Hazelcast init Utilities
//
public GenericRecordQueryReader reader(Portable portable) throws IOException {
SerializationConfig serializationConfig = new SerializationConfig();
serializationConfig.addPortableFactory(TestPortableFactory.ID, new TestPortableFactory());
InternalSerializationService ss = new DefaultSerializationServiceBuilder().setConfig(serializationConfig).build();
// put fully initialised object to a map
// avoid the case where there's no class definition
ss.toData(P_NON_EMPTY);
ss.toData(G_NON_EMPTY);
ss.toData(N_NON_EMPTY);
Data data = ss.toData(portable);
return new GenericRecordQueryReader(ss.readAsInternalGenericRecord(data));
}
use of com.hazelcast.config.SerializationConfig in project hazelcast by hazelcast.
the class AbstractGenericRecordIntegrationTest method testCloneWithGenericBuilderOnEntryProcessor.
@Test
public void testCloneWithGenericBuilderOnEntryProcessor() {
HazelcastInstance[] instances = createCluster();
HazelcastInstance instance = createAccessorInstance(serializationConfig);
IMap<Object, Object> map = instance.getMap("test");
NamedPortable expected = new NamedPortable("foo", 900);
String key = generateKeyOwnedBy(instances[0]);
map.put(key, expected);
Object returnValue = map.executeOnKey(key, (EntryProcessor<Object, Object, Object>) entry -> {
Object value = entry.getValue();
GenericRecord genericRecord = (GenericRecord) value;
GenericRecord modifiedGenericRecord = genericRecord.cloneWithBuilder().setInt32("myint", 4).build();
entry.setValue(modifiedGenericRecord);
return genericRecord.getInt32("myint");
});
assertEquals(expected.myint, returnValue);
NamedPortable actualPortable = (NamedPortable) map.get(key);
assertEquals("foo", actualPortable.name);
assertEquals(4, actualPortable.myint);
}
use of com.hazelcast.config.SerializationConfig in project hazelcast by hazelcast.
the class AbstractGenericRecordIntegrationTest method testInconsistentClassDefinition_whenCheckClassDefErrorsIsFalse.
@Test
public void testInconsistentClassDefinition_whenCheckClassDefErrorsIsFalse() {
createCluster();
SerializationConfig serializationConfig = new SerializationConfig(this.serializationConfig);
serializationConfig.setCheckClassDefErrors(false);
HazelcastInstance instance = createAccessorInstance(serializationConfig);
IMap<Object, Object> map = instance.getMap("test");
BiTuple<GenericRecord, GenericRecord> records = getInconsistentGenericRecords();
map.put(1, records.element1);
map.put(2, records.element2);
}
Aggregations