use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.
the class EzySessionTicketsRequestQueues method addRequest.
public boolean addRequest(EzySocketRequest request) {
EzyRequestQueue queue;
EzySessionTicketsQueue ticketsQueue;
EzySession session = request.getSession();
if (request.isSystemRequest()) {
ticketsQueue = systemQueue;
queue = session.getSystemRequestQueue();
} else {
ticketsQueue = extensionQueue;
queue = session.getExtensionRequestQueue();
}
boolean success;
// noinspection SynchronizationOnLocalVariableOrMethodParameter
synchronized (queue) {
boolean empty = queue.isEmpty();
success = queue.add(request);
if (empty && success) {
ticketsQueue.add(session);
}
}
return success;
}
use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.
the class EzySocketDisconnectionHandler method processDisconnection.
private void processDisconnection(EzySocketDisconnection disconnection) {
try {
EzySession session = disconnection.getSession();
EzyConstant disconnectReason = disconnection.getDisconnectReason();
EzySocketDataHandlerGroup handlerGroup = removeDataHandlerGroup(session);
if (handlerGroup != null) {
handlerGroup.fireChannelInactive(disconnectReason);
} else {
logger.warn("has no handler group with session: {}, ignore disconnection: {}", session, disconnection);
}
} finally {
disconnection.release();
}
}
use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.
the class EzySimpleDataHandlerTest method dataReceivedValidateSessionInActive.
@Test
public void dataReceivedValidateSessionInActive() {
// given
MyTestDataHandler sut = createHandler();
EzySession session = FieldUtil.getFieldValue(sut, "session");
session.setActivated(false);
EzyArray msg = EzyEntityFactory.newArray();
// when
sut.dataReceived(EzyCommand.APP_ACCESS, msg);
// then
Asserts.assertFalse(session.isActivated());
}
use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.
the class EzySimpleDataHandlerTest method processMaxRequestPerSecondDisconnect.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void processMaxRequestPerSecondDisconnect() {
// given
EzySession session = spy(EzyAbstractSession.class);
EzyServerContext serverContext = mock(EzyServerContext.class);
EzyServer server = mock(EzyServer.class);
EzySessionManager sessionManager = mock(EzySessionManager.class);
when(server.getSessionManager()).thenReturn(sessionManager);
when(serverContext.getServer()).thenReturn(server);
EzySessionManagementSetting sessionManagementSetting = mock(EzySessionManagementSetting.class);
EzySessionManagementSetting.EzyMaxRequestPerSecond maxRequestPerSecond = mock(EzySessionManagementSetting.EzyMaxRequestPerSecond.class);
when(maxRequestPerSecond.getAction()).thenReturn(EzyMaxRequestPerSecondAction.DISCONNECT_SESSION);
when(sessionManagementSetting.getSessionMaxRequestPerSecond()).thenReturn(maxRequestPerSecond);
EzySettings settings = mock(EzySettings.class);
when(server.getSettings()).thenReturn(settings);
when(settings.getSessionManagement()).thenReturn(sessionManagementSetting);
EzyLoggerSetting loggerSetting = mock(EzyLoggerSetting.class);
EzyLoggerSetting.EzyIgnoredCommandsSetting ignoredCommandsSetting = mock(EzyLoggerSetting.EzyIgnoredCommandsSetting.class);
when(ignoredCommandsSetting.getCommands()).thenReturn(Collections.emptySet());
when(loggerSetting.getIgnoredCommands()).thenReturn(ignoredCommandsSetting);
when(settings.getLogger()).thenReturn(loggerSetting);
MyTestDataHandler sut = new MyTestDataHandler(serverContext, session);
// when
sut.processMaxRequestPerSecond();
// then
verify(sessionManager, times(1)).removeSession(session, EzyDisconnectReason.MAX_REQUEST_PER_SECOND);
}
use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.
the class EzyLoginControllerTest method maximumSession1Test.
@Test(expectedExceptions = EzyLoginErrorException.class)
public void maximumSession1Test() {
EzySimpleServerContext ctx = (EzySimpleServerContext) newServerContext();
EzySimpleServer server = (EzySimpleServer) ctx.getServer();
EzyZoneContext zoneContext = ctx.getZoneContext("example");
EzyZoneSetting zoneSetting = zoneContext.getZone().getSetting();
EzySimpleUserManagementSetting userManagementSetting = (EzySimpleUserManagementSetting) zoneSetting.getUserManagement();
userManagementSetting.setMaxSessionPerUser(0);
server.setResponseApi(mock(EzyResponseApi.class));
EzySession session = newSession();
session.setToken("abcdef");
EzyArray data = newLoginData();
data.set(1, "");
EzyLoginController controller = new EzyLoginController();
EzySimpleLoginRequest request = new EzySimpleLoginRequest();
request.deserializeParams(data);
request.setSession(session);
controller.handle(ctx, request);
}
Aggregations