From ed17ebd4024adafb342cef636cadd800bc98a14d Mon Sep 17 00:00:00 2001 From: Risto Lahtela <24460436+AuroraLS3@users.noreply.github.com> Date: Sun, 9 Jan 2022 12:37:29 +0200 Subject: [PATCH] Fix top category queries - Moved group by before order by - Fixed off by one error in the offset Affects issues: - Fixed #2206 --- .../queries/analysis/TopListQueries.java | 8 +-- .../plan/storage/database/MySQLTest.java | 17 ++--- .../plan/storage/database/SQLiteTest.java | 16 +---- .../queries/QueriesTestAggregate.java | 35 +++++++++++ .../queries/analysis/TopListQueriesTest.java | 63 +++++++++++++++++++ 5 files changed, 109 insertions(+), 30 deletions(-) create mode 100644 Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/QueriesTestAggregate.java create mode 100644 Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/analysis/TopListQueriesTest.java diff --git a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/analysis/TopListQueries.java b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/analysis/TopListQueries.java index 92b1a0a9a..85da37bc2 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/analysis/TopListQueries.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/analysis/TopListQueries.java @@ -43,8 +43,8 @@ public class TopListQueries { WHERE + SessionsTable.SERVER_UUID + "=?" + AND + SessionsTable.SESSION_START + ">?" + AND + SessionsTable.SESSION_END + "?" + AND + SessionsTable.SESSION_END + ". + */ +package com.djrapitops.plan.storage.database.queries; + +import com.djrapitops.plan.storage.database.queries.analysis.TopListQueriesTest; + +public interface QueriesTestAggregate extends + ActivityIndexQueriesTest, + DatabaseBackupTest, + ExtensionsDatabaseTest, + GeolocationQueriesTest, + NicknameQueriesTest, + PingQueriesTest, + ServerQueriesTest, + SessionQueriesTest, + TopListQueriesTest, + TPSQueriesTest, + UserInfoQueriesTest, + WebUserQueriesTest { + /* Collects all query tests together so its easier to implement database tests */ +} diff --git a/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/analysis/TopListQueriesTest.java b/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/analysis/TopListQueriesTest.java new file mode 100644 index 000000000..ee49818db --- /dev/null +++ b/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/analysis/TopListQueriesTest.java @@ -0,0 +1,63 @@ +/* + * This file is part of Player Analytics (Plan). + * + * Plan is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License v3 as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Plan is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Plan. If not, see . + */ +package com.djrapitops.plan.storage.database.queries.analysis; + +import com.djrapitops.plan.gathering.domain.FinishedSession; +import com.djrapitops.plan.storage.database.DatabaseTestPreparer; +import com.djrapitops.plan.storage.database.queries.DataStoreQueries; +import com.djrapitops.plan.storage.database.transactions.events.PlayerServerRegisterTransaction; +import com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction; +import org.junit.jupiter.api.Test; +import utilities.RandomData; +import utilities.TestConstants; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public interface TopListQueriesTest extends DatabaseTestPreparer { + + private void storeSessionForTopListQueries() { + db().executeTransaction(new WorldNameStoreTransaction(serverUUID(), worlds[0])); + db().executeTransaction(new WorldNameStoreTransaction(serverUUID(), worlds[1])); + db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, RandomData::randomTime, + TestConstants.PLAYER_ONE_NAME, serverUUID(), TestConstants.GET_PLAYER_HOSTNAME)); + db().executeTransaction(new PlayerServerRegisterTransaction(player2UUID, RandomData::randomTime, + TestConstants.PLAYER_TWO_NAME, serverUUID(), TestConstants.GET_PLAYER_HOSTNAME)); + FinishedSession session = RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID); + execute(DataStoreQueries.storeSession(session)); + } + + @Test + default void topActivePlaytimeListQueryReturnsSinglePlayer() { + storeSessionForTopListQueries(); + + String expected = TestConstants.PLAYER_ONE_NAME; + String result = db().query(TopListQueries.fetchNthTop10ActivePlaytimePlayerOn(serverUUID(), 1, 0, System.currentTimeMillis())) + .orElseThrow(AssertionError::new); + assertEquals(expected, result); + } + + @Test + default void topPlaytimeListQueryReturnsSinglePlayer() { + storeSessionForTopListQueries(); + + String expected = TestConstants.PLAYER_ONE_NAME; + String result = db().query(TopListQueries.fetchNthTop10ActivePlaytimePlayerOn(serverUUID(), 1, 0, System.currentTimeMillis())) + .orElseThrow(AssertionError::new); + assertEquals(expected, result); + } + +} \ No newline at end of file