Search in sources :

Example 51 with SerializationService

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

the class SerializationIssueTest method testCompressionOnExternalizables.

/**
 * Ensures that SerializationService correctly handles compressed Serializables,
 * using a test-specific object as a test case.
 */
@Test
public void testCompressionOnExternalizables() {
    SerializationService serializationService = new DefaultSerializationServiceBuilder().setEnableCompression(true).build();
    String test = "test";
    ExternalizableString ex = new ExternalizableString(test);
    Data data = serializationService.toData(ex);
    ExternalizableString actual = serializationService.toObject(data);
    assertEquals(test, actual.value);
}
Also used : SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 52 with SerializationService

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

the class SerializationIssueTest method testEmptyData.

@Test
public void testEmptyData() {
    SerializationConfig serializationConfig = new SerializationConfig().addSerializerConfig(new SerializerConfig().setTypeClass(SingletonValue.class).setImplementation(new StreamSerializer<SingletonValue>() {

        @Override
        public void write(ObjectDataOutput out, SingletonValue v) throws IOException {
        }

        @Override
        public SingletonValue read(ObjectDataInput in) throws IOException {
            return new SingletonValue();
        }

        @Override
        public int getTypeId() {
            return 123;
        }

        @Override
        public void destroy() {
        }
    }));
    SerializationService ss1 = new DefaultSerializationServiceBuilder().setConfig(serializationConfig).build();
    Data data = ss1.toData(new SingletonValue());
    Assert.assertNotNull(data);
    SerializationService ss2 = new DefaultSerializationServiceBuilder().setConfig(serializationConfig).build();
    Object o = ss2.toObject(data);
    Assert.assertEquals(new SingletonValue(), o);
}
Also used : GlobalSerializerConfig(com.hazelcast.config.GlobalSerializerConfig) SerializerConfig(com.hazelcast.config.SerializerConfig) ObjectDataOutput(com.hazelcast.nio.ObjectDataOutput) SerializationConfig(com.hazelcast.config.SerializationConfig) SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data) StreamSerializer(com.hazelcast.nio.serialization.StreamSerializer) ObjectDataInput(com.hazelcast.nio.ObjectDataInput) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 53 with SerializationService

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

the class SerializationIssueTest 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 : SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 54 with SerializationService

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

the class SerializationIssueTest method testCompressionOnSerializables.

/**
 * Ensures that SerializationService correctly handles compressed Serializables,
 * using a Properties object as a test case.
 */
@Test
public void testCompressionOnSerializables() {
    SerializationService serializationService = new DefaultSerializationServiceBuilder().setEnableCompression(true).build();
    long key = 1;
    long value = 5000;
    Properties properties = new Properties();
    properties.put(key, value);
    Data data = serializationService.toData(properties);
    Properties output = serializationService.toObject(data);
    assertEquals(value, output.get(key));
}
Also used : SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data) Properties(java.util.Properties) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 55 with SerializationService

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

the class GenericRecordTest method testCloneObjectConvertedFromData.

@Test
public void testCloneObjectConvertedFromData() {
    SerializationService serializationService = createSerializationService();
    GenericRecordBuilder builder = compact("fooBarTypeName");
    builder.setInt32("foo", 1);
    assertTrue(trySetAndGetMessage("foo", 5, builder).startsWith("Field can only be written once"));
    builder.setInt64("bar", 1231L);
    GenericRecord expectedGenericRecord = builder.build();
    Data data = serializationService.toData(expectedGenericRecord);
    Object object = serializationService.toObject(data);
    GenericRecord genericRecord = (GenericRecord) object;
    GenericRecordBuilder cloneBuilder = genericRecord.cloneWithBuilder();
    cloneBuilder.setInt32("foo", 2);
    assertTrue(trySetAndGetMessage("foo", 5, cloneBuilder).startsWith("Field can only be written once"));
    assertTrue(trySetAndGetMessage("notExisting", 3, cloneBuilder).startsWith("Invalid field name"));
    GenericRecord clone = cloneBuilder.build();
    assertEquals(2, clone.getInt32("foo"));
    assertEquals(1231L, clone.getInt64("bar"));
}
Also used : InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) SerializationService(com.hazelcast.internal.serialization.SerializationService) GenericRecordBuilder(com.hazelcast.nio.serialization.GenericRecordBuilder) Data(com.hazelcast.internal.serialization.Data) InternalGenericRecord(com.hazelcast.internal.serialization.impl.InternalGenericRecord) GenericRecord(com.hazelcast.nio.serialization.GenericRecord) CompactTestUtil.createCompactGenericRecord(com.hazelcast.internal.serialization.impl.compact.CompactTestUtil.createCompactGenericRecord) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

SerializationService (com.hazelcast.internal.serialization.SerializationService)170 Data (com.hazelcast.internal.serialization.Data)117 Test (org.junit.Test)100 QuickTest (com.hazelcast.test.annotation.QuickTest)99 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)59 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)50 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)43 ArrayList (java.util.ArrayList)15 SerializationConfig (com.hazelcast.config.SerializationConfig)14 HazelcastInstance (com.hazelcast.core.HazelcastInstance)13 Node (com.hazelcast.instance.impl.Node)12 CustomSerializationTest (com.hazelcast.internal.serialization.impl.CustomSerializationTest)12 Accessors.getNode (com.hazelcast.test.Accessors.getNode)12 GenericRecord (com.hazelcast.nio.serialization.GenericRecord)11 EmployeeDTO (example.serialization.EmployeeDTO)11 ExternalizableEmployeeDTO (example.serialization.ExternalizableEmployeeDTO)11 PortableFactory (com.hazelcast.nio.serialization.PortableFactory)8 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)8 HashMap (java.util.HashMap)8 Map (java.util.Map)8