Search in sources :

Example 16 with InternalSerializationService

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

the class DataInputOutputTest method testDataStreams.

private void testDataStreams(Object object, ByteOrder byteOrder, boolean allowUnsafe) throws IOException {
    InternalSerializationService ss = createSerializationServiceBuilder().setUseNativeByteOrder(false).setAllowUnsafe(allowUnsafe).setByteOrder(byteOrder).build();
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    ObjectDataOutput out = createObjectDataOutputStream(bout, ss);
    out.writeObject(object);
    byte[] data1 = bout.toByteArray();
    ObjectDataOutput out2 = ss.createObjectDataOutput(1024);
    out2.writeObject(object);
    byte[] data2 = out2.toByteArray();
    assertEquals(data1.length, data2.length);
    assertTrue(Arrays.equals(data1, data2));
    final ByteArrayInputStream bin = new ByteArrayInputStream(data2);
    final ObjectDataInput in = createObjectDataInputStream(bin, ss);
    final Object object1 = in.readObject();
    final ObjectDataInput in2 = ss.createObjectDataInput(data1);
    final Object object2 = in2.readObject();
    Assert.assertEquals(object, object1);
    Assert.assertEquals(object, object2);
}
Also used : ObjectDataOutput(com.hazelcast.nio.ObjectDataOutput) ByteArrayInputStream(java.io.ByteArrayInputStream) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectDataInput(com.hazelcast.nio.ObjectDataInput)

Example 17 with InternalSerializationService

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

the class PortableClassVersionTest method testPreDefinedDifferentVersionsWithNullInnerPortable.

@Test
public void testPreDefinedDifferentVersionsWithNullInnerPortable() {
    InternalSerializationService serializationService = createSerializationService(1);
    serializationService.getPortableContext().registerClassDefinition(createInnerPortableClassDefinition(1));
    InternalSerializationService serializationService2 = createSerializationService(2);
    serializationService2.getPortableContext().registerClassDefinition(createInnerPortableClassDefinition(2));
    MainPortable mainWithNullInner = new MainPortable((byte) 113, true, 'x', (short) -500, 56789, -50992225L, 900.5678f, -897543.3678909d, "this is main portable object created for testing!", null);
    testPreDefinedDifferentVersions(serializationService, serializationService2, mainWithNullInner);
}
Also used : InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 18 with InternalSerializationService

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

the class PortableClassVersionTest method testPreDefinedDifferentVersionsWithInnerPortable.

@Test
public void testPreDefinedDifferentVersionsWithInnerPortable() {
    InternalSerializationService serializationService = createSerializationService(1);
    serializationService.getPortableContext().registerClassDefinition(createInnerPortableClassDefinition(1));
    InternalSerializationService serializationService2 = createSerializationService(2);
    serializationService2.getPortableContext().registerClassDefinition(createInnerPortableClassDefinition(2));
    NamedPortable[] nn = new NamedPortable[1];
    nn[0] = new NamedPortable("name", 123);
    InnerPortable inner = new InnerPortable(new byte[] { 0, 1, 2 }, new char[] { 'c', 'h', 'a', 'r' }, new short[] { 3, 4, 5 }, new int[] { 9, 8, 7, 6 }, new long[] { 0, 1, 5, 7, 9, 11 }, new float[] { 0.6543f, -3.56f, 45.67f }, new double[] { 456.456, 789.789, 321.321 }, nn);
    MainPortable mainWithInner = new MainPortable((byte) 113, true, 'x', (short) -500, 56789, -50992225L, 900.5678f, -897543.3678909d, "this is main portable object created for testing!", inner);
    testPreDefinedDifferentVersions(serializationService, serializationService2, mainWithInner);
}
Also used : InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 19 with InternalSerializationService

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

the class PortableTest method testRawDataInvalidRead.

@Test(expected = HazelcastSerializationException.class)
public void testRawDataInvalidRead() {
    int portableVersion = 1;
    final InternalSerializationService serializationService = createSerializationService(1);
    RawDataPortable p = new InvalidRawDataPortable2(System.currentTimeMillis(), "test chars".toCharArray(), new NamedPortable("named portable", 34567), 9876, "Testing raw portable", new ByteArrayDataSerializable("test bytes".getBytes()));
    ClassDefinitionBuilder builder = new ClassDefinitionBuilder(p.getFactoryId(), p.getClassId(), portableVersion);
    builder.addLongField("l").addCharArrayField("c").addPortableField("p", createNamedPortableClassDefinition(portableVersion));
    serializationService.getPortableContext().registerClassDefinition(builder.build());
    final Data data = serializationService.toData(p);
    assertEquals(p, serializationService.toObject(data));
}
Also used : InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 20 with InternalSerializationService

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

the class CollectionTxnUtilTest method testWriteRead.

@Test
public void testWriteRead() throws IOException {
    InternalSerializationService ss = new DefaultSerializationServiceBuilder().build();
    BufferObjectDataOutput out = ss.createObjectDataOutput();
    CollectionTxnUtil.write(out, operationList);
    BufferObjectDataInput in = ss.createObjectDataInput(out.toByteArray());
    List<Operation> resultList = CollectionTxnUtil.read(in);
    assertEquals(operationList.size(), resultList.size());
    for (int i = 0; i < operationList.size(); i++) {
        assertEquals(operationList.get(i), resultList.get(i));
    }
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) BufferObjectDataOutput(com.hazelcast.nio.BufferObjectDataOutput) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) BackupAwareOperation(com.hazelcast.spi.BackupAwareOperation) Operation(com.hazelcast.spi.Operation) BufferObjectDataInput(com.hazelcast.nio.BufferObjectDataInput) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)38 QuickTest (com.hazelcast.test.annotation.QuickTest)15 Test (org.junit.Test)15 Data (com.hazelcast.nio.serialization.Data)14 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)12 Map (java.util.Map)6 CachedQueryEntry (com.hazelcast.query.impl.CachedQueryEntry)5 IMap (com.hazelcast.core.IMap)4 QueryCacheRecord (com.hazelcast.map.impl.querycache.subscriber.record.QueryCacheRecord)4 SerializationService (com.hazelcast.spi.serialization.SerializationService)4 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)3 QueryEntry (com.hazelcast.query.impl.QueryEntry)3 QueryableEntry (com.hazelcast.query.impl.QueryableEntry)3 SerializationConfig (com.hazelcast.config.SerializationConfig)2 PartitioningStrategy (com.hazelcast.core.PartitioningStrategy)2 TransactionalMap (com.hazelcast.core.TransactionalMap)2 NearCacheRecord (com.hazelcast.internal.nearcache.NearCacheRecord)2 DefaultNearCache (com.hazelcast.internal.nearcache.impl.DefaultNearCache)2 AbstractNearCacheRecordStore (com.hazelcast.internal.nearcache.impl.store.AbstractNearCacheRecordStore)2 SerializationServiceBuilder (com.hazelcast.internal.serialization.SerializationServiceBuilder)2