Search in sources :

Example 86 with SerializationService

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

the class NearCachePreloaderConfigTest method testSerialization.

@Test
public void testSerialization() {
    config.setEnabled(true);
    config.setDirectory("myParentDirectory");
    config.setStoreInitialDelaySeconds(23);
    config.setStoreIntervalSeconds(42);
    SerializationService serializationService = new DefaultSerializationServiceBuilder().build();
    Data serialized = serializationService.toData(config);
    NearCachePreloaderConfig deserialized = serializationService.toObject(serialized);
    assertEquals(config.isEnabled(), deserialized.isEnabled());
    assertEquals(config.getDirectory(), deserialized.getDirectory());
    assertEquals(config.getStoreInitialDelaySeconds(), deserialized.getStoreInitialDelaySeconds());
    assertEquals(config.getStoreIntervalSeconds(), deserialized.getStoreIntervalSeconds());
    assertEquals(config.toString(), deserialized.toString());
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 87 with SerializationService

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

the class CustomSerializationOverrideDefaultTest method testUsageOfEmbeddedSerializer.

private void testUsageOfEmbeddedSerializer(final boolean allowOverride) {
    final SerializationConfig config = new SerializationConfig().setAllowOverrideDefaultSerializers(allowOverride);
    final SerializationService ss = new DefaultSerializationServiceBuilder().setConfig(config).build();
    final Optional<Integer> answer = Optional.of(42);
    final Data d = ss.toData(answer);
    assertEquals(OPTIONAL_INTEGER_SIZE, d.dataSize());
    final Optional<Integer> deserializedAnswer = ss.toObject(d);
    assertEquals(answer, deserializedAnswer);
}
Also used : SerializationConfig(com.hazelcast.config.SerializationConfig) SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data)

Example 88 with SerializationService

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

the class CustomSerializationOverrideDefaultTest method testUsageOfCustomSerializer.

private void testUsageOfCustomSerializer(final boolean allowOverrideDefaultSerializers) {
    final SerializationConfig config = new SerializationConfig().setAllowOverrideDefaultSerializers(allowOverrideDefaultSerializers);
    final SerializerConfig sc = new SerializerConfig().setImplementation(new TestOptionalSerializer()).setTypeClass(Optional.class);
    config.addSerializerConfig(sc);
    final SerializationService ss = new DefaultSerializationServiceBuilder().setConfig(config).build();
    final Optional<Integer> answer = Optional.of(42);
    final Data d = ss.toData(answer);
    // string Optional[Integer.MAX_VALUE] from TestOptionalSerializer
    assertNotEquals(OPTIONAL_INTEGER_SIZE, d.dataSize());
    final Optional<Integer> deserializedAnswer = ss.toObject(d);
    assertEquals(Optional.of(Integer.MAX_VALUE), deserializedAnswer);
}
Also used : SerializerConfig(com.hazelcast.config.SerializerConfig) SerializationConfig(com.hazelcast.config.SerializationConfig) SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data)

Example 89 with SerializationService

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

the class CompressionTest method testCompression_externalizable.

@Test
public void testCompression_externalizable() {
    DefaultSerializationServiceBuilder defaultSerializationServiceBuilder = new DefaultSerializationServiceBuilder();
    SerializationService ss = defaultSerializationServiceBuilder.setEnableCompression(true).build();
    SampleExternalizable expected = new SampleExternalizable(5);
    Data data = ss.toData(expected);
    SampleExternalizable result = ss.toObject(data);
    assertEquals(expected, result);
}
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 90 with SerializationService

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

the class CompressionTest method testCompression_serializable.

@Test
public void testCompression_serializable() {
    DefaultSerializationServiceBuilder defaultSerializationServiceBuilder = new DefaultSerializationServiceBuilder();
    SerializationService ss = defaultSerializationServiceBuilder.setEnableCompression(true).build();
    SampleSerializable expected = new SampleSerializable(5);
    Data data = ss.toData(expected);
    SampleSerializable result = ss.toObject(data);
    assertEquals(expected, result);
}
Also used : SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data) 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