Search in sources :

Example 11 with EzySimplePacket

use of com.tvd12.ezyfoxserver.socket.EzySimplePacket 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

Test (org.testng.annotations.Test)8 BaseTest (com.tvd12.test.base.BaseTest)7 EzySimplePacket (com.tvd12.ezyfoxserver.socket.EzySimplePacket)5 EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)4 EzySimpleServerContext (com.tvd12.ezyfoxserver.context.EzySimpleServerContext)4 EzyAbstractSession (com.tvd12.ezyfoxserver.entity.EzyAbstractSession)4 EzyNioSession (com.tvd12.ezyfoxserver.nio.entity.EzyNioSession)4 EzyHandlerGroupBuilderFactory (com.tvd12.ezyfoxserver.nio.factory.EzyHandlerGroupBuilderFactory)4 EzySimpleSessionTokenGenerator (com.tvd12.ezyfoxserver.service.impl.EzySimpleSessionTokenGenerator)4 EzySimpleSessionManagementSetting (com.tvd12.ezyfoxserver.setting.EzySimpleSessionManagementSetting)4 EzySimpleSettings (com.tvd12.ezyfoxserver.setting.EzySimpleSettings)4 EzySimpleStreamingSetting (com.tvd12.ezyfoxserver.setting.EzySimpleStreamingSetting)4 EzySimpleStatistics (com.tvd12.ezyfoxserver.statistics.EzySimpleStatistics)4 EzyStatistics (com.tvd12.ezyfoxserver.statistics.EzyStatistics)4 EzySessionManager (com.tvd12.ezyfoxserver.wrapper.EzySessionManager)4 ByteBuffer (java.nio.ByteBuffer)4 ExecutorService (java.util.concurrent.ExecutorService)4 EzySimpleNioHandlerGroup (com.tvd12.ezyfoxserver.nio.handler.EzySimpleNioHandlerGroup)3 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)2 EzyController (com.tvd12.ezyfoxserver.controller.EzyController)1