use of com.tvd12.ezyfoxserver.nio.entity.EzySimpleSession in project ezyfox-server by youngmonkeys.
the class EzySimpleWsHandlerGroupTest method newHandlerGroup.
@SuppressWarnings("rawtypes")
private EzySimpleWsHandlerGroup newHandlerGroup(boolean streamEnable) throws IOException {
EzySessionTicketsQueue socketSessionTicketsQueue = new EzyBlockingSessionTicketsQueue();
EzySessionTicketsQueue webSocketSessionTicketsQueue = new EzyBlockingSessionTicketsQueue();
EzySessionManager sessionManager = EzyNioSessionManagerImpl.builder().maxRequestPerSecond(new EzySimpleSessionManagementSetting.EzySimpleMaxRequestPerSecond()).tokenGenerator(new EzySimpleSessionTokenGenerator()).build();
EzyStatistics statistics = new EzySimpleStatistics();
EzySimpleSettings settings = new EzySimpleSettings();
EzySimpleStreamingSetting streaming = settings.getStreaming();
streaming.setEnable(streamEnable);
EzySimpleServer server = new EzySimpleServer();
server.setSettings(settings);
server.setSessionManager(sessionManager);
EzyServerControllers controllers = mock(EzyServerControllers.class);
server.setControllers(controllers);
EzySimpleConfig config = new EzySimpleConfig();
server.setConfig(config);
EzySimpleServerContext serverContext = new EzySimpleServerContext();
serverContext.setServer(server);
serverContext.init();
EzyChannel channel = mock(EzyChannel.class);
when(channel.isConnected()).thenReturn(true);
when(channel.getConnection()).thenReturn(SocketChannel.open());
when(channel.getConnectionType()).thenReturn(EzyConnectionType.WEBSOCKET);
ExecutorService statsThreadPool = EzyExecutors.newFixedThreadPool(1, "stats");
EzySocketStreamQueue streamQueue = new EzyBlockingSocketStreamQueue();
EzySessionTicketsRequestQueues sessionTicketsRequestQueues = new EzySessionTicketsRequestQueues();
EzySimpleSession session = mock(EzySimpleSession.class);
when(session.getChannel()).thenReturn(channel);
EzyHandlerGroupBuilderFactory handlerGroupBuilderFactory = EzyHandlerGroupBuilderFactoryImpl.builder().statistics(statistics).serverContext(serverContext).statsThreadPool(statsThreadPool).streamQueue(streamQueue).codecFactory(new ExCodecFactory()).sessionTicketsRequestQueues(sessionTicketsRequestQueues).socketSessionTicketsQueue(socketSessionTicketsQueue).webSocketSessionTicketsQueue(webSocketSessionTicketsQueue).build();
return (EzySimpleWsHandlerGroup) handlerGroupBuilderFactory.newBuilder(channel, EzyConnectionType.WEBSOCKET).session(session).build();
}
use of com.tvd12.ezyfoxserver.nio.entity.EzySimpleSession in project ezyfox-server by youngmonkeys.
the class EzyAbstractHandlerGroupTest method newHandlerGroup.
@SuppressWarnings("rawtypes")
private ExHandlerGroup newHandlerGroup() throws Exception {
EzyStatistics statistics = new EzySimpleStatistics();
EzySimpleSettings settings = new EzySimpleSettings();
EzySimpleStreamingSetting streaming = settings.getStreaming();
streaming.setEnable(true);
EzySimpleServer server = new EzySimpleServer();
server.setSettings(settings);
EzySimpleServerContext serverContext = new EzySimpleServerContext();
serverContext.setServer(server);
serverContext.init();
EzyChannel channel = mock(EzyChannel.class);
when(channel.isConnected()).thenReturn(true);
when(channel.getConnection()).thenReturn(SocketChannel.open());
when(channel.getConnectionType()).thenReturn(EzyConnectionType.SOCKET);
EzySimpleSession session = mock(EzySimpleSession.class);
EzySessionManager sessionManager = mock(EzySessionManager.class);
server.setSessionManager(sessionManager);
EzyResponseApi responseApi = mock(EzyResponseApi.class);
server.setResponseApi(responseApi);
ExEzyByteToObjectDecoder decoder = new ExEzyByteToObjectDecoder();
ExecutorService statsThreadPool = EzyExecutors.newFixedThreadPool(1, "stats");
EzySessionTicketsRequestQueues sessionTicketsRequestQueues = mock(EzySessionTicketsRequestQueues.class);
when(channel.write(any(ByteBuffer.class), anyBoolean())).thenReturn(123456);
return (ExHandlerGroup) new ExHandlerGroup.Builder().session(session).decoder(decoder).sessionCount(new AtomicInteger()).networkStats((EzyNetworkStats) statistics.getSocketStats().getNetworkStats()).sessionStats((EzySessionStats) statistics.getSocketStats().getSessionStats()).serverContext(serverContext).statsThreadPool(statsThreadPool).sessionTicketsRequestQueues(sessionTicketsRequestQueues).build();
}
use of com.tvd12.ezyfoxserver.nio.entity.EzySimpleSession in project ezyfox-server by youngmonkeys.
the class EzySimpleNioHandlerGroupTest method newHandlerGroup.
@SuppressWarnings("rawtypes")
private EzySimpleNioHandlerGroup newHandlerGroup(boolean streamEnable) throws IOException {
EzySessionTicketsQueue socketSessionTicketsQueue = new EzyBlockingSessionTicketsQueue();
EzySessionTicketsQueue webSocketSessionTicketsQueue = new EzyBlockingSessionTicketsQueue();
EzySessionManager sessionManager = EzyNioSessionManagerImpl.builder().maxRequestPerSecond(new EzySimpleSessionManagementSetting.EzySimpleMaxRequestPerSecond()).tokenGenerator(new EzySimpleSessionTokenGenerator()).build();
EzyStatistics statistics = new EzySimpleStatistics();
EzySimpleSettings settings = new EzySimpleSettings();
EzySimpleStreamingSetting streaming = settings.getStreaming();
streaming.setEnable(streamEnable);
EzySimpleServer server = new EzySimpleServer();
server.setSettings(settings);
server.setSessionManager(sessionManager);
EzySimpleServerContext serverContext = new EzySimpleServerContext();
serverContext.setServer(server);
serverContext.init();
EzyChannel channel = mock(EzyChannel.class);
when(channel.isConnected()).thenReturn(true);
when(channel.getConnection()).thenReturn(SocketChannel.open());
when(channel.getConnectionType()).thenReturn(EzyConnectionType.SOCKET);
EzySimpleSession session = mock(EzySimpleSession.class);
when(session.getChannel()).thenReturn(channel);
ExecutorService statsThreadPool = EzyExecutors.newFixedThreadPool(1, "stats");
EzySessionTicketsRequestQueues sessionTicketsRequestQueues = new EzySessionTicketsRequestQueues();
SelectionKey selectionKey = mock(SelectionKey.class);
when(selectionKey.isValid()).thenReturn(true);
when(session.getProperty(EzyNioSession.SELECTION_KEY)).thenReturn(selectionKey);
EzyCodecFactory codecFactory = mock(EzyCodecFactory.class);
EzyByteToObjectDecoder decoder = mock(EzyByteToObjectDecoder.class);
when(codecFactory.newDecoder(any())).thenReturn(decoder);
EzyHandlerGroupBuilderFactory handlerGroupBuilderFactory = EzyHandlerGroupBuilderFactoryImpl.builder().statistics(statistics).serverContext(serverContext).statsThreadPool(statsThreadPool).codecFactory(codecFactory).sessionTicketsRequestQueues(sessionTicketsRequestQueues).socketSessionTicketsQueue(socketSessionTicketsQueue).webSocketSessionTicketsQueue(webSocketSessionTicketsQueue).build();
return (EzySimpleNioHandlerGroup) handlerGroupBuilderFactory.newBuilder(channel, EzyConnectionType.SOCKET).session(session).decoder(decoder).serverContext(serverContext).statsThreadPool(statsThreadPool).sessionTicketsRequestQueues(sessionTicketsRequestQueues).build();
}
use of com.tvd12.ezyfoxserver.nio.entity.EzySimpleSession 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