Search in sources :

Example 81 with DefaultSerializationServiceBuilder

use of com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder in project hazelcast by hazelcast.

the class DefaultPortableReaderQuickTest method reader.

// 
// 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();
    ss.toData(NON_EMPTY_PORSCHE);
    return new GenericRecordQueryReader(ss.readAsInternalGenericRecord(ss.toData(portable)));
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) SerializationConfig(com.hazelcast.config.SerializationConfig) GenericRecordQueryReader(com.hazelcast.internal.serialization.impl.GenericRecordQueryReader) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService)

Example 82 with DefaultSerializationServiceBuilder

use of com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder in project hazelcast by hazelcast.

the class PortableTest method test_1096_ByteArrayContentSame.

// https://github.com/hazelcast/hazelcast/issues/1096
@Test
public void test_1096_ByteArrayContentSame() {
    SerializationService ss = new DefaultSerializationServiceBuilder().addPortableFactory(PORTABLE_FACTORY_ID, new TestPortableFactory()).build();
    assertRepeatedSerialisationGivesSameByteArrays(ss, new NamedPortable("issue-1096", 1096));
    assertRepeatedSerialisationGivesSameByteArrays(ss, new InnerPortable(new byte[] { 0, 1, 2 }, new char[] { 'c', 'h', 'a', 'r' }, new short[] { 3, 4, 5 }, new int[] { 9, 8, 7, 6 }, new long[] { 0, 1, 5, 7, 9, 11 }, new float[] { 0.6543f, -3.56f, 45.67f }, new double[] { 456.456, 789.789, 321.321 }, new NamedPortable[] { new NamedPortable("issue-1096", 1096) }, new BigDecimal[] { new BigDecimal("12345"), new BigDecimal("123456") }, new LocalTime[] { LocalTime.now(), LocalTime.now() }, new LocalDate[] { LocalDate.now(), LocalDate.now() }, new LocalDateTime[] { LocalDateTime.now() }, new OffsetDateTime[] { OffsetDateTime.now() }));
    assertRepeatedSerialisationGivesSameByteArrays(ss, new RawDataPortable(1096L, "issue-1096".toCharArray(), new NamedPortable("issue-1096", 1096), 1096, "issue-1096", new ByteArrayDataSerializable(new byte[1])));
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) LocalDateTime(java.time.LocalDateTime) LocalTime(java.time.LocalTime) OffsetDateTime(java.time.OffsetDateTime) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) SerializationService(com.hazelcast.internal.serialization.SerializationService) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) QuickTest(com.hazelcast.test.annotation.QuickTest) CustomSerializationTest(com.hazelcast.internal.serialization.impl.CustomSerializationTest) Test(org.junit.Test)

Example 83 with DefaultSerializationServiceBuilder

use of com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder in project hazelcast by hazelcast.

the class PortableTest method testGenericPortable_whenMultipleTypesAreUsed.

@Test(expected = HazelcastSerializationException.class)
public void testGenericPortable_whenMultipleTypesAreUsed() {
    SerializationService ss = new DefaultSerializationServiceBuilder().addPortableFactory(1, new PortableFactory() {

        @Override
        public Portable create(int classId) {
            switch(classId) {
                case ParentGenericPortable.CLASS_ID:
                    return new ParentGenericPortable();
                case ChildGenericPortable1.CLASS_ID:
                    return new ChildGenericPortable1();
                case ChildGenericPortable2.CLASS_ID:
                    return new ChildGenericPortable2();
                default:
                    throw new IllegalArgumentException();
            }
        }
    }).build();
    ss.toData(new ParentGenericPortable<ChildGenericPortable1>(new ChildGenericPortable1("aaa", "bbb")));
    Data data = ss.toData(new ParentGenericPortable<ChildGenericPortable2>(new ChildGenericPortable2("ccc")));
    ss.toObject(data);
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data) PortableFactory(com.hazelcast.nio.serialization.PortableFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) CustomSerializationTest(com.hazelcast.internal.serialization.impl.CustomSerializationTest) Test(org.junit.Test)

Example 84 with DefaultSerializationServiceBuilder

use of com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder in project hazelcast by hazelcast.

the class PortableTest method testWriteRead_withNullPortableArray.

@Test
public void testWriteRead_withNullPortableArray() {
    int portableVersion = 1;
    ClassDefinitionBuilder builder0 = new ClassDefinitionBuilder(PORTABLE_FACTORY_ID, 1, portableVersion);
    ClassDefinitionBuilder builder1 = new ClassDefinitionBuilder(PORTABLE_FACTORY_ID, 2, portableVersion);
    builder0.addPortableArrayField("list", builder1.build());
    SerializationService ss = new DefaultSerializationServiceBuilder().setPortableVersion(portableVersion).addClassDefinition(builder0.build()).addClassDefinition(builder1.build()).build();
    Data data = ss.toData(new TestObject1());
    SerializationService ss2 = new DefaultSerializationServiceBuilder().addPortableFactory(1, new PortableFactory() {

        @Override
        public Portable create(int classId) {
            switch(classId) {
                case 1:
                    return new TestObject1();
                case 2:
                    return new TestObject2();
                default:
                    return null;
            }
        }
    }).build();
    Object object = ss2.toObject(data);
    assertNotNull(object);
    assertTrue(object instanceof TestObject1);
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data) PortableFactory(com.hazelcast.nio.serialization.PortableFactory) ClassDefinitionBuilder(com.hazelcast.nio.serialization.ClassDefinitionBuilder) QuickTest(com.hazelcast.test.annotation.QuickTest) CustomSerializationTest(com.hazelcast.internal.serialization.impl.CustomSerializationTest) Test(org.junit.Test)

Example 85 with DefaultSerializationServiceBuilder

use of com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder in project hazelcast by hazelcast.

the class PortableTest method testWriteObjectWithCustomSerializable.

@Test
public void testWriteObjectWithCustomSerializable() {
    SerializationConfig config = new SerializationConfig();
    SerializerConfig sc = new SerializerConfig().setImplementation(new CustomSerializationTest.FooXmlSerializer()).setTypeClass(CustomSerializationTest.Foo.class);
    config.addSerializerConfig(sc);
    SerializationService serializationService = new DefaultSerializationServiceBuilder().setPortableVersion(1).addPortableFactory(PORTABLE_FACTORY_ID, new TestPortableFactory()).setConfig(config).build();
    CustomSerializationTest.Foo foo = new CustomSerializationTest.Foo("f");
    ObjectCarryingPortable objectCarryingPortable1 = new ObjectCarryingPortable(foo);
    Data data = serializationService.toData(objectCarryingPortable1);
    ObjectCarryingPortable objectCarryingPortable2 = serializationService.toObject(data);
    assertEquals(objectCarryingPortable1, objectCarryingPortable2);
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) SerializerConfig(com.hazelcast.config.SerializerConfig) SerializationConfig(com.hazelcast.config.SerializationConfig) CustomSerializationTest(com.hazelcast.internal.serialization.impl.CustomSerializationTest) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data) QuickTest(com.hazelcast.test.annotation.QuickTest) CustomSerializationTest(com.hazelcast.internal.serialization.impl.CustomSerializationTest) Test(org.junit.Test)

Aggregations

DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)197 Test (org.junit.Test)146 QuickTest (com.hazelcast.test.annotation.QuickTest)119 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)91 Data (com.hazelcast.internal.serialization.Data)56 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)56 SerializationService (com.hazelcast.internal.serialization.SerializationService)50 SerializationService (com.hazelcast.spi.serialization.SerializationService)40 SerializationConfig (com.hazelcast.config.SerializationConfig)36 Before (org.junit.Before)22 ClassDefinitionBuilder (com.hazelcast.nio.serialization.ClassDefinitionBuilder)20 HeapData (com.hazelcast.internal.serialization.impl.HeapData)18 ClassDefinition (com.hazelcast.nio.serialization.ClassDefinition)16 CompactSerializationConfig (com.hazelcast.config.CompactSerializationConfig)15 CustomSerializationTest (com.hazelcast.internal.serialization.impl.CustomSerializationTest)14 ParallelTest (com.hazelcast.test.annotation.ParallelTest)13 Parameters (junitparams.Parameters)13 ArrayList (java.util.ArrayList)12 PortableFactory (com.hazelcast.nio.serialization.PortableFactory)10 SerializationServiceBuilder (com.hazelcast.internal.serialization.SerializationServiceBuilder)9