use of com.hazelcast.internal.nio.Packet in project hazelcast by hazelcast.
the class PacketTest method raiseFlags.
@Test
public void raiseFlags() {
Packet packet = new Packet();
packet.raiseFlags(FLAG_URGENT);
assertEquals(FLAG_4_0 | FLAG_URGENT, packet.getFlags());
}
use of com.hazelcast.internal.nio.Packet in project hazelcast by hazelcast.
the class PacketIOHelperTest method cloningOfPacket.
/**
* Verifies that writing a Packet to a ByteBuffer and then reading it from the ByteBuffer, gives the same Packet (content).
*/
@Test
public void cloningOfPacket() {
Packet originalPacket = new Packet("foobarbaz".getBytes());
ByteBuffer bb = ByteBuffer.allocate(100);
boolean written = packetWriter.writeTo(originalPacket, bb);
assertTrue(written);
upcast(bb).flip();
Packet clonedPacket = packetReader.readFrom(bb);
assertNotNull(clonedPacket);
assertPacketEquals(originalPacket, clonedPacket);
}
use of com.hazelcast.internal.nio.Packet in project hazelcast by hazelcast.
the class PacketIOHelperTest method largeValue.
/**
* Checks if the packet can deal with a buffer that is very small, but the data is very large, which
* needs repeated calls to {@link PacketIOHelper#writeTo(Packet, ByteBuffer)} and
* {@link PacketIOHelper#readFrom(ByteBuffer)}.
*/
@Test
public void largeValue() {
Packet originalPacket = new Packet(generateRandomString(100000).getBytes());
Packet clonedPacket;
ByteBuffer bb = ByteBuffer.allocate(20);
boolean writeCompleted;
do {
writeCompleted = packetWriter.writeTo(originalPacket, bb);
upcast(bb).flip();
clonedPacket = packetReader.readFrom(bb);
upcast(bb).clear();
} while (!writeCompleted);
assertNotNull(clonedPacket);
assertPacketEquals(originalPacket, clonedPacket);
}
use of com.hazelcast.internal.nio.Packet in project hazelcast by hazelcast.
the class PacketIOHelperTest method testPacketWriteRead.
private void testPacketWriteRead(Object originalObject) throws IOException {
InternalSerializationService ss = createSerializationServiceBuilder().build();
byte[] originalPayload = ss.toBytes(originalObject);
ByteBuffer buffer = ByteBuffer.allocate(originalPayload.length * 2);
Packet originalPacket = new Packet(originalPayload);
assertTrue(packetWriter.writeTo(originalPacket, buffer));
upcast(buffer).flip();
SerializationService ss2 = createSerializationServiceBuilder().build();
Packet clonedPacket = packetReader.readFrom(buffer);
assertNotNull(clonedPacket);
Object clonedObject = ss2.toObject(clonedPacket);
assertEquals(originalPacket, clonedPacket);
assertEquals(originalObject, clonedObject);
}
use of com.hazelcast.internal.nio.Packet in project hazelcast by hazelcast.
the class OperationThreadTest method testOOME_whenDeserializing.
@Test
public void testOOME_whenDeserializing() throws Exception {
handlerFactory = mock(OperationRunnerFactory.class);
OperationRunner handler = mock(OperationRunner.class);
when(handlerFactory.createGenericRunner()).thenReturn(handler);
when(handlerFactory.createPartitionRunner(anyInt())).thenReturn(handler);
initExecutor();
DummyOperation operation = new DummyOperation(Operation.GENERIC_PARTITION_ID);
Packet packet = new Packet(serializationService.toBytes(operation), operation.getPartitionId()).setPacketType(Packet.Type.OPERATION);
doThrow(new OutOfMemoryError()).when(handler).run(packet);
final int oldCount = OutOfMemoryErrorDispatcher.getOutOfMemoryErrorCount();
executor.accept(packet);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(oldCount + 1, OutOfMemoryErrorDispatcher.getOutOfMemoryErrorCount());
}
});
}
Aggregations