Search in sources :

Example 26 with Packet

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

the class TcpServerConnection_AbstractBasicTest method lastWriteTimeMillis_whenPacketWritten.

@Test
public void lastWriteTimeMillis_whenPacketWritten() {
    TcpServerConnection connAB = connect(tcpServerA, addressB);
    // we need to sleep some so that the lastWriteTime of the connection gets nice and old.
    // we need this so we can determine the lastWriteTime got updated
    sleepSeconds(LAST_READ_WRITE_SLEEP_SECONDS);
    Packet packet = new Packet(serializationService.toBytes("foo"));
    connAB.write(packet);
    // wait for the packet to get written
    assertTrueEventually(() -> assertEquals(1, packetsB.size()));
    long lastWriteTimeMs = connAB.lastWriteTimeMillis();
    long nowMs = currentTimeMillis();
    // make sure that the lastWrite time is within the given MARGIN_OF_ERROR_MS
    // last write time should be equal or smaller than now
    assertTrue("nowMs = " + nowMs + ", lastWriteTimeMs = " + lastWriteTimeMs, lastWriteTimeMs <= nowMs);
    // last write time should be larger or equal than the now - MARGIN_OF_ERROR_MS
    assertTrue("nowMs = " + nowMs + ", lastWriteTimeMs = " + lastWriteTimeMs, lastWriteTimeMs >= nowMs - MARGIN_OF_ERROR_MS);
}
Also used : Packet(com.hazelcast.internal.nio.Packet) Test(org.junit.Test)

Example 27 with Packet

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

the class TcpServerConnection_AbstractBasicTest method write_whenNotAlive.

@Test
public void write_whenNotAlive() {
    TcpServerConnection c = connect(tcpServerA, addressB);
    c.close(null, null);
    Packet packet = new Packet(serializationService.toBytes("foo"));
    boolean result = c.write(packet);
    assertFalse(result);
}
Also used : Packet(com.hazelcast.internal.nio.Packet) Test(org.junit.Test)

Example 28 with Packet

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

the class TcpServerConnectionManager_TransmitTest method withAddress_whenConnectionNotExists_thenCreated.

@Test
public void withAddress_whenConnectionNotExists_thenCreated() {
    tcpServerB.start();
    final Packet packet = new Packet(serializationService.toBytes("foo"));
    boolean result = tcpServerA.getConnectionManager(MEMBER).transmit(packet, addressB);
    assertTrue(result);
    assertTrueEventually(() -> assertContains(packetsB, packet));
    assertNotNull(tcpServerA.getConnectionManager(MEMBER).get(addressB));
}
Also used : Packet(com.hazelcast.internal.nio.Packet) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 29 with Packet

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

the class TcpServerConnectionManager_TransmitTest method withAddress_whenNullAddress.

@Test(expected = NullPointerException.class)
public void withAddress_whenNullAddress() {
    Packet packet = new Packet(serializationService.toBytes("foo"));
    tcpServerA.getConnectionManager(MEMBER).transmit(packet, (Address) null);
}
Also used : Packet(com.hazelcast.internal.nio.Packet) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 30 with Packet

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

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