use of com.tvd12.ezyfoxserver.nio.wrapper.EzyHandlerGroupManager 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();
}
use of com.tvd12.ezyfoxserver.nio.wrapper.EzyHandlerGroupManager in project ezyfox-server by youngmonkeys.
the class EzyHandlerGroupManagerImplTest method removeHandlerGroupUdpClientAddressIsNull.
@Test
public void removeHandlerGroupUdpClientAddressIsNull() {
// given
EzyHandlerGroupManager sut = newHandlerGroupManager();
EzySession session = mock(EzySession.class);
EzyChannel channel = mock(EzyChannel.class);
when(session.getChannel()).thenReturn(channel);
Object connection = new Object();
when(channel.getConnection()).thenReturn(connection);
SocketAddress udpClientAddress = mock(SocketAddress.class);
when(session.getUdpClientAddress()).thenReturn(udpClientAddress);
// when
sut.removeHandlerGroup(session);
// then
verify(session, times(1)).getChannel();
verify(session, times(1)).getUdpClientAddress();
verify(channel, times(1)).getConnection();
}
use of com.tvd12.ezyfoxserver.nio.wrapper.EzyHandlerGroupManager in project ezyfox-server by youngmonkeys.
the class EzyHandlerGroupManagerImplTest method mapSocketChannelChannelNull.
@Test
public void mapSocketChannelChannelNull() {
// given
EzyHandlerGroupManager sut = newHandlerGroupManager();
EzySession session = mock(EzySession.class);
// when
sut.mapSocketChannel(null, session);
// then
verify(session, times(1)).getChannel();
}
use of com.tvd12.ezyfoxserver.nio.wrapper.EzyHandlerGroupManager in project ezyfox-server by youngmonkeys.
the class EzyHandlerGroupManagerImplTest method test.
@Test
public void test() {
EzyNioSessionManager sessionManager = (EzyNioSessionManager) EzyNioSessionManagerImpl.builder().maxRequestPerSecond(new EzySimpleSessionManagementSetting.EzySimpleMaxRequestPerSecond()).tokenGenerator(new EzySimpleSessionTokenGenerator()).build();
ExEzyByteToObjectDecoder decoder = new ExEzyByteToObjectDecoder();
EzyCodecFactory codecFactory = mock(EzyCodecFactory.class);
when(codecFactory.newDecoder(any())).thenReturn(decoder);
ExecutorService statsThreadPool = EzyExecutors.newSingleThreadExecutor("stats");
EzySocketStreamQueue streamQueue = new EzyBlockingSocketStreamQueue();
EzySocketDisconnectionQueue disconnectionQueue = new EzyBlockingSocketDisconnectionQueue();
EzySessionTicketsRequestQueues sessionTicketsRequestQueues = new EzySessionTicketsRequestQueues();
EzySimpleSettings settings = new EzySimpleSettings();
EzySimpleStreamingSetting streaming = settings.getStreaming();
streaming.setEnable(true);
EzySimpleServer server = new EzySimpleServer();
server.setSettings(settings);
server.setSessionManager(sessionManager);
EzySimpleServerContext serverContext = new EzySimpleServerContext();
serverContext.setServer(server);
serverContext.init();
EzySessionTicketsQueue socketSessionTicketsQueue = new EzyBlockingSessionTicketsQueue();
EzySessionTicketsQueue webSocketSessionTicketsQueue = new EzyBlockingSessionTicketsQueue();
EzyStatistics statistics = new EzySimpleStatistics();
EzyHandlerGroupBuilderFactory handlerGroupBuilderFactory = EzyHandlerGroupBuilderFactoryImpl.builder().statistics(statistics).statsThreadPool(statsThreadPool).streamQueue(streamQueue).disconnectionQueue(disconnectionQueue).codecFactory(codecFactory).serverContext(serverContext).socketSessionTicketsQueue(socketSessionTicketsQueue).webSocketSessionTicketsQueue(webSocketSessionTicketsQueue).socketSessionTicketsQueue(webSocketSessionTicketsQueue).sessionTicketsRequestQueues(sessionTicketsRequestQueues).build();
EzyHandlerGroupManager handlerGroupManager = EzyHandlerGroupManagerImpl.builder().handlerGroupBuilderFactory(handlerGroupBuilderFactory).build();
handlerGroupManager.removeHandlerGroup(null);
EzySession session1 = mock(EzyAbstractSession.class);
handlerGroupManager.removeHandlerGroup(session1);
EzySession session2 = mock(EzyAbstractSession.class);
EzyChannel channel2 = mock(EzyChannel.class);
when(session2.getChannel()).thenReturn(channel2);
handlerGroupManager.removeHandlerGroup(session2);
EzyChannel channel3 = mock(EzyChannel.class);
Session connection3 = mock(Session.class);
when(channel3.getConnection()).thenReturn(connection3);
EzyHandlerGroup handlerGroup3 = handlerGroupManager.newHandlerGroup(channel3, EzyConnectionType.WEBSOCKET);
EzySession session3 = mock(EzyAbstractSession.class);
when(session3.getChannel()).thenReturn(channel3);
assert handlerGroupManager.getDataHandlerGroup(null) == null;
assert handlerGroupManager.getDataHandlerGroup(session1) == null;
assert handlerGroupManager.getDataHandlerGroup(session2) == null;
assert handlerGroupManager.getWriterGroup(session3) == handlerGroup3;
InetSocketAddress udpAddress = new InetSocketAddress("127.0.0.1", 12345);
handlerGroupManager.mapSocketChannel(udpAddress, session3);
assert handlerGroupManager.getSocketChannel(udpAddress) != null;
handlerGroupManager.unmapHandlerGroup(udpAddress);
handlerGroupManager.removeHandlerGroup(session3);
handlerGroupManager.destroy();
}
use of com.tvd12.ezyfoxserver.nio.wrapper.EzyHandlerGroupManager in project ezyfox-server by youngmonkeys.
the class EzySimpleNioUdpDataHandlerTest method testNotHandshakeCase.
@Test
public void testNotHandshakeCase() 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;
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);
EzyNioHandlerGroup handlerGroup = mock(EzyNioHandlerGroup.class);
when(handlerGroupManager.getHandlerGroup(packet.getAddress())).thenReturn(handlerGroup);
EzyNioSession session = new EzySimpleSession();
session.setToken(sessionToken);
EzyChannel channel = mock(EzyChannel.class);
when(channel.getClientAddress()).thenReturn(new InetSocketAddress(12345));
session.setChannel(channel);
when(handlerGroup.getSession()).thenReturn(session);
handler.setHandlerGroupManager(handlerGroupManager);
handler.fireUdpPacketReceived(packet);
Thread.sleep(200);
handler.destroy();
}
Aggregations