Search in sources :

Example 11 with SessionsMutator

use of com.djrapitops.plan.delivery.domain.mutators.SessionsMutator in project Plan by plan-player-analytics.

the class SessionQueriesTest method sessionPlaytimeIsCalculatedCorrectlyAfterStorage.

@Test
default void sessionPlaytimeIsCalculatedCorrectlyAfterStorage() {
    prepareForSessionSave();
    FinishedSession session = RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID);
    long expectedLength = session.getLength();
    long sessionEnd = session.getEnd();
    execute(DataStoreQueries.storeSession(session));
    forcePersistenceCheck();
    Map<ServerUUID, List<FinishedSession>> sessions = db().query(SessionQueries.fetchSessionsOfPlayer(playerUUID));
    assertTrue(sessions.containsKey(serverUUID()));
    SessionsMutator sessionsMutator = new SessionsMutator(sessions.get(serverUUID()));
    assertEquals(expectedLength, sessionsMutator.toPlaytime());
    assertEquals(1, sessionsMutator.count());
    SessionsMutator afterTimeSessionsMutator = sessionsMutator.filterSessionsBetween(sessionEnd + 1L, System.currentTimeMillis());
    assertEquals(0L, afterTimeSessionsMutator.toPlaytime());
    assertEquals(0, afterTimeSessionsMutator.count());
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) SessionsMutator(com.djrapitops.plan.delivery.domain.mutators.SessionsMutator) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test)

Aggregations

SessionsMutator (com.djrapitops.plan.delivery.domain.mutators.SessionsMutator)11 FinishedSession (com.djrapitops.plan.gathering.domain.FinishedSession)6 RepeatedTest (org.junit.jupiter.api.RepeatedTest)6 Test (org.junit.jupiter.api.Test)5 TablePlayer (com.djrapitops.plan.delivery.domain.TablePlayer)4 ActivityIndex (com.djrapitops.plan.delivery.domain.mutators.ActivityIndex)4 ServerUUID (com.djrapitops.plan.identification.ServerUUID)4 ServerTablePlayersQuery (com.djrapitops.plan.storage.database.queries.objects.playertable.ServerTablePlayersQuery)4 WorldNameStoreTransaction (com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction)4 Database (com.djrapitops.plan.storage.database.Database)3 DatabaseTestPreparer (com.djrapitops.plan.storage.database.DatabaseTestPreparer)3 ActivityIndexQueries (com.djrapitops.plan.storage.database.queries.analysis.ActivityIndexQueries)3 SessionQueries (com.djrapitops.plan.storage.database.queries.objects.SessionQueries)3 NetworkTablePlayersQuery (com.djrapitops.plan.storage.database.queries.objects.playertable.NetworkTablePlayersQuery)3 Sql (com.djrapitops.plan.storage.database.sql.building.Sql)3 SessionsTable (com.djrapitops.plan.storage.database.sql.tables.SessionsTable)3 UsersTable (com.djrapitops.plan.storage.database.sql.tables.UsersTable)3 PlayerServerRegisterTransaction (com.djrapitops.plan.storage.database.transactions.events.PlayerServerRegisterTransaction)3 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3