Search in sources :

Example 11 with EzySimpleAppSetting

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

the class EzySimpleAppSettingTest method configFileIsNull.

@Test
public void configFileIsNull() {
    // given
    EzySimpleAppSetting sut = new EzySimpleAppSetting();
    sut.setConfigFile(null);
    // when
    String configFile = sut.getConfigFile(true);
    // then
    Asserts.assertNull(configFile);
    System.out.println(sut.toMap());
}
Also used : EzySimpleAppSetting(com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting) BaseTest(com.tvd12.test.base.BaseTest) Test(org.testng.annotations.Test)

Example 12 with EzySimpleAppSetting

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

the class HelloEmbeddedServer3 method main.

public static void main(String[] args) throws Exception {
    EzySimplePluginSetting pluginSetting = new EzyPluginSettingBuilder().name(// plugin name
    "hello").addListenEvent(// listen able events USER_LOGIN, USER_ADDED, USER_REMOVED
    EzyEventType.USER_LOGIN).configFile("config.properties").entryLoader(HelloPluginEntryLoader.class).priority(// set priority, bigger number is lower, default 0
    1).threadPoolSize(// set thread pool size to create executor service for this plugin, default 0
    3).build();
    EzySimpleAppSetting appSetting = new EzyAppSettingBuilder().name(// app's name
    "hello").configFile("config.properties").entryLoader(HelloAppEntryLoader.class).maxUsers(// set max user in this app, default 999999
    9999).threadPoolSize(// set thread pool size to create executor service for this app, default 0
    3).build();
    EzySimpleUserManagementSetting userManagementSetting = new EzyUserManagementSettingBuilder().allowChangeSession(// allow change user's session, default true
    true).allowGuestLogin(// allow guest login, default false
    true).guestNamePrefix(// set name prefix for guest
    "Guest#").maxSessionPerUser(// set number of max sessions per user // default 5
    5).userMaxIdleTimeInSecond(// set max idle time of an user, default 0
    15).userNamePattern(// set username pattern, default ^[a-z0-9_.]{3,36}$
    "^[a-z0-9_.]{3,36}$").build();
    EzySimpleZoneSetting zoneSetting = new EzyZoneSettingBuilder().name(// zone's name
    "hello").plugin(// add a plug-in to zone
    pluginSetting).application(// add an app to zone
    appSetting).configFile(// set config file
    "config.properties").maxUsers(// set maximum user for zone
    999999).userManagement(// set user management settings
    userManagementSetting).addEventController(EzyEventType.SERVER_READY, HelloZoneServerReadyController.class).build();
    EzySimpleSocketSetting socketSetting = new EzySocketSettingBuilder().active(// active or not,  default true
    true).address(// loopback address, default 0.0.0.0
    "0.0.0.0").codecCreator(// encoder/decoder creator, default MsgPackCodecCreator
    MsgPackCodecCreator.class).maxRequestSize(// max request size, default 32768
    1024).port(// port, default 3005
    3005).tcpNoDelay(// tcp no delay, default false
    true).writerThreadPoolSize(// thread pool size for socket writer, default 8
    8).build();
    EzySimpleWebSocketSetting webSocketSetting = new EzyWebSocketSettingBuilder().active(// active or not,  default true
    true).address(// loopback address, default 0.0.0.0
    "0.0.0.0").codecCreator(// encoder/decoder creator, default JacksonCodecCreator
    JacksonCodecCreator.class).maxFrameSize(// max frame size, default 32768
    32678).port(// port, default 3005
    2208).writerThreadPoolSize(// thread pool size for socket writer, default 8
    8).build();
    EzySimpleMaxRequestPerSecond maxRequestPerSecond = new EzyMaxRequestPerSecondBuilder().value(// max request in a second
    15).action(// action when get max
    EzyMaxRequestPerSecondAction.DROP_REQUEST).build();
    EzySimpleSessionManagementSetting sessionManagementSetting = new EzySessionManagementSettingBuilder().sessionMaxIdleTimeInSecond(// set max idle time for session, default 30s
    30).sessionMaxWaitingTimeInSecond(// set max waiting time to login for session, default 30s
    30).sessionMaxRequestPerSecond(// set max request in a session for a session
    maxRequestPerSecond).build();
    EzySimpleUdpSetting udpSetting = new EzyUdpSettingBuilder().active(// active or not
    true).address(// set loopback IP
    "0.0.0.0").channelPoolSize(// set number of udp channel for socket writing, default 16
    16).codecCreator(// encoder/decoder creator, default MsgPackCodecCreator
    MsgPackCodecCreator.class).handlerThreadPoolSize(// set number of handler's thread, default 5
    5).maxRequestSize(// set max request's size
    1024).port(// set listen port
    2611).build();
    EzySimpleSettings settings = new EzySettingsBuilder().debug(// allow debug to print log or not, default false
    true).nodeName(// for convenient
    "hello").zone(// add a zone to server
    zoneSetting).socket(// set socket setting
    socketSetting).websocket(// set websocket setting
    webSocketSetting).udp(// set udp setting
    udpSetting).sessionManagement(// set session management setting
    sessionManagementSetting).addEventController(EzyEventType.SERVER_INITIALIZING, HelloServerInitializingReadyController.class).build();
    EzyEmbeddedServer server = EzyEmbeddedServer.builder().settings(settings).build();
    server.start();
}
Also used : EzySimpleMaxRequestPerSecond(com.tvd12.ezyfoxserver.setting.EzySimpleSessionManagementSetting.EzySimpleMaxRequestPerSecond) MsgPackCodecCreator(com.tvd12.ezyfox.codec.MsgPackCodecCreator) EzyMaxRequestPerSecondBuilder(com.tvd12.ezyfoxserver.setting.EzySessionManagementSettingBuilder.EzyMaxRequestPerSecondBuilder) EzyEmbeddedServer(com.tvd12.ezyfoxserver.embedded.EzyEmbeddedServer)

Example 13 with EzySimpleAppSetting

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

the class EzyDefaultAppEntryTest method test2.

@Test
public void test2() throws Exception {
    EzySimpleSettings settings = new EzySimpleSettings();
    EzySimpleServer server = new EzySimpleServer();
    server.setSettings(settings);
    EzySimpleServerContext serverContext = new EzySimpleServerContext();
    serverContext.setServer(server);
    serverContext.init();
    EzySimpleZoneSetting zoneSetting = new EzySimpleZoneSetting();
    EzySimpleZone zone = new EzySimpleZone();
    zone.setSetting(zoneSetting);
    EzySimpleZoneContext zoneContext = new EzySimpleZoneContext();
    zoneContext.setZone(zone);
    zoneContext.init();
    zoneContext.setParent(serverContext);
    EzySimpleAppSetting appSetting = new EzySimpleAppSetting();
    appSetting.setName("test");
    EzyAppUserManager appUserManager = EzyAppUserManagerImpl.builder().build();
    EzyEventControllersSetting eventControllersSetting = new EzySimpleEventControllersSetting();
    EzyEventControllers eventControllers = EzyEventControllersImpl.create(eventControllersSetting);
    EzySimpleApplication application = new EzySimpleApplication();
    application.setSetting(appSetting);
    application.setUserManager(appUserManager);
    application.setEventControllers(eventControllers);
    ScheduledExecutorService appScheduledExecutorService = new EzyErrorScheduledExecutorService("not implement");
    EzySimpleAppContext appContext = new EzySimpleAppContext();
    appContext.setApp(application);
    appContext.setParent(zoneContext);
    appContext.setExecutorService(appScheduledExecutorService);
    appContext.init();
    EzySimpleAppEntry entry = new EzyAppEntryEx2();
    entry.config(appContext);
    entry.start();
    entry.destroy();
}
Also used : EzyErrorScheduledExecutorService(com.tvd12.ezyfox.concurrent.EzyErrorScheduledExecutorService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) EzyErrorScheduledExecutorService(com.tvd12.ezyfox.concurrent.EzyErrorScheduledExecutorService) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzySimpleServerContext(com.tvd12.ezyfoxserver.context.EzySimpleServerContext) EzySimpleZoneContext(com.tvd12.ezyfoxserver.context.EzySimpleZoneContext) EzySimpleZone(com.tvd12.ezyfoxserver.EzySimpleZone) EzySimpleApplication(com.tvd12.ezyfoxserver.EzySimpleApplication) EzyEventControllers(com.tvd12.ezyfoxserver.wrapper.EzyEventControllers) EzyAppUserManager(com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager) EzySimpleAppContext(com.tvd12.ezyfoxserver.context.EzySimpleAppContext) EzySimpleAppEntry(com.tvd12.ezyfoxserver.support.entry.EzySimpleAppEntry) Test(org.testng.annotations.Test)

Example 14 with EzySimpleAppSetting

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

the class EzySimpleAppEntryTest method test2.

@Test
public void test2() throws Exception {
    EzySimpleSettings settings = new EzySimpleSettings();
    EzySimpleServer server = new EzySimpleServer();
    server.setSettings(settings);
    EzySimpleServerContext serverContext = new EzySimpleServerContext();
    serverContext.setServer(server);
    serverContext.init();
    EzySimpleZoneSetting zoneSetting = new EzySimpleZoneSetting();
    EzySimpleZone zone = new EzySimpleZone();
    zone.setSetting(zoneSetting);
    EzySimpleZoneContext zoneContext = new EzySimpleZoneContext();
    zoneContext.setZone(zone);
    zoneContext.init();
    zoneContext.setParent(serverContext);
    EzySimpleAppSetting appSetting = new EzySimpleAppSetting();
    appSetting.setName("test");
    EzyAppUserManager appUserManager = EzyAppUserManagerImpl.builder().build();
    EzyEventControllersSetting eventControllersSetting = new EzySimpleEventControllersSetting();
    EzyEventControllers eventControllers = EzyEventControllersImpl.create(eventControllersSetting);
    EzySimpleApplication application = new EzySimpleApplication();
    application.setSetting(appSetting);
    application.setUserManager(appUserManager);
    application.setEventControllers(eventControllers);
    ScheduledExecutorService appScheduledExecutorService = new EzyErrorScheduledExecutorService("not implement");
    EzySimpleAppContext appContext = new EzySimpleAppContext();
    appContext.setApp(application);
    appContext.setParent(zoneContext);
    appContext.setExecutorService(appScheduledExecutorService);
    appContext.init();
    EzySimpleAppEntry entry = new EzyAppEntryEx2();
    entry.config(appContext);
    entry.start();
    entry.destroy();
}
Also used : EzyErrorScheduledExecutorService(com.tvd12.ezyfox.concurrent.EzyErrorScheduledExecutorService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) EzyErrorScheduledExecutorService(com.tvd12.ezyfox.concurrent.EzyErrorScheduledExecutorService) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzySimpleServerContext(com.tvd12.ezyfoxserver.context.EzySimpleServerContext) EzySimpleZoneContext(com.tvd12.ezyfoxserver.context.EzySimpleZoneContext) EzySimpleZone(com.tvd12.ezyfoxserver.EzySimpleZone) EzySimpleApplication(com.tvd12.ezyfoxserver.EzySimpleApplication) EzyEventControllers(com.tvd12.ezyfoxserver.wrapper.EzyEventControllers) EzyAppUserManager(com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager) EzySimpleAppContext(com.tvd12.ezyfoxserver.context.EzySimpleAppContext) EzySimpleAppEntry(com.tvd12.ezyfoxserver.support.entry.EzySimpleAppEntry) Test(org.testng.annotations.Test)

Example 15 with EzySimpleAppSetting

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

the class EzyZoneSettingBuilderTest method test.

@Test
public void test() {
    EzySimpleAppSetting appSetting = new EzyAppSettingBuilder().configFile("config.properties").entryLoader(TestAppEntryLoader.class).entryLoaderArgs(new String[] { "hello" }).maxUsers(100).name("test").threadPoolSize(3).build();
    EzySimpleAppsSetting appsSetting = new EzySimpleAppsSetting();
    EzySimpleListenEvents listenEvents = new EzySimpleListenEvents();
    EzySimplePluginSetting pluginSetting = new EzyPluginSettingBuilder().configFile("config.properties").entryLoader(TestPluginEntryLoader.class).name("test").threadPoolSize(3).priority(1).listenEvents(listenEvents).addListenEvent(EzyEventType.USER_LOGIN).addListenEvent(EzyEventType.USER_LOGIN.toString()).build();
    EzySimplePluginsSetting pluginsSetting = new EzySimplePluginsSetting();
    EzySimpleStreamingSetting streamingSetting = new EzySimpleStreamingSetting();
    EzySimpleEventControllersSetting eventControllersSetting = new EzySimpleEventControllersSetting();
    EzySimpleUserManagementSetting userManagementSetting = new EzyUserManagementSettingBuilder().allowChangeSession(true).allowGuestLogin(true).guestNamePrefix("Guest#").maxSessionPerUser(3).userMaxIdleTimeInSecond(100).userNamePattern("user#name").build();
    EzySimpleZoneSetting setting = new EzyZoneSettingBuilder().configFile("config.properties").maxUsers(1000).name("test").applications(appsSetting).application(appSetting).plugins(pluginsSetting).plugin(pluginSetting).streaming(streamingSetting).eventControllers(eventControllersSetting).userManagement(userManagementSetting).addEventController(EzyEventType.SERVER_READY, HelloZoneServerReadyController.class).build();
    assertEquals(setting.getConfigFile(), "config.properties");
    assertEquals(setting.getMaxUsers(), 1000);
    assertEquals(setting.getName(), "test");
    assertEquals(setting.getApplications(), appsSetting);
    assertEquals(setting.getPlugins(), pluginsSetting);
    assertEquals(setting.getStreaming(), streamingSetting);
    assertEquals(setting.getEventControllers(), eventControllersSetting);
    assertEquals(setting.getUserManagement(), userManagementSetting);
    appSetting = appsSetting.getAppByName("test");
    assertEquals(appSetting.getConfigFile(true), "config.properties");
    assertEquals(appSetting.getEntryLoader(), TestAppEntryLoader.class.getName());
    assertEquals(appSetting.getFolder(), "test");
    assertEquals(appSetting.getMaxUsers(), 100);
    assertEquals(appSetting.getName(), "test");
    assertEquals(appSetting.getThreadPoolSize(), 3);
    assertEquals(appSetting.getConfigFileInput(), "config.properties");
    pluginSetting = pluginsSetting.getPluginByName("test");
    assertEquals(pluginSetting.getConfigFile(true), "config.properties");
    assertEquals(pluginSetting.getEntryLoader(), TestPluginEntryLoader.class.getName());
    assertEquals(pluginSetting.getFolder(), "test");
    assertEquals(pluginSetting.getName(), "test");
    assertEquals(pluginSetting.getThreadPoolSize(), 3);
    assertEquals(pluginSetting.getPriority(), 1);
    assertEquals(pluginSetting.getListenEvents().getEvents().size(), 1);
    userManagementSetting = setting.getUserManagement();
    assertTrue(userManagementSetting.isAllowChangeSession());
    assertTrue(userManagementSetting.isAllowGuestLogin());
    assertEquals(userManagementSetting.getGuestNamePrefix(), "Guest#");
    assertEquals(userManagementSetting.getMaxSessionPerUser(), 3);
    assertEquals(userManagementSetting.getUserMaxIdleTimeInSecond(), 100);
    assertEquals(userManagementSetting.getUserNamePattern(), "user#name");
}
Also used : EzySimpleListenEvents(com.tvd12.ezyfoxserver.setting.EzySimplePluginSetting.EzySimpleListenEvents) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)34 EzySimpleAppSetting (com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting)29 BaseTest (com.tvd12.test.base.BaseTest)25 EzySimpleApplication (com.tvd12.ezyfoxserver.EzySimpleApplication)17 EzyAppContext (com.tvd12.ezyfoxserver.context.EzyAppContext)12 EzySimpleAppContext (com.tvd12.ezyfoxserver.context.EzySimpleAppContext)11 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)11 EzyAppUserManager (com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager)11 EzyApplication (com.tvd12.ezyfoxserver.EzyApplication)9 EzySimpleZoneContext (com.tvd12.ezyfoxserver.context.EzySimpleZoneContext)9 EzySimpleZone (com.tvd12.ezyfoxserver.EzySimpleZone)8 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)8 EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)6 EzySimpleServerContext (com.tvd12.ezyfoxserver.context.EzySimpleServerContext)6 EzySimpleAppUserDelegate (com.tvd12.ezyfoxserver.delegate.EzySimpleAppUserDelegate)6 EzySimpleUser (com.tvd12.ezyfoxserver.entity.EzySimpleUser)6 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)6 EzyErrorScheduledExecutorService (com.tvd12.ezyfox.concurrent.EzyErrorScheduledExecutorService)5 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)5 EzyResponse (com.tvd12.ezyfoxserver.response.EzyResponse)5