Search in sources :

Example 1 with TestBlockingSocketUserRemovalQueue

use of com.tvd12.ezyfoxserver.testing.socket.TestBlockingSocketUserRemovalQueue 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 2 with TestBlockingSocketUserRemovalQueue

use of com.tvd12.ezyfoxserver.testing.socket.TestBlockingSocketUserRemovalQueue 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)

Example 3 with TestBlockingSocketUserRemovalQueue

use of com.tvd12.ezyfoxserver.testing.socket.TestBlockingSocketUserRemovalQueue in project ezyfox-server by youngmonkeys.

the class EzySocketUserRemovalHandlerTest method processUserRemovalQueueThrowableCaseTest.

@Test
public void processUserRemovalQueueThrowableCaseTest() {
    TestBlockingSocketUserRemovalQueue queue = new TestBlockingSocketUserRemovalQueue();
    EzyZoneContext zoneContext = mock(EzyZoneContext.class);
    EzySimpleUser user = new EzySimpleUser();
    user.setName("test");
    EzySocketUserRemoval item = new EzySimpleSocketUserRemoval(zoneContext, user, EzyUserRemoveReason.EXIT_APP) {

        @Override
        public void release() {
            throw new RuntimeException();
        }
    };
    queue.add(item);
    EzySocketUserRemovalHandler handler = new EzySocketUserRemovalHandler(queue);
    handler.handleEvent();
}
Also used : EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) Test(org.testng.annotations.Test)

Example 4 with TestBlockingSocketUserRemovalQueue

use of com.tvd12.ezyfoxserver.testing.socket.TestBlockingSocketUserRemovalQueue in project ezyfox-server by youngmonkeys.

the class EzySocketUserRemovalHandlerTest method removeUserFromAppExceptionCaseTest.

@Test
public void removeUserFromAppExceptionCaseTest() {
    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);
    doThrow(new IllegalArgumentException()).when(userManager1).removeUser(any(), any());
    EzySimpleAppSetting appSetting1 = new EzySimpleAppSetting();
    appSetting1.setName("app1");
    when(app1.getSetting()).thenReturn(appSetting1);
    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);
    EzySocketUserRemovalQueue userRemovalQueue = new EzyBlockingSocketUserRemovalQueue();
    new EzySocketUserRemovalHandler(userRemovalQueue);
    EzySocketUserRemovalHandler handler = new EzySocketUserRemovalHandler(queue);
    handler.handleEvent();
    handler.destroy();
}
Also used : EzySimpleAppSetting(com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting) EzyUser(com.tvd12.ezyfoxserver.entity.EzyUser) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext) EzyApplication(com.tvd12.ezyfoxserver.EzyApplication) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyAppUserManager(com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager) Test(org.testng.annotations.Test)

Example 5 with TestBlockingSocketUserRemovalQueue

use of com.tvd12.ezyfoxserver.testing.socket.TestBlockingSocketUserRemovalQueue in project ezyfox-server by youngmonkeys.

the class EzyZoneUserManagerImplTest method newZoneUserManager.

private EzyZoneUserManagerImpl newZoneUserManager() {
    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);
    return (EzyZoneUserManagerImpl) EzyZoneUserManagerImpl.builder().idleValidationDelay(10).idleValidationInterval(10).idleValidationThreadPoolSize(1).userDelegate(userDelegate).build();
}
Also used : EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) 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)

Aggregations

EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)6 EzySimpleUser (com.tvd12.ezyfoxserver.entity.EzySimpleUser)5 Test (org.testng.annotations.Test)5 EzyApplication (com.tvd12.ezyfoxserver.EzyApplication)3 EzyAppContext (com.tvd12.ezyfoxserver.context.EzyAppContext)3 EzyUser (com.tvd12.ezyfoxserver.entity.EzyUser)3 EzyAppUserManager (com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager)3 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)2 EzySimpleUserDelegate (com.tvd12.ezyfoxserver.delegate.EzySimpleUserDelegate)2 TestBlockingSocketUserRemovalQueue (com.tvd12.ezyfoxserver.testing.socket.TestBlockingSocketUserRemovalQueue)2 EzyZoneUserManagerImpl (com.tvd12.ezyfoxserver.wrapper.impl.EzyZoneUserManagerImpl)2 EzyConstant (com.tvd12.ezyfox.constant.EzyConstant)1 EzyZone (com.tvd12.ezyfoxserver.EzyZone)1 EzyAbstractSession (com.tvd12.ezyfoxserver.entity.EzyAbstractSession)1 EzyUserEvent (com.tvd12.ezyfoxserver.event.EzyUserEvent)1 EzySimpleAppSetting (com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting)1 EzyZoneSetting (com.tvd12.ezyfoxserver.setting.EzyZoneSetting)1