Search in sources :

Example 56 with SerializationConfig

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));
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) SerializationConfig(com.hazelcast.config.SerializationConfig) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data) ClassDefinitionBuilder(com.hazelcast.nio.serialization.ClassDefinitionBuilder) QuickTest(com.hazelcast.test.annotation.QuickTest) CustomSerializationTest(com.hazelcast.internal.serialization.impl.CustomSerializationTest) Test(org.junit.Test)

Example 57 with SerializationConfig

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));
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) CompactSerializationConfig(com.hazelcast.config.CompactSerializationConfig) SchemaService(com.hazelcast.internal.serialization.impl.compact.SchemaService) SerializationConfig(com.hazelcast.config.SerializationConfig) CompactSerializationConfig(com.hazelcast.config.CompactSerializationConfig) GenericRecordQueryReader(com.hazelcast.internal.serialization.impl.GenericRecordQueryReader) Data(com.hazelcast.internal.serialization.Data) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService)

Example 58 with SerializationConfig

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));
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) TestPortableFactory(com.hazelcast.internal.serialization.impl.portable.portablereader.DefaultPortableReaderTestStructure.TestPortableFactory) SerializationConfig(com.hazelcast.config.SerializationConfig) GenericRecordQueryReader(com.hazelcast.internal.serialization.impl.GenericRecordQueryReader) Data(com.hazelcast.internal.serialization.Data) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService)

Example 59 with SerializationConfig

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);
}
Also used : HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) TestSerializationConstants(com.hazelcast.internal.serialization.impl.TestSerializationConstants) LocalDateTime(java.time.LocalDateTime) Callable(java.util.concurrent.Callable) ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition) SerializationConfig(com.hazelcast.config.SerializationConfig) Json(com.hazelcast.internal.json.Json) BigDecimal(java.math.BigDecimal) Future(java.util.concurrent.Future) PortableTest(com.hazelcast.internal.serialization.impl.portable.PortableTest) BiTuple(com.hazelcast.internal.util.BiTuple) ClassDefinitionBuilder(com.hazelcast.nio.serialization.ClassDefinitionBuilder) LocalTime(java.time.LocalTime) Nonnull(javax.annotation.Nonnull) MainPortable(com.hazelcast.internal.serialization.impl.portable.MainPortable) HazelcastInstance(com.hazelcast.core.HazelcastInstance) NamedPortable(com.hazelcast.internal.serialization.impl.portable.NamedPortable) GenericRecord(com.hazelcast.nio.serialization.GenericRecord) HazelcastTestSupport(com.hazelcast.test.HazelcastTestSupport) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Serializable(java.io.Serializable) OffsetDateTime(java.time.OffsetDateTime) IExecutorService(com.hazelcast.core.IExecutorService) EntryProcessor(com.hazelcast.map.EntryProcessor) LocalDate(java.time.LocalDate) InnerPortable(com.hazelcast.internal.serialization.impl.portable.InnerPortable) GenericRecordBuilder(com.hazelcast.nio.serialization.GenericRecordBuilder) HazelcastInstanceAware(com.hazelcast.core.HazelcastInstanceAware) Assert.assertEquals(org.junit.Assert.assertEquals) IMap(com.hazelcast.map.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) GenericRecord(com.hazelcast.nio.serialization.GenericRecord) NamedPortable(com.hazelcast.internal.serialization.impl.portable.NamedPortable) PortableTest(com.hazelcast.internal.serialization.impl.portable.PortableTest) Test(org.junit.Test)

Example 60 with SerializationConfig

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);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) SerializationConfig(com.hazelcast.config.SerializationConfig) GenericRecord(com.hazelcast.nio.serialization.GenericRecord) PortableTest(com.hazelcast.internal.serialization.impl.portable.PortableTest) Test(org.junit.Test)

Aggregations

SerializationConfig (com.hazelcast.config.SerializationConfig)73 Test (org.junit.Test)45 QuickTest (com.hazelcast.test.annotation.QuickTest)37 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)36 CompactSerializationConfig (com.hazelcast.config.CompactSerializationConfig)23 SerializerConfig (com.hazelcast.config.SerializerConfig)21 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)21 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)21 Data (com.hazelcast.internal.serialization.Data)18 SerializationService (com.hazelcast.internal.serialization.SerializationService)14 GlobalSerializerConfig (com.hazelcast.config.GlobalSerializerConfig)13 HazelcastInstance (com.hazelcast.core.HazelcastInstance)11 ClientConfig (com.hazelcast.client.config.ClientConfig)8 ClassDefinitionBuilder (com.hazelcast.nio.serialization.ClassDefinitionBuilder)7 GenericRecord (com.hazelcast.nio.serialization.GenericRecord)7 ObjectDataInput (com.hazelcast.nio.ObjectDataInput)6 ObjectDataOutput (com.hazelcast.nio.ObjectDataOutput)6 SerializationService (com.hazelcast.spi.serialization.SerializationService)6 ExternalizableEmployeeDTO (example.serialization.ExternalizableEmployeeDTO)6 Config (com.hazelcast.config.Config)5