Search in sources :

Example 1 with EzyZoneUserManagerImpl

use of com.tvd12.ezyfoxserver.wrapper.impl.EzyZoneUserManagerImpl 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 EzyZoneUserManagerImpl

use of com.tvd12.ezyfoxserver.wrapper.impl.EzyZoneUserManagerImpl in project ezyfox-server by youngmonkeys.

the class EzyZoneUserManagerImplTest method startIdleValidationServiceWithIdleValidationService.

@Test
public void startIdleValidationServiceWithIdleValidationService() {
    // given
    EzyZoneUserManagerImpl sut = newZoneUserManager();
    // when
    MethodUtil.invokeMethod("startIdleValidationService", sut);
    // then
    Asserts.assertNull(FieldUtil.getFieldValue(sut, "idleValidationService"));
}
Also used : EzyZoneUserManagerImpl(com.tvd12.ezyfoxserver.wrapper.impl.EzyZoneUserManagerImpl) Test(org.testng.annotations.Test)

Example 3 with EzyZoneUserManagerImpl

use of com.tvd12.ezyfoxserver.wrapper.impl.EzyZoneUserManagerImpl in project ezyfox-server by youngmonkeys.

the class EzyZoneUserManagerImplTest method unmapSessionUserWithSessionCountGreaterThan1.

@Test
public void unmapSessionUserWithSessionCountGreaterThan1() {
    // given
    EzyZoneUserManagerImpl sut = newZoneUserManager();
    EzySession session = mock(EzySession.class);
    EzyUser user = mock(EzyUser.class);
    when(user.getSessionCount()).thenReturn(1);
    Map<EzySession, EzyUser> usersBySession = FieldUtil.getFieldValue(sut, "usersBySession");
    usersBySession.put(session, user);
    // when
    sut.unmapSessionUser(session, mock(EzyConstant.class));
    // then
    Asserts.assertNull(sut.getUser(session));
}
Also used : EzyUser(com.tvd12.ezyfoxserver.entity.EzyUser) EzyZoneUserManagerImpl(com.tvd12.ezyfoxserver.wrapper.impl.EzyZoneUserManagerImpl) EzyConstant(com.tvd12.ezyfox.constant.EzyConstant) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test)

Example 4 with EzyZoneUserManagerImpl

use of com.tvd12.ezyfoxserver.wrapper.impl.EzyZoneUserManagerImpl in project ezyfox-server by youngmonkeys.

the class EzyZoneUserManagerImplTest method unmapSessionUserWithUserIsNull.

@Test
public void unmapSessionUserWithUserIsNull() {
    // given
    EzyZoneUserManagerImpl sut = newZoneUserManager();
    EzySession session = mock(EzySession.class);
    // when
    sut.unmapSessionUser(session, mock(EzyConstant.class));
    // then
    Asserts.assertNull(sut.getUser(session));
}
Also used : EzyZoneUserManagerImpl(com.tvd12.ezyfoxserver.wrapper.impl.EzyZoneUserManagerImpl) EzyConstant(com.tvd12.ezyfox.constant.EzyConstant) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test)

Example 5 with EzyZoneUserManagerImpl

use of com.tvd12.ezyfoxserver.wrapper.impl.EzyZoneUserManagerImpl in project ezyfox-server by youngmonkeys.

the class EzyZoneUserManagerImplTest method unmapSessionUserWithMaxIdleTimeGreaterThanZero.

@Test
public void unmapSessionUserWithMaxIdleTimeGreaterThanZero() {
    // given
    EzyZoneUserManagerImpl sut = newZoneUserManager();
    EzySession session = mock(EzySession.class);
    EzyUser user = mock(EzyUser.class);
    when(user.getMaxIdleTime()).thenReturn(1000L);
    Map<EzySession, EzyUser> usersBySession = FieldUtil.getFieldValue(sut, "usersBySession");
    usersBySession.put(session, user);
    // when
    sut.unmapSessionUser(session, mock(EzyConstant.class));
    // then
    Asserts.assertNull(sut.getUser(session));
}
Also used : EzyUser(com.tvd12.ezyfoxserver.entity.EzyUser) EzyZoneUserManagerImpl(com.tvd12.ezyfoxserver.wrapper.impl.EzyZoneUserManagerImpl) EzyConstant(com.tvd12.ezyfox.constant.EzyConstant) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test)

Aggregations

EzyZoneUserManagerImpl (com.tvd12.ezyfoxserver.wrapper.impl.EzyZoneUserManagerImpl)7 Test (org.testng.annotations.Test)6 EzyConstant (com.tvd12.ezyfox.constant.EzyConstant)3 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)3 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)2 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)2 EzySimpleUserDelegate (com.tvd12.ezyfoxserver.delegate.EzySimpleUserDelegate)2 EzyAbstractSession (com.tvd12.ezyfoxserver.entity.EzyAbstractSession)2 EzySimpleUser (com.tvd12.ezyfoxserver.entity.EzySimpleUser)2 EzyUser (com.tvd12.ezyfoxserver.entity.EzyUser)2 TestBlockingSocketUserRemovalQueue (com.tvd12.ezyfoxserver.testing.socket.TestBlockingSocketUserRemovalQueue)2