Search in sources :

Example 36 with SerializationService

use of com.hazelcast.spi.serialization.SerializationService 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) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) SerializationService(com.hazelcast.spi.serialization.SerializationService) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 37 with SerializationService

use of com.hazelcast.spi.serialization.SerializationService 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[3], new char[5], new short[2], new int[10], new long[7], new float[9], new double[1], new NamedPortable[] { new NamedPortable("issue-1096", 1096) }));
    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) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) SerializationService(com.hazelcast.spi.serialization.SerializationService) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 38 with SerializationService

use of com.hazelcast.spi.serialization.SerializationService in project hazelcast by hazelcast.

the class SerializationTest method testVersionedDataSerializable_outputHasUnknownVersion.

@Test
public void testVersionedDataSerializable_outputHasUnknownVersion() {
    SerializationService ss = new DefaultSerializationServiceBuilder().build();
    VersionedDataSerializable object = new VersionedDataSerializable();
    ss.toData(object);
    assertEquals("ObjectDataOutput.getVersion should be UNKNOWN", Version.UNKNOWN, object.getVersion());
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) SerializationService(com.hazelcast.spi.serialization.SerializationService) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 39 with SerializationService

use of com.hazelcast.spi.serialization.SerializationService in project hazelcast by hazelcast.

the class CustomSerializationTest method testSerializer.

private void testSerializer(ByteOrder order, boolean allowUnsafe) throws Exception {
    SerializationConfig config = new SerializationConfig();
    config.setAllowUnsafe(allowUnsafe).setByteOrder(order).setUseNativeByteOrder(false);
    SerializerConfig sc = new SerializerConfig().setImplementation(new FooXmlSerializer()).setTypeClass(Foo.class);
    config.addSerializerConfig(sc);
    SerializationService ss = new DefaultSerializationServiceBuilder().setConfig(config).build();
    Foo foo = new Foo("f");
    Data d = ss.toData(foo);
    Foo newFoo = ss.toObject(d);
    assertEquals(newFoo, foo);
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) SerializerConfig(com.hazelcast.config.SerializerConfig) SerializationConfig(com.hazelcast.config.SerializationConfig) SerializationService(com.hazelcast.spi.serialization.SerializationService)

Example 40 with SerializationService

use of com.hazelcast.spi.serialization.SerializationService in project hazelcast by hazelcast.

the class PortableClassVersionTest method testDifferentClassVersions.

@Test
public void testDifferentClassVersions() {
    SerializationService serializationService = new DefaultSerializationServiceBuilder().addPortableFactory(FACTORY_ID, new PortableFactory() {

        public Portable create(int classId) {
            return new NamedPortable();
        }
    }).build();
    SerializationService serializationService2 = new DefaultSerializationServiceBuilder().addPortableFactory(FACTORY_ID, new PortableFactory() {

        public Portable create(int classId) {
            return new NamedPortableV2();
        }
    }).build();
    testDifferentClassVersions(serializationService, serializationService2);
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) PortableTest.createSerializationService(com.hazelcast.nio.serialization.PortableTest.createSerializationService) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) SerializationService(com.hazelcast.spi.serialization.SerializationService) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

SerializationService (com.hazelcast.spi.serialization.SerializationService)120 Test (org.junit.Test)59 QuickTest (com.hazelcast.test.annotation.QuickTest)56 Data (com.hazelcast.nio.serialization.Data)54 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)46 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)28 ParallelTest (com.hazelcast.test.annotation.ParallelTest)22 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)18 HeapData (com.hazelcast.internal.serialization.impl.HeapData)17 Map (java.util.Map)15 ArrayList (java.util.ArrayList)12 HashMap (java.util.HashMap)10 ClientInvocationFuture (com.hazelcast.client.spi.impl.ClientInvocationFuture)9 ClientDelegatingFuture (com.hazelcast.client.util.ClientDelegatingFuture)8 Node (com.hazelcast.instance.Node)7 SerializationConfig (com.hazelcast.config.SerializationConfig)6 ICacheService (com.hazelcast.cache.impl.ICacheService)5 ClientInvocation (com.hazelcast.client.spi.impl.ClientInvocation)5 Record (com.hazelcast.map.impl.record.Record)5 ICacheRecordStore (com.hazelcast.cache.impl.ICacheRecordStore)3