use of com.tvd12.ezyfoxserver.socket.EzySocketUserRemoval in project ezyfox-server by youngmonkeys.
the class EzySimpleUserDelegate method onUserRemoved.
@Override
public void onUserRemoved(EzyUser user, EzyConstant reason) {
EzyZoneContext zoneContext = serverContext.getZoneContext(user.getZoneId());
EzySocketUserRemoval removal = new EzySimpleSocketUserRemoval(zoneContext, user, reason);
userRemovalQueue.add(removal);
}
use of com.tvd12.ezyfoxserver.socket.EzySocketUserRemoval in project ezyfox-server by youngmonkeys.
the class EzyBlockingSocketUserRemovalQueueTest method test.
@Test
public void test() {
EzyBlockingSocketUserRemovalQueue queue = new EzyBlockingSocketUserRemovalQueue();
queue.clear();
assert queue.isEmpty();
assert queue.size() == 0;
EzySocketUserRemoval removal = mock(EzySocketUserRemoval.class);
queue.add(removal);
assert queue.size() == 1;
queue.remove(removal);
assert queue.size() == 0;
try {
queue.add(removal);
System.out.println(queue.take());
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.tvd12.ezyfoxserver.socket.EzySocketUserRemoval in project ezyfox-server by youngmonkeys.
the class EzySocketUserRemovalHandlerTest method test.
@Test
public void test() {
TestBlockingSocketUserRemovalQueue queue = new TestBlockingSocketUserRemovalQueue();
EzyAppContext appContext1 = mock(EzyAppContext.class);
EzyAppUserManager userManager1 = mock(EzyAppUserManager.class);
when(userManager1.containsUser(any(EzyUser.class))).thenReturn(true);
EzyApplication app1 = mock(EzyApplication.class);
when(app1.getUserManager()).thenReturn(userManager1);
when(appContext1.getApp()).thenReturn(app1);
EzyAppContext appContext2 = mock(EzyAppContext.class);
EzyAppUserManager userManager2 = mock(EzyAppUserManager.class);
when(userManager2.containsUser(any(EzyUser.class))).thenReturn(false);
EzyApplication app2 = mock(EzyApplication.class);
when(app2.getUserManager()).thenReturn(userManager2);
when(appContext2.getApp()).thenReturn(app2);
EzyZoneContext zoneContext = mock(EzyZoneContext.class);
when(zoneContext.getAppContexts()).thenReturn(Lists.newArrayList(appContext1, appContext2));
EzySimpleUser user = new EzySimpleUser();
user.setName("test");
EzySocketUserRemoval item = new EzySimpleSocketUserRemoval(zoneContext, user, EzyUserRemoveReason.EXIT_APP);
queue.add(item);
EzySocketUserRemovalHandler handler = new EzySocketUserRemovalHandler(queue);
handler.handleEvent();
handler.destroy();
}
use of com.tvd12.ezyfoxserver.socket.EzySocketUserRemoval in project ezyfox-server by youngmonkeys.
the class EzySocketUserRemovalHandlerTest method processUserRemovalQueueThrowableCaseTest.
@Test
public void processUserRemovalQueueThrowableCaseTest() {
TestBlockingSocketUserRemovalQueue queue = new TestBlockingSocketUserRemovalQueue();
EzyZoneContext zoneContext = mock(EzyZoneContext.class);
EzySimpleUser user = new EzySimpleUser();
user.setName("test");
EzySocketUserRemoval item = new EzySimpleSocketUserRemoval(zoneContext, user, EzyUserRemoveReason.EXIT_APP) {
@Override
public void release() {
throw new RuntimeException();
}
};
queue.add(item);
EzySocketUserRemovalHandler handler = new EzySocketUserRemovalHandler(queue);
handler.handleEvent();
}
use of com.tvd12.ezyfoxserver.socket.EzySocketUserRemoval in project ezyfox-server by youngmonkeys.
the class EzySocketUserRemovalHandlerTest method removeUserFromAppExceptionCaseTest.
@Test
public void removeUserFromAppExceptionCaseTest() {
TestBlockingSocketUserRemovalQueue queue = new TestBlockingSocketUserRemovalQueue();
EzyAppContext appContext1 = mock(EzyAppContext.class);
EzyAppUserManager userManager1 = mock(EzyAppUserManager.class);
when(userManager1.containsUser(any(EzyUser.class))).thenReturn(true);
EzyApplication app1 = mock(EzyApplication.class);
when(app1.getUserManager()).thenReturn(userManager1);
when(appContext1.getApp()).thenReturn(app1);
doThrow(new IllegalArgumentException()).when(userManager1).removeUser(any(), any());
EzySimpleAppSetting appSetting1 = new EzySimpleAppSetting();
appSetting1.setName("app1");
when(app1.getSetting()).thenReturn(appSetting1);
EzyAppContext appContext2 = mock(EzyAppContext.class);
EzyAppUserManager userManager2 = mock(EzyAppUserManager.class);
when(userManager2.containsUser(any(EzyUser.class))).thenReturn(false);
EzyApplication app2 = mock(EzyApplication.class);
when(app2.getUserManager()).thenReturn(userManager2);
when(appContext2.getApp()).thenReturn(app2);
EzyZoneContext zoneContext = mock(EzyZoneContext.class);
when(zoneContext.getAppContexts()).thenReturn(Lists.newArrayList(appContext1, appContext2));
EzySimpleUser user = new EzySimpleUser();
user.setName("test");
EzySocketUserRemoval item = new EzySimpleSocketUserRemoval(zoneContext, user, EzyUserRemoveReason.EXIT_APP);
queue.add(item);
EzySocketUserRemovalQueue userRemovalQueue = new EzyBlockingSocketUserRemovalQueue();
new EzySocketUserRemovalHandler(userRemovalQueue);
EzySocketUserRemovalHandler handler = new EzySocketUserRemovalHandler(queue);
handler.handleEvent();
handler.destroy();
}
Aggregations