Search in sources :

Example 1 with PacketIOHelper

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);
}
Also used : Packet(com.hazelcast.internal.nio.Packet) HandlerStatus(com.hazelcast.internal.networking.HandlerStatus) PacketIOHelper(com.hazelcast.internal.nio.PacketIOHelper) ByteBuffer(java.nio.ByteBuffer) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with PacketIOHelper

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());
}
Also used : Packet(com.hazelcast.internal.nio.Packet) PacketIOHelper(com.hazelcast.internal.nio.PacketIOHelper) ByteBuffer(java.nio.ByteBuffer) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with PacketIOHelper

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());
}
Also used : Packet(com.hazelcast.internal.nio.Packet) PacketIOHelper(com.hazelcast.internal.nio.PacketIOHelper) ByteBuffer(java.nio.ByteBuffer) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with PacketIOHelper

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());
}
Also used : Packet(com.hazelcast.internal.nio.Packet) PacketIOHelper(com.hazelcast.internal.nio.PacketIOHelper) ByteBuffer(java.nio.ByteBuffer) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with PacketIOHelper

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();
}
Also used : PacketIOHelper(com.hazelcast.internal.nio.PacketIOHelper) Before(org.junit.Before)

Aggregations

PacketIOHelper (com.hazelcast.internal.nio.PacketIOHelper)6 Packet (com.hazelcast.internal.nio.Packet)5 ByteBuffer (java.nio.ByteBuffer)5 QuickTest (com.hazelcast.test.annotation.QuickTest)4 Test (org.junit.Test)4 HandlerStatus (com.hazelcast.internal.networking.HandlerStatus)1 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1 Before (org.junit.Before)1