Search in sources :

Example 41 with EzyAbstractSession

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

the class EzyProxyResponseApiTest method test.

@Test
public void test() throws Exception {
    EzyCodecFactory codecFactory = mock(EzyCodecFactory.class);
    EzyProxyResponseApi api = new EzyProxyResponseApi(codecFactory);
    EzyPackage pack = mock(EzyPackage.class);
    api.response(pack);
    EzyObjectToByteEncoder byteEncoder = mock(EzyObjectToByteEncoder.class);
    EzyObjectToStringEncoder stringEncoder = mock(EzyObjectToStringEncoder.class);
    when(codecFactory.newEncoder(EzyConnectionType.SOCKET)).thenReturn(byteEncoder);
    when(codecFactory.newEncoder(EzyConnectionType.WEBSOCKET)).thenReturn(stringEncoder);
    api = new EzyProxyResponseApi(codecFactory);
    api.response(pack);
    api.response(pack, true);
    EzyImmediateDeliver immediateDeliver = mock(EzyImmediateDeliver.class);
    EzyAbstractSession session = spy(EzyAbstractSession.class);
    session.setImmediateDeliver(immediateDeliver);
    when(pack.getRecipients(any(EzyConstant.class))).thenReturn(Lists.newArrayList(session));
    api.response(pack);
    api.response(pack, true);
}
Also used : EzyAbstractSession(com.tvd12.ezyfoxserver.entity.EzyAbstractSession) EzyProxyResponseApi(com.tvd12.ezyfoxserver.api.EzyProxyResponseApi) EzyPackage(com.tvd12.ezyfoxserver.response.EzyPackage) EzyConstant(com.tvd12.ezyfox.constant.EzyConstant) EzyObjectToStringEncoder(com.tvd12.ezyfox.codec.EzyObjectToStringEncoder) EzyCodecFactory(com.tvd12.ezyfoxserver.codec.EzyCodecFactory) EzyImmediateDeliver(com.tvd12.ezyfoxserver.entity.EzyImmediateDeliver) EzyObjectToByteEncoder(com.tvd12.ezyfox.codec.EzyObjectToByteEncoder) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 42 with EzyAbstractSession

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

the class EzySimplePluginEntryTest method handleClientRequest.

private void handleClientRequest(EzyPluginContext context) {
    EzySimplePlugin plugin = (EzySimplePlugin) context.getPlugin();
    EzyPluginRequestController requestController = plugin.getRequestController();
    EzyAbstractSession session = spy(EzyAbstractSession.class);
    EzySimpleUser user = new EzySimpleUser();
    EzyArray data = EzyEntityFactory.newArrayBuilder().append("chat").append(EzyEntityFactory.newObjectBuilder().append("message", "greet")).build();
    EzyUserRequestPluginEvent event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("chat").build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("no command").append(EzyEntityFactory.newObjectBuilder().append("message", "greet")).build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("noUser").append(EzyEntityFactory.newObjectBuilder().append("message", "greet")).build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("noSession").append(EzyEntityFactory.newObjectBuilder().append("message", "greet")).build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("noDataBinding").build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("badRequestSend").build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("badRequestNoSend").build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("exception").build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    try {
        requestController.handle(context, event);
    } catch (Exception e) {
        assert e instanceof IllegalStateException;
    }
    data = EzyEntityFactory.newArrayBuilder().append("plugin").build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
}
Also used : EzySimpleUserRequestPluginEvent(com.tvd12.ezyfoxserver.event.EzySimpleUserRequestPluginEvent) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyAbstractSession(com.tvd12.ezyfoxserver.entity.EzyAbstractSession) EzyPluginRequestController(com.tvd12.ezyfoxserver.plugin.EzyPluginRequestController) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzySimplePlugin(com.tvd12.ezyfoxserver.EzySimplePlugin) EzyUserRequestPluginEvent(com.tvd12.ezyfoxserver.event.EzyUserRequestPluginEvent)

Example 43 with EzyAbstractSession

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

the class EzyZoneUserManagerImplTest method newAndAddIdleUser.

private void newAndAddIdleUser(EzyZoneUserManagerImpl manager) {
    EzyAbstractSession session = mock(EzyAbstractSession.class);
    EzySimpleUser user = new EzySimpleUser();
    user.setZoneId(1);
    user.setName("user3");
    user.setMaxIdleTime(Integer.MAX_VALUE);
    manager.addUser(session, user);
    user.removeSession(session);
    user.setMaxIdleTime(0);
}
Also used : EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyAbstractSession(com.tvd12.ezyfoxserver.entity.EzyAbstractSession)

Example 44 with EzyAbstractSession

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

the class EzySocketWriterTest method packageQueueNullCaseTest.

@Test
public void packageQueueNullCaseTest() {
    EzySessionTicketsQueue sessionTicketsQueue = new EzyBlockingSessionTicketsQueue();
    EzySocketWriterGroupFetcher writerGroupFetcher = mock(EzySocketWriterGroupFetcher.class);
    EzySocketWriterGroup writerGroup = mock(EzySocketWriterGroup.class);
    when(writerGroupFetcher.getWriterGroup(any(EzySession.class))).thenReturn(writerGroup);
    EzySocketWriter socketWriter = new EzySocketWriter();
    socketWriter.setSessionTicketsQueue(sessionTicketsQueue);
    socketWriter.setWriterGroupFetcher(writerGroupFetcher);
    EzyAbstractSession session = spy(EzyAbstractSession.class);
    session.setActivated(true);
    session.setSessionTicketsQueue(sessionTicketsQueue);
    session.setPacketQueue(null);
    sessionTicketsQueue.add(session);
    socketWriter.handleEvent();
}
Also used : EzyAbstractSession(com.tvd12.ezyfoxserver.entity.EzyAbstractSession) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) BaseTest(com.tvd12.test.base.BaseTest) Test(org.testng.annotations.Test)

Example 45 with EzyAbstractSession

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

the class EzySocketWriterTest method processSessionTicketsQueue0ExceptionCase.

@Test
public void processSessionTicketsQueue0ExceptionCase() {
    EzySessionTicketsQueue sessionTicketsQueue = new EzyBlockingSessionTicketsQueue();
    EzySocketWriterGroupFetcher writerGroupFetcher = mock(EzySocketWriterGroupFetcher.class);
    when(writerGroupFetcher.getWriterGroup(any(EzySession.class))).thenThrow(new IllegalArgumentException());
    EzySocketWriter socketWriter = new EzySocketWriter();
    socketWriter.setSessionTicketsQueue(sessionTicketsQueue);
    socketWriter.setWriterGroupFetcher(writerGroupFetcher);
    EzyPacketQueue packetQueue = new EzyNonBlockingPacketQueue();
    EzyPacket packet = new EzySimplePacket();
    packetQueue.add(packet);
    EzyAbstractSession session = spy(EzyAbstractSession.class);
    session.setActivated(true);
    session.setSessionTicketsQueue(sessionTicketsQueue);
    session.setPacketQueue(packetQueue);
    sessionTicketsQueue.add(session);
    socketWriter.handleEvent();
}
Also used : EzyAbstractSession(com.tvd12.ezyfoxserver.entity.EzyAbstractSession) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) BaseTest(com.tvd12.test.base.BaseTest) Test(org.testng.annotations.Test)

Aggregations

EzyAbstractSession (com.tvd12.ezyfoxserver.entity.EzyAbstractSession)46 Test (org.testng.annotations.Test)35 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)25 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)23 BaseTest (com.tvd12.test.base.BaseTest)20 EzySessionManager (com.tvd12.ezyfoxserver.wrapper.EzySessionManager)19 EzySimpleUser (com.tvd12.ezyfoxserver.entity.EzySimpleUser)17 EzyZoneUserManager (com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager)16 EzyArray (com.tvd12.ezyfox.entity.EzyArray)14 EzyChannel (com.tvd12.ezyfoxserver.socket.EzyChannel)12 EzyController (com.tvd12.ezyfoxserver.controller.EzyController)11 EzyStreamingController (com.tvd12.ezyfoxserver.controller.EzyStreamingController)11 EzyInterceptor (com.tvd12.ezyfoxserver.interceptor.EzyInterceptor)11 EzyServerControllers (com.tvd12.ezyfoxserver.wrapper.EzyServerControllers)11 EzyServer (com.tvd12.ezyfoxserver.EzyServer)10 EzyZone (com.tvd12.ezyfoxserver.EzyZone)10 EzyCloseSession (com.tvd12.ezyfoxserver.command.EzyCloseSession)10 EzyLoggerSetting (com.tvd12.ezyfoxserver.setting.EzyLoggerSetting)10 EzySessionManagementSetting (com.tvd12.ezyfoxserver.setting.EzySessionManagementSetting)10 EzySettings (com.tvd12.ezyfoxserver.setting.EzySettings)10