use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.
the class EzySocketStreamHandlerTest method test.
@Test
public void test() {
EzySocketStreamHandler handler = new EzySocketStreamHandler();
EzySocketDataHandlerGroupFetcher dataHandlerGroupFetcher = mock(EzySocketDataHandlerGroupFetcher.class);
EzySocketDataHandlerGroup dataHandlerGroup = mock(EzySocketDataHandlerGroup.class);
when(dataHandlerGroupFetcher.getDataHandlerGroup(any(EzySession.class))).thenReturn(dataHandlerGroup);
EzySocketStreamQueue streamQueue = new EzyBlockingSocketStreamQueue();
EzySession session = spy(EzyAbstractSession.class);
EzySocketStream stream = new EzySimpleSocketStream(session, new byte[0]);
streamQueue.add(stream);
handler.setStreamQueue(streamQueue);
handler.setDataHandlerGroupFetcher(dataHandlerGroupFetcher);
handler.handleEvent();
handler.destroy();
}
use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.
the class EzySocketStreamHandlerTest method hasNoHandlerGroupCaseTest.
@Test
public void hasNoHandlerGroupCaseTest() {
EzySocketStreamHandler handler = new EzySocketStreamHandler();
EzySocketDataHandlerGroupFetcher dataHandlerGroupFetcher = mock(EzySocketDataHandlerGroupFetcher.class);
when(dataHandlerGroupFetcher.getDataHandlerGroup(any(EzySession.class))).thenReturn(null);
EzySocketStreamQueue streamQueue = new EzyBlockingSocketStreamQueue();
EzySession session = spy(EzyAbstractSession.class);
EzySocketStream stream = new EzySimpleSocketStream(session, new byte[0]);
streamQueue.add(stream);
handler.setStreamQueue(streamQueue);
handler.setDataHandlerGroupFetcher(dataHandlerGroupFetcher);
handler.handleEvent();
}
use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.
the class EzySocketStreamHandlerTest method doProcessStreamQueueExceptionCaseTest.
@Test
public void doProcessStreamQueueExceptionCaseTest() {
EzySocketStreamHandler handler = new EzySocketStreamHandler();
EzySocketDataHandlerGroupFetcher dataHandlerGroupFetcher = mock(EzySocketDataHandlerGroupFetcher.class);
when(dataHandlerGroupFetcher.getDataHandlerGroup(any(EzySession.class))).thenThrow(new IllegalArgumentException());
EzySocketStreamQueue streamQueue = new EzyBlockingSocketStreamQueue();
EzySession session = spy(EzyAbstractSession.class);
EzySocketStream stream = new EzySimpleSocketStream(session, new byte[0]);
streamQueue.add(stream);
handler.setStreamQueue(streamQueue);
handler.setDataHandlerGroupFetcher(dataHandlerGroupFetcher);
handler.handleEvent();
}
use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.
the class EzySimpleNioUdpDataHandlerTest method test.
@SuppressWarnings("rawtypes")
@Test
public void test() throws Exception {
String sessionToken = "12345678";
long sessionId = 12345L;
EzySimpleNioUdpDataHandler handler = new EzySimpleNioUdpDataHandler(1);
int tokenSize = sessionToken.length();
int messageSize = 0;
// sessionIdSize
messageSize += 8;
// tokenLengthSize
messageSize += 2;
// messageSize
messageSize += tokenSize;
ByteBuffer buffer = ByteBuffer.allocate(1 + 2 + messageSize);
byte header = 0;
header |= 1 << 5;
buffer.put(header);
buffer.putShort((short) messageSize);
buffer.putLong(sessionId);
buffer.putShort((short) tokenSize);
buffer.put(sessionToken.getBytes());
buffer.flip();
byte[] bytes = EzyByteBuffers.getBytes(buffer);
EzyUdpReceivedPacket packet = new EzySimpleUdpReceivedPacket(DatagramChannel.open(), new InetSocketAddress(12345), bytes);
EzyHandlerGroupManager handlerGroupManager = mock(EzyHandlerGroupManager.class);
EzySessionManager sessionManager = mock(EzySessionManager.class);
EzySession session = spy(EzyAbstractSession.class);
session.setToken(sessionToken);
when(sessionManager.getSession(sessionId)).thenReturn(session);
EzyResponseApi responseApi = mock(EzyResponseApi.class);
EzyDatagramChannelPool channelPool = new EzyDatagramChannelPool(1);
handler.setHandlerGroupManager(handlerGroupManager);
handler.setSessionManager(sessionManager);
handler.setResponseApi(responseApi);
handler.setDatagramChannelPool(channelPool);
handler.fireUdpPacketReceived(packet);
Thread.sleep(200);
handler.destroy();
}
use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.
the class EzySimpleWsHandlerGroupTest method handleReceivedSessionStreamEnable.
@Test
public void handleReceivedSessionStreamEnable() throws Exception {
// given
EzyWsHandlerGroup sut = newHandlerGroup();
EzySession session = FieldUtil.getFieldValue(sut, "session");
when(session.isStreamingEnable()).thenReturn(true);
byte[] bytes = new byte[] { 1 << 4, 2, 3 };
int offset = 0;
int len = 3;
// when
MethodInvoker.create().object(sut).method("handleReceivedBytes").param(byte[].class, bytes).param(int.class, offset).param(int.class, len).call();
// then
verify(session, times(1)).isStreamingEnable();
}
Aggregations