Search in sources :

Example 6 with ServerTablePlayersQuery

use of com.djrapitops.plan.storage.database.queries.objects.playertable.ServerTablePlayersQuery in project Plan by plan-player-analytics.

the class SessionQueriesTest method playersTableAndPlayerPagePlaytimeMatches.

@RepeatedTest(value = 3, name = "Players table and Player page playtimes match {currentRepetition}/{totalRepetitions}")
default void playersTableAndPlayerPagePlaytimeMatches() {
    prepareForSessionSave();
    List<FinishedSession> player1Sessions = RandomData.randomSessions(serverUUID(), worlds, playerUUID, player2UUID);
    List<FinishedSession> player2Sessions = RandomData.randomSessions(serverUUID(), worlds, player2UUID, playerUUID);
    player1Sessions.forEach(session -> db().executeTransaction(new StoreSessionTransaction(session)));
    player2Sessions.forEach(session -> db().executeTransaction(new StoreSessionTransaction(session)));
    long playtimeThreshold = RandomData.randomLong(TimeUnit.HOURS.toMillis(1L), TimeUnit.DAYS.toMillis(2L));
    PlayerContainer playerContainer = db().query(new PlayerContainerQuery(playerUUID));
    TablePlayer tablePlayer = db().query(new ServerTablePlayersQuery(serverUUID(), System.currentTimeMillis(), playtimeThreshold, 5)).stream().filter(player -> playerUUID.equals(player.getPlayerUUID())).findAny().orElseThrow(AssertionError::new);
    long expected = SessionsMutator.forContainer(playerContainer).toActivePlaytime();
    long got = tablePlayer.getActivePlaytime().orElseThrow(AssertionError::new);
    assertEquals(expected, got);
}
Also used : ServerTablePlayersQuery(com.djrapitops.plan.storage.database.queries.objects.playertable.ServerTablePlayersQuery) PlayerContainer(com.djrapitops.plan.delivery.domain.container.PlayerContainer) PlayerContainerQuery(com.djrapitops.plan.storage.database.queries.containers.PlayerContainerQuery) TablePlayer(com.djrapitops.plan.delivery.domain.TablePlayer) RepeatedTest(org.junit.jupiter.api.RepeatedTest)

Aggregations

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