Search in sources :

Example 91 with SerializationService

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

the class CompressionTest method testCompression_externalizable_withArrayList.

@Test
public void testCompression_externalizable_withArrayList() {
    DefaultSerializationServiceBuilder defaultSerializationServiceBuilder = new DefaultSerializationServiceBuilder();
    SerializationService ss = defaultSerializationServiceBuilder.setEnableCompression(true).build();
    ArrayList<SampleExternalizable> expected = new ArrayList<SampleExternalizable>();
    for (int i = 0; i < 10; i++) {
        expected.add(new SampleExternalizable(i));
    }
    Data data = ss.toData(expected);
    ArrayList<SampleExternalizable> result = ss.toObject(data);
    assertEquals(expected, result);
}
Also used : ArrayList(java.util.ArrayList) SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 92 with SerializationService

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

the class CustomSerializationTest method testSerializer.

private void testSerializer(ByteOrder order, boolean allowUnsafe) {
    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 : SerializerConfig(com.hazelcast.config.SerializerConfig) SerializationConfig(com.hazelcast.config.SerializationConfig) SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data)

Example 93 with SerializationService

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

the class CollectionUtilTest method testObjectToDataCollection_deserializeBack.

@Test
public void testObjectToDataCollection_deserializeBack() {
    SerializationService serializationService = new DefaultSerializationServiceBuilder().build();
    Collection<Object> list = new ArrayList<Object>();
    list.add(1);
    list.add("foo");
    Collection<Data> dataCollection = objectToDataCollection(list, serializationService);
    Iterator<Data> it1 = dataCollection.iterator();
    Iterator it2 = list.iterator();
    while (it1.hasNext() && it2.hasNext()) {
        assertEquals(serializationService.toObject(it1.next()), it2.next());
    }
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) 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 94 with SerializationService

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

the class CollectionUtilTest method testObjectToDataCollection_withNullCollection.

@Test(expected = NullPointerException.class)
public void testObjectToDataCollection_withNullCollection() {
    SerializationService serializationService = new DefaultSerializationServiceBuilder().build();
    objectToDataCollection(null, serializationService);
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) SerializationService(com.hazelcast.internal.serialization.SerializationService) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 95 with SerializationService

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

the class CollectionUtilTest method testObjectToDataCollection_withNullItem.

@Test(expected = NullPointerException.class)
public void testObjectToDataCollection_withNullItem() {
    SerializationService serializationService = new DefaultSerializationServiceBuilder().build();
    Collection<Object> list = new ArrayList<Object>();
    list.add(null);
    objectToDataCollection(list, serializationService);
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) ArrayList(java.util.ArrayList) SerializationService(com.hazelcast.internal.serialization.SerializationService) 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