Search in sources :

Example 6 with PacketIOHelper

use of com.hazelcast.internal.nio.PacketIOHelper in project hazelcast by hazelcast.

the class MockServerConnection method readFromPacket.

private Packet readFromPacket(Packet packet) {
    Packet newPacket;
    PacketIOHelper packetReader = new PacketIOHelper();
    PacketIOHelper packetWriter = new PacketIOHelper();
    ByteBuffer buffer = ByteBuffer.allocate(4096);
    boolean writeDone;
    do {
        writeDone = packetWriter.writeTo(packet, buffer);
        upcast(buffer).flip();
        newPacket = packetReader.readFrom(buffer);
        if (buffer.hasRemaining()) {
            throw new IllegalStateException("Buffer should be empty! " + buffer);
        }
        upcast(buffer).clear();
    } while (!writeDone);
    assertNotNull(newPacket);
    newPacket.setConn(otherConnection);
    return newPacket;
}
Also used : Packet(com.hazelcast.internal.nio.Packet) PacketIOHelper(com.hazelcast.internal.nio.PacketIOHelper) ByteBuffer(java.nio.ByteBuffer)

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