Search in sources :

Example 11 with FinishedSession

use of com.djrapitops.plan.gathering.domain.FinishedSession in project Plan by plan-player-analytics.

the class ShutdownDataPreservationTransaction method ensureAllPlayersAreRegistered.

private void ensureAllPlayersAreRegistered() {
    Set<UUID> playerUUIDs = new HashSet<>();
    Map<UUID, String> playerNames = new HashMap<>();
    Map<UUID, Long> earliestDates = new HashMap<>();
    for (FinishedSession finishedSession : finishedSessions) {
        UUID playerUUID = finishedSession.getPlayerUUID();
        playerUUIDs.add(playerUUID);
        finishedSession.getExtraData(PlayerKills.class).map(PlayerKills::asList).ifPresent(kills -> {
            for (PlayerKill kill : kills) {
                playerUUIDs.add(kill.getKiller().getUuid());
                playerUUIDs.add(kill.getVictim().getUuid());
            }
        });
        finishedSession.getExtraData(PlayerName.class).map(PlayerName::get).ifPresent(playerName -> playerNames.put(playerUUID, playerName));
        long start = finishedSession.getStart();
        Long previous = earliestDates.get(playerUUID);
        if (previous == null || start < previous) {
            earliestDates.put(playerUUID, start);
        }
    }
    Set<UUID> existingUUIDs = query(BaseUserQueries.fetchExistingUUIDs(playerUUIDs));
    for (UUID playerUUID : playerUUIDs) {
        if (!existingUUIDs.contains(playerUUID)) {
            LongSupplier registerDate = () -> Optional.ofNullable(earliestDates.get(playerUUID)).orElseGet(System::currentTimeMillis);
            String playerName = Optional.ofNullable(playerNames.get(playerUUID)).orElseGet(playerUUID::toString);
            executeOther(new PlayerRegisterTransaction(playerUUID, registerDate, playerName));
        }
    }
}
Also used : PlayerKill(com.djrapitops.plan.gathering.domain.PlayerKill) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) LongSupplier(java.util.function.LongSupplier)

Example 12 with FinishedSession

use of com.djrapitops.plan.gathering.domain.FinishedSession in project Plan by plan-player-analytics.

the class DatabaseTest method testRemovalSingleUser.

@Test
default void testRemovalSingleUser() {
    saveUserTwo();
    db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, RandomData::randomTime, TestConstants.PLAYER_ONE_NAME, serverUUID(), TestConstants.GET_PLAYER_HOSTNAME));
    saveTwoWorlds();
    FinishedSession session = RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID);
    db().executeTransaction(new StoreSessionTransaction(session));
    db().executeTransaction(new NicknameStoreTransaction(playerUUID, new Nickname("TestNick", RandomData.randomTime(), serverUUID()), (uuid, name) -> false));
    db().executeTransaction(new StoreGeoInfoTransaction(playerUUID, new GeoInfo("TestLoc", RandomData.randomTime())));
    assertTrue(db().query(PlayerFetchQueries.isPlayerRegistered(playerUUID)));
    db().executeTransaction(new RemovePlayerTransaction(playerUUID));
    assertFalse(db().query(PlayerFetchQueries.isPlayerRegistered(playerUUID)));
    assertFalse(db().query(PlayerFetchQueries.isPlayerRegisteredOnServer(playerUUID, serverUUID())));
    assertTrue(db().query(NicknameQueries.fetchNicknameDataOfPlayer(playerUUID)).isEmpty());
    assertTrue(db().query(GeoInfoQueries.fetchPlayerGeoInformation(playerUUID)).isEmpty());
    assertQueryIsEmpty(db(), SessionQueries.fetchSessionsOfPlayer(playerUUID));
}
Also used : java.util(java.util) PlanConfig(com.djrapitops.plan.settings.config.PlanConfig) ServerTablePlayersQuery(com.djrapitops.plan.storage.database.queries.objects.playertable.ServerTablePlayersQuery) UserInfoTable(com.djrapitops.plan.storage.database.sql.tables.UserInfoTable) ServerUUID(com.djrapitops.plan.identification.ServerUUID) Query(com.djrapitops.plan.storage.database.queries.Query) LocalDateTime(java.time.LocalDateTime) TablePlayer(com.djrapitops.plan.delivery.domain.TablePlayer) FieldFetcher(utilities.FieldFetcher) GeoInfo(com.djrapitops.plan.gathering.domain.GeoInfo) SQLException(java.sql.SQLException) NetworkTablePlayersQuery(com.djrapitops.plan.storage.database.queries.objects.playertable.NetworkTablePlayersQuery) ResultSet(java.sql.ResultSet) BaseUser(com.djrapitops.plan.gathering.domain.BaseUser) PlayerKeys(com.djrapitops.plan.delivery.domain.keys.PlayerKeys) ActiveSession(com.djrapitops.plan.gathering.domain.ActiveSession) ServerAggregateQueries(com.djrapitops.plan.storage.database.queries.ServerAggregateQueries) StoreConfigTransaction(com.djrapitops.plan.storage.database.transactions.StoreConfigTransaction) ZoneOffset(java.time.ZoneOffset) UsersTable(com.djrapitops.plan.storage.database.sql.tables.UsersTable) TestConstants(utilities.TestConstants) FormatSettings(com.djrapitops.plan.settings.config.paths.FormatSettings) Transaction(com.djrapitops.plan.storage.database.transactions.Transaction) ContainerFetchQueries(com.djrapitops.plan.storage.database.queries.containers.ContainerFetchQueries) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) PlayerFetchQueries(com.djrapitops.plan.storage.database.queries.PlayerFetchQueries) QueryAllStatement(com.djrapitops.plan.storage.database.queries.QueryAllStatement) QuerySvc(com.djrapitops.plan.query.QuerySvc) Sql(com.djrapitops.plan.storage.database.sql.building.Sql) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) Key(com.djrapitops.plan.delivery.domain.keys.Key) DBCleanTask(com.djrapitops.plan.storage.upkeep.DBCleanTask) Locale(com.djrapitops.plan.settings.locale.Locale) com.djrapitops.plan.storage.database.transactions.events(com.djrapitops.plan.storage.database.transactions.events) Assertions(org.junit.jupiter.api.Assertions) RandomData(utilities.RandomData) PlayerContainer(com.djrapitops.plan.delivery.domain.container.PlayerContainer) TestPluginLogger(utilities.TestPluginLogger) com.djrapitops.plan.storage.database.queries.objects(com.djrapitops.plan.storage.database.queries.objects) RemovePlayerTransaction(com.djrapitops.plan.storage.database.transactions.commands.RemovePlayerTransaction) CreateIndexTransaction(com.djrapitops.plan.storage.database.transactions.init.CreateIndexTransaction) RegisterDateMinimizationPatch(com.djrapitops.plan.storage.database.transactions.patches.RegisterDateMinimizationPatch) Nickname(com.djrapitops.plan.delivery.domain.Nickname) Config(com.djrapitops.plan.settings.config.Config) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) GeoInfo(com.djrapitops.plan.gathering.domain.GeoInfo) RemovePlayerTransaction(com.djrapitops.plan.storage.database.transactions.commands.RemovePlayerTransaction) Nickname(com.djrapitops.plan.delivery.domain.Nickname) Test(org.junit.jupiter.api.Test)

Example 13 with FinishedSession

use of com.djrapitops.plan.gathering.domain.FinishedSession in project Plan by plan-player-analytics.

the class ShutdownSaveTest method sessionsAreNotSavedWhenNotShuttingDown.

@Test
void sessionsAreNotSavedWhenNotShuttingDown() {
    for (int i = 0; i < 100; i++) {
        UUID playerUUID = UUID.randomUUID();
        ActiveSession session = RandomData.randomUnfinishedSession(TestConstants.SERVER_UUID, new String[] { "w1", "w2" }, playerUUID);
        sessionCache.cacheSession(playerUUID, session);
    }
    Optional<Future<?>> save = underTest.performSave();
    assertFalse(save.isPresent());
    List<FinishedSession> sessions = database.query(SessionQueries.fetchAllSessions());
    assertEquals(0, sessions.size());
}
Also used : ActiveSession(com.djrapitops.plan.gathering.domain.ActiveSession) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) Future(java.util.concurrent.Future) ServerUUID(com.djrapitops.plan.identification.ServerUUID) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 14 with FinishedSession

use of com.djrapitops.plan.gathering.domain.FinishedSession in project Plan by plan-player-analytics.

the class SessionCacheTest method sessionsAreRemovedFromCacheOnStart.

@Test
void sessionsAreRemovedFromCacheOnStart() {
    Optional<FinishedSession> ended = new SessionCache().cacheSession(uuid, new ActiveSession(uuid, serverUUID, 52345L, "World1", "SURVIVAL"));
    assertTrue(ended.isPresent());
    for (ActiveSession session : SessionCache.getActiveSessions()) {
        if (session.getStart() == 12345L) {
            fail("Session was still in cache: " + session);
        }
    }
}
Also used : ActiveSession(com.djrapitops.plan.gathering.domain.ActiveSession) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) Test(org.junit.jupiter.api.Test)

Example 15 with FinishedSession

use of com.djrapitops.plan.gathering.domain.FinishedSession in project Plan by plan-player-analytics.

the class ExportJSErrorRegressionTest method savePlayerData.

private static void savePlayerData() {
    DBSystem dbSystem = planSystem.getDatabaseSystem();
    Database database = dbSystem.getDatabase();
    UUID uuid = TestConstants.PLAYER_ONE_UUID;
    database.executeTransaction(new PlayerRegisterTransaction(uuid, RandomData::randomTime, TestConstants.PLAYER_ONE_NAME));
    FinishedSession session = new FinishedSession(uuid, serverUUID, 1000L, 11000L, 500L, new DataMap());
    database.executeTransaction(new WorldNameStoreTransaction(serverUUID, "world"));
    database.executeTransaction(new StoreSessionTransaction(session));
}
Also used : StoreSessionTransaction(com.djrapitops.plan.storage.database.transactions.events.StoreSessionTransaction) DBSystem(com.djrapitops.plan.storage.database.DBSystem) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) Database(com.djrapitops.plan.storage.database.Database) WorldNameStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction) PlayerRegisterTransaction(com.djrapitops.plan.storage.database.transactions.events.PlayerRegisterTransaction) ServerUUID(com.djrapitops.plan.identification.ServerUUID) DataMap(com.djrapitops.plan.gathering.domain.DataMap)

Aggregations

FinishedSession (com.djrapitops.plan.gathering.domain.FinishedSession)32 Test (org.junit.jupiter.api.Test)22 ServerUUID (com.djrapitops.plan.identification.ServerUUID)13 RepeatedTest (org.junit.jupiter.api.RepeatedTest)11 StoreSessionTransaction (com.djrapitops.plan.storage.database.transactions.events.StoreSessionTransaction)10 WorldNameStoreTransaction (com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction)8 ActiveSession (com.djrapitops.plan.gathering.domain.ActiveSession)6 RandomData (utilities.RandomData)6 TestConstants (utilities.TestConstants)6 TablePlayer (com.djrapitops.plan.delivery.domain.TablePlayer)5 List (java.util.List)5 WorldTimes (com.djrapitops.plan.gathering.domain.WorldTimes)4 NetworkTablePlayersQuery (com.djrapitops.plan.storage.database.queries.objects.playertable.NetworkTablePlayersQuery)4 ServerTablePlayersQuery (com.djrapitops.plan.storage.database.queries.objects.playertable.ServerTablePlayersQuery)4 Sql (com.djrapitops.plan.storage.database.sql.building.Sql)4 UsersTable (com.djrapitops.plan.storage.database.sql.tables.UsersTable)4 ResultSet (java.sql.ResultSet)4 SQLException (java.sql.SQLException)4 Collection (java.util.Collection)4 TimeUnit (java.util.concurrent.TimeUnit)4