use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.
the class EzyAbstractStreamingApi method response.
@Override
public void response(EzyBytesPackage pack) throws Exception {
EzyConstant connectionType = getConnectionType();
Collection<EzySession> recipients = pack.getRecipients(connectionType);
if (recipients.isEmpty()) {
return;
}
byte[] bytes = pack.getBytes();
for (EzySession session : recipients) {
session.send(createPacket(bytes, pack));
}
}
use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.
the class EzySimpleNioUdpDataHandlerTest method handleUdpHandshakeSessionTokenIsNotMatch.
@SuppressWarnings("rawtypes")
@Test
public void handleUdpHandshakeSessionTokenIsNotMatch() throws Exception {
// given
EzySimpleNioUdpDataHandler sut = new EzySimpleNioUdpDataHandler(1);
DatagramChannel channel = mock(DatagramChannel.class);
InetSocketAddress address = new InetSocketAddress(3005);
EzyMessage message = mock(EzyMessage.class);
String sessionToken = RandomUtil.randomAlphabetString(8);
long sessionId = 12345L;
int tokenSize = sessionToken.length();
int messageSize = 0;
// sessionIdSize
messageSize += 8;
// tokenLengthSize
messageSize += 2;
// messageSize
messageSize += tokenSize;
ByteBuffer buffer = ByteBuffer.allocate(messageSize);
buffer.putLong(sessionId);
buffer.putShort((short) tokenSize);
buffer.put(sessionToken.getBytes());
buffer.flip();
byte[] bytes = EzyByteBuffers.getBytes(buffer);
when(message.getContent()).thenReturn(bytes);
EzySessionManager sessionManager = mock(EzySessionManager.class);
sut.setSessionManager(sessionManager);
EzySession session = mock(EzySession.class);
when(session.getToken()).thenReturn(RandomUtil.randomShortAlphabetString());
when(sessionManager.getSession(sessionId)).thenReturn(session);
EzyResponseApi responseApi = mock(EzyResponseApi.class);
sut.setResponseApi(responseApi);
// when
MethodInvoker.create().object(sut).method("handleUdpHandshake").param(DatagramChannel.class, channel).param(InetSocketAddress.class, address).param(EzyMessage.class, message).call();
// then
verify(message, times(1)).getContent();
verify(sessionManager, times(1)).getSession(sessionId);
verify(session, times(1)).getToken();
verify(responseApi, times(1)).response(any());
sut.destroy();
}
use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.
the class EzySimpleWsHandlerGroupTest method handleReceivedSessionStreamNotEnable.
@Test
public void handleReceivedSessionStreamNotEnable() throws Exception {
// given
EzyWsHandlerGroup sut = newHandlerGroup();
EzySession session = FieldUtil.getFieldValue(sut, "session");
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();
}
use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.
the class EzySimpleWsHandlerGroupTest method handleReceivedStreamEnableAndSessionStream.
@Test
public void handleReceivedStreamEnableAndSessionStream() 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();
}
use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.
the class EzyHandlerGroupManagerImplTest method mapSocketChannelConnectionNull.
@Test
public void mapSocketChannelConnectionNull() {
// given
EzyHandlerGroupManager sut = newHandlerGroupManager();
EzySession session = mock(EzySession.class);
EzyChannel channel = mock(EzyChannel.class);
when(session.getChannel()).thenReturn(channel);
// when
sut.mapSocketChannel(null, session);
// then
verify(session, times(1)).getChannel();
}
Aggregations