Search in sources :

Example 91 with EzySession

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

the class EzyAbstractStreamingApi method response.

@Override
public void response(EzyBytesPackage pack) throws Exception {
    EzyConstant connectionType = getConnectionType();
    Collection<EzySession> recipients = pack.getRecipients(connectionType);
    if (recipients.isEmpty()) {
        return;
    }
    byte[] bytes = pack.getBytes();
    for (EzySession session : recipients) {
        session.send(createPacket(bytes, pack));
    }
}
Also used : EzyConstant(com.tvd12.ezyfox.constant.EzyConstant) EzySession(com.tvd12.ezyfoxserver.entity.EzySession)

Example 92 with EzySession

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

the class EzySimpleNioUdpDataHandlerTest method handleUdpHandshakeSessionTokenIsNotMatch.

@SuppressWarnings("rawtypes")
@Test
public void handleUdpHandshakeSessionTokenIsNotMatch() throws Exception {
    // given
    EzySimpleNioUdpDataHandler sut = new EzySimpleNioUdpDataHandler(1);
    DatagramChannel channel = mock(DatagramChannel.class);
    InetSocketAddress address = new InetSocketAddress(3005);
    EzyMessage message = mock(EzyMessage.class);
    String sessionToken = RandomUtil.randomAlphabetString(8);
    long sessionId = 12345L;
    int tokenSize = sessionToken.length();
    int messageSize = 0;
    // sessionIdSize
    messageSize += 8;
    // tokenLengthSize
    messageSize += 2;
    // messageSize
    messageSize += tokenSize;
    ByteBuffer buffer = ByteBuffer.allocate(messageSize);
    buffer.putLong(sessionId);
    buffer.putShort((short) tokenSize);
    buffer.put(sessionToken.getBytes());
    buffer.flip();
    byte[] bytes = EzyByteBuffers.getBytes(buffer);
    when(message.getContent()).thenReturn(bytes);
    EzySessionManager sessionManager = mock(EzySessionManager.class);
    sut.setSessionManager(sessionManager);
    EzySession session = mock(EzySession.class);
    when(session.getToken()).thenReturn(RandomUtil.randomShortAlphabetString());
    when(sessionManager.getSession(sessionId)).thenReturn(session);
    EzyResponseApi responseApi = mock(EzyResponseApi.class);
    sut.setResponseApi(responseApi);
    // when
    MethodInvoker.create().object(sut).method("handleUdpHandshake").param(DatagramChannel.class, channel).param(InetSocketAddress.class, address).param(EzyMessage.class, message).call();
    // then
    verify(message, times(1)).getContent();
    verify(sessionManager, times(1)).getSession(sessionId);
    verify(session, times(1)).getToken();
    verify(responseApi, times(1)).response(any());
    sut.destroy();
}
Also used : EzySimpleNioUdpDataHandler(com.tvd12.ezyfoxserver.nio.handler.EzySimpleNioUdpDataHandler) InetSocketAddress(java.net.InetSocketAddress) DatagramChannel(java.nio.channels.DatagramChannel) EzySessionManager(com.tvd12.ezyfoxserver.wrapper.EzySessionManager) EzyMessage(com.tvd12.ezyfox.codec.EzyMessage) ByteBuffer(java.nio.ByteBuffer) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzyResponseApi(com.tvd12.ezyfoxserver.api.EzyResponseApi) Test(org.testng.annotations.Test)

Example 93 with EzySession

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

the class EzySimpleWsHandlerGroupTest method handleReceivedSessionStreamNotEnable.

@Test
public void handleReceivedSessionStreamNotEnable() throws Exception {
    // given
    EzyWsHandlerGroup sut = newHandlerGroup();
    EzySession session = FieldUtil.getFieldValue(sut, "session");
    byte[] bytes = new byte[] { 1 << 4, 2, 3 };
    int offset = 0;
    int len = 3;
    // when
    MethodInvoker.create().object(sut).method("handleReceivedBytes").param(byte[].class, bytes).param(int.class, offset).param(int.class, len).call();
    // then
    verify(session, times(1)).isStreamingEnable();
}
Also used : EzyWsHandlerGroup(com.tvd12.ezyfoxserver.nio.websocket.EzyWsHandlerGroup) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 94 with EzySession

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

the class EzySimpleWsHandlerGroupTest method handleReceivedStreamEnableAndSessionStream.

@Test
public void handleReceivedStreamEnableAndSessionStream() throws Exception {
    // given
    EzyWsHandlerGroup sut = newHandlerGroup();
    EzySession session = FieldUtil.getFieldValue(sut, "session");
    when(session.isStreamingEnable()).thenReturn(true);
    byte[] bytes = new byte[] { 1 << 4, 2, 3 };
    int offset = 0;
    int len = 3;
    // when
    MethodInvoker.create().object(sut).method("handleReceivedBytes").param(byte[].class, bytes).param(int.class, offset).param(int.class, len).call();
    // then
    verify(session, times(1)).isStreamingEnable();
}
Also used : EzyWsHandlerGroup(com.tvd12.ezyfoxserver.nio.websocket.EzyWsHandlerGroup) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 95 with EzySession

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

the class EzyHandlerGroupManagerImplTest method mapSocketChannelConnectionNull.

@Test
public void mapSocketChannelConnectionNull() {
    // given
    EzyHandlerGroupManager sut = newHandlerGroupManager();
    EzySession session = mock(EzySession.class);
    EzyChannel channel = mock(EzyChannel.class);
    when(session.getChannel()).thenReturn(channel);
    // when
    sut.mapSocketChannel(null, session);
    // then
    verify(session, times(1)).getChannel();
}
Also used : EzyHandlerGroupManager(com.tvd12.ezyfoxserver.nio.wrapper.EzyHandlerGroupManager) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Aggregations

EzySession (com.tvd12.ezyfoxserver.entity.EzySession)112 Test (org.testng.annotations.Test)92 EzyArray (com.tvd12.ezyfox.entity.EzyArray)33 EzyResponseApi (com.tvd12.ezyfoxserver.api.EzyResponseApi)26 EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)25 EzyResponse (com.tvd12.ezyfoxserver.response.EzyResponse)25 BaseTest (com.tvd12.test.base.BaseTest)25 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)15 EzySimpleServerContext (com.tvd12.ezyfoxserver.context.EzySimpleServerContext)14 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)13 EzyUser (com.tvd12.ezyfoxserver.entity.EzyUser)13 EzySimpleLoginRequest (com.tvd12.ezyfoxserver.request.EzySimpleLoginRequest)13 EzyLoginController (com.tvd12.ezyfoxserver.controller.EzyLoginController)12 EzySimpleSettings (com.tvd12.ezyfoxserver.setting.EzySimpleSettings)11 EzySendResponseImpl (com.tvd12.ezyfoxserver.command.impl.EzySendResponseImpl)8 EzyHandshakeController (com.tvd12.ezyfoxserver.controller.EzyHandshakeController)8 EzyHandshakeParams (com.tvd12.ezyfoxserver.request.EzyHandshakeParams)8 EzySimpleResponse (com.tvd12.ezyfoxserver.response.EzySimpleResponse)8 GreetResponse (com.tvd12.ezyfoxserver.support.test.data.GreetResponse)8 BaseCoreTest (com.tvd12.ezyfoxserver.testing.BaseCoreTest)8