Search in sources :

Example 1 with EzyImmediateDeliver

use of com.tvd12.ezyfoxserver.entity.EzyImmediateDeliver in project ezyfox-server by youngmonkeys.

the class EzySimpleUserTest method test.

@Test
public void test() {
    EzySimpleUser user = new EzySimpleUser();
    user.setId(1);
    user.setPassword("abc");
    assert user.getPassword().equals("abc");
    user.setName("dungtv1");
    EzySimpleUser user2 = new EzySimpleUser();
    user2.setPassword("abc");
    user2.setId(2);
    assert user2.getPassword().equals("abc");
    user.setName("dungtv2");
    assert !user.equals(user2);
    assert user.hashCode() != user2.hashCode();
    assert user.getLocks() != null;
    assert user.getSessionMap() != null;
    assert user.getMaxSessions() == 30;
    assert user.getStartIdleTime() > 0;
    assert !user.isDestroyed();
    assert user.getSession() == null;
    EzyAbstractSession session = spy(EzyAbstractSession.class);
    EzyImmediateDeliver immediateDeliver = mock(EzyImmediateDeliver.class);
    EzySocketDisconnectionQueue disconnectionQueue = mock(EzySocketDisconnectionQueue.class);
    session.setImmediateDeliver(immediateDeliver);
    session.setDisconnectionQueue(disconnectionQueue);
    user.addSession(session);
    assert user.getSession() == session;
    Lock lock = user.getLock("test");
    assert lock != null;
    EzyPacket packet = mock(EzyPacket.class);
    user.send(packet);
    user.sendNow(packet);
    user.disconnect(EzyDisconnectReason.IDLE);
    user.disconnect();
    user.removeSession(session);
    user.setMaxIdleTime(100 * 60 * 1000);
    assert !user.isIdle();
    user.setMaxIdleTime(-1);
    assert user.isIdle();
    user.destroy();
    user.destroy();
    assert user.getSessions().size() == 0;
}
Also used : EzyPacket(com.tvd12.ezyfoxserver.socket.EzyPacket) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyAbstractSession(com.tvd12.ezyfoxserver.entity.EzyAbstractSession) EzyImmediateDeliver(com.tvd12.ezyfoxserver.entity.EzyImmediateDeliver) EzySocketDisconnectionQueue(com.tvd12.ezyfoxserver.socket.EzySocketDisconnectionQueue) Lock(java.util.concurrent.locks.Lock) BaseTest(com.tvd12.test.base.BaseTest) Test(org.testng.annotations.Test)

Example 2 with EzyImmediateDeliver

use of com.tvd12.ezyfoxserver.entity.EzyImmediateDeliver in project ezyfox-server by youngmonkeys.

the class EzyProxyResponseApiTest method test.

@Test
public void test() throws Exception {
    EzyCodecFactory codecFactory = mock(EzyCodecFactory.class);
    EzyProxyResponseApi api = new EzyProxyResponseApi(codecFactory);
    EzyPackage pack = mock(EzyPackage.class);
    api.response(pack);
    EzyObjectToByteEncoder byteEncoder = mock(EzyObjectToByteEncoder.class);
    EzyObjectToStringEncoder stringEncoder = mock(EzyObjectToStringEncoder.class);
    when(codecFactory.newEncoder(EzyConnectionType.SOCKET)).thenReturn(byteEncoder);
    when(codecFactory.newEncoder(EzyConnectionType.WEBSOCKET)).thenReturn(stringEncoder);
    api = new EzyProxyResponseApi(codecFactory);
    api.response(pack);
    api.response(pack, true);
    EzyImmediateDeliver immediateDeliver = mock(EzyImmediateDeliver.class);
    EzyAbstractSession session = spy(EzyAbstractSession.class);
    session.setImmediateDeliver(immediateDeliver);
    when(pack.getRecipients(any(EzyConstant.class))).thenReturn(Lists.newArrayList(session));
    api.response(pack);
    api.response(pack, true);
}
Also used : EzyAbstractSession(com.tvd12.ezyfoxserver.entity.EzyAbstractSession) EzyProxyResponseApi(com.tvd12.ezyfoxserver.api.EzyProxyResponseApi) EzyPackage(com.tvd12.ezyfoxserver.response.EzyPackage) EzyConstant(com.tvd12.ezyfox.constant.EzyConstant) EzyObjectToStringEncoder(com.tvd12.ezyfox.codec.EzyObjectToStringEncoder) EzyCodecFactory(com.tvd12.ezyfoxserver.codec.EzyCodecFactory) EzyImmediateDeliver(com.tvd12.ezyfoxserver.entity.EzyImmediateDeliver) EzyObjectToByteEncoder(com.tvd12.ezyfox.codec.EzyObjectToByteEncoder) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Aggregations

EzyAbstractSession (com.tvd12.ezyfoxserver.entity.EzyAbstractSession)2 EzyImmediateDeliver (com.tvd12.ezyfoxserver.entity.EzyImmediateDeliver)2 BaseTest (com.tvd12.test.base.BaseTest)2 Test (org.testng.annotations.Test)2 EzyObjectToByteEncoder (com.tvd12.ezyfox.codec.EzyObjectToByteEncoder)1 EzyObjectToStringEncoder (com.tvd12.ezyfox.codec.EzyObjectToStringEncoder)1 EzyConstant (com.tvd12.ezyfox.constant.EzyConstant)1 EzyProxyResponseApi (com.tvd12.ezyfoxserver.api.EzyProxyResponseApi)1 EzyCodecFactory (com.tvd12.ezyfoxserver.codec.EzyCodecFactory)1 EzySimpleUser (com.tvd12.ezyfoxserver.entity.EzySimpleUser)1 EzyPackage (com.tvd12.ezyfoxserver.response.EzyPackage)1 EzyPacket (com.tvd12.ezyfoxserver.socket.EzyPacket)1 EzySocketDisconnectionQueue (com.tvd12.ezyfoxserver.socket.EzySocketDisconnectionQueue)1 Lock (java.util.concurrent.locks.Lock)1