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