mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-29 11:31:41 +01:00
Reproduced, tested and fixed DbOpException
Error was caused by table name alias in the query Affects issues: - Fixed #1731
This commit is contained in:
parent
2ab49aa60f
commit
25e98ef7b5
@ -745,7 +745,7 @@ public class SessionQueries {
|
||||
public static Query<Map<String, Long>> playtimePerServer(long after, long before) {
|
||||
String sql = SELECT +
|
||||
"SUM(" + SessionsTable.SESSION_END + '-' + SessionsTable.SESSION_START + ") as playtime," +
|
||||
ServerTable.TABLE_NAME + '.' + ServerTable.SERVER_ID + ',' +
|
||||
"s." + ServerTable.SERVER_ID + ',' +
|
||||
ServerTable.NAME +
|
||||
FROM + SessionsTable.TABLE_NAME +
|
||||
INNER_JOIN + ServerTable.TABLE_NAME + " s on s." + ServerTable.SERVER_UUID + '=' + SessionsTable.TABLE_NAME + '.' + SessionsTable.SERVER_UUID +
|
||||
|
@ -36,6 +36,7 @@ import org.mockito.Mockito;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import utilities.DBPreparer;
|
||||
import utilities.RandomData;
|
||||
import utilities.TestConstants;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.Optional;
|
||||
@ -106,7 +107,7 @@ class MySQLTest implements DatabaseTest,
|
||||
db().executeTransaction(new CreateTablesTransaction());
|
||||
db().executeTransaction(new RemoveEverythingTransaction());
|
||||
|
||||
db().executeTransaction(new StoreServerInformationTransaction(new Server(serverUUID(), "ServerName", "")));
|
||||
db().executeTransaction(new StoreServerInformationTransaction(new Server(serverUUID(), TestConstants.SERVER_NAME, "")));
|
||||
assertEquals(serverUUID(), ((SQLDB) db()).getServerUUIDSupplier().get());
|
||||
}
|
||||
@AfterAll
|
||||
|
@ -23,16 +23,19 @@ import com.djrapitops.plan.delivery.domain.mutators.SessionsMutator;
|
||||
import com.djrapitops.plan.gathering.domain.PlayerKill;
|
||||
import com.djrapitops.plan.gathering.domain.Session;
|
||||
import com.djrapitops.plan.gathering.domain.WorldTimes;
|
||||
import com.djrapitops.plan.identification.Server;
|
||||
import com.djrapitops.plan.storage.database.DatabaseTestPreparer;
|
||||
import com.djrapitops.plan.storage.database.queries.containers.PlayerContainerQuery;
|
||||
import com.djrapitops.plan.storage.database.queries.objects.KillQueries;
|
||||
import com.djrapitops.plan.storage.database.queries.objects.SessionQueries;
|
||||
import com.djrapitops.plan.storage.database.queries.objects.WorldTimesQueries;
|
||||
import com.djrapitops.plan.storage.database.queries.objects.playertable.ServerTablePlayersQuery;
|
||||
import com.djrapitops.plan.storage.database.transactions.StoreServerInformationTransaction;
|
||||
import com.djrapitops.plan.storage.database.transactions.Transaction;
|
||||
import com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction;
|
||||
import com.djrapitops.plan.storage.database.transactions.events.PlayerServerRegisterTransaction;
|
||||
import com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction;
|
||||
import com.djrapitops.plan.utilities.java.Maps;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
import org.junit.jupiter.api.RepeatedTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@ -321,4 +324,22 @@ public interface SessionQueriesTest extends DatabaseTestPreparer {
|
||||
". Playtime for reference container: <w1:" + playtime1 + ", w2:" + playtime2 + ", w3:" + playtime3 + ">"
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
default void serverPreferencePieValuesAreCorrect() {
|
||||
prepareForSessionSave();
|
||||
UUID serverTwoUuid = TestConstants.SERVER_TWO_UUID;
|
||||
executeTransactions(new StoreServerInformationTransaction(new Server(serverTwoUuid, TestConstants.SERVER_TWO_NAME, "")));
|
||||
List<Session> server1Sessions = RandomData.randomSessions(serverUUID(), worlds, playerUUID, player2UUID);
|
||||
List<Session> server2Sessions = RandomData.randomSessions(serverTwoUuid, worlds, playerUUID, player2UUID);
|
||||
server1Sessions.forEach(session -> execute(DataStoreQueries.storeSession(session)));
|
||||
server2Sessions.forEach(session -> execute(DataStoreQueries.storeSession(session)));
|
||||
|
||||
Map<String, Long> expected = Maps.builder(String.class, Long.class)
|
||||
.put(TestConstants.SERVER_NAME, new SessionsMutator(server1Sessions).toPlaytime())
|
||||
.put(TestConstants.SERVER_TWO_NAME, new SessionsMutator(server2Sessions).toPlaytime())
|
||||
.build();
|
||||
Map<String, Long> results = db().query(SessionQueries.playtimePerServer(Long.MIN_VALUE, Long.MAX_VALUE));
|
||||
assertEquals(expected, results);
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,8 @@ public class TestConstants {
|
||||
/* Static variable class */
|
||||
}
|
||||
|
||||
public static final String SERVER_NAME = "ServerName";
|
||||
public static final String SERVER_TWO_NAME = "ServerName2";
|
||||
public static final UUID SERVER_UUID = UUID.fromString("e4ec2edd-e0ed-3c58-a87d-8a9021899479");
|
||||
public static final UUID SERVER_TWO_UUID = UUID.fromString("c4ec2edd-e0ed-3c58-a87d-8a9024791899");
|
||||
public static final UUID PLAYER_ONE_UUID = UUID.fromString("45b0dfdb-f71d-4cf3-8c21-27c9d4c651db");
|
||||
|
Loading…
Reference in New Issue
Block a user