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);
}
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);
}
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);
}
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));
}
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));
}
}
Aggregations