Search in sources :

Example 41 with Packet

use of com.hazelcast.internal.nio.Packet 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 42 with Packet

use of com.hazelcast.internal.nio.Packet 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 43 with Packet

use of com.hazelcast.internal.nio.Packet 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 44 with Packet

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

the class PacketTest method resetFlagsTo.

@Test
public void resetFlagsTo() {
    Packet packet = new Packet().setPacketType(Packet.Type.OPERATION);
    packet.resetFlagsTo(FLAG_URGENT);
    assertSame(Packet.Type.NULL, packet.getPacketType());
    assertEquals(FLAG_URGENT, packet.getFlags());
}
Also used : Packet(com.hazelcast.internal.nio.Packet) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 45 with Packet

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

the class PacketTest method isFlagSet.

@Test
public void isFlagSet() {
    Packet packet = new Packet();
    packet.setPacketType(Packet.Type.OPERATION);
    packet.raiseFlags(FLAG_URGENT);
    assertSame(Packet.Type.OPERATION, packet.getPacketType());
    assertTrue(packet.isFlagRaised(FLAG_URGENT));
    assertFalse(packet.isFlagRaised(FLAG_OP_CONTROL));
}
Also used : Packet(com.hazelcast.internal.nio.Packet) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

Packet (com.hazelcast.internal.nio.Packet)65 Test (org.junit.Test)46 QuickTest (com.hazelcast.test.annotation.QuickTest)41 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)19 Operation (com.hazelcast.spi.impl.operationservice.Operation)11 ByteBuffer (java.nio.ByteBuffer)10 NormalResponse (com.hazelcast.spi.impl.operationservice.impl.responses.NormalResponse)9 AssertTask (com.hazelcast.test.AssertTask)6 PacketIOHelper (com.hazelcast.internal.nio.PacketIOHelper)5 SerializationConcurrencyTest (com.hazelcast.internal.serialization.impl.SerializationConcurrencyTest)3 OperationRunner (com.hazelcast.spi.impl.operationexecutor.OperationRunner)3 IOException (java.io.IOException)3 Address (com.hazelcast.cluster.Address)2 MemberHandshake (com.hazelcast.internal.cluster.impl.MemberHandshake)2 HandlerStatus (com.hazelcast.internal.networking.HandlerStatus)2 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)2 HeapData (com.hazelcast.internal.serialization.impl.HeapData)2 ServerConnection (com.hazelcast.internal.server.ServerConnection)2 ServerConnectionManager (com.hazelcast.internal.server.ServerConnectionManager)2 OperationRunnerFactory (com.hazelcast.spi.impl.operationexecutor.OperationRunnerFactory)2