Search in sources :

Example 56 with EzyZoneContext

use of com.tvd12.ezyfoxserver.context.EzyZoneContext in project ezyfox-server by youngmonkeys.

the class EzySimpleDataHandlerTest method notifyAppsSessionRemoved0Case.

@SuppressWarnings({ "rawtypes" })
@Test
public void notifyAppsSessionRemoved0Case() {
    int zoneId = 1;
    EzyServerContext serverContext = mock(EzyServerContext.class);
    EzyZoneContext zoneContext = mock(EzyZoneContext.class);
    EzyZone zone = mock(EzyZone.class);
    when(zoneContext.getZone()).thenReturn(zone);
    EzyZoneUserManager zoneUserManager = mock(EzyZoneUserManager.class);
    when(zone.getUserManager()).thenReturn(zoneUserManager);
    when(serverContext.getZoneContext(zoneId)).thenReturn(zoneContext);
    EzyAbstractSession session = spy(EzyAbstractSession.class);
    EzyChannel channel = mock(EzyChannel.class);
    when(session.getChannel()).thenReturn(channel);
    EzyServer server = mock(EzyServer.class);
    when(serverContext.getServer()).thenReturn(server);
    EzyServerControllers controllers = mock(EzyServerControllers.class);
    EzyInterceptor streamingInterceptor = mock(EzyInterceptor.class);
    when(controllers.getStreamingInterceptor()).thenReturn(streamingInterceptor);
    EzyStreamingController streamingController = mock(EzyStreamingController.class);
    when(controllers.getStreamingController()).thenReturn(streamingController);
    EzyInterceptor loginInterceptor = mock(EzyInterceptor.class);
    when(controllers.getInterceptor(EzyCommand.LOGIN)).thenReturn(loginInterceptor);
    EzyController loginController = mock(EzyController.class);
    when(controllers.getController(EzyCommand.LOGIN)).thenReturn(loginController);
    when(server.getControllers()).thenReturn(controllers);
    EzySessionManager sessionManager = mock(EzySessionManager.class);
    when(server.getSessionManager()).thenReturn(sessionManager);
    EzyCloseSession closeSession = mock(EzyCloseSession.class);
    when(serverContext.get(EzyCloseSession.class)).thenReturn(closeSession);
    EzySettings settings = mock(EzySettings.class);
    when(settings.isDebug()).thenReturn(true);
    when(server.getSettings()).thenReturn(settings);
    EzySessionManagementSetting sessionManagementSetting = mock(EzySessionManagementSetting.class);
    when(settings.getSessionManagement()).thenReturn(sessionManagementSetting);
    EzyLoggerSetting loggerSetting = mock(EzyLoggerSetting.class);
    when(settings.getLogger()).thenReturn(loggerSetting);
    EzyLoggerSetting.EzyIgnoredCommandsSetting ignoredCommandsSetting = mock(EzyLoggerSetting.EzyIgnoredCommandsSetting.class);
    when(loggerSetting.getIgnoredCommands()).thenReturn(ignoredCommandsSetting);
    when(ignoredCommandsSetting.getCommands()).thenReturn(new HashSet<>());
    EzySessionManagementSetting.EzyMaxRequestPerSecond maxRequestPerSecond = mock(EzySessionManagementSetting.EzyMaxRequestPerSecond.class);
    when(maxRequestPerSecond.getValue()).thenReturn(3);
    when(maxRequestPerSecond.getAction()).thenReturn(EzyMaxRequestPerSecondAction.DISCONNECT_SESSION);
    when(sessionManagementSetting.getSessionMaxRequestPerSecond()).thenReturn(maxRequestPerSecond);
    MyTestDataHandler handler = new MyTestDataHandler(serverContext, session);
    when(session.getDelegate()).thenReturn(handler);
    when(session.isActivated()).thenReturn(true);
    FieldUtil.setFieldValue(handler, "zoneContext", zoneContext);
    doThrow(new IllegalArgumentException("notifyAppsSessionRemoved0Case")).when(zoneContext).broadcastApps(any(EzyConstant.class), any(EzyEvent.class), any(EzyUser.class), anyBoolean());
    MethodInvoker.create().object(handler).method("doNotifyAppsSessionRemoved").param(EzyEvent.class, mock(EzyEvent.class)).invoke();
}
Also used : EzyZone(com.tvd12.ezyfoxserver.EzyZone) EzyChannel(com.tvd12.ezyfoxserver.socket.EzyChannel) EzyInterceptor(com.tvd12.ezyfoxserver.interceptor.EzyInterceptor) EzyStreamingController(com.tvd12.ezyfoxserver.controller.EzyStreamingController) EzyCloseSession(com.tvd12.ezyfoxserver.command.EzyCloseSession) EzyEvent(com.tvd12.ezyfoxserver.event.EzyEvent) EzySessionManagementSetting(com.tvd12.ezyfoxserver.setting.EzySessionManagementSetting) EzyAbstractSession(com.tvd12.ezyfoxserver.entity.EzyAbstractSession) EzyServer(com.tvd12.ezyfoxserver.EzyServer) EzySettings(com.tvd12.ezyfoxserver.setting.EzySettings) EzyUser(com.tvd12.ezyfoxserver.entity.EzyUser) EzyController(com.tvd12.ezyfoxserver.controller.EzyController) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzySessionManager(com.tvd12.ezyfoxserver.wrapper.EzySessionManager) EzyServerControllers(com.tvd12.ezyfoxserver.wrapper.EzyServerControllers) EzyLoggerSetting(com.tvd12.ezyfoxserver.setting.EzyLoggerSetting) EzyZoneUserManager(com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager) EzyConstant(com.tvd12.ezyfox.constant.EzyConstant) BaseCoreTest(com.tvd12.ezyfoxserver.testing.BaseCoreTest) Test(org.testng.annotations.Test)

Example 57 with EzyZoneContext

use of com.tvd12.ezyfoxserver.context.EzyZoneContext in project ezyfox-server by youngmonkeys.

the class EzySimpleServerContextBuilder method newZoneContexts.

protected Collection<EzyZoneContext> newZoneContexts(EzyServerContext parent) {
    Collection<EzyZoneContext> contexts = new ArrayList<>();
    EzySettings settings = EzyServerContexts.getSettings(parent);
    for (Integer zoneId : settings.getZoneIds()) {
        EzyZoneSetting zoneSetting = settings.getZoneById(zoneId);
        EzySimpleZone zone = new EzySimpleZone();
        zone.setSetting(zoneSetting);
        EzyUserDelegate userDelegate = newUserDelegate(parent);
        EzyZoneUserManager userManager = newZoneUserManager(zoneSetting, userDelegate);
        EzyEventControllers eventControllers = newEventControllers(zoneSetting.getEventControllers());
        zone.setUserManager(userManager);
        zone.setEventControllers(eventControllers);
        EzySimpleZoneContext zoneContext = new EzySimpleZoneContext();
        zoneContext.setParent(parent);
        zoneContext.setZone(zone);
        zoneContext.addAppContexts(newAppContexts(zoneContext));
        zoneContext.addPluginContexts(newPluginContexts(zoneContext));
        zoneContext.init();
        contexts.add(zoneContext);
        processWithException(((EzyStartable) userManager)::start);
    }
    return contexts;
}
Also used : EzyEventControllers(com.tvd12.ezyfoxserver.wrapper.EzyEventControllers) ArrayList(java.util.ArrayList) EzyUserDelegate(com.tvd12.ezyfoxserver.delegate.EzyUserDelegate) EzyZoneUserManager(com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager)

Example 58 with EzyZoneContext

use of com.tvd12.ezyfoxserver.context.EzyZoneContext in project ezyfox-server by youngmonkeys.

the class EzySimpleServerContextBuilder method newAppContext.

protected EzyAppContext newAppContext(EzyZoneContext parent, EzyAppSetting setting) {
    EzySimpleAppUserDelegate userDelegate = new EzySimpleAppUserDelegate();
    EzyAppUserManager appUserManager = newAppUserManager(setting, userDelegate);
    EzyEventControllers eventControllers = newEventControllers();
    EzySimpleApplication app = new EzySimpleApplication();
    app.setSetting(setting);
    app.setUserManager(appUserManager);
    app.setEventControllers(eventControllers);
    ScheduledExecutorService appExecutorService = newAppExecutorService(setting);
    EzySimpleAppContext appContext = new EzySimpleAppContext();
    userDelegate.setAppContext(appContext);
    appContext.setApp(app);
    appContext.setParent(parent);
    appContext.setExecutorService(appExecutorService);
    appContext.init();
    return appContext;
}
Also used : EzyEventControllers(com.tvd12.ezyfoxserver.wrapper.EzyEventControllers) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) EzyAppUserManager(com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager) EzySimpleAppUserDelegate(com.tvd12.ezyfoxserver.delegate.EzySimpleAppUserDelegate)

Example 59 with EzyZoneContext

use of com.tvd12.ezyfoxserver.context.EzyZoneContext in project ezyfox-server by youngmonkeys.

the class EzyAppSendResponseImplTest method test.

@Test
public void test() {
    EzyAppContext appContext = mock(EzyAppContext.class);
    EzyApplication app = mock(EzyApplication.class);
    when(appContext.getApp()).thenReturn(app);
    EzySimpleAppSetting appSetting = new EzySimpleAppSetting();
    appSetting.setName("test");
    when(app.getSetting()).thenReturn(appSetting);
    EzyZoneContext zoneContext = mock(EzyZoneContext.class);
    when(appContext.getParent()).thenReturn(zoneContext);
    EzyServerContext serverContext = mock(EzyServerContext.class);
    when(zoneContext.getParent()).thenReturn(serverContext);
    EzyAppSendResponseImpl cmd = new EzyAppSendResponseImpl(appContext);
    EzyData data = EzyEntityFactory.newArrayBuilder().build();
    EzyAbstractSession session = spy(EzyAbstractSession.class);
    cmd.execute(data, session, false);
    cmd.execute(data, Lists.newArrayList(session), false);
}
Also used : EzySimpleAppSetting(com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting) EzyApplication(com.tvd12.ezyfoxserver.EzyApplication) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyAbstractSession(com.tvd12.ezyfoxserver.entity.EzyAbstractSession) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyData(com.tvd12.ezyfox.entity.EzyData) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext) EzyAppSendResponseImpl(com.tvd12.ezyfoxserver.command.impl.EzyAppSendResponseImpl) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 60 with EzyZoneContext

use of com.tvd12.ezyfoxserver.context.EzyZoneContext in project ezyfox-server by youngmonkeys.

the class EzyBroadcastEventImplTest method test.

@Test
public void test() {
    EzyServerContext serverContext = mock(EzyServerContext.class);
    EzyZoneContext zoneContext1 = mock(EzyZoneContext.class);
    EzyZoneContext zoneContext2 = mock(EzyZoneContext.class);
    doThrow(new IllegalStateException()).when(zoneContext2).handleEvent(any(), any());
    when(serverContext.getZoneContexts()).thenReturn(Lists.newArrayList(zoneContext1, zoneContext2));
    EzyBroadcastEventImpl cmd = new EzyBroadcastEventImpl(serverContext);
    EzyServerInitializingEvent event = new EzySimpleServerInitializingEvent();
    cmd.fire(EzyEventType.SERVER_INITIALIZING, event, true);
    try {
        cmd.fire(EzyEventType.SERVER_INITIALIZING, event, false);
    } catch (Exception e) {
        assert e instanceof IllegalStateException;
    }
}
Also used : EzySimpleServerInitializingEvent(com.tvd12.ezyfoxserver.event.EzySimpleServerInitializingEvent) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyServerInitializingEvent(com.tvd12.ezyfoxserver.event.EzyServerInitializingEvent) EzyBroadcastEventImpl(com.tvd12.ezyfoxserver.command.impl.EzyBroadcastEventImpl) BaseTest(com.tvd12.test.base.BaseTest) Test(org.testng.annotations.Test)

Aggregations

EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)77 Test (org.testng.annotations.Test)65 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)42 BaseTest (com.tvd12.test.base.BaseTest)26 EzyZoneUserManager (com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager)24 EzyAbstractSession (com.tvd12.ezyfoxserver.entity.EzyAbstractSession)23 EzyZone (com.tvd12.ezyfoxserver.EzyZone)21 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)21 EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)20 EzySessionManager (com.tvd12.ezyfoxserver.wrapper.EzySessionManager)20 EzyAppContext (com.tvd12.ezyfoxserver.context.EzyAppContext)18 EzySimpleZoneSetting (com.tvd12.ezyfoxserver.setting.EzySimpleZoneSetting)18 EzyArray (com.tvd12.ezyfox.entity.EzyArray)17 EzySimpleUser (com.tvd12.ezyfoxserver.entity.EzySimpleUser)17 EzyUser (com.tvd12.ezyfoxserver.entity.EzyUser)15 EzySimpleZone (com.tvd12.ezyfoxserver.EzySimpleZone)13 EzyPluginContext (com.tvd12.ezyfoxserver.context.EzyPluginContext)13 EzyApplication (com.tvd12.ezyfoxserver.EzyApplication)12 EzyResponseApi (com.tvd12.ezyfoxserver.api.EzyResponseApi)12 EzyServer (com.tvd12.ezyfoxserver.EzyServer)11