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);
}
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);
}
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));
}
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);
}
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);
}
Aggregations