use of com.hazelcast.internal.nio.PacketIOHelper in project hazelcast by hazelcast.
the class PacketEncoderTest method whenPacketFullyWritten.
@Test
public void whenPacketFullyWritten() {
final Packet packet = new Packet(serializationService.toBytes("foobar"));
ByteBuffer dst = ByteBuffer.allocate(1000);
upcast(dst).flip();
PacketSupplier src = new PacketSupplier();
src.queue.add(packet);
encoder.dst(dst);
encoder.src(src);
HandlerStatus result = encoder.onWrite();
assertEquals(CLEAN, result);
// now we read out the dst and check if we can find the written packet.
Packet resultPacket = new PacketIOHelper().readFrom(dst);
assertEquals(packet, resultPacket);
}
use of com.hazelcast.internal.nio.PacketIOHelper in project hazelcast by hazelcast.
the class PacketDecoderTest method whenPriorityPacket.
@Test
public void whenPriorityPacket() throws Exception {
ByteBuffer src = ByteBuffer.allocate(1000);
Packet packet = new Packet(serializationService.toBytes("foobar")).raiseFlags(Packet.FLAG_URGENT);
new PacketIOHelper().writeTo(packet, src);
decoder.src(src);
decoder.onRead();
assertEquals(1, dispatcher.packets.size());
Packet found = dispatcher.packets.get(0);
assertEquals(packet, found);
assertEquals(0, normalPacketCounter.get());
assertEquals(1, priorityPacketCounter.get());
}
use of com.hazelcast.internal.nio.PacketIOHelper in project hazelcast by hazelcast.
the class PacketDecoderTest method whenMultiplePackets.
@Test
public void whenMultiplePackets() throws Exception {
ByteBuffer src = ByteBuffer.allocate(1000);
Packet packet1 = new Packet(serializationService.toBytes("packet1"));
new PacketIOHelper().writeTo(packet1, src);
Packet packet2 = new Packet(serializationService.toBytes("packet2"));
new PacketIOHelper().writeTo(packet2, src);
Packet packet3 = new Packet(serializationService.toBytes("packet3"));
new PacketIOHelper().writeTo(packet3, src);
Packet packet4 = new Packet(serializationService.toBytes("packet4"));
packet4.raiseFlags(Packet.FLAG_URGENT);
new PacketIOHelper().writeTo(packet4, src);
decoder.src(src);
decoder.onRead();
assertEquals(asList(packet1, packet2, packet3, packet4), dispatcher.packets);
assertEquals(3, normalPacketCounter.get());
assertEquals(1, priorityPacketCounter.get());
}
use of com.hazelcast.internal.nio.PacketIOHelper in project hazelcast by hazelcast.
the class PacketDecoderTest method whenNormalPacket.
@Test
public void whenNormalPacket() throws Exception {
ByteBuffer src = ByteBuffer.allocate(1000);
Packet packet = new Packet(serializationService.toBytes("foobar"));
new PacketIOHelper().writeTo(packet, src);
decoder.src(src);
decoder.onRead();
assertEquals(1, dispatcher.packets.size());
Packet found = dispatcher.packets.get(0);
assertEquals(packet, found);
assertEquals(1, normalPacketCounter.get());
assertEquals(0, priorityPacketCounter.get());
}
use of com.hazelcast.internal.nio.PacketIOHelper in project hazelcast by hazelcast.
the class PacketIOHelperTest method before.
@Before
public void before() {
packetWriter = new PacketIOHelper();
packetReader = new PacketIOHelper();
}
Aggregations