Search in sources :

Example 36 with EzyZoneContext

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

the class EzyPluginInfoControllerTest method test.

@Test
public void test() {
    EzyPluginInfoController controller = new EzyPluginInfoController();
    EzyServerContext serverContext = mock(EzyServerContext.class);
    EzyZoneContext zoneContext = mock(EzyZoneContext.class);
    when(serverContext.getZoneContext(1)).thenReturn(zoneContext);
    EzySimplePluginInfoRequest request = new EzySimplePluginInfoRequest();
    EzyAbstractSession session = spy(EzyAbstractSession.class);
    EzySimpleUser user = new EzySimpleUser();
    user.setZoneId(1);
    request.setSession(session);
    request.setUser(user);
    EzyArray data = EzyEntityFactory.newArrayBuilder().append("test").build();
    request.deserializeParams(data);
    controller.handle(serverContext, request);
    EzyPluginContext pluginContext = mock(EzyPluginContext.class);
    EzySimplePlugin plugin = new EzySimplePlugin();
    EzySimplePluginSetting pluginSetting = new EzySimplePluginSetting();
    plugin.setSetting(pluginSetting);
    when(pluginContext.getPlugin()).thenReturn(plugin);
    when(zoneContext.getPluginContext("test")).thenReturn(pluginContext);
    controller.handle(serverContext, request);
}
Also used : EzySimplePluginInfoRequest(com.tvd12.ezyfoxserver.request.EzySimplePluginInfoRequest) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyAbstractSession(com.tvd12.ezyfoxserver.entity.EzyAbstractSession) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyPluginContext(com.tvd12.ezyfoxserver.context.EzyPluginContext) EzyPluginInfoController(com.tvd12.ezyfoxserver.controller.EzyPluginInfoController) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzySimplePlugin(com.tvd12.ezyfoxserver.EzySimplePlugin) EzySimplePluginSetting(com.tvd12.ezyfoxserver.setting.EzySimplePluginSetting) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 37 with EzyZoneContext

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

the class EzyZoneUserManagerImplTest method test.

@Test
public void test() throws Exception {
    EzyServerContext serverContext = mock(EzyServerContext.class);
    EzyZoneContext zoneContext = mock(EzyZoneContext.class);
    when(serverContext.getZoneContext(1)).thenReturn(zoneContext);
    TestBlockingSocketUserRemovalQueue queue = new TestBlockingSocketUserRemovalQueue();
    EzySimpleUserDelegate userDelegate = new EzySimpleUserDelegate(serverContext, queue);
    EzyZoneUserManagerImpl manager = (EzyZoneUserManagerImpl) EzyZoneUserManagerImpl.builder().idleValidationDelay(10).idleValidationInterval(10).idleValidationThreadPoolSize(1).userDelegate(userDelegate).maxIdleTime(10).build();
    EzyAbstractSession session1 = mock(EzyAbstractSession.class);
    EzySimpleUser user1 = new EzySimpleUser();
    user1.setZoneId(1);
    user1.setName("user1");
    user1.setMaxIdleTime(0);
    manager.addUser(session1, user1);
    assert manager.getUserCount() == 1;
    assert manager.getUser(session1) == user1;
    EzyAbstractSession session12 = mock(EzyAbstractSession.class);
    manager.bind(session12, user1);
    manager.unmapSessionUser(session12, EzyUserRemoveReason.EXIT_APP);
    assert manager.getUserCount() == 0;
    EzyAbstractSession session2 = mock(EzyAbstractSession.class);
    EzySimpleUser user2 = new EzySimpleUser();
    user2.setZoneId(1);
    user2.setName("user2");
    user2.setMaxIdleTime(Integer.MAX_VALUE);
    user2.addSession(session2);
    manager.addUser(session2, user2);
    assert manager.getUserCount() == 1;
    newAndAddIdleUser(manager);
    assert manager.getUserCount() == 2;
    newAndAddIdleUser(manager);
    assert manager.getUserCount() == 3;
    manager.start();
    Thread.sleep(300);
    assert manager.getUserCount() == 1;
    manager.destroy();
}
Also used : EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyAbstractSession(com.tvd12.ezyfoxserver.entity.EzyAbstractSession) EzySimpleUserDelegate(com.tvd12.ezyfoxserver.delegate.EzySimpleUserDelegate) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyZoneUserManagerImpl(com.tvd12.ezyfoxserver.wrapper.impl.EzyZoneUserManagerImpl) TestBlockingSocketUserRemovalQueue(com.tvd12.ezyfoxserver.testing.socket.TestBlockingSocketUserRemovalQueue) Test(org.testng.annotations.Test)

Example 38 with EzyZoneContext

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

the class EzySimpleAppEntryTest method scanPackages.

@Test
public void scanPackages() {
    // given
    EzyAppContext appContext = mock(EzyAppContext.class);
    ScheduledExecutorService executorService = mock(ScheduledExecutorService.class);
    EzyZoneContext zoneContext = mock(EzyZoneContext.class);
    EzyServerContext serverContext = mock(EzyServerContext.class);
    EzyApplication application = mock(EzyApplication.class);
    EzyAppUserManager appUserManager = mock(EzyAppUserManager.class);
    EzyAppSetup appSetup = mock(EzyAppSetup.class);
    EzyAppSetting appSetting = mock(EzyAppSetting.class);
    when(application.getSetting()).thenReturn(appSetting);
    InternalAppEntry sut = new InternalAppEntry();
    // when
    when(appContext.get(ScheduledExecutorService.class)).thenReturn(executorService);
    when(appContext.getParent()).thenReturn(zoneContext);
    when(zoneContext.getParent()).thenReturn(serverContext);
    when(appContext.getApp()).thenReturn(application);
    when(application.getUserManager()).thenReturn(appUserManager);
    when(appContext.get(EzyAppSetup.class)).thenReturn(appSetup);
    sut.config(appContext);
    // then
    EzyBeanContext beanContext = sut.beanContext;
    MongoConfig mongoConfig = (MongoConfig) beanContext.getBean(MongoConfig.class);
    Set<String> expectedPackages = Sets.newHashSet(EzySupportConstants.DEFAULT_PACKAGE_TO_SCAN, "com.tvd12.ezyfoxserver.support.v120.test.entry");
    Asserts.assertEquals(expectedPackages, mongoConfig.packagesToScan);
    Singleton singleton = (Singleton) beanContext.getBean(Singleton.class);
    Asserts.assertNotNull(singleton);
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) EzyAppSetup(com.tvd12.ezyfoxserver.command.EzyAppSetup) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyBeanContext(com.tvd12.ezyfox.bean.EzyBeanContext) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext) EzyAppSetting(com.tvd12.ezyfoxserver.setting.EzyAppSetting) EzyApplication(com.tvd12.ezyfoxserver.EzyApplication) EzyAppUserManager(com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager) EzySingleton(com.tvd12.ezyfox.bean.annotation.EzySingleton) Test(org.testng.annotations.Test)

Example 39 with EzyZoneContext

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

the class EzySimplePluginEntryTest method notAllowRequestTest.

@Test
public void notAllowRequestTest() {
    // given
    EzyPluginContext pluginContext = mock(EzyPluginContext.class);
    ScheduledExecutorService executorService = mock(ScheduledExecutorService.class);
    EzyZoneContext zoneContext = mock(EzyZoneContext.class);
    EzyServerContext serverContext = mock(EzyServerContext.class);
    EzyPluginSetup pluginSetup = mock(EzyPluginSetup.class);
    EzyPlugin plugin = mock(EzyPlugin.class);
    when(pluginContext.getPlugin()).thenReturn(plugin);
    EzyPluginSetting pluginSetting = mock(EzyPluginSetting.class);
    when(plugin.getSetting()).thenReturn(pluginSetting);
    NotAllowRequestEntry sut = new NotAllowRequestEntry();
    // when
    when(pluginContext.get(ScheduledExecutorService.class)).thenReturn(executorService);
    when(pluginContext.getParent()).thenReturn(zoneContext);
    when(zoneContext.getParent()).thenReturn(serverContext);
    when(pluginContext.get(EzyPluginSetup.class)).thenReturn(pluginSetup);
    sut.config(pluginContext);
    // then
    verify(pluginContext, times(0)).get(EzyPluginSetup.class);
}
Also used : EzyPluginSetup(com.tvd12.ezyfoxserver.command.EzyPluginSetup) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyPluginContext(com.tvd12.ezyfoxserver.context.EzyPluginContext) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyPlugin(com.tvd12.ezyfoxserver.EzyPlugin) EzyPluginSetting(com.tvd12.ezyfoxserver.setting.EzyPluginSetting) Test(org.testng.annotations.Test)

Example 40 with EzyZoneContext

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

the class EzySocketUserRemovalHandlerTest method test.

@Test
public void test() {
    TestBlockingSocketUserRemovalQueue queue = new TestBlockingSocketUserRemovalQueue();
    EzyAppContext appContext1 = mock(EzyAppContext.class);
    EzyAppUserManager userManager1 = mock(EzyAppUserManager.class);
    when(userManager1.containsUser(any(EzyUser.class))).thenReturn(true);
    EzyApplication app1 = mock(EzyApplication.class);
    when(app1.getUserManager()).thenReturn(userManager1);
    when(appContext1.getApp()).thenReturn(app1);
    EzyAppContext appContext2 = mock(EzyAppContext.class);
    EzyAppUserManager userManager2 = mock(EzyAppUserManager.class);
    when(userManager2.containsUser(any(EzyUser.class))).thenReturn(false);
    EzyApplication app2 = mock(EzyApplication.class);
    when(app2.getUserManager()).thenReturn(userManager2);
    when(appContext2.getApp()).thenReturn(app2);
    EzyZoneContext zoneContext = mock(EzyZoneContext.class);
    when(zoneContext.getAppContexts()).thenReturn(Lists.newArrayList(appContext1, appContext2));
    EzySimpleUser user = new EzySimpleUser();
    user.setName("test");
    EzySocketUserRemoval item = new EzySimpleSocketUserRemoval(zoneContext, user, EzyUserRemoveReason.EXIT_APP);
    queue.add(item);
    EzySocketUserRemovalHandler handler = new EzySocketUserRemovalHandler(queue);
    handler.handleEvent();
    handler.destroy();
}
Also used : EzyUser(com.tvd12.ezyfoxserver.entity.EzyUser) EzyApplication(com.tvd12.ezyfoxserver.EzyApplication) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyAppUserManager(com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext) 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