Search in sources :

Example 46 with SerializationService

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

the class SerializationTest method testInternallySupportedClassExtended.

@Test
public void testInternallySupportedClassExtended() {
    SerializationService ss = new DefaultSerializationServiceBuilder().build();
    TheClassThatExtendArrayList obj = new TheClassThatExtendArrayList();
    Data data = ss.toData(obj);
    Object obj2 = ss.toObject(data);
    assertEquals(obj2.getClass(), TheClassThatExtendArrayList.class);
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) SerializationService(com.hazelcast.spi.serialization.SerializationService) HeapData(com.hazelcast.internal.serialization.impl.HeapData) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 47 with SerializationService

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

the class SerializationTest method testVersionedDataSerializable_inputHasUnknownVersion.

@Test
public void testVersionedDataSerializable_inputHasUnknownVersion() {
    SerializationService ss = new DefaultSerializationServiceBuilder().build();
    VersionedDataSerializable object = new VersionedDataSerializable();
    VersionedDataSerializable otherObject = ss.toObject(ss.toData(object));
    assertEquals("ObjectDataInput.getVersion should be UNKNOWN", Version.UNKNOWN, otherObject.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 48 with SerializationService

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

the class SerializationTest method testUnsharedJavaSerialization.

/**
     * issue #1265
     */
@Test
public void testUnsharedJavaSerialization() {
    SerializationService ss = new DefaultSerializationServiceBuilder().setEnableSharedObject(false).build();
    Data data = ss.toData(new Foo());
    Foo foo = ss.toObject(data);
    Assert.assertFalse("Objects should not be identical!", foo == foo.getBar().getFoo());
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) SerializationService(com.hazelcast.spi.serialization.SerializationService) HeapData(com.hazelcast.internal.serialization.impl.HeapData) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 49 with SerializationService

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

the class SerializationTest method testArraySerialization.

@Test
public void testArraySerialization() {
    SerializationService ss = new DefaultSerializationServiceBuilder().build();
    byte[] array = new byte[1024];
    new Random().nextBytes(array);
    Data data = ss.toData(array);
    byte[] deserialized = ss.toObject(data);
    assertArrayEquals(array, deserialized);
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) Random(java.util.Random) SerializationService(com.hazelcast.spi.serialization.SerializationService) HeapData(com.hazelcast.internal.serialization.impl.HeapData) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 50 with SerializationService

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

the class SerializationTest method testGlobalSerializer_withOverrideJavaSerializable.

@Test
public void testGlobalSerializer_withOverrideJavaSerializable() {
    GlobalSerializerConfig globalSerializerConfig = new GlobalSerializerConfig();
    globalSerializerConfig.setOverrideJavaSerialization(true);
    final AtomicInteger writeCounter = new AtomicInteger();
    final AtomicInteger readCounter = new AtomicInteger();
    final JavaSerializer javaSerializer = new JavaSerializer(true, false);
    SerializationConfig serializationConfig = new SerializationConfig().setGlobalSerializerConfig(globalSerializerConfig.setImplementation(new StreamSerializer<Object>() {

        @Override
        public void write(ObjectDataOutput out, Object v) throws IOException {
            writeCounter.incrementAndGet();
            if (v instanceof Serializable) {
                out.writeBoolean(true);
                javaSerializer.write(out, v);
            } else if (v instanceof DummyValue) {
                out.writeBoolean(false);
                out.writeUTF(((DummyValue) v).s);
                out.writeInt(((DummyValue) v).k);
            }
        }

        @Override
        public Object read(ObjectDataInput in) throws IOException {
            readCounter.incrementAndGet();
            boolean java = in.readBoolean();
            if (java) {
                return javaSerializer.read(in);
            }
            return new DummyValue(in.readUTF(), in.readInt());
        }

        public int getTypeId() {
            return 123;
        }

        public void destroy() {
        }
    }));
    SerializationService ss1 = new DefaultSerializationServiceBuilder().setConfig(serializationConfig).build();
    DummyValue value = new DummyValue("test", 111);
    Data data1 = ss1.toData(value);
    Data data2 = ss1.toData(new Foo());
    Assert.assertNotNull(data1);
    Assert.assertNotNull(data2);
    assertEquals(2, writeCounter.get());
    SerializationService ss2 = new DefaultSerializationServiceBuilder().setConfig(serializationConfig).build();
    Object o1 = ss2.toObject(data1);
    Object o2 = ss2.toObject(data2);
    Assert.assertEquals(value, o1);
    Assert.assertNotNull(o2);
    assertEquals(2, readCounter.get());
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) ObjectDataOutput(com.hazelcast.nio.ObjectDataOutput) Serializable(java.io.Serializable) SerializationConfig(com.hazelcast.config.SerializationConfig) SerializationService(com.hazelcast.spi.serialization.SerializationService) HeapData(com.hazelcast.internal.serialization.impl.HeapData) GlobalSerializerConfig(com.hazelcast.config.GlobalSerializerConfig) JavaSerializer(com.hazelcast.internal.serialization.impl.JavaDefaultSerializers.JavaSerializer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ObjectDataInput(com.hazelcast.nio.ObjectDataInput) 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