Search in sources :

Example 16 with EzySimpleStreamingSetting

use of com.tvd12.ezyfoxserver.setting.EzySimpleStreamingSetting in project ezyfox-server by youngmonkeys.

the class EzySimpleNioHandlerGroupTest method writeSuccessTest.

@SuppressWarnings("rawtypes")
@Test
public void writeSuccessTest() throws Exception {
    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(true);
    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);
    EzyNioSession session = (EzyNioSession) sessionManager.provideSession(channel);
    ExEzyByteToObjectDecoder decoder = new ExEzyByteToObjectDecoder();
    ExecutorService statsThreadPool = EzyExecutors.newFixedThreadPool(1, "stats");
    EzySessionTicketsRequestQueues sessionTicketsRequestQueues = new EzySessionTicketsRequestQueues();
    when(channel.write(any(ByteBuffer.class), anyBoolean())).thenReturn(123456);
    EzyHandlerGroupBuilderFactory handlerGroupBuilderFactory = EzyHandlerGroupBuilderFactoryImpl.builder().statistics(statistics).serverContext(serverContext).statsThreadPool(statsThreadPool).codecFactory(new ExCodecFactory()).sessionTicketsRequestQueues(sessionTicketsRequestQueues).socketSessionTicketsQueue(socketSessionTicketsQueue).webSocketSessionTicketsQueue(webSocketSessionTicketsQueue).build();
    EzySimpleNioHandlerGroup group = (EzySimpleNioHandlerGroup) handlerGroupBuilderFactory.newBuilder(channel, EzyConnectionType.SOCKET).session(session).decoder(decoder).serverContext(serverContext).statsThreadPool(statsThreadPool).sessionTicketsRequestQueues(sessionTicketsRequestQueues).build();
    EzySimplePacket packet = new EzySimplePacket();
    packet.setBinary(true);
    packet.setData("world".getBytes());
    packet.setTransportType(EzyTransportType.TCP);
    ByteBuffer writeBuffer = ByteBuffer.allocate(1024);
    group.firePacketSend(packet, writeBuffer);
    Thread.sleep(1000);
}
Also used : EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzySimpleSessionManagementSetting(com.tvd12.ezyfoxserver.setting.EzySimpleSessionManagementSetting) EzyHandlerGroupBuilderFactory(com.tvd12.ezyfoxserver.nio.factory.EzyHandlerGroupBuilderFactory) EzySimpleServerContext(com.tvd12.ezyfoxserver.context.EzySimpleServerContext) EzySimpleNioHandlerGroup(com.tvd12.ezyfoxserver.nio.handler.EzySimpleNioHandlerGroup) EzyStatistics(com.tvd12.ezyfoxserver.statistics.EzyStatistics) EzySimpleStreamingSetting(com.tvd12.ezyfoxserver.setting.EzySimpleStreamingSetting) EzySessionManager(com.tvd12.ezyfoxserver.wrapper.EzySessionManager) EzyNioSession(com.tvd12.ezyfoxserver.nio.entity.EzyNioSession) EzySimpleSettings(com.tvd12.ezyfoxserver.setting.EzySimpleSettings) ByteBuffer(java.nio.ByteBuffer) ExecutorService(java.util.concurrent.ExecutorService) EzySimpleStatistics(com.tvd12.ezyfoxserver.statistics.EzySimpleStatistics) EzySimpleSessionTokenGenerator(com.tvd12.ezyfoxserver.service.impl.EzySimpleSessionTokenGenerator) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 17 with EzySimpleStreamingSetting

use of com.tvd12.ezyfoxserver.setting.EzySimpleStreamingSetting in project ezyfox-server by youngmonkeys.

the class EzySimpleNioHandlerGroupTest method writeFailureTest.

@SuppressWarnings("rawtypes")
@Test
public void writeFailureTest() throws Exception {
    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(true);
    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);
    EzyNioSession session = (EzyNioSession) sessionManager.provideSession(channel);
    ExEzyByteToObjectDecoder decoder = new ExEzyByteToObjectDecoder();
    ExecutorService statsThreadPool = EzyExecutors.newFixedThreadPool(1, "stats");
    EzySessionTicketsRequestQueues sessionTicketsRequestQueues = new EzySessionTicketsRequestQueues();
    SelectionKey selectionKey = mock(SelectionKey.class);
    when(selectionKey.isValid()).thenReturn(true);
    session.setProperty(EzyNioSession.SELECTION_KEY, selectionKey);
    EzyHandlerGroupBuilderFactory handlerGroupBuilderFactory = EzyHandlerGroupBuilderFactoryImpl.builder().statistics(statistics).serverContext(serverContext).statsThreadPool(statsThreadPool).codecFactory(new ExCodecFactory()).sessionTicketsRequestQueues(sessionTicketsRequestQueues).socketSessionTicketsQueue(socketSessionTicketsQueue).webSocketSessionTicketsQueue(webSocketSessionTicketsQueue).build();
    EzySimpleNioHandlerGroup group = (EzySimpleNioHandlerGroup) handlerGroupBuilderFactory.newBuilder(channel, EzyConnectionType.SOCKET).session(session).decoder(decoder).serverContext(serverContext).statsThreadPool(statsThreadPool).sessionTicketsRequestQueues(sessionTicketsRequestQueues).build();
    EzySimplePacket packet = new EzySimplePacket();
    packet.setBinary(true);
    packet.setData("world".getBytes());
    packet.setTransportType(EzyTransportType.TCP);
    ByteBuffer writeBuffer = ByteBuffer.allocate(1024);
    group.firePacketSend(packet, writeBuffer);
    Thread.sleep(1000);
}
Also used : SelectionKey(java.nio.channels.SelectionKey) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzySimpleSessionManagementSetting(com.tvd12.ezyfoxserver.setting.EzySimpleSessionManagementSetting) EzyHandlerGroupBuilderFactory(com.tvd12.ezyfoxserver.nio.factory.EzyHandlerGroupBuilderFactory) EzySimpleServerContext(com.tvd12.ezyfoxserver.context.EzySimpleServerContext) EzySimpleNioHandlerGroup(com.tvd12.ezyfoxserver.nio.handler.EzySimpleNioHandlerGroup) EzyStatistics(com.tvd12.ezyfoxserver.statistics.EzyStatistics) EzySimpleStreamingSetting(com.tvd12.ezyfoxserver.setting.EzySimpleStreamingSetting) EzySessionManager(com.tvd12.ezyfoxserver.wrapper.EzySessionManager) EzyNioSession(com.tvd12.ezyfoxserver.nio.entity.EzyNioSession) EzySimpleSettings(com.tvd12.ezyfoxserver.setting.EzySimpleSettings) ByteBuffer(java.nio.ByteBuffer) ExecutorService(java.util.concurrent.ExecutorService) EzySimpleStatistics(com.tvd12.ezyfoxserver.statistics.EzySimpleStatistics) EzySimpleSessionTokenGenerator(com.tvd12.ezyfoxserver.service.impl.EzySimpleSessionTokenGenerator) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Aggregations

EzySimpleStreamingSetting (com.tvd12.ezyfoxserver.setting.EzySimpleStreamingSetting)15 EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)14 EzySimpleServerContext (com.tvd12.ezyfoxserver.context.EzySimpleServerContext)14 EzySimpleSettings (com.tvd12.ezyfoxserver.setting.EzySimpleSettings)14 EzySimpleStatistics (com.tvd12.ezyfoxserver.statistics.EzySimpleStatistics)13 EzyStatistics (com.tvd12.ezyfoxserver.statistics.EzyStatistics)13 ExecutorService (java.util.concurrent.ExecutorService)13 EzySimpleSessionTokenGenerator (com.tvd12.ezyfoxserver.service.impl.EzySimpleSessionTokenGenerator)12 EzyHandlerGroupBuilderFactory (com.tvd12.ezyfoxserver.nio.factory.EzyHandlerGroupBuilderFactory)11 Test (org.testng.annotations.Test)11 BaseTest (com.tvd12.test.base.BaseTest)9 EzySimpleSessionManagementSetting (com.tvd12.ezyfoxserver.setting.EzySimpleSessionManagementSetting)8 EzySessionManager (com.tvd12.ezyfoxserver.wrapper.EzySessionManager)8 EzyCodecFactory (com.tvd12.ezyfoxserver.codec.EzyCodecFactory)6 EzyNioSession (com.tvd12.ezyfoxserver.nio.entity.EzyNioSession)6 ByteBuffer (java.nio.ByteBuffer)6 EzyNioSessionManager (com.tvd12.ezyfoxserver.nio.wrapper.EzyNioSessionManager)5 EzySimpleNioHandlerGroup (com.tvd12.ezyfoxserver.nio.handler.EzySimpleNioHandlerGroup)4 EzyAbstractSession (com.tvd12.ezyfoxserver.entity.EzyAbstractSession)3 EzySimpleSession (com.tvd12.ezyfoxserver.nio.entity.EzySimpleSession)3