Search in sources :

Example 21 with Packet

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

the class PacketTest method setPacketType.

@Test
public void setPacketType() {
    Packet packet = new Packet();
    for (Packet.Type type : Packet.Type.values()) {
        packet.setPacketType(type);
        assertSame(type, packet.getPacketType());
    }
}
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 22 with Packet

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

the class PacketTest method isFlag_4_xSet.

@Test
public void isFlag_4_xSet() {
    byte[] payload = {};
    Packet packet = new Packet();
    Packet packet2 = new Packet(payload);
    Packet packet3 = new Packet(payload, 1);
    assertTrue(packet.isFlagRaised(FLAG_4_0));
    assertTrue(packet2.isFlagRaised(FLAG_4_0));
    assertTrue(packet3.isFlagRaised(FLAG_4_0));
}
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 23 with Packet

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

the class TcpServerConnection_AbstractBasicTest method lastReadTimeMillis.

// we check the lastReadTimeMillis by sending a packet on the local connection, and
// on the remote side we check the if the lastReadTime is updated
@Test
public void lastReadTimeMillis() {
    TcpServerConnection connAB = connect(tcpServerA, addressB);
    TcpServerConnection connBA = connect(tcpServerB, addressA);
    // we need to sleep some so that the lastReadTime of the connection gets nice and old.
    // we need this so we can determine the lastReadTime got updated
    sleepSeconds(LAST_READ_WRITE_SLEEP_SECONDS);
    Packet packet = new Packet(serializationService.toBytes("foo"));
    connAB.write(packet);
    // wait for the packet to get read
    assertTrueEventually(() -> {
        assertEquals(1, packetsB.size());
        System.out.println("Packet processed");
    });
    long lastReadTimeMs = connBA.lastReadTimeMillis();
    long nowMs = currentTimeMillis();
    // make sure that the lastRead time is within the given MARGIN_OF_ERROR_MS
    // last read time should be equal or smaller than now
    assertTrue("nowMs = " + nowMs + ", lastReadTimeMs = " + lastReadTimeMs, lastReadTimeMs <= nowMs);
    // last read time should be larger or equal than the now - MARGIN_OF_ERROR_MS
    assertTrue("nowMs = " + nowMs + ", lastReadTimeMs = " + lastReadTimeMs, lastReadTimeMs >= nowMs - MARGIN_OF_ERROR_MS);
}
Also used : Packet(com.hazelcast.internal.nio.Packet) Test(org.junit.Test)

Example 24 with Packet

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

the class TcpServerConnection_AbstractBasicTest method write_whenNonUrgent.

@Test
public void write_whenNonUrgent() {
    TcpServerConnection c = connect(tcpServerA, addressB);
    Packet packet = new Packet(serializationService.toBytes("foo"));
    boolean result = c.write(packet);
    assertTrue(result);
    assertTrueEventually(() -> assertEquals(1, packetsB.size()));
    Packet found = packetsB.get(0);
    assertEquals(packet, found);
}
Also used : Packet(com.hazelcast.internal.nio.Packet) Test(org.junit.Test)

Example 25 with Packet

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

the class TcpServerConnection_AbstractBasicTest method write_whenUrgent.

@Test
public void write_whenUrgent() {
    TcpServerConnection c = connect(tcpServerA, addressB);
    Packet packet = new Packet(serializationService.toBytes("foo"));
    packet.raiseFlags(Packet.FLAG_URGENT);
    boolean result = c.write(packet);
    assertTrue(result);
    assertTrueEventually(() -> assertEquals(1, packetsB.size()));
    Packet found = packetsB.get(0);
    assertEquals(packet, found);
}
Also used : Packet(com.hazelcast.internal.nio.Packet) 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