Search in sources :

Example 1 with EzySimpleSocketStream

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

the class EzySimpleNioHandlerGroup method handleReceivedMessage.

private void handleReceivedMessage(EzyMessage message) {
    try {
        EzyMessageHeader header = message.getHeader();
        if (header.isRawBytes()) {
            boolean sessionStreamingEnable = session.isStreamingEnable();
            if (!streamingEnable || !sessionStreamingEnable) {
                return;
            }
            byte[] rawBytes = message.getContent();
            EzySocketStream stream = new EzySimpleSocketStream(session, rawBytes);
            streamQueue.add(stream);
        } else {
            Object data = decodeMessage(message);
            int dataSize = message.getByteCount();
            handleReceivedData(data, dataSize);
        }
    } catch (Exception e) {
        fireExceptionCaught(e);
    } finally {
        executeAddReadBytes(message.getByteCount());
    }
}
Also used : EzySimpleSocketStream(com.tvd12.ezyfoxserver.socket.EzySimpleSocketStream) EzySocketStream(com.tvd12.ezyfoxserver.socket.EzySocketStream)

Example 2 with EzySimpleSocketStream

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

the class EzySocketStreamHandlerTest method test.

@Test
public void test() {
    EzySocketStreamHandler handler = new EzySocketStreamHandler();
    EzySocketDataHandlerGroupFetcher dataHandlerGroupFetcher = mock(EzySocketDataHandlerGroupFetcher.class);
    EzySocketDataHandlerGroup dataHandlerGroup = mock(EzySocketDataHandlerGroup.class);
    when(dataHandlerGroupFetcher.getDataHandlerGroup(any(EzySession.class))).thenReturn(dataHandlerGroup);
    EzySocketStreamQueue streamQueue = new EzyBlockingSocketStreamQueue();
    EzySession session = spy(EzyAbstractSession.class);
    EzySocketStream stream = new EzySimpleSocketStream(session, new byte[0]);
    streamQueue.add(stream);
    handler.setStreamQueue(streamQueue);
    handler.setDataHandlerGroupFetcher(dataHandlerGroupFetcher);
    handler.handleEvent();
    handler.destroy();
}
Also used : EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test)

Example 3 with EzySimpleSocketStream

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

the class EzySocketStreamHandlerTest method hasNoHandlerGroupCaseTest.

@Test
public void hasNoHandlerGroupCaseTest() {
    EzySocketStreamHandler handler = new EzySocketStreamHandler();
    EzySocketDataHandlerGroupFetcher dataHandlerGroupFetcher = mock(EzySocketDataHandlerGroupFetcher.class);
    when(dataHandlerGroupFetcher.getDataHandlerGroup(any(EzySession.class))).thenReturn(null);
    EzySocketStreamQueue streamQueue = new EzyBlockingSocketStreamQueue();
    EzySession session = spy(EzyAbstractSession.class);
    EzySocketStream stream = new EzySimpleSocketStream(session, new byte[0]);
    streamQueue.add(stream);
    handler.setStreamQueue(streamQueue);
    handler.setDataHandlerGroupFetcher(dataHandlerGroupFetcher);
    handler.handleEvent();
}
Also used : EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test)

Example 4 with EzySimpleSocketStream

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

the class EzySocketStreamHandlerTest method doProcessStreamQueueExceptionCaseTest.

@Test
public void doProcessStreamQueueExceptionCaseTest() {
    EzySocketStreamHandler handler = new EzySocketStreamHandler();
    EzySocketDataHandlerGroupFetcher dataHandlerGroupFetcher = mock(EzySocketDataHandlerGroupFetcher.class);
    when(dataHandlerGroupFetcher.getDataHandlerGroup(any(EzySession.class))).thenThrow(new IllegalArgumentException());
    EzySocketStreamQueue streamQueue = new EzyBlockingSocketStreamQueue();
    EzySession session = spy(EzyAbstractSession.class);
    EzySocketStream stream = new EzySimpleSocketStream(session, new byte[0]);
    streamQueue.add(stream);
    handler.setStreamQueue(streamQueue);
    handler.setDataHandlerGroupFetcher(dataHandlerGroupFetcher);
    handler.handleEvent();
}
Also used : EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test)

Example 5 with EzySimpleSocketStream

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

the class EzySimpleSocketStreamTest method test.

@Test
public void test() {
    EzyAbstractSession session = spy(EzyAbstractSession.class);
    EzySimpleSocketStream stream = new EzySimpleSocketStream(session, new byte[0]);
    System.out.println(stream.getTimestamp());
}
Also used : EzyAbstractSession(com.tvd12.ezyfoxserver.entity.EzyAbstractSession) EzySimpleSocketStream(com.tvd12.ezyfoxserver.socket.EzySimpleSocketStream) BaseTest(com.tvd12.test.base.BaseTest) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)4 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)3 EzySimpleSocketStream (com.tvd12.ezyfoxserver.socket.EzySimpleSocketStream)3 EzySocketStream (com.tvd12.ezyfoxserver.socket.EzySocketStream)2 EzyAbstractSession (com.tvd12.ezyfoxserver.entity.EzyAbstractSession)1 BaseTest (com.tvd12.test.base.BaseTest)1