use of com.tvd12.ezyfoxserver.socket.EzyPacket in project ezyfox-server by youngmonkeys.
the class EzyAbstractSessionTest method addPacketToSessionQueueWithDroppedPacketsNowIsNull.
@Test
public void addPacketToSessionQueueWithDroppedPacketsNowIsNull() {
// given
EzyPacket packet = mock(EzyPacket.class);
MyTestSession session = new MyTestSession();
session.setActivated(true);
EzyPacketQueue packetQueue = mock(EzyPacketQueue.class);
when(packetQueue.isEmpty()).thenReturn(true);
when(packetQueue.add(packet)).thenReturn(false);
session.setPacketQueue(packetQueue);
// when
session.send(packet);
// then
Asserts.assertNull(session.getDroppedPackets());
}
use of com.tvd12.ezyfoxserver.socket.EzyPacket in project ezyfox-server by youngmonkeys.
the class EzyAbstractHandlerGroupTest method executeSendingPacketCanNotWriteBytes.
@Test
public void executeSendingPacketCanNotWriteBytes() throws Exception {
// given
ExHandlerGroup sut = newHandlerGroup();
EzyPacket packet = mock(EzyPacket.class);
ByteBuffer writeBuffer = ByteBuffer.wrap(new byte[0]);
// when
MethodInvoker.create().object(sut).method("executeSendingPacket").param(EzyPacket.class, packet).param(Object.class, writeBuffer).call();
// then
EzySession session = FieldUtil.getFieldValue(sut, "session");
verify(session, times(3)).getChannel();
}
use of com.tvd12.ezyfoxserver.socket.EzyPacket in project ezyfox-server by youngmonkeys.
the class EzySimpleNioHandlerGroupTest method writePacketToSocketSessionKeyIsInvalid.
@Test
public void writePacketToSocketSessionKeyIsInvalid() throws Exception {
// given
EzySimpleNioHandlerGroup sut = newHandlerGroup();
EzyNioSession session = FieldUtil.getFieldValue(sut, "session");
SelectionKey selectionKey = mock(SelectionKey.class);
when(session.getSelectionKey()).thenReturn(selectionKey);
when(selectionKey.isValid()).thenReturn(false);
EzyPacket packet = mock(EzyPacket.class);
when(packet.getData()).thenReturn(new byte[] { 1, 2, 3, 5 });
when(packet.isBinary()).thenReturn(true);
ByteBuffer writeBuffer = ByteBuffer.allocate(5);
// when
MethodInvoker.create().object(sut).method("writePacketToSocket").param(EzyPacket.class, packet).param(Object.class, writeBuffer).call();
// then
verify(session, times(1)).getSelectionKey();
verify(selectionKey, times(1)).isValid();
}
use of com.tvd12.ezyfoxserver.socket.EzyPacket in project ezyfox-server by youngmonkeys.
the class EzyPacketTest method test.
@Test
public void test() {
EzyPacket packet = new EzySimplePacket();
packet.setFragment(new byte[] { 1, 2, 3 });
long start = System.currentTimeMillis();
for (int i = 0; i < 1000000; ++i) {
packet.getSize();
}
long offset = System.currentTimeMillis() - start;
System.out.println(offset);
}
use of com.tvd12.ezyfoxserver.socket.EzyPacket in project ezyfox-server by youngmonkeys.
the class EzySocketWriterTest method test.
@Test
public void test() throws Exception {
EzySessionTicketsQueue sessionTicketsQueue = new EzyBlockingSessionTicketsQueue();
EzySocketWriterGroupFetcher writerGroupFetcher = mock(EzySocketWriterGroupFetcher.class);
EzySocketWriterGroup writerGroup = mock(EzySocketWriterGroup.class);
when(writerGroupFetcher.getWriterGroup(any(EzySession.class))).thenReturn(writerGroup);
EzySocketWriter socketWriter = new EzySocketWriter();
socketWriter.setSessionTicketsQueue(sessionTicketsQueue);
socketWriter.setWriterGroupFetcher(writerGroupFetcher);
EzyPacketQueue packetQueue = new EzyNonBlockingPacketQueue();
EzyPacket packet = new EzySimplePacket();
packetQueue.add(packet);
packetQueue.add(packet);
EzyAbstractSession session = spy(EzyAbstractSession.class);
session.setActivated(true);
session.setSessionTicketsQueue(sessionTicketsQueue);
session.setPacketQueue(packetQueue);
sessionTicketsQueue.add(session);
socketWriter.handleEvent();
packet.release();
socketWriter.handleEvent();
socketWriter.destroy();
}
Aggregations