Class InMemorySessionRecordRepository

java.lang.Object
org.jwcarman.who.test.InMemorySessionRecordRepository
All Implemented Interfaces:
SessionRecordRepository

public final class InMemorySessionRecordRepository extends Object implements SessionRecordRepository
who's record of sessions kept in memory, for tests that do not run a database. Thread-safe.
  • Constructor Details

    • InMemorySessionRecordRepository

      public InMemorySessionRecordRepository()
      Creates an empty store.
  • Method Details

    • whoSessions

      public static WhoSessions whoSessions(Clock clock, WhoEventPublisher events)
      Creates a WhoSessions over a fresh in-memory store, with Spring Boot's default 30 minute idle timeout, a 5 minute last-seen interval and no auto-purge.
      Parameters:
      clock - the current time
      events - receives ended and purged sessions
      Returns:
      the sessions
    • insert

      public void insert(SessionRecord session)
      Description copied from interface: SessionRecordRepository
      Saves a new session.
      Specified by:
      insert in interface SessionRecordRepository
      Parameters:
      session - the session
    • findById

      public Optional<SessionRecord> findById(UUID id)
      Description copied from interface: SessionRecordRepository
      Finds a session, ended or not.
      Specified by:
      findById in interface SessionRecordRepository
      Parameters:
      id - the session's id
      Returns:
      the session, or empty
    • findLiveByIdentity

      public List<SessionRecord> findLiveByIdentity(UUID identityId, Instant seenSince)
      Description copied from interface: SessionRecordRepository
      Finds an identity's sessions that are not ended and were seen at or after seenSince, most recently signed in first.
      Specified by:
      findLiveByIdentity in interface SessionRecordRepository
      Parameters:
      identityId - the identity
      seenSince - the oldest last-seen time that still counts as live
      Returns:
      the sessions
    • touch

      public boolean touch(UUID id, Instant now, Instant notSince)
      Description copied from interface: SessionRecordRepository
      Records that a session made a request, unless it is ended or was already seen at or after notSince.
      Specified by:
      touch in interface SessionRecordRepository
      Parameters:
      id - the session's id
      now - the time to record
      notSince - write only when the session was last seen before this
      Returns:
      whether it was written
    • end

      public boolean end(UUID id, Instant now)
      Description copied from interface: SessionRecordRepository
      Ends a session that is not already ended.
      Specified by:
      end in interface SessionRecordRepository
      Parameters:
      id - the session's id
      now - when it ended
      Returns:
      whether it was ended by this call
    • deleteDead

      public int deleteDead(Instant seenBefore, int limit)
      Description copied from interface: SessionRecordRepository
      Deletes up to limit dead sessions: ended ones, and ones last seen before seenBefore.
      Specified by:
      deleteDead in interface SessionRecordRepository
      Parameters:
      seenBefore - a session last seen before this is dead
      limit - the most rows to delete
      Returns:
      how many were deleted