Search in sources :

Example 26 with DefaultSerializationServiceBuilder

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

the class SerializationTest method testPartitionHash.

@Test
public void testPartitionHash() {
    PartitioningStrategy partitionStrategy = new PartitioningStrategy() {

        @Override
        public Object getPartitionKey(Object key) {
            return key.hashCode();
        }
    };
    SerializationService ss = new DefaultSerializationServiceBuilder().build();
    String obj = String.valueOf(System.nanoTime());
    Data dataWithPartitionHash = ss.toData(obj, partitionStrategy);
    Data dataWithOutPartitionHash = ss.toData(obj);
    assertTrue(dataWithPartitionHash.hasPartitionHash());
    assertNotEquals(dataWithPartitionHash.hashCode(), dataWithPartitionHash.getPartitionHash());
    assertFalse(dataWithOutPartitionHash.hasPartitionHash());
    assertEquals(dataWithOutPartitionHash.hashCode(), dataWithOutPartitionHash.getPartitionHash());
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) PartitioningStrategy(com.hazelcast.core.PartitioningStrategy) SerializationService(com.hazelcast.spi.serialization.SerializationService) HeapData(com.hazelcast.internal.serialization.impl.HeapData) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 27 with DefaultSerializationServiceBuilder

use of com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder 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 28 with DefaultSerializationServiceBuilder

use of com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder 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 29 with DefaultSerializationServiceBuilder

use of com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder 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 30 with DefaultSerializationServiceBuilder

use of com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder 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)

Aggregations

DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)70 Test (org.junit.Test)56 QuickTest (com.hazelcast.test.annotation.QuickTest)55 SerializationService (com.hazelcast.spi.serialization.SerializationService)46 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)22 ParallelTest (com.hazelcast.test.annotation.ParallelTest)18 HeapData (com.hazelcast.internal.serialization.impl.HeapData)16 Data (com.hazelcast.nio.serialization.Data)15 SerializationConfig (com.hazelcast.config.SerializationConfig)11 SerializationServiceBuilder (com.hazelcast.internal.serialization.SerializationServiceBuilder)6 ArrayList (java.util.ArrayList)6 SerializerConfig (com.hazelcast.config.SerializerConfig)5 Before (org.junit.Before)5 PartitioningStrategy (com.hazelcast.core.PartitioningStrategy)4 Config (com.hazelcast.config.Config)3 GlobalSerializerConfig (com.hazelcast.config.GlobalSerializerConfig)3 ObjectDataInput (com.hazelcast.nio.ObjectDataInput)3 ObjectDataOutput (com.hazelcast.nio.ObjectDataOutput)3 HashMap (java.util.HashMap)3 HazelcastThreadGroup (com.hazelcast.instance.HazelcastThreadGroup)2