use of com.hazelcast.nio.BufferObjectDataOutput in project hazelcast by hazelcast.
the class StringSerializationTest method testNullStringEncodeDecode2.
@Test
public void testNullStringEncodeDecode2() throws Exception {
BufferObjectDataOutput objectDataOutput = serializationService.createObjectDataOutput();
objectDataOutput.writeUTF(null);
byte[] bytes = objectDataOutput.toByteArray();
objectDataOutput.close();
BufferObjectDataInput objectDataInput = serializationService.createObjectDataInput(bytes);
String decodedStr = objectDataInput.readUTF();
assertNull(decodedStr);
}
use of com.hazelcast.nio.BufferObjectDataOutput in project hazelcast by hazelcast.
the class PortableClassVersionTest method testDifferentClassVersionsUsingDataWriteAndRead.
// used in EE, so needs to be package private
static void testDifferentClassVersionsUsingDataWriteAndRead(InternalSerializationService serializationService, InternalSerializationService serializationService2) throws Exception {
NamedPortable portableV1 = new NamedPortable("portable-v1", 111);
Data dataV1 = serializationService.toData(portableV1);
// emulate socket write by writing data to stream
BufferObjectDataOutput out = serializationService.createObjectDataOutput(1024);
out.writeData(dataV1);
byte[] bytes = out.toByteArray();
// emulate socket read by reading data from stream
BufferObjectDataInput in = serializationService2.createObjectDataInput(bytes);
dataV1 = in.readData();
// serialize new portable version
NamedPortableV2 portableV2 = new NamedPortableV2("portable-v2", 123, 500);
Data dataV2 = serializationService2.toData(portableV2);
NamedPortable v1FromV2 = serializationService.toObject(dataV2);
assertEquals(portableV2.name, v1FromV2.name);
assertEquals(portableV2.k, v1FromV2.k);
NamedPortableV2 v2FromV1 = serializationService2.toObject(dataV1);
assertEquals(portableV1.name, v2FromV1.name);
assertEquals(portableV1.k, v2FromV1.k);
assertNull(v2FromV1.v);
}
use of com.hazelcast.nio.BufferObjectDataOutput 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));
}
}
use of com.hazelcast.nio.BufferObjectDataOutput in project hazelcast by hazelcast.
the class RingbufferContainerSerializationTest method clone.
private RingbufferContainer clone(RingbufferContainer original) {
BufferObjectDataOutput out = serializationService.createObjectDataOutput(100000);
BufferObjectDataInput in = null;
try {
out.writeObject(original);
byte[] bytes = out.toByteArray();
sleepMillis(CLOCK_DIFFERENCE_MS);
in = serializationService.createObjectDataInput(bytes);
RingbufferContainer clone = in.readObject();
return clone;
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
closeResource(out);
closeResource(in);
}
}
use of com.hazelcast.nio.BufferObjectDataOutput in project hazelcast by hazelcast.
the class PartitionTableViewTest method test_writeAndReadData.
@Test
public void test_writeAndReadData() throws Exception {
InternalSerializationService serializationService = new DefaultSerializationServiceBuilder().build();
PartitionTableView table1 = createRandomPartitionTable();
BufferObjectDataOutput out = serializationService.createObjectDataOutput();
PartitionTableView.writeData(table1, out);
BufferObjectDataInput in = serializationService.createObjectDataInput(out.toByteArray());
PartitionTableView table2 = PartitionTableView.readData(in);
assertEquals(table1, table2);
assertEquals(table1.hashCode(), table2.hashCode());
}
Aggregations