use of com.hazelcast.internal.nio.BufferObjectDataInput 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);
writeData(out, dataV1);
byte[] bytes = out.toByteArray();
// emulate socket read by reading data from stream
BufferObjectDataInput in = serializationService2.createObjectDataInput(bytes);
dataV1 = readData(in);
// 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.myint, v1FromV2.myint);
NamedPortableV2 v2FromV1 = serializationService2.toObject(dataV1);
assertEquals(portableV1.name, v2FromV1.name);
assertEquals(portableV1.myint, v2FromV1.myint);
assertNull(v2FromV1.v);
}
use of com.hazelcast.internal.nio.BufferObjectDataInput in project hazelcast by hazelcast.
the class GenericRecordBuilderTest method testWriteReadGenericRecordToObjectDataInput.
@Test
public void testWriteReadGenericRecordToObjectDataInput() throws IOException {
ClassDefinitionBuilder classDefinitionBuilder = new ClassDefinitionBuilder(1, 1);
classDefinitionBuilder.addIntField("age");
classDefinitionBuilder.addStringField("name");
ClassDefinition classDefinition = classDefinitionBuilder.build();
InternalSerializationService serializationService = new DefaultSerializationServiceBuilder().build();
BufferObjectDataOutput objectDataOutput = serializationService.createObjectDataOutput();
List<GenericRecord> list = new ArrayList<>();
for (int i = 0; i < 10; i++) {
GenericRecord record = GenericRecordBuilder.portable(classDefinition).setInt32("age", i).setString("name", " " + i).build();
objectDataOutput.writeObject(record);
list.add(record);
}
byte[] bytes = objectDataOutput.toByteArray();
BufferObjectDataInput objectDataInput = serializationService.createObjectDataInput(bytes);
for (int i = 0; i < 10; i++) {
GenericRecord record = objectDataInput.readObject();
assertEquals(list.get(i), record);
}
}
use of com.hazelcast.internal.nio.BufferObjectDataInput in project hazelcast by hazelcast.
the class MorphingPortableReaderTest method before.
@Before
public void before() throws Exception {
service1 = (SerializationServiceV1) new DefaultSerializationServiceBuilder().addPortableFactory(TestSerializationConstants.PORTABLE_FACTORY_ID, new PortableFactory() {
public Portable create(int classId) {
return new MorphingBasePortable();
}
}).build();
service2 = (SerializationServiceV1) new DefaultSerializationServiceBuilder().addPortableFactory(TestSerializationConstants.PORTABLE_FACTORY_ID, new PortableFactory() {
public Portable create(int classId) {
return new MorphingPortable();
}
}).build();
Data data = service1.toData(new MorphingBasePortable((byte) 1, true, (char) 2, (short) 3, 4, 5, 1f, 2d, "test"));
BufferObjectDataInput in = service2.createObjectDataInput(data);
PortableSerializer portableSerializer = service2.getPortableSerializer();
reader = portableSerializer.createMorphingReader(in);
}
use of com.hazelcast.internal.nio.BufferObjectDataInput 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.internal.nio.BufferObjectDataInput in project hazelcast by hazelcast.
the class ReceiverTasklet method tryFillInbox.
private void tryFillInbox() {
try {
long totalBytes = 0;
long totalItems = 0;
for (byte[] payload; (payload = incoming.poll()) != null; ) {
BufferObjectDataInput input = serializationService.createObjectDataInput(payload, PACKET_HEADER_SIZE);
final int itemCount = input.readInt();
for (int i = 0; i < itemCount; i++) {
final int mark = input.position();
final Object item = input.readObject();
final int itemSize = input.position() - mark;
inbox.add(new ObjWithPtionIdAndSize(item, input.readInt(), itemSize));
}
totalItems += itemCount;
totalBytes += input.position();
tracker.madeProgress();
}
bytesInCounter.inc(totalBytes);
itemsInCounter.inc(totalItems);
} catch (IOException e) {
throw rethrow(e);
}
}
Aggregations