Search in sources :

Example 96 with EzySession

use of com.tvd12.ezyfoxserver.entity.EzySession 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();
}
Also used : EzyHandlerGroupManager(com.tvd12.ezyfoxserver.nio.wrapper.EzyHandlerGroupManager) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 97 with EzySession

use of com.tvd12.ezyfoxserver.entity.EzySession 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();
}
Also used : EzyHandlerGroupManager(com.tvd12.ezyfoxserver.nio.wrapper.EzyHandlerGroupManager) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 98 with EzySession

use of com.tvd12.ezyfoxserver.entity.EzySession 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();
}
Also used : EzyHandlerGroupBuilderFactory(com.tvd12.ezyfoxserver.nio.factory.EzyHandlerGroupBuilderFactory) EzySimpleServerContext(com.tvd12.ezyfoxserver.context.EzySimpleServerContext) InetSocketAddress(java.net.InetSocketAddress) EzyStatistics(com.tvd12.ezyfoxserver.statistics.EzyStatistics) EzyHandlerGroup(com.tvd12.ezyfoxserver.nio.handler.EzyHandlerGroup) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzySimpleStreamingSetting(com.tvd12.ezyfoxserver.setting.EzySimpleStreamingSetting) EzyNioSessionManager(com.tvd12.ezyfoxserver.nio.wrapper.EzyNioSessionManager) EzyCodecFactory(com.tvd12.ezyfoxserver.codec.EzyCodecFactory) EzySimpleSettings(com.tvd12.ezyfoxserver.setting.EzySimpleSettings) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzyHandlerGroupManager(com.tvd12.ezyfoxserver.nio.wrapper.EzyHandlerGroupManager) ExecutorService(java.util.concurrent.ExecutorService) EzySimpleStatistics(com.tvd12.ezyfoxserver.statistics.EzySimpleStatistics) EzySimpleSessionTokenGenerator(com.tvd12.ezyfoxserver.service.impl.EzySimpleSessionTokenGenerator) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Session(org.eclipse.jetty.websocket.api.Session) EzyAbstractSession(com.tvd12.ezyfoxserver.entity.EzyAbstractSession) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 99 with EzySession

use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.

the class HelloController method greet.

@EzyDoHandle("Hello2")
public void greet(@EzyRequestData GreetRequest request, EzyUser user, EzySession session, Integer nothing) {
    GreetResponse response = new GreetResponse("Hello " + request.getWho() + "!");
    System.out.println("HelloController::Big/Hello response: " + response);
}
Also used : GreetResponse(com.tvd12.ezyfoxserver.support.test.data.GreetResponse) EzyDoHandle(com.tvd12.ezyfox.core.annotation.EzyDoHandle)

Example 100 with EzySession

use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.

the class HelloController method greet.

@EzyDoHandle("Hello")
public void greet(GreetRequest request, EzyUser user, EzySession session) {
    GreetResponse response = new GreetResponse("Hello " + request.getWho() + "!");
    System.out.println("HelloController::Big/Hello response: " + response);
}
Also used : GreetResponse(com.tvd12.ezyfoxserver.support.test.data.GreetResponse) EzyDoHandle(com.tvd12.ezyfox.core.annotation.EzyDoHandle)

Aggregations

EzySession (com.tvd12.ezyfoxserver.entity.EzySession)112 Test (org.testng.annotations.Test)92 EzyArray (com.tvd12.ezyfox.entity.EzyArray)33 EzyResponseApi (com.tvd12.ezyfoxserver.api.EzyResponseApi)26 EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)25 EzyResponse (com.tvd12.ezyfoxserver.response.EzyResponse)25 BaseTest (com.tvd12.test.base.BaseTest)25 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)15 EzySimpleServerContext (com.tvd12.ezyfoxserver.context.EzySimpleServerContext)14 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)13 EzyUser (com.tvd12.ezyfoxserver.entity.EzyUser)13 EzySimpleLoginRequest (com.tvd12.ezyfoxserver.request.EzySimpleLoginRequest)13 EzyLoginController (com.tvd12.ezyfoxserver.controller.EzyLoginController)12 EzySimpleSettings (com.tvd12.ezyfoxserver.setting.EzySimpleSettings)11 EzySendResponseImpl (com.tvd12.ezyfoxserver.command.impl.EzySendResponseImpl)8 EzyHandshakeController (com.tvd12.ezyfoxserver.controller.EzyHandshakeController)8 EzyHandshakeParams (com.tvd12.ezyfoxserver.request.EzyHandshakeParams)8 EzySimpleResponse (com.tvd12.ezyfoxserver.response.EzySimpleResponse)8 GreetResponse (com.tvd12.ezyfoxserver.support.test.data.GreetResponse)8 BaseCoreTest (com.tvd12.ezyfoxserver.testing.BaseCoreTest)8