use of com.hazelcast.nio.BufferObjectDataInput 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.BufferObjectDataInput 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());
}
use of com.hazelcast.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.nio.BufferObjectDataInput in project hazelcast by hazelcast.
the class BufferPoolTest method takeInputBuffer_whenNestedInstance.
@Test
public void takeInputBuffer_whenNestedInstance() {
Data data = new HeapData(new byte[] {});
BufferObjectDataInput found1 = bufferPool.takeInputBuffer(data);
BufferObjectDataInput found2 = bufferPool.takeInputBuffer(data);
assertNotSame(found1, found2);
}
use of com.hazelcast.nio.BufferObjectDataInput in project hazelcast by hazelcast.
the class BufferPoolTest method returnInputBuffer_whenOverflowing.
@Test
public void returnInputBuffer_whenOverflowing() throws IOException {
for (int k = 0; k < BufferPoolImpl.MAX_POOLED_ITEMS; k++) {
bufferPool.returnInputBuffer(mock(BufferObjectDataInput.class));
}
BufferObjectDataInput in = mock(BufferObjectDataInput.class);
bufferPool.returnInputBuffer(in);
assertEquals(BufferPoolImpl.MAX_POOLED_ITEMS, bufferPool.inputQueue.size());
// we need to make sure that the in was closed since we are not going to pool it.
verify(in, times(1)).close();
}
Aggregations