Search in sources :

Example 36 with EzyServerContext

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

the class EzyRequestAppControllerTest method testHasNotAccessed.

@Test
public void testHasNotAccessed() {
    EzyArray data = EzyEntityArrays.newArray(1, EzyEntityArrays.newArray());
    EzyRequestAppController controller = new EzyRequestAppController();
    MyTestUser user = new MyTestUser();
    user.setName("dungtv1");
    user.addSession(session);
    EzySimpleRequestAppRequest request = new EzySimpleRequestAppRequest();
    request.deserializeParams(data);
    request.setUser(user);
    request.setSession(session);
    EzyServerContext ctx = newServerContext();
    controller.handle(ctx, request);
}
Also used : EzyRequestAppController(com.tvd12.ezyfoxserver.controller.EzyRequestAppController) MyTestUser(com.tvd12.ezyfoxserver.testing.MyTestUser) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzySimpleRequestAppRequest(com.tvd12.ezyfoxserver.request.EzySimpleRequestAppRequest) Test(org.testng.annotations.Test) BaseCoreContextTest(com.tvd12.ezyfoxserver.testing.BaseCoreContextTest)

Example 37 with EzyServerContext

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

the class EzyRequestAppControllerTest method newServerContext.

@Override
protected EzyServerContext newServerContext() {
    session = newSession();
    session.setToken("abc");
    user = new MyTestUser();
    user.setName("dungtv");
    user.addSession(session);
    EzyAppContext appContext = mock(EzyAppContext.class);
    EzySimpleApplication app = new EzySimpleApplication();
    app.setSetting(new EzySimpleAppSetting());
    app.setUserManager(EzyAppUserManagerImpl.builder().build());
    app.getUserManager().addUser(user);
    when(appContext.getApp()).thenReturn(app);
    EzyServerContext serverContext = mock(EzyServerContext.class);
    when(serverContext.getAppContext(1)).thenReturn(appContext);
    return serverContext;
}
Also used : EzySimpleAppSetting(com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting) EzySimpleApplication(com.tvd12.ezyfoxserver.EzySimpleApplication) MyTestUser(com.tvd12.ezyfoxserver.testing.MyTestUser) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext)

Example 38 with EzyServerContext

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

the class EzyRequestAppControllerTest method test.

@Test
public void test() {
    EzyArray data = EzyEntityArrays.newArray(1, EzyEntityArrays.newArray());
    EzyRequestAppController controller = new EzyRequestAppController();
    EzySimpleRequestAppRequest request = new EzySimpleRequestAppRequest();
    request.deserializeParams(data);
    request.setUser(user);
    request.setSession(session);
    EzyServerContext ctx = newServerContext();
    controller.handle(ctx, request);
}
Also used : EzyRequestAppController(com.tvd12.ezyfoxserver.controller.EzyRequestAppController) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzySimpleRequestAppRequest(com.tvd12.ezyfoxserver.request.EzySimpleRequestAppRequest) Test(org.testng.annotations.Test) BaseCoreContextTest(com.tvd12.ezyfoxserver.testing.BaseCoreContextTest)

Example 39 with EzyServerContext

use of com.tvd12.ezyfoxserver.context.EzyServerContext 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 40 with EzyServerContext

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

the class EzyEmbeddedServer method start.

public EzyServerContext start() throws Exception {
    EzyRunner runner = EzyEmbeddedRunner.builder().config(config).settings(settings).build();
    runner.run(new String[] { configFile });
    serverContext = runner.getServerContext();
    return serverContext;
}
Also used : EzyRunner(com.tvd12.ezyfoxserver.EzyRunner)

Aggregations

EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)72 Test (org.testng.annotations.Test)67 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)46 EzyAbstractSession (com.tvd12.ezyfoxserver.entity.EzyAbstractSession)25 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)25 BaseTest (com.tvd12.test.base.BaseTest)23 EzySessionManager (com.tvd12.ezyfoxserver.wrapper.EzySessionManager)22 EzyZoneUserManager (com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager)21 EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)20 EzyServer (com.tvd12.ezyfoxserver.EzyServer)17 EzySettings (com.tvd12.ezyfoxserver.setting.EzySettings)16 EzyArray (com.tvd12.ezyfox.entity.EzyArray)14 EzyAppContext (com.tvd12.ezyfoxserver.context.EzyAppContext)14 EzyResponse (com.tvd12.ezyfoxserver.response.EzyResponse)13 BaseCoreTest (com.tvd12.ezyfoxserver.testing.BaseCoreTest)13 EzySimpleZone (com.tvd12.ezyfoxserver.EzySimpleZone)12 EzyChannel (com.tvd12.ezyfoxserver.socket.EzyChannel)12 EzyZone (com.tvd12.ezyfoxserver.EzyZone)11 EzyController (com.tvd12.ezyfoxserver.controller.EzyController)11 EzyLoggerSetting (com.tvd12.ezyfoxserver.setting.EzyLoggerSetting)11