GroupServer extends SessionServer { @Override HITWorkerImpl sessionAccept(ServerSession conn, String hitId, String assignmentId, String workerId) { HITWorkerImpl hitw = super.sessionAccept(conn, hitId, assignmentId, workerId); if( hitw == null ) return null; if( this.requireUsernames && hitw.getUsername() == null ) { Map<String, String> data = ImmutableMap.of( "status", Codec.status_usernameneeded ); SessionUtils.sendServiceMsg(conn, data); } boolean inExperiment; synchronized(lobby) { if( inExperiment = experiments.workerIsInProgress(hitw) ) { sessionReconnect(conn, hitw); } else { lobby.userJoined(hitw); } } if( !inExperiment ) { Map<String, String> data = ImmutableMap.of( "status", Codec.status_connectlobby ); SessionUtils.sendServiceMsg(conn, data); logger.info(hitw.toString() + " connected to lobby"); if( serverGUI != null ) serverGUI.updateLobbyModel(); } return hitw; } @Inject  GroupServer(			
			ExperimentDataTracker tracker,
			HITController hitCont,
			WorkerAuthenticator workerAuth,
			Experiments experiments,			
			Configuration config,
			Lobby lobby			
			); @Inject(optional=true) void injectWebServer(JettyCometD jetty); @Inject(optional=true) void injectGUI(final TSTabbedPanel guiTabs); @Override int getExpsInProgress(); @Override int getExpsCompleted(); boolean lobbyLogin(ServerSession conn, String username); boolean lobbyUpdate(ServerSession conn, Map<String, Object> data); @Override void sessionDisconnect(ServerSession conn);  }
@Test public void testAcceptHITLimit() { String hitId = "testHITId"; String workerId = "testWorkerId"; String assignmentId = "testAssignmentId"; Session s = new Session(); s.setHitId(hitId); s.setWorkerId(workerId); s.setAssignmentId(assignmentId); s.setInactivePercent(0.0); assertEquals(SessionStatus.COMPLETED, SessionRecord.status(s)); tracker.saveSession(s); String hitId2 = "testHITId2"; String assignmentId2 = "assignmentId2"; MockServerSession conn = new MockServerSession(); server.sessionAccept(conn, hitId2, assignmentId2, workerId); assertEquals(conn.lastChannel, USER_CHANNEL); assertEquals(Codec.status_toomanysessions, ((Map<String, Object>) conn.lastData).get("status")); }
@Test public void testAcceptQuizRequired() { MockServerSession conn = new MockServerSession(); server.sessionAccept(conn, "hitId", "assignmentId", "workerId"); assertEquals(conn.lastChannel, USER_CHANNEL); assertEquals(Codec.status_quizneeded, ((Map<String, Object>) conn.lastData).get("status")); }
@Test public void testAcceptQuizFailsauce() { String hitId = "testHITId"; String workerId = "testWorkerId"; String assignmentId = "testAssignmentId"; Quiz failedQuiz = new Quiz(); failedQuiz.setNumCorrect(0); failedQuiz.setNumTotal(1); failedQuiz.setScore(0d); tracker.saveQuizResults(hitId, workerId, failedQuiz); MockServerSession conn = new MockServerSession(); server.sessionAccept(conn, hitId, assignmentId, workerId); assertEquals(conn.lastChannel, USER_CHANNEL); assertEquals(Codec.status_failsauce, ((Map<String, Object>) conn.lastData).get("status")); }
@Test public void testAcceptLobby() { String hitId = "testHITId"; String workerId = "testWorkerId"; String assignmentId = "testAssignmentId"; Quiz passedQuiz = new Quiz(); passedQuiz.setNumCorrect(1); passedQuiz.setNumTotal(1); passedQuiz.setScore(1d); tracker.saveQuizResults(hitId, workerId, passedQuiz); MockServerSession conn = new MockServerSession(); server.sessionAccept(conn, hitId, assignmentId, workerId); assertEquals(conn.lastChannel, USER_CHANNEL); assertEquals(Codec.status_connectlobby, ((Map<String, Object>) conn.lastData).get("status")); }
@Test public void testAcceptCompleted() { String hitId = "testHITId"; String assignmentId = "testAssignmentId"; String workerId = "workerId"; Session s = new Session(); s.setHitId(hitId); s.setWorkerId(workerId); s.setInactivePercent(0.00); tracker.saveSession(s); HITWorkerImpl hitw = new HITWorkerImpl(null, s); server.hitWorkerTable.put(hitId, workerId, hitw); assertEquals(0, server.completedHITs); assertEquals(SessionStatus.COMPLETED, SessionRecord.status(s)); MockServerSession conn = new MockServerSession(); server.sessionAccept(conn, hitId, assignmentId, workerId); assertEquals(conn.lastChannel, USER_CHANNEL); assertEquals(Codec.status_expfinished, ((Map<String, Object>) conn.lastData).get("status")); server.updateCompletion(); server.sessionSubmit(conn, "some random results"); assertEquals(conn.lastChannel, USER_CHANNEL); assertEquals(Codec.status_completed, ((Map<String, Object>) conn.lastData).get("status")); assertEquals(1, server.completedHITs); server.updateCompletion(); server.sessionSubmit(conn, "some random results"); assertEquals(conn.lastChannel, USER_CHANNEL); assertEquals(Codec.status_completed, ((Map<String, Object>) conn.lastData).get("status") ); assertEquals(1, server.completedHITs); }
@Test public void testAcceptOverlap() { String hitId = "testHITId"; Session s = new Session(); s.setHitId(hitId); s.setWorkerId("someOtherWorker"); s.setExperimentId("random experiment"); assertEquals(SessionStatus.EXPERIMENT, SessionRecord.status(s)); tracker.saveSession(s); MockServerSession conn = new MockServerSession(); server.sessionAccept(conn, hitId, "someAssignment", "thisWorker"); assertEquals(conn.lastChannel, USER_CHANNEL); assertEquals(Codec.status_sessionoverlap, ((Map<String, Object>) conn.lastData).get("status")); }
@Test public void testAcceptSimultaneousLimit() { String hitId = "testHITId"; String workerId = "testWorkerId"; String assignmentId = "testAssignmentId"; Session takenSession = new Session(); takenSession.setHitId(hitId); takenSession.setWorkerId(workerId); takenSession.setAssignmentId(assignmentId); assertEquals(SessionStatus.ASSIGNED, SessionRecord.status(takenSession)); tracker.saveSession(takenSession); String hitId2 = "testHITId2"; String assignmentId2 = "assignmentId2"; MockServerSession conn = new MockServerSession(); server.sessionAccept(conn, hitId2, assignmentId2, workerId); assertEquals(conn.lastChannel, USER_CHANNEL); assertEquals(Codec.status_simultaneoussessions, ((Map<String, Object>) conn.lastData).get("status")); }