UserSessionLookup implements ResponseContextCodes { public UserSession expected(String userName) throws GameBootRuntimeException { Optional<Context> ctx = helper.startTimer(CACHED_SESSION_TIMER); try { String noSession = "No session for " + userName; check(NO_USERNAME, isEmpty(userName), "No username specified"); check(NO_USER_SESSION, !activeSessions.hasSession(userName), noSession); List<UserSession> sessions = assist.activeSessions(); Optional<UserSession> o = find(sessions, us -> us.getUser().getUserName().equals(userName)); return o.isPresent() ? o.get() : sessionCheck(repository.findOpenSession(userName)); } finally { helper.stopTimer(ctx); } }  @PostConstruct void postConstruct(); UserSession expected(String userName); UserSession expected(Long id); boolean hasSession(String userName); boolean hasSession(Long id); void clearMDC(); static final String MDC_SESSION_ID; static final String MDC_USER_ID; }
@Test @Transactional public void testExceptions() throws Exception { gameBootExcpected(() -> lookup.expected(NON_EXISTENT), "No session for username"); gameBootExcpected(() -> lookup.expected((String) null), "Null username"); gameBootExcpected(() -> lookup.expected((Long) null), "Null id"); gameBootExcpected(() -> lookup.expected(Long.MAX_VALUE), "No session for id"); }
@Test @Transactional public void metricsWithSessionId() throws Exception { generateUncachedStats(); for (int i = 0; i < METRICS_ITR; i++) { lookup.expected(sessionId); } metrics(); }
@Test @Transactional public void metricsWithUserName() throws Exception { generateUncachedStats(); for (int i = 0; i < METRICS_ITR; i++) { lookup.expected(USER_NAME); } metrics(); }